forked from Mirror/frr
Merge pull request #15645 from opensourcerouting/fix/show_ip_route_vrf_all_summary_json
zebra: Fix JSON output for `show route summary json`
This commit is contained in:
commit
8cfa3b57e9
|
@ -68,10 +68,11 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
|
||||||
bool show_ng, struct route_show_ctx *ctx);
|
bool show_ng, struct route_show_ctx *ctx);
|
||||||
static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
|
static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
|
||||||
int mcast, bool use_fib, bool show_ng);
|
int mcast, bool use_fib, bool show_ng);
|
||||||
static void vty_show_ip_route_summary(struct vty *vty,
|
static void vty_show_ip_route_summary(struct vty *vty, struct route_table *table,
|
||||||
struct route_table *table, bool use_json);
|
json_object *vrf_json, bool use_json);
|
||||||
static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
||||||
struct route_table *table,
|
struct route_table *table,
|
||||||
|
json_object *vrf_json,
|
||||||
bool use_json);
|
bool use_json);
|
||||||
/* Helper api to format a nexthop in the 'detailed' output path. */
|
/* Helper api to format a nexthop in the 'detailed' output path. */
|
||||||
static void show_nexthop_detail_helper(struct vty *vty,
|
static void show_nexthop_detail_helper(struct vty *vty,
|
||||||
|
@ -1997,11 +1998,15 @@ DEFPY (show_route_summary,
|
||||||
afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
|
afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
|
||||||
struct route_table *table;
|
struct route_table *table;
|
||||||
bool uj = use_json(argc, argv);
|
bool uj = use_json(argc, argv);
|
||||||
|
json_object *vrf_json = NULL;
|
||||||
|
|
||||||
if (vrf_all) {
|
if (vrf_all) {
|
||||||
struct vrf *vrf;
|
struct vrf *vrf;
|
||||||
struct zebra_vrf *zvrf;
|
struct zebra_vrf *zvrf;
|
||||||
|
|
||||||
|
if (uj && !vrf_json)
|
||||||
|
vrf_json = json_object_new_object();
|
||||||
|
|
||||||
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
||||||
if ((zvrf = vrf->info) == NULL)
|
if ((zvrf = vrf->info) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -2019,10 +2024,14 @@ DEFPY (show_route_summary,
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
vty_show_ip_route_summary_prefix(vty, table,
|
vty_show_ip_route_summary_prefix(vty, table,
|
||||||
uj);
|
vrf_json, uj);
|
||||||
else
|
else
|
||||||
vty_show_ip_route_summary(vty, table, uj);
|
vty_show_ip_route_summary(vty, table, vrf_json,
|
||||||
|
uj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uj)
|
||||||
|
vty_json(vty, vrf_json);
|
||||||
} else {
|
} else {
|
||||||
vrf_id_t vrf_id = VRF_DEFAULT;
|
vrf_id_t vrf_id = VRF_DEFAULT;
|
||||||
|
|
||||||
|
@ -2038,9 +2047,9 @@ DEFPY (show_route_summary,
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
vty_show_ip_route_summary_prefix(vty, table, uj);
|
vty_show_ip_route_summary_prefix(vty, table, NULL, uj);
|
||||||
else
|
else
|
||||||
vty_show_ip_route_summary(vty, table, uj);
|
vty_show_ip_route_summary(vty, table, NULL, uj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
|
@ -2246,8 +2255,8 @@ static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vty_show_ip_route_summary(struct vty *vty,
|
static void vty_show_ip_route_summary(struct vty *vty, struct route_table *table,
|
||||||
struct route_table *table, bool use_json)
|
json_object *vrf_json, bool use_json)
|
||||||
{
|
{
|
||||||
struct route_node *rn;
|
struct route_node *rn;
|
||||||
struct route_entry *re;
|
struct route_entry *re;
|
||||||
|
@ -2261,6 +2270,8 @@ static void vty_show_ip_route_summary(struct vty *vty,
|
||||||
uint32_t is_ibgp;
|
uint32_t is_ibgp;
|
||||||
json_object *json_route_summary = NULL;
|
json_object *json_route_summary = NULL;
|
||||||
json_object *json_route_routes = NULL;
|
json_object *json_route_routes = NULL;
|
||||||
|
const char *vrf_name = zvrf_name(
|
||||||
|
((struct rib_table_info *)route_table_get_info(table))->zvrf);
|
||||||
|
|
||||||
memset(&rib_cnt, 0, sizeof(rib_cnt));
|
memset(&rib_cnt, 0, sizeof(rib_cnt));
|
||||||
memset(&fib_cnt, 0, sizeof(fib_cnt));
|
memset(&fib_cnt, 0, sizeof(fib_cnt));
|
||||||
|
@ -2311,10 +2322,7 @@ static void vty_show_ip_route_summary(struct vty *vty,
|
||||||
|
|
||||||
if (!use_json)
|
if (!use_json)
|
||||||
vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
|
vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
|
||||||
"Routes", "FIB",
|
"Routes", "FIB", vrf_name);
|
||||||
zvrf_name(((struct rib_table_info *)
|
|
||||||
route_table_get_info(table))
|
|
||||||
->zvrf));
|
|
||||||
|
|
||||||
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
||||||
if ((rib_cnt[i] > 0) || (i == ZEBRA_ROUTE_BGP
|
if ((rib_cnt[i] > 0) || (i == ZEBRA_ROUTE_BGP
|
||||||
|
@ -2406,7 +2414,11 @@ static void vty_show_ip_route_summary(struct vty *vty,
|
||||||
json_object_int_add(json_route_summary, "routesTotalFib",
|
json_object_int_add(json_route_summary, "routesTotalFib",
|
||||||
fib_cnt[ZEBRA_ROUTE_TOTAL]);
|
fib_cnt[ZEBRA_ROUTE_TOTAL]);
|
||||||
|
|
||||||
vty_json(vty, json_route_summary);
|
if (!vrf_json)
|
||||||
|
vty_json(vty, json_route_summary);
|
||||||
|
else
|
||||||
|
json_object_object_add(vrf_json, vrf_name,
|
||||||
|
json_route_summary);
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, "------\n");
|
vty_out(vty, "------\n");
|
||||||
vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
|
vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
|
||||||
|
@ -2424,6 +2436,7 @@ static void vty_show_ip_route_summary(struct vty *vty,
|
||||||
*/
|
*/
|
||||||
static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
||||||
struct route_table *table,
|
struct route_table *table,
|
||||||
|
json_object *vrf_json,
|
||||||
bool use_json)
|
bool use_json)
|
||||||
{
|
{
|
||||||
struct route_node *rn;
|
struct route_node *rn;
|
||||||
|
@ -2437,6 +2450,8 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
||||||
int cnt;
|
int cnt;
|
||||||
json_object *json_route_summary = NULL;
|
json_object *json_route_summary = NULL;
|
||||||
json_object *json_route_routes = NULL;
|
json_object *json_route_routes = NULL;
|
||||||
|
const char *vrf_name = zvrf_name(
|
||||||
|
((struct rib_table_info *)route_table_get_info(table))->zvrf);
|
||||||
|
|
||||||
memset(&rib_cnt, 0, sizeof(rib_cnt));
|
memset(&rib_cnt, 0, sizeof(rib_cnt));
|
||||||
memset(&fib_cnt, 0, sizeof(fib_cnt));
|
memset(&fib_cnt, 0, sizeof(fib_cnt));
|
||||||
|
@ -2476,10 +2491,7 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
||||||
|
|
||||||
if (!use_json)
|
if (!use_json)
|
||||||
vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
|
vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
|
||||||
"Prefix Routes", "FIB",
|
"Prefix Routes", "FIB", vrf_name);
|
||||||
zvrf_name(((struct rib_table_info *)
|
|
||||||
route_table_get_info(table))
|
|
||||||
->zvrf));
|
|
||||||
|
|
||||||
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
|
||||||
if (rib_cnt[i] > 0) {
|
if (rib_cnt[i] > 0) {
|
||||||
|
@ -2554,7 +2566,11 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty,
|
||||||
json_object_int_add(json_route_summary, "prefixRoutesTotalFib",
|
json_object_int_add(json_route_summary, "prefixRoutesTotalFib",
|
||||||
fib_cnt[ZEBRA_ROUTE_TOTAL]);
|
fib_cnt[ZEBRA_ROUTE_TOTAL]);
|
||||||
|
|
||||||
vty_json(vty, json_route_summary);
|
if (!vrf_json)
|
||||||
|
vty_json(vty, json_route_summary);
|
||||||
|
else
|
||||||
|
json_object_object_add(vrf_json, vrf_name,
|
||||||
|
json_route_summary);
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, "------\n");
|
vty_out(vty, "------\n");
|
||||||
vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
|
vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
|
||||||
|
|
Loading…
Reference in a new issue