From 3ab18ff268c297e7279d71f8f82fc8ce7712c23e Mon Sep 17 00:00:00 2001 From: vivek Date: Sat, 16 Apr 2016 11:23:04 -0700 Subject: [PATCH] Quagga: Display MPLS label forwarding table Signed-off-by: Vivek Venkatraman Reviewed-by: Donald Sharp Ticket: CM-4084, ... Reviewed By: CCR-3089 Testing Done: Manual --- zebra/zebra_mpls.c | 112 ++++++++++++++++++++++++++++++++++++++++ zebra/zebra_mpls.h | 26 ++++++++++ zebra/zebra_mpls_null.c | 10 ++++ zebra/zebra_vty.c | 36 +++++++++++++ 4 files changed, 184 insertions(+) diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 892aec965a..688585d6da 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -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). */ diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h index 5fb481781a..7d1f494142 100644 --- a/zebra/zebra_mpls.h +++ b/zebra/zebra_mpls.h @@ -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 */ diff --git a/zebra/zebra_mpls_null.c b/zebra/zebra_mpls_null.c index 15169f0f25..03b1f5694b 100644 --- a/zebra/zebra_mpls_null.c +++ b/zebra/zebra_mpls_null.c @@ -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) { diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 4e0df372bb..e5f7c181f9 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -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); } -- 2.39.5