From 09af6961d4b736096eb479322f99a284f6115366 Mon Sep 17 00:00:00 2001 From: Nitin Soni Date: Thu, 15 Nov 2018 09:33:43 -0800 Subject: [PATCH] zebra: Add "show evpn vni detail" command Change helps display detailed output for all possible VNIs without specifying VNI. It helps in troubleshooting - a single command can be fired to capture detailed info on all VNIs. Ticket: CM-22831 Signed-off-by: Nitin Soni Reviewed-by: CCR-8013 --- zebra/zebra_vty.c | 19 ++++++++- zebra/zebra_vxlan.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ zebra/zebra_vxlan.h | 3 ++ 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 263cb3d22..53853037f 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1782,7 +1782,7 @@ DEFUN (show_evpn_vni, "show evpn vni [json]", SHOW_STR "EVPN\n" - "VxLAN information\n" + "VxLAN Network Identifier\n" JSON_STR) { struct zebra_vrf *zvrf; @@ -1793,6 +1793,22 @@ DEFUN (show_evpn_vni, return CMD_SUCCESS; } +DEFUN (show_evpn_vni_detail, show_evpn_vni_detail_cmd, + "show evpn vni detail [json]", + SHOW_STR + "EVPN\n" + "VxLAN Network Identifier\n" + "Detailed Information On Each VNI\n" + JSON_STR) +{ + struct zebra_vrf *zvrf; + bool uj = use_json(argc, argv); + + zvrf = vrf_info_lookup(VRF_DEFAULT); + zebra_vxlan_print_vnis_detail(vty, zvrf, uj); + return CMD_SUCCESS; +} + DEFUN (show_evpn_vni_vni, show_evpn_vni_vni_cmd, "show evpn vni " CMD_VNI_RANGE "[json]", @@ -2743,6 +2759,7 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_evpn_global_cmd); install_element(VIEW_NODE, &show_evpn_vni_cmd); + install_element(VIEW_NODE, &show_evpn_vni_detail_cmd); install_element(VIEW_NODE, &show_evpn_vni_vni_cmd); install_element(VIEW_NODE, &show_evpn_rmac_vni_mac_cmd); install_element(VIEW_NODE, &show_evpn_rmac_vni_cmd); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index d372d3e83..ee6091a18 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -1195,6 +1195,35 @@ static void zl3vni_print_hash(struct hash_backet *backet, void *ctx[]) } } +/* Private Structure to pass callback data for hash iterator */ +struct zvni_evpn_show { + struct vty *vty; + json_object *json; + struct zebra_vrf *zvrf; +}; + +/* print a L3 VNI hash entry in detail*/ +static void zl3vni_print_hash_detail(struct hash_backet *backet, void *data) +{ + struct vty *vty = NULL; + zebra_l3vni_t *zl3vni = NULL; + json_object *json = NULL; + bool use_json = false; + struct zvni_evpn_show *zes = data; + + vty = zes->vty; + json = zes->json; + + if (json) + use_json = true; + + zl3vni = (zebra_l3vni_t *)backet->data; + + zebra_vxlan_print_vni(vty, zes->zvrf, zl3vni->vni, use_json); + vty_out(vty, "\n"); +} + + /* * Print a VNI hash entry - called for display of all VNIs. */ @@ -1259,6 +1288,29 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) } } +/* + * Print a VNI hash entry in detail - called for display of all VNIs. + */ +static void zvni_print_hash_detail(struct hash_backet *backet, void *data) +{ + struct vty *vty; + zebra_vni_t *zvni; + json_object *json = NULL; + bool use_json = false; + struct zvni_evpn_show *zes = data; + + vty = zes->vty; + json = zes->json; + + if (json) + use_json = true; + + zvni = (zebra_vni_t *)backet->data; + + zebra_vxlan_print_vni(vty, zes->zvrf, zvni->vni, use_json); + vty_out(vty, "\n"); +} + /* * Inform BGP about local MACIP. */ @@ -5426,6 +5478,49 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, } } +/* + * Display VNI hash table in detail(VTY command handler). + */ +void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf, + bool use_json) +{ + json_object *json = NULL; + struct zebra_ns *zns = NULL; + struct zvni_evpn_show zes; + + if (!is_evpn_enabled()) + return; + + zns = zebra_ns_lookup(NS_DEFAULT); + if (!zns) + return; + + + if (use_json) + json = json_object_new_object(); + + zes.vty = vty; + zes.json = json; + zes.zvrf = zvrf; + + /* Display all L2-VNIs */ + hash_iterate(zvrf->vni_table, (void (*)(struct hash_backet *, + void *))zvni_print_hash_detail, + &zes); + + /* Display all L3-VNIs */ + hash_iterate(zrouter.l3vni_table, + (void (*)(struct hash_backet *, + void *))zl3vni_print_hash_detail, + &zes); + + if (use_json) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } +} + /* * Handle neighbor delete notification from the kernel (on a VLAN device * / L3 interface). This may result in either the neighbor getting deleted diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index 1c394e9ef..0db40188e 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -117,6 +117,9 @@ extern void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, bool use_json); extern void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, bool use_json); +extern void zebra_vxlan_print_vnis_detail(struct vty *vty, + struct zebra_vrf *zvrf, + bool use_json); extern void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t vni, bool use_json); extern void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json); -- 2.39.2