From a49ef569deadf4ad6932d185b2bf131691593364 Mon Sep 17 00:00:00 2001 From: Yash Ranjan Date: Sun, 18 Apr 2021 23:40:51 -0700 Subject: [PATCH] ospf6d: Change structure of "show ipv6 ospf6 route json" command The output of "show ipv6 ospf6 route json" was not in the same format as "show ip ospf route json". Currently ipv6 and ipv4 route tables as well as ospfv2 have prefix as the key, but the same is not true for ospfv3. The structure of the json objects needs to be changed. Currently the structure present is frr(config-ospf6)# do show ipv6 ospf6 route json { "routes":[ { "destination":"66:ff::\/64", "isBestRoute":true, "destinationType":"N", "pathType":"IA", "duration":"00:00:06", "nextHops":[ { "nextHop":"::", "interfaceName":"ens256" } ] } ] } It is changed to: frr(config-ospf6)# do show ipv6 ospf6 route json { "routes":{ "12::2\/128":{ "isBestRoute":true, "destinationType":"N", "pathType":"IA", "duration":"00:01:22", "nextHops":[ { "nextHop":"::", "interfaceName":"ens192" } ] } } Signed-off-by: Yash Ranjan --- ospf6d/ospf6_route.c | 61 ++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 9770dd0444..2daf119c52 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -1039,7 +1039,7 @@ void ospf6_route_table_delete(struct ospf6_route_table *table) /* VTY commands */ void ospf6_route_show(struct vty *vty, struct ospf6_route *route, - json_object *json_array_routes, bool use_json) + json_object *json_routes, bool use_json) { int i; char destination[PREFIX2STR_BUFFER], nexthop[64]; @@ -1072,7 +1072,6 @@ void ospf6_route_show(struct vty *vty, struct ospf6_route *route, if (use_json) { json_route = json_object_new_object(); - json_object_string_add(json_route, "destination", destination); json_object_boolean_add(json_route, "isBestRoute", ospf6_route_is_best(route)); json_object_string_add(json_route, "destinationType", @@ -1121,12 +1120,12 @@ void ospf6_route_show(struct vty *vty, struct ospf6_route *route, if (use_json) { json_object_object_add(json_route, "nextHops", json_array_next_hops); - json_object_array_add(json_array_routes, json_route); + json_object_object_add(json_routes, destination, json_route); } } void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route, - json_object *json_array_routes, bool use_json) + json_object *json_routes, bool use_json) { char destination[PREFIX2STR_BUFFER], nexthop[64]; char area_id[16], id[16], adv_router[16], capa[16], options[16]; @@ -1158,7 +1157,6 @@ void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route, if (use_json) { json_route = json_object_new_object(); - json_object_string_add(json_route, "destination", destination); json_object_string_add(json_route, "destinationType", OSPF6_DEST_TYPE_NAME(route->type)); } else { @@ -1311,7 +1309,7 @@ void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route, if (use_json) { json_object_object_add(json_route, "nextHops", json_array_next_hops); - json_object_array_add(json_array_routes, json_route); + json_object_object_add(json_routes, destination, json_route); } else vty_out(vty, "\n"); } @@ -1377,24 +1375,23 @@ static void ospf6_route_show_table_prefix(struct vty *vty, json_object *json, bool use_json) { struct ospf6_route *route; - json_object *json_array_routes = NULL; + json_object *json_routes = NULL; route = ospf6_route_lookup(prefix, table); if (route == NULL) return; if (use_json) - json_array_routes = json_object_new_array(); + json_routes = json_object_new_object(); ospf6_route_lock(route); while (route && ospf6_route_is_prefix(prefix, route)) { /* Specifying a prefix will always display details */ - ospf6_route_show_detail(vty, route, json_array_routes, - use_json); + ospf6_route_show_detail(vty, route, json_routes, use_json); route = ospf6_route_next(route); } if (use_json) - json_object_object_add(json, "routes", json_array_routes); + json_object_object_add(json, "routes", json_routes); if (route) ospf6_route_unlock(route); } @@ -1405,24 +1402,23 @@ static void ospf6_route_show_table_address(struct vty *vty, json_object *json, bool use_json) { struct ospf6_route *route; - json_object *json_array_routes = NULL; + json_object *json_routes = NULL; route = ospf6_route_lookup_bestmatch(prefix, table); if (route == NULL) return; if (use_json) - json_array_routes = json_object_new_array(); + json_routes = json_object_new_object(); prefix = &route->prefix; ospf6_route_lock(route); while (route && ospf6_route_is_prefix(prefix, route)) { /* Specifying a prefix will always display details */ - ospf6_route_show_detail(vty, route, json_array_routes, - use_json); + ospf6_route_show_detail(vty, route, json_routes, use_json); route = ospf6_route_next(route); } if (use_json) - json_object_object_add(json, "routes", json_array_routes); + json_object_object_add(json, "routes", json_routes); if (route) ospf6_route_unlock(route); } @@ -1433,24 +1429,23 @@ static void ospf6_route_show_table_match(struct vty *vty, int detail, json_object *json, bool use_json) { struct ospf6_route *route; - json_object *json_array_routes = NULL; + json_object *json_routes = NULL; assert(prefix->family); route = ospf6_route_match_head(prefix, table); if (use_json) - json_array_routes = json_object_new_array(); + json_routes = json_object_new_object(); while (route) { if (detail) - ospf6_route_show_detail(vty, route, json_array_routes, + ospf6_route_show_detail(vty, route, json_routes, use_json); else - ospf6_route_show(vty, route, json_array_routes, - use_json); + ospf6_route_show(vty, route, json_routes, use_json); route = ospf6_route_match_next(prefix, route); } if (use_json) - json_object_object_add(json, "routes", json_array_routes); + json_object_object_add(json, "routes", json_routes); } static void ospf6_route_show_table_type(struct vty *vty, int detail, @@ -1459,25 +1454,24 @@ static void ospf6_route_show_table_type(struct vty *vty, int detail, json_object *json, bool use_json) { struct ospf6_route *route; - json_object *json_array_routes = NULL; + json_object *json_routes = NULL; route = ospf6_route_head(table); if (use_json) - json_array_routes = json_object_new_array(); + json_routes = json_object_new_object(); while (route) { if (route->path.type == type) { if (detail) - ospf6_route_show_detail(vty, route, - json_array_routes, + ospf6_route_show_detail(vty, route, json_routes, use_json); else - ospf6_route_show(vty, route, json_array_routes, + ospf6_route_show(vty, route, json_routes, use_json); } route = ospf6_route_next(route); } if (use_json) - json_object_object_add(json, "routes", json_array_routes); + json_object_object_add(json, "routes", json_routes); } static void ospf6_route_show_table(struct vty *vty, int detail, @@ -1485,22 +1479,21 @@ static void ospf6_route_show_table(struct vty *vty, int detail, json_object *json, bool use_json) { struct ospf6_route *route; - json_object *json_array_routes = NULL; + json_object *json_routes = NULL; route = ospf6_route_head(table); if (use_json) - json_array_routes = json_object_new_array(); + json_routes = json_object_new_object(); while (route) { if (detail) - ospf6_route_show_detail(vty, route, json_array_routes, + ospf6_route_show_detail(vty, route, json_routes, use_json); else - ospf6_route_show(vty, route, json_array_routes, - use_json); + ospf6_route_show(vty, route, json_routes, use_json); route = ospf6_route_next(route); } if (use_json) - json_object_object_add(json, "routes", json_array_routes); + json_object_object_add(json, "routes", json_routes); } int ospf6_route_table_show(struct vty *vty, int argc_start, int argc, -- 2.39.5