From 1a4a394d45653b37ddbc8e2321dd09329790ce7c Mon Sep 17 00:00:00 2001 From: Pooja Jagadeesh Doijode Date: Thu, 26 Jan 2023 10:31:08 -0800 Subject: [PATCH] zebra: fix JSON fields for show evpn vni detail Few of the JSON field in show evpn vni detail command is confusing and a few fields were missing. Following is the updated output. primary# show evpn vni detail json [ { "vni":200, "type":"L2", "vrf":"default", "tenantVrf":"default", "vxlanInterface":"vni200", "ifindex":19, "vxlanIfindex":19, "sviInterface":"br200", "sviIfindex":18, "vtepIp":"2.2.2.1", "mcastGroup":"0.0.0.0", "advertiseGatewayMacip":"No", "advertiseSviMacip":"No", "numMacs":0, "numArpNd":0, "numRemoteVteps":1, "remoteVteps":[ { "ip":"2.2.2.2", "flood":"HER" } ] }, { "vni":100, "type":"L3", "vrf":"default", "tenantVrf":"default", "localVtepIp":"2.2.2.1", "vxlanIntf":"vni100", "sviIntf":"br100", "state":"Up", "sysMac":"aa:bb:cc:dd:ee:f1", "routerMac":"aa:bb:cc:dd:ee:f1", "vniFilter":"none", "l2Vnis":[ 20, 30, 200 ] } ] Signed-off-by: Pooja Jagadeesh Doijode --- .../bgp_evpn_vxlan_topo1/PE1/evpn.vni.json | 10 +++- .../bgp_evpn_vxlan_topo1/PE2/evpn.vni.json | 12 ++-- .../test_bgp_evpn_vxlan.py | 1 - zebra/zebra_evpn.c | 55 +++++++++++++------ zebra/zebra_vxlan.c | 7 ++- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json index ce7915c4af..eb8668b7be 100644 --- a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json +++ b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/evpn.vni.json @@ -1,13 +1,17 @@ { "vni":101, "type":"L2", - "vrf":"default", + "tenantVrf":"default", "vxlanInterface":"vxlan101", "vtepIp":"10.10.10.10", "mcastGroup":"0.0.0.0", "advertiseGatewayMacip":"No", - "numRemoteVteps":[ - "10.30.30.30" + "numRemoteVteps":1, + "remoteVteps":[ + { + "ip":"10.30.30.30", + "flood":"HER" + } ] } diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json index 6c69202642..befb416074 100644 --- a/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json +++ b/tests/topotests/bgp_evpn_vxlan_topo1/PE2/evpn.vni.json @@ -1,12 +1,16 @@ { "vni":101, "type":"L2", - "vrf":"default", + "tenantVrf":"default", "vxlanInterface":"vxlan101", "vtepIp":"10.30.30.30", "mcastGroup":"0.0.0.0", "advertiseGatewayMacip":"No", - "numRemoteVteps":[ - "10.10.10.10" - ] + "numRemoteVteps":1, + "remoteVteps":[ + { + "ip":"10.10.10.10", + "flood":"HER" + } + ] } diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py index 5d0a326afb..83ee53c4cc 100755 --- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py @@ -144,7 +144,6 @@ def teardown_module(mod): def show_vni_json_elide_ifindex(pe, vni, expected): output_json = pe.vtysh_cmd("show evpn vni {} json".format(vni), isjson=True) - if "ifindex" in output_json: output_json.pop("ifindex") diff --git a/zebra/zebra_evpn.c b/zebra/zebra_evpn.c index f207477445..ff9ca1ac25 100644 --- a/zebra/zebra_evpn.c +++ b/zebra/zebra_evpn.c @@ -101,14 +101,15 @@ int advertise_svi_macip_enabled(struct zebra_evpn *zevpn) */ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) { - struct vty *vty; - struct zebra_vtep *zvtep; - uint32_t num_macs; - uint32_t num_neigh; + + struct vty *vty = NULL; + struct zebra_vtep *zvtep = NULL; + uint32_t num_macs = 0; + uint32_t num_neigh = 0; + uint32_t num_vteps = 0; json_object *json = NULL; json_object *json_vtep_list = NULL; - json_object *json_ip_str = NULL; - char buf[PREFIX_STRLEN]; + json_object *json_vtep = NULL; vty = ctxt[0]; json = ctxt[1]; @@ -120,13 +121,21 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) } else { json_object_int_add(json, "vni", zevpn->vni); json_object_string_add(json, "type", "L2"); +#if CONFDATE > 20240210 +CPP_NOTICE("Drop `vrf` from JSON output") +#endif json_object_string_add(json, "vrf", vrf_id_to_name(zevpn->vrf_id)); + json_object_string_add(json, "tenantVrf", + vrf_id_to_name(zevpn->vrf_id)); } if (!zevpn->vxlan_if) { // unexpected if (json == NULL) vty_out(vty, " VxLAN interface: unknown\n"); + else + json_object_string_add(json, "vxlanInterface", + "unknown"); return; } num_macs = num_valid_macs(zevpn); @@ -145,7 +154,12 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) } else { json_object_string_add(json, "vxlanInterface", zevpn->vxlan_if->name); +#if CONFDATE > 20240210 +CPP_NOTICE("Drop `ifindex` from JSON output") +#endif json_object_int_add(json, "ifindex", zevpn->vxlan_if->ifindex); + json_object_int_add(json, "vxlanIfindex", + zevpn->vxlan_if->ifindex); if (zevpn->svi_if) { json_object_string_add(json, "sviInterface", zevpn->svi_if->name); @@ -157,7 +171,8 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) json_object_string_addf(json, "mcastGroup", "%pI4", &zevpn->mcast_grp); json_object_string_add(json, "advertiseGatewayMacip", - zevpn->advertise_gw_macip ? "Yes" : "No"); + zevpn->advertise_gw_macip ? "Yes" + : "No"); json_object_string_add(json, "advertiseSviMacip", zevpn->advertise_svi_macip ? "Yes" : "No"); @@ -167,32 +182,38 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) if (!zevpn->vteps) { if (json == NULL) vty_out(vty, " No remote VTEPs known for this VNI\n"); + else + json_object_int_add(json, "numRemoteVteps", num_vteps); } else { if (json == NULL) vty_out(vty, " Remote VTEPs for this VNI:\n"); else json_vtep_list = json_object_new_array(); for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { - const char *flood_str = lookup_msg(zvtep_flood_str, - zvtep->flood_control, - VXLAN_FLOOD_STR_DEFAULT); + const char *flood_str = lookup_msg( + zvtep_flood_str, zvtep->flood_control, + VXLAN_FLOOD_STR_DEFAULT); if (json == NULL) { vty_out(vty, " %pI4 flood: %s\n", &zvtep->vtep_ip, flood_str); } else { - json_ip_str = json_object_new_string( - inet_ntop(AF_INET, - &zvtep->vtep_ip, buf, - sizeof(buf))); + json_vtep = json_object_new_object(); + json_object_string_addf(json_vtep, "ip", "%pI4", + &zvtep->vtep_ip); + json_object_string_add(json_vtep, "flood", + flood_str); json_object_array_add(json_vtep_list, - json_ip_str); + json_vtep); } + num_vteps++; } - if (json) - json_object_object_add(json, "numRemoteVteps", + if (json) { + json_object_int_add(json, "numRemoteVteps", num_vteps); + json_object_object_add(json, "remoteVteps", json_vtep_list); + } } if (json == NULL) { vty_out(vty, diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 7e86d15b4b..177659f5ce 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -750,6 +750,12 @@ static void zl3vni_print(struct zebra_l3vni *zl3vni, void **ctx) json_evpn_list = json_object_new_array(); json_object_int_add(json, "vni", zl3vni->vni); json_object_string_add(json, "type", "L3"); +#if CONFDATE > 20240210 +CPP_NOTICE("Drop `vrf` from JSON outputs") +#endif + json_object_string_add(json, "vrf", zl3vni_vrf_name(zl3vni)); + json_object_string_add(json, "tenantVrf", + zl3vni_vrf_name(zl3vni)); json_object_string_addf(json, "localVtepIp", "%pI4", &zl3vni->local_vtep_ip); json_object_string_add(json, "vxlanIntf", @@ -757,7 +763,6 @@ static void zl3vni_print(struct zebra_l3vni *zl3vni, void **ctx) json_object_string_add(json, "sviIntf", zl3vni_svi_if_name(zl3vni)); json_object_string_add(json, "state", zl3vni_state2str(zl3vni)); - json_object_string_add(json, "vrf", zl3vni_vrf_name(zl3vni)); json_object_string_add( json, "sysMac", zl3vni_sysmac2str(zl3vni, buf, sizeof(buf))); -- 2.39.5