]> git.puffer.fish Git - matthieu/frr.git/commitdiff
Quagga: Display MPLS label forwarding table
authorvivek <vivek@cumulusnetworks.com>
Sat, 16 Apr 2016 18:23:04 +0000 (11:23 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 23 Sep 2016 13:30:57 +0000 (09:30 -0400)
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Ticket: CM-4084, ...
Reviewed By: CCR-3089
Testing Done: Manual

zebra/zebra_mpls.c
zebra/zebra_mpls.h
zebra/zebra_mpls_null.c
zebra/zebra_vty.c

index 892aec965ad410273568c628b36528814099603c..688585d6daf8d68308a4bc8a861a5ea5e9b4c9ec 100644 (file)
@@ -108,6 +108,12 @@ static_lsp_uninstall (struct zebra_vrf *zvrf, mpls_label_t in_label,
 static int
 static_lsp_uninstall_all (struct zebra_vrf *zvrf, mpls_label_t in_label);
 static void
+nhlfe_print (zebra_nhlfe_t *nhlfe, struct vty *vty);
+static void
+lsp_print (zebra_lsp_t *lsp, void *ctxt);
+static void
+lsp_print_hash (struct hash_backet *backet, void *ctxt);
+static void
 lsp_config_write (struct hash_backet *backet, void *ctxt);
 static void *
 slsp_alloc (void *p);
@@ -962,6 +968,78 @@ static_lsp_uninstall_all (struct zebra_vrf *zvrf, mpls_label_t in_label)
   return 0;
 }
 
+/*
+ * Print the NHLFE for a LSP forwarding entry.
+ */
+static void
+nhlfe_print (zebra_nhlfe_t *nhlfe, struct vty *vty)
+{
+  struct nexthop *nexthop;
+  char buf[BUFSIZ];
+
+  nexthop = nhlfe->nexthop;
+  if (!nexthop || !nexthop->nh_label) // unexpected
+    return;
+
+  vty_out(vty, " type: %s remote label: %s distance: %d%s",
+          nhlfe_type2str(nhlfe->type),
+          label2str(nexthop->nh_label->label[0], buf, BUFSIZ),
+          nhlfe->distance, VTY_NEWLINE);
+  switch (nexthop->type)
+    {
+    case NEXTHOP_TYPE_IPV4:
+      vty_out (vty, "  via %s", inet_ntoa (nexthop->gate.ipv4));
+      break;
+    case NEXTHOP_TYPE_IPV6:
+    case NEXTHOP_TYPE_IPV6_IFINDEX:
+      vty_out (vty, "  via %s",
+              inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
+      if (nexthop->ifindex)
+        vty_out (vty, " dev %s", ifindex2ifname (nexthop->ifindex));
+      break;
+    default:
+      break;
+    }
+  vty_out(vty, "%s", CHECK_FLAG (nhlfe->flags, NHLFE_FLAG_INSTALLED) ?
+          " (installed)" : "");
+  vty_out(vty, "%s", VTY_NEWLINE);
+}
+
+/*
+ * Print an LSP forwarding entry.
+ */
+static void
+lsp_print (zebra_lsp_t *lsp, void *ctxt)
+{
+  zebra_nhlfe_t *nhlfe;
+  struct vty *vty;
+
+  vty = (struct vty *) ctxt;
+
+  vty_out(vty, "Local label: %u%s%s",
+          lsp->ile.in_label,
+          CHECK_FLAG (lsp->flags, LSP_FLAG_INSTALLED) ? " (installed)" : "",
+          VTY_NEWLINE);
+
+  for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next)
+    nhlfe_print (nhlfe, vty);
+}
+
+/*
+ * Print an LSP forwarding hash entry.
+ */
+static void
+lsp_print_hash (struct hash_backet *backet, void *ctxt)
+{
+  zebra_lsp_t *lsp;
+
+  lsp = (zebra_lsp_t *) backet->data;
+  if (!lsp)
+    return;
+
+  lsp_print (lsp, ctxt);
+}
+
 /*
  * Write out static LSP configuration.
  */
@@ -1408,6 +1486,40 @@ zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf)
   hash_iterate(zvrf->lsp_table, lsp_schedule, NULL);
 }
 
