Skip to content

Commit

Permalink
Merge pull request #17431 from krishna-samy/bgpd_json_commits
Browse files Browse the repository at this point in the history
bgpd: show json output changes to optimize various show commands
  • Loading branch information
riw777 authored Jan 7, 2025
2 parents a92231a + 4d8207c commit c9c9608
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 122 deletions.
69 changes: 42 additions & 27 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
afi_t afi;
safi_t safi;
uint32_t prefix_cnt, path_cnt;
int first = true;

afi = AFI_L2VPN;
safi = SAFI_EVPN;
Expand All @@ -3132,8 +3133,15 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
prefix_rd2str((struct prefix_rd *)rd_destp, rd_str,
sizeof(rd_str), bgp->asnotation);

if (json)
if (json) {
if (first) {
vty_out(vty, "\"%s\":", rd_str);
first = false;
} else {
vty_out(vty, ",\"%s\":", rd_str);
}
json_rd = json_object_new_object();
}

rd_header = 1;

Expand Down Expand Up @@ -3247,18 +3255,18 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
}

if (json) {
if (add_rd_to_json)
json_object_object_add(json, rd_str, json_rd);
else {
if (add_rd_to_json) {
vty_json_no_pretty(vty, json_rd);
} else {
vty_out(vty, "{}");
json_object_free(json_rd);
json_rd = NULL;
}
}
}

if (json) {
json_object_int_add(json, "numPrefix", prefix_cnt);
json_object_int_add(json, "numPaths", path_cnt);
vty_out(vty, ",\"numPrefix\":%u", prefix_cnt);
vty_out(vty, ",\"numPaths\":%u", path_cnt);
} else {
if (prefix_cnt == 0) {
vty_out(vty, "No EVPN prefixes %sexist\n",
Expand All @@ -3276,20 +3284,18 @@ int bgp_evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
{
json_object *json = NULL;

if (use_json)
if (use_json) {
json = json_object_new_object();
vty_out(vty, "{\n");
}

evpn_show_all_routes(vty, bgp, type, json, detail, false);

if (use_json)
/*
* We are using no_pretty here because under extremely high
* settings (lots of routes with many different paths) this can
* save several minutes of output when FRR is run on older cpu's
* or more underperforming routers out there. So for route
* scale, we need to use no_pretty json.
*/
vty_json_no_pretty(vty, json);
if (use_json) {
vty_out(vty, "}\n");
json_object_free(json);
}

return CMD_SUCCESS;
}

Expand Down Expand Up @@ -4940,8 +4946,10 @@ DEFUN(show_bgp_l2vpn_evpn_route,
if (!bgp)
return CMD_WARNING;

if (uj)
if (uj) {
json = json_object_new_object();
vty_out(vty, "{\n");
}

if (bgp_evpn_cli_parse_type(&type, argv, argc) < 0)
return CMD_WARNING;
Expand All @@ -4954,13 +4962,10 @@ DEFUN(show_bgp_l2vpn_evpn_route,

evpn_show_all_routes(vty, bgp, type, json, detail, self_orig);

/*
* This is an extremely expensive operation at scale
* and as such we need to save as much time as is
* possible.
*/
if (uj)
vty_json_no_pretty(vty, json);
if (uj) {
vty_out(vty, "}\n");
json_object_free(json);
}

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -5017,10 +5022,20 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,
if (bgp_evpn_cli_parse_type(&type, argv, argc) < 0)
return CMD_WARNING;

if (rd_all)
if (rd_all) {
if (uj)
vty_out(vty, "{\n");

evpn_show_all_routes(vty, bgp, type, json, 1, false);
else

if (uj) {
vty_out(vty, "}\n");
json_object_free(json);
return CMD_SUCCESS;
}
} else {
evpn_show_route_rd(vty, bgp, &prd, type, json);
}

if (uj)
vty_json(vty, json);
Expand Down
Loading

0 comments on commit c9c9608

Please sign in to comment.