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 <pdoijode@nvidia.com>
This commit is contained in:
Pooja Jagadeesh Doijode 2023-01-26 10:31:08 -08:00 committed by Mergify
parent 2d5928355c
commit 1a4a394d45
5 changed files with 59 additions and 26 deletions

View File

@ -1,13 +1,17 @@
{ {
"vni":101, "vni":101,
"type":"L2", "type":"L2",
"vrf":"default", "tenantVrf":"default",
"vxlanInterface":"vxlan101", "vxlanInterface":"vxlan101",
"vtepIp":"10.10.10.10", "vtepIp":"10.10.10.10",
"mcastGroup":"0.0.0.0", "mcastGroup":"0.0.0.0",
"advertiseGatewayMacip":"No", "advertiseGatewayMacip":"No",
"numRemoteVteps":[ "numRemoteVteps":1,
"10.30.30.30" "remoteVteps":[
{
"ip":"10.30.30.30",
"flood":"HER"
}
] ]
} }

View File

@ -1,12 +1,16 @@
{ {
"vni":101, "vni":101,
"type":"L2", "type":"L2",
"vrf":"default", "tenantVrf":"default",
"vxlanInterface":"vxlan101", "vxlanInterface":"vxlan101",
"vtepIp":"10.30.30.30", "vtepIp":"10.30.30.30",
"mcastGroup":"0.0.0.0", "mcastGroup":"0.0.0.0",
"advertiseGatewayMacip":"No", "advertiseGatewayMacip":"No",
"numRemoteVteps":[ "numRemoteVteps":1,
"10.10.10.10" "remoteVteps":[
{
"ip":"10.10.10.10",
"flood":"HER"
}
] ]
} }

View File

@ -144,7 +144,6 @@ def teardown_module(mod):
def show_vni_json_elide_ifindex(pe, vni, expected): def show_vni_json_elide_ifindex(pe, vni, expected):
output_json = pe.vtysh_cmd("show evpn vni {} json".format(vni), isjson=True) output_json = pe.vtysh_cmd("show evpn vni {} json".format(vni), isjson=True)
if "ifindex" in output_json: if "ifindex" in output_json:
output_json.pop("ifindex") output_json.pop("ifindex")

View File

