Skip to content

Commit ef0460b

Browse files
Sindhu Parvathi Gopinathanchiragshah6
authored andcommitted
zebra: add dynamic nhg-count field into json output
Currently, nexthop-group JSON doesn’t have the field to show the dynamic nexthop group count. Fix: Added nhg_count field to provide the dynamic nexthop grp count info. supported commands: ``` show nexthop-group rib brief json show nexthop-group rib json ``` Ticket:#3963582 Issue:3963582 Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
1 parent e500624 commit ef0460b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

zebra/zebra_vty.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ struct nhe_show_context {
15011501
int type;
15021502
json_object *json;
15031503
bool brief;
1504+
uint32_t nhg_count;
15041505
};
15051506

15061507
static int nhe_show_walker(struct hash_bucket *bucket, void *arg)
@@ -1520,13 +1521,14 @@ static int nhe_show_walker(struct hash_bucket *bucket, void *arg)
15201521
goto done;
15211522

15221523
show_nexthop_group_out(ctx->vty, nhe, ctx->json, ctx->brief);
1524+
ctx->nhg_count++;
15231525

15241526
done:
15251527
return HASHWALK_CONTINUE;
15261528
}
15271529

15281530
static void show_nexthop_group_cmd_helper(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi,
1529-
int type, json_object *json, bool brief)
1531+
int type, json_object *json, bool brief, uint32_t *nhg_count)
15301532
{
15311533
struct nhe_show_context ctx;
15321534

@@ -1536,8 +1538,10 @@ static void show_nexthop_group_cmd_helper(struct vty *vty, struct zebra_vrf *zvr
15361538
ctx.type = type;
15371539
ctx.json = json;
15381540
ctx.brief = brief;
1541+
ctx.nhg_count = 0;
15391542

15401543
hash_walk(zrouter.nhgs_id, nhe_show_walker, &ctx);
1544+
*nhg_count = ctx.nhg_count;
15411545
}
15421546

15431547
static void if_nexthop_group_dump_vty(struct vty *vty, struct interface *ifp)
@@ -1609,6 +1613,7 @@ DEFPY(show_nexthop_group, show_nexthop_group_cmd,
16091613
bool uj = use_json(argc, argv);
16101614
json_object *json = NULL;
16111615
json_object *json_vrf = NULL;
1616+
uint32_t nhg_count = 0;
16121617

16131618
if (uj)
16141619
json = json_object_new_object();
@@ -1652,10 +1657,13 @@ DEFPY(show_nexthop_group, show_nexthop_group_cmd,
16521657
else
16531658
vty_out(vty, "VRF: %s\n", vrf->name);
16541659

1655-
show_nexthop_group_cmd_helper(vty, zvrf, afi, type, json_vrf, brief);
1656-
if (uj)
1660+
show_nexthop_group_cmd_helper(vty, zvrf, afi, type, json_vrf, brief, &nhg_count);
1661+
if (uj) {
1662+
json_object_int_add(json, "nhgCount",
1663+
nhg_count);
16571664
json_object_object_add(json, vrf->name,
16581665
json_vrf);
1666+
}
16591667
}
16601668

16611669
if (uj)
@@ -1678,9 +1686,11 @@ DEFPY(show_nexthop_group, show_nexthop_group_cmd,
16781686
return CMD_WARNING;
16791687
}
16801688

1681-
show_nexthop_group_cmd_helper(vty, zvrf, afi, type, json, brief);
1689+
show_nexthop_group_cmd_helper(vty, zvrf, afi, type, json, brief,
1690+
&nhg_count);
16821691

16831692
if (uj) {
1693+
json_object_int_add(json, "nhgCount", nhg_count);
16841694
if (brief)
16851695
vty_json_no_pretty(vty, json);
16861696
else

0 commit comments

Comments
 (0)