From 66ef3576af1fb043d625fe6ed62369d9c95e86ae Mon Sep 17 00:00:00 2001 From: baozhen-H3C Date: Tue, 22 Oct 2024 15:59:39 +0800 Subject: [PATCH] isisd: The command "'show isis vrf all summary json" has no output. When input 'show isis vrf all summary', output is as follow: sonic# show isis vrf all summary vrf : default Process Id : 55 System Id : 0000.0000.0006 Symbolic name : RouterA Up time : 4d01h52m ago Number of areas : 1 Area 10: Net: 10.0000.0000.0006.00 IS_name: RouterA TX counters per PDU type: L1 IIH: 365003 L1 LSP: 20468 L1 PSNP: 8 LSP RXMT: 0 RX counters per PDU type: L1 IIH: 361577 L2 IIH: 434 L1 LSP: 10492 L1 CSNP: 114260 Level-1: LSP0 regenerated: 4840 LSPs purged: 0 SPF: minimum interval : 1 IPv4 route computation: last run elapsed : 00:01:02 ago last run duration : 327 usec run count : 12053 However, json display is null. After the commit: sonic# show isis vrf all summary json { "vrfs":[ { "vrf":"default", "process-id":56, "system-id":"0000.0000.0007", "up-time":"20:40:33", "number-areas":1, "areas":[ { "area":"10", "net":"10.0000.0000.0007.00", "tx-pdu-type":{ "l1-iih":52234, "l1-lsp":1053, "l1-csnp":8269, "l1-psnp":1, "lsp-rxmt":0 }, "rx-pdu-type":{ "l1-iih":52245, "l2-iih":26116, "l1-lsp":1388, "l1-csnp":8269 }, "levels":[ { "id":1, "lsp0-regenerated":89, "lsp-purged":0, "spf":"no pending", "minimum-interval":1, "last-run-elapsed":"00:00:05", "last-run-duration-usec":192, "last-run-count":1454 } ] } ] } ] } Signed-off-by: baozhen-H3C --- isisd/isisd.c | 63 ++++++++++--------- tests/topotests/isis_topo1/test_isis_topo1.py | 6 +- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/isisd/isisd.c b/isisd/isisd.c index 2863fd913f..fed6d3c6dc 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -2366,35 +2366,34 @@ static void common_isis_summary_json(struct json_object *json, struct isis *isis) { int level; - json_object *areas_json, *area_json, *tx_pdu_json, *rx_pdu_json, - *levels_json, *level_json; + json_object *vrf_json, *areas_json, *area_json, *tx_pdu_json, *rx_pdu_json, *levels_json, + *level_json; struct listnode *node, *node2; struct isis_area *area; time_t cur; char uptime[MONOTIME_STRLEN]; char stier[5]; - json_object_string_add(json, "vrf", isis->name); - json_object_int_add(json, "process-id", isis->process_id); + vrf_json = json_object_new_object(); + json_object_string_add(vrf_json, "vrf", isis->name); + json_object_int_add(vrf_json, "process-id", isis->process_id); if (isis->sysid_set) - json_object_string_addf(json, "system-id", "%pSY", isis->sysid); + json_object_string_addf(vrf_json, "system-id", "%pSY", isis->sysid); cur = time(NULL); cur -= isis->uptime; frrtime_to_interval(cur, uptime, sizeof(uptime)); - json_object_string_add(json, "up-time", uptime); + json_object_string_add(vrf_json, "up-time", uptime); if (isis->area_list) - json_object_int_add(json, "number-areas", - isis->area_list->count); + json_object_int_add(vrf_json, "number-areas", isis->area_list->count); areas_json = json_object_new_array(); - json_object_object_add(json, "areas", areas_json); + json_object_object_add(vrf_json, "areas", areas_json); for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { area_json = json_object_new_object(); json_object_string_add(area_json, "area", area->area_tag ? area->area_tag : "null"); - if (fabricd) { uint8_t tier = fabricd_tier(area); snprintfrr(stier, sizeof(stier), "%s", &tier); @@ -2471,6 +2470,7 @@ static void common_isis_summary_json(struct json_object *json, } json_object_array_add(areas_json, area_json); } + json_object_array_add(json, vrf_json); } static void common_isis_summary_vty(struct vty *vty, struct isis *isis) @@ -2573,13 +2573,27 @@ static void common_isis_summary_vty(struct vty *vty, struct isis *isis) } } -static void common_isis_summary(struct vty *vty, struct json_object *json, - struct isis *isis) +static void common_isis_summary(struct vty *vty, struct json_object *json, const char *vrf_name, + bool all_vrf) { - if (json) { - common_isis_summary_json(json, isis); + struct listnode *node; + struct isis *isis; + + if (all_vrf) { + for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) { + if (json) + common_isis_summary_json(json, isis); + else + common_isis_summary_vty(vty, isis); + } } else { - common_isis_summary_vty(vty, isis); + isis = isis_lookup_by_vrfname(vrf_name); + if (isis != NULL) { + if (json) + common_isis_summary_json(json, isis); + else + common_isis_summary_vty(vty, isis); + } } } @@ -2590,31 +2604,24 @@ DEFUN(show_isis_summary, show_isis_summary_cmd, "json output\n" "summary\n") { - struct listnode *node; int idx_vrf = 0; - struct isis *isis; const char *vrf_name = VRF_DEFAULT_NAME; bool all_vrf = false; bool uj = use_json(argc, argv); - json_object *json = NULL; + json_object *json = NULL, *vrfs_json = NULL; ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) if (!im) { vty_out(vty, PROTO_NAME " is not running\n"); return CMD_SUCCESS; } - if (uj) + if (uj) { json = json_object_new_object(); - - if (all_vrf) { - for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) - common_isis_summary(vty, json, isis); - - return CMD_SUCCESS; + vrfs_json = json_object_new_array(); + json_object_object_add(json, "vrfs", vrfs_json); } - isis = isis_lookup_by_vrfname(vrf_name); - if (isis != NULL) - common_isis_summary(vty, json, isis); + + common_isis_summary(vty, vrfs_json, vrf_name, all_vrf); if (uj) vty_json(vty, json); diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index 1cec2f16f0..fe3d865565 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -237,9 +237,9 @@ def test_isis_summary_json(): assertmsg = "Test isis summary json failed in '{}' data '{}'".format( rname, json_output ) - assert json_output["vrf"] == "default", assertmsg - assert json_output["areas"][0]["area"] == "1", assertmsg - assert json_output["areas"][0]["levels"][0]["id"] != "3", assertmsg + assert json_output["vrfs"][0]["vrf"] == "default", assertmsg + assert json_output["vrfs"][0]["areas"][0]["area"] == "1", assertmsg + assert json_output["vrfs"][0]["areas"][0]["levels"][0]["id"] != "3", assertmsg def test_isis_interface_json():