@ -101,14 +101,15 @@ int advertise_svi_macip_enabled(struct zebra_evpn *zevpn)
*/ */
void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt) void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
{ {
struct vty *vty;
struct zebra_vtep *zvtep; struct vty *vty = NULL;
uint32_t num_macs; struct zebra_vtep *zvtep = NULL;
uint32_t num_neigh; uint32_t num_macs = 0;
uint32_t num_neigh = 0;
uint32_t num_vteps = 0;
json_object *json = NULL; json_object *json = NULL;
json_object *json_vtep_list = NULL; json_object *json_vtep_list = NULL;
json_object *json_ip_str = NULL; json_object *json_vtep = NULL;
char buf[PREFIX_STRLEN];
vty = ctxt[0]; vty = ctxt[0];
json = ctxt[1]; json = ctxt[1];
@ -120,13 +121,21 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
} else { } else {
json_object_int_add(json, "vni", zevpn->vni); json_object_int_add(json, "vni", zevpn->vni);
json_object_string_add(json, "type", "L2"); json_object_string_add(json, "type", "L2");
#if CONFDATE > 20240210
CPP_NOTICE("Drop `vrf` from JSON output")
#endif
json_object_string_add(json, "vrf", json_object_string_add(json, "vrf",
vrf_id_to_name(zevpn->vrf_id)); 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 (!zevpn->vxlan_if) { // unexpected
if (json == NULL) if (json == NULL)
vty_out(vty, " VxLAN interface: unknown\n"); vty_out(vty, " VxLAN interface: unknown\n");
else
json_object_string_add(json, "vxlanInterface",
"unknown");
return; return;
} }
num_macs = num_valid_macs(zevpn); num_macs = num_valid_macs(zevpn);
@ -145,7 +154,12 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
} else { } else {
json_object_string_add(json, "vxlanInterface", json_object_string_add(json, "vxlanInterface",
zevpn->vxlan_if->name); 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, "ifindex", zevpn->vxlan_if->ifindex);
json_object_int_add(json, "vxlanIfindex",
zevpn->vxlan_if->ifindex);
if (zevpn->svi_if) { if (zevpn->svi_if) {
json_object_string_add(json, "sviInterface", json_object_string_add(json, "sviInterface",
zevpn->svi_if->name); 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", json_object_string_addf(json, "mcastGroup", "%pI4",
&zevpn->mcast_grp); &zevpn->mcast_grp);
json_object_string_add(json, "advertiseGatewayMacip", json_object_string_add(json, "advertiseGatewayMacip",
zevpn->advertise_gw_macip ? "Yes" : "No"); zevpn->advertise_gw_macip ? "Yes"
: "No");
json_object_string_add(json, "advertiseSviMacip", json_object_string_add(json, "advertiseSviMacip",
zevpn->advertise_svi_macip ? "Yes" zevpn->advertise_svi_macip ? "Yes"
: "No"); : "No");
@ -167,14 +182,16 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
if (!zevpn->vteps) { if (!zevpn->vteps) {
if (json == NULL) if (json == NULL)
vty_out(vty, " No remote VTEPs known for this VNI\n"); vty_out(vty, " No remote VTEPs known for this VNI\n");
else
json_object_int_add(json, "numRemoteVteps", num_vteps);
} else { } else {
if (json == NULL) if (json == NULL)
vty_out(vty, " Remote VTEPs for this VNI:\n"); vty_out(vty, " Remote VTEPs for this VNI:\n");
else else
json_vtep_list = json_object_new_array(); json_vtep_list = json_object_new_array();
for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) {
const char *flood_str = lookup_msg(zvtep_flood_str, const char *flood_str = lookup_msg(
zvtep->flood_control, zvtep_flood_str, zvtep->flood_control,
VXLAN_FLOOD_STR_DEFAULT); VXLAN_FLOOD_STR_DEFAULT);
if (json == NULL) { if (json == NULL) {
@ -182,18 +199,22 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
&zvtep->vtep_ip, &zvtep->vtep_ip,
flood_str); flood_str);
} else { } else {
json_ip_str = json_object_new_string( json_vtep = json_object_new_object();
inet_ntop(AF_INET, json_object_string_addf(json_vtep, "ip", "%pI4",
&zvtep->vtep_ip, buf, &zvtep->vtep_ip);
sizeof(buf))); json_object_string_add(json_vtep, "flood",
flood_str);
json_object_array_add(json_vtep_list, json_object_array_add(json_vtep_list,
json_ip_str); json_vtep);
} }
num_vteps++;
} }
if (json) if (json) {
json_object_object_add(json, "numRemoteVteps", json_object_int_add(json, "numRemoteVteps", num_vteps);
json_object_object_add(json, "remoteVteps",
json_vtep_list); json_vtep_list);
} }
}
if (json == NULL) { if (json == NULL) {
vty_out(vty, vty_out(vty,
" Number of MACs (local and remote) known for this VNI: %u\n", " Number of MACs (local and remote) known for this VNI: %u\n",

View File

@ -750,6 +750,12 @@ static void zl3vni_print(struct zebra_l3vni *zl3vni, void **ctx)
json_evpn_list = json_object_new_array(); json_evpn_list = json_object_new_array();
json_object_int_add(json, "vni", zl3vni->vni); json_object_int_add(json, "vni", zl3vni->vni);
json_object_string_add(json, "type", "L3"); 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", json_object_string_addf(json, "localVtepIp", "%pI4",
&zl3vni->local_vtep_ip); &zl3vni->local_vtep_ip);
json_object_string_add(json, "vxlanIntf", 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", json_object_string_add(json, "sviIntf",
zl3vni_svi_if_name(zl3vni)); zl3vni_svi_if_name(zl3vni));
json_object_string_add(json, "state", zl3vni_state2str(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_object_string_add(
json, "sysMac", json, "sysMac",
zl3vni_sysmac2str(zl3vni, buf, sizeof(buf))); zl3vni_sysmac2str(zl3vni, buf, sizeof(buf)));