+/*
+ * Display MPLS label forwarding table for a specific LSP
+ * (VTY command handler).
+ */
+void
+zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label)
+{
+  struct hash *lsp_table;
+  zebra_lsp_t *lsp;
+  zebra_ile_t tmp_ile;
+
+  /* Lookup table. */
+  lsp_table = zvrf->lsp_table;
+  if (!lsp_table)
+    return;
+
+  /* If entry is not present, exit. */
+  tmp_ile.in_label = label;
+  lsp = hash_lookup (lsp_table, &tmp_ile);
+  if (!lsp)
+    return;
+
+  lsp_print (lsp, (void *)vty);
+}
+
+/*
+ * Display MPLS label forwarding table (VTY command handler).
+ */
+void
+zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf)
+{
+  hash_iterate(zvrf->lsp_table, lsp_print_hash, vty);
+}
+
 /*
  * Display MPLS LSP configuration of all static LSPs (VTY command handler).
  */
index 5fb481781a991e8288f29ee21342b04225cb4491..7d1f4941426cb0389f2cb3fb8194fd0048532190 100644 (file)
@@ -197,6 +197,19 @@ zebra_mpls_static_lsp_del (struct zebra_vrf *zvrf, mpls_label_t in_label,
 void
 zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf);
 
+/*
+ * Display MPLS label forwarding table for a specific LSP
+ * (VTY command handler).
+ */
+void
+zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label);
+
+/*
+ * Display MPLS label forwarding table (VTY command handler).
+ */
+void
+zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf);
+
 /*
  * Display MPLS LSP configuration of all static LSPs (VTY command handler).
  */
@@ -254,4 +267,17 @@ lsp_type_from_rib_type (int rib_type)
     }
 }
 
+/* NHLFE type as printable string. */
+static inline const char *
+nhlfe_type2str(enum lsp_types_t lsp_type)
+{
+  switch (lsp_type)
+    {
+      case ZEBRA_LSP_STATIC:
+        return "Static";
+      default:
+        return "Unknown";
+    }
+}
+
 #endif /*_ZEBRA_MPLS_H */
index 15169f0f2569d49e6af72079727b5b2a4312d166..03b1f5694bd1406cf7a9981b2eab09d6270db60f 100644 (file)
@@ -33,6 +33,16 @@ zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf)
 {
 }
 
+void
+zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label)
+{
+}
+
+void
+zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf)
+{
+}
+
 int
 zebra_mpls_write_lsp_config (struct vty *vty, struct zebra_vrf *zvrf)
 {
index 4e0df372bbbb1fa42b07123106cbc89d89efd32d..e5f7c181f9137dac77a38cd28f835fe633a48fae 100644 (file)
@@ -5909,6 +5909,37 @@ zebra_mpls_config (struct vty *vty)
   return write;
 }
 
+DEFUN (show_mpls_table,
+       show_mpls_table_cmd,
+       "show mpls table",
+       SHOW_STR
+       MPLS_STR
+       "MPLS table\n")
+{
+  struct zebra_vrf *zvrf;
+
+  zvrf = vrf_info_lookup(VRF_DEFAULT);
+  zebra_mpls_print_lsp_table(vty, zvrf);
+  return CMD_SUCCESS;
+}
+
+DEFUN (show_mpls_table_lsp,
+       show_mpls_table_lsp_cmd,
+       "show mpls table <16-1048575>",
+       SHOW_STR
+       MPLS_STR
+       "MPLS table\n"
+       "LSP to display information about\n")
+{
+  u_int32_t label;
+  struct zebra_vrf *zvrf;
+
+  zvrf = vrf_info_lookup(VRF_DEFAULT);
+  label = atoi(argv[0]);
+  zebra_mpls_print_lsp (vty, zvrf, label);
+  return CMD_SUCCESS;
+}
+
 DEFUN (ip_zebra_import_table_distance,
        ip_zebra_import_table_distance_cmd,
        "ip import-table <1-252> distance <1-255>",
@@ -6418,4 +6449,9 @@ zebra_vty_init (void)
   install_element (CONFIG_NODE, &no_mpls_transit_lsp_cmd);
   install_element (CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd);
   install_element (CONFIG_NODE, &no_mpls_transit_lsp_all_cmd);
+
+  install_element (VIEW_NODE, &show_mpls_table_cmd);
+  install_element (ENABLE_NODE, &show_mpls_table_cmd);
+  install_element (VIEW_NODE, &show_mpls_table_lsp_cmd);
+  install_element (ENABLE_NODE, &show_mpls_table_lsp_cmd);
 }