From 88e368b4dc9b5bebb507ca24f63afc8d57c80631 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 15 Dec 2022 09:26:45 +0100 Subject: [PATCH 1/4] isisd: make optional algorithm id in 'show isis route' To avoid calling for each algorithm the 'show isis route' command, the algorithm id is optional. The below command will dump the routes for all the algorithms: > show isis route algorithm Signed-off-by: Philippe Guibert Signed-off-by: Louis Scalbert --- isisd/isis_spf.c | 73 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 7a4b45a0de17..8689742a5e87 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -3011,6 +3011,39 @@ static void show_isis_route_common(struct vty *vty, int levels, } } +static void show_isis_route_all_algos(struct vty *vty, int levels, + struct isis *isis, bool prefix_sid, + bool backup, json_object **json) +{ + uint16_t algo; + + json_object *json_algo = NULL, *json_algos = NULL; + + if (json) { + *json = json_object_new_object(); + json_algos = json_object_new_array(); + } + + for (algo = SR_ALGORITHM_FLEX_MIN; algo <= SR_ALGORITHM_FLEX_MAX; + algo++) { + show_isis_route_common(vty, levels, isis, prefix_sid, backup, + (uint8_t)algo, json ? &json_algo : NULL); + if (!json) + continue; + if (json_object_object_length(json_algo) == 0) { + json_object_free(json_algo); + continue; + } + json_object_object_add(json_algo, "algorithm", + json_object_new_int(algo)); + json_object_array_add(json_algos, json_algo); + } + + if (json) + json_object_object_add(*json, "algorithms", json_algos); +} + + DEFUN(show_isis_route, show_isis_route_cmd, "show " PROTO_NAME " [vrf ] route" @@ -3019,7 +3052,7 @@ DEFUN(show_isis_route, show_isis_route_cmd, #endif /* ifndef FABRICD */ " []" #ifndef FABRICD - " [algorithm (128-255)]" + " [algorithm [(128-255)]]" #endif /* ifndef FABRICD */ " [json$uj]", SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR @@ -3041,6 +3074,7 @@ DEFUN(show_isis_route, show_isis_route_cmd, struct listnode *node; const char *vrf_name = VRF_DEFAULT_NAME; bool all_vrf = false; + bool all_algorithm = false; bool prefix_sid = false; bool backup = false; bool uj = use_json(argc, argv); @@ -3067,8 +3101,13 @@ DEFUN(show_isis_route, show_isis_route_cmd, backup = true; #ifndef FABRICD - if (argv_find(argv, argc, "algorithm", &idx)) - algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL, 10); + if (argv_find(argv, argc, "algorithm", &idx)) { + if (argv_find(argv, argc, "(128-255)", &idx)) + algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL, + 10); + else + all_algorithm = true; + } #endif /* ifndef FABRICD */ if (uj) @@ -3077,9 +3116,19 @@ DEFUN(show_isis_route, show_isis_route_cmd, if (vrf_name) { if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) { - show_isis_route_common( - vty, levels, isis, prefix_sid, backup, - algorithm, uj ? &json_vrf : NULL); + if (all_algorithm) + show_isis_route_all_algos(vty, levels, + isis, + prefix_sid, + backup, + uj ? &json_vrf + : NULL); + else + show_isis_route_common(vty, levels, + isis, prefix_sid, + backup, algorithm, + uj ? &json_vrf + : NULL); if (uj) { json_object_object_add( json_vrf, "vrf_id", @@ -3092,9 +3141,15 @@ DEFUN(show_isis_route, show_isis_route_cmd, } isis = isis_lookup_by_vrfname(vrf_name); if (isis != NULL) { - show_isis_route_common(vty, levels, isis, prefix_sid, - backup, algorithm, - uj ? &json_vrf : NULL); + if (all_algorithm) + show_isis_route_all_algos(vty, levels, isis, + prefix_sid, backup, + uj ? &json_vrf : NULL); + else + show_isis_route_common(vty, levels, isis, + prefix_sid, backup, + algorithm, + uj ? &json_vrf : NULL); if (uj) { json_object_object_add( json_vrf, "vrf_id", From 4d63d8cd62b700393b07fe1487f54e38197e9979 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 19 Dec 2022 15:39:00 +0100 Subject: [PATCH 2/4] isisd: show isis route .. json adds the algorithm value When walking over all the flex-algorithm routes, it is difficult to know which route is associated to which algorithm: add "algorithm" attribute to the json object. Output example: > ubuntu2004(config-router)# do show isis route algorithm json > [ > { > "area":"1", > "algorithm":128, > "level-1":{ > ] > }, > "level-2":{ > "area":"1" > }, > "vrf_id":0 > }, > { > "area":"1", > "algorithm":129, > "level-1":{ > "area":"1", Signed-off-by: Philippe Guibert Signed-off-by: Louis Scalbert --- isisd/isis_spf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 8689742a5e87..773136d03433 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -2912,6 +2912,7 @@ static void show_isis_route_common(struct vty *vty, int levels, jstr = json_object_new_string( area->area_tag ? area->area_tag : "null"); json_object_object_add(*json, "area", jstr); + json_object_int_add(*json, "algorithm", algo); } else { vty_out(vty, "Area %s:", area->area_tag ? area->area_tag : "null"); From f93b08f4a06f110fbfb0f21005504a4b381cd64d Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 15 Dec 2022 09:28:19 +0100 Subject: [PATCH 3/4] isisd: make algorithm id optional in show isis commands The following two isis commands have now the algorithm id optional: > # show isis segment-routing node algorithm > # show isis topology algorithm Signed-off-by: Philippe Guibert Signed-off-by: Louis Scalbert --- isisd/isis_spf.c | 44 +++++++++++++++++++++++++++++++++++--------- isisd/isis_sr.c | 26 ++++++++++++++++++++------ 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 773136d03433..36986a19c558 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -2424,7 +2424,7 @@ DEFUN(show_isis_topology, show_isis_topology_cmd, " [vrf ] topology" #ifndef FABRICD " []" - " [algorithm (128-255)]" + " [algorithm [(128-255)]]" #endif /* ifndef FABRICD */ , SHOW_STR PROTO_HELP VRF_CMD_HELP_STR @@ -2443,8 +2443,10 @@ DEFUN(show_isis_topology, show_isis_topology_cmd, struct isis *isis = NULL; const char *vrf_name = VRF_DEFAULT_NAME; bool all_vrf = false; + bool all_algorithm = false; int idx_vrf = 0; - uint8_t algorithm = SR_ALGORITHM_SPF; + uint16_t algorithm = SR_ALGORITHM_SPF; + #ifndef FABRICD int idx = 0; @@ -2453,8 +2455,12 @@ DEFUN(show_isis_topology, show_isis_topology_cmd, levels = ISIS_LEVEL1; if (argv_find(argv, argc, "level-2", &idx)) levels = ISIS_LEVEL2; - if (argv_find(argv, argc, "algorithm", &idx)) - algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL, 10); + if (argv_find(argv, argc, "algorithm", &idx)) { + if (argv_find(argv, argc, "(128-255)", &idx)) + algorithm = (uint16_t)strtoul(argv[idx]->arg, NULL, 10); + else + all_algorithm = true; + } #endif /* ifndef FABRICD */ if (!im) { @@ -2465,14 +2471,34 @@ DEFUN(show_isis_topology, show_isis_topology_cmd, if (vrf_name) { if (all_vrf) { - for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) - show_isis_topology_common(vty, levels, isis, - algorithm); + for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) { + if (all_algorithm) { + for (algorithm = SR_ALGORITHM_FLEX_MIN; + algorithm <= SR_ALGORITHM_FLEX_MAX; + algorithm++) + show_isis_topology_common( + vty, levels, isis, + (uint8_t)algorithm); + } else { + show_isis_topology_common( + vty, levels, isis, + (uint8_t)algorithm); + } + } return CMD_SUCCESS; } isis = isis_lookup_by_vrfname(vrf_name); - if (isis != NULL) - show_isis_topology_common(vty, levels, isis, algorithm); + if (isis == NULL) + return CMD_SUCCESS; + if (all_algorithm) { + for (algorithm = SR_ALGORITHM_FLEX_MIN; + algorithm <= SR_ALGORITHM_FLEX_MAX; algorithm++) { + show_isis_topology_common(vty, levels, isis, + (uint8_t)algorithm); + } + } else + show_isis_topology_common(vty, levels, isis, + (uint8_t)algorithm); } return CMD_SUCCESS; diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index 1d69dbbbfa41..e8354fdf9226 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1074,7 +1074,7 @@ DEFUN(show_sr_node, show_sr_node_cmd, "show " PROTO_NAME " segment-routing node" #ifndef FABRICD - " [algorithm (128-255)]" + " [algorithm [(128-255)]]" #endif /* ifndef FABRICD */ , SHOW_STR PROTO_HELP @@ -1088,13 +1088,18 @@ DEFUN(show_sr_node, show_sr_node_cmd, { struct listnode *node, *inode; struct isis_area *area; - uint8_t algorithm = SR_ALGORITHM_SPF; + uint16_t algorithm = SR_ALGORITHM_SPF; + bool all_algorithm = false; struct isis *isis; #ifndef FABRICD int idx = 0; - if (argv_find(argv, argc, "algorithm", &idx)) - algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL, 10); + if (argv_find(argv, argc, "algorithm", &idx)) { + if (argv_find(argv, argc, "(128-255)", &idx)) + algorithm = (uint16_t)strtoul(argv[idx]->arg, NULL, 10); + else + all_algorithm = true; + } #endif /* ifndef FABRICD */ for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) { @@ -1106,8 +1111,17 @@ DEFUN(show_sr_node, show_sr_node_cmd, continue; } for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS; - level++) - show_node(vty, area, level, algorithm); + level++) { + if (all_algorithm) { + for (algorithm = SR_ALGORITHM_FLEX_MIN; + algorithm <= SR_ALGORITHM_FLEX_MAX; + algorithm++) + show_node(vty, area, level, + (uint8_t)algorithm); + } else + show_node(vty, area, level, + (uint8_t)algorithm); + } } } From 21e542e2c68101792aaf36d2fae21108537ae291 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 19 Feb 2024 10:13:51 +0100 Subject: [PATCH 4/4] doc: show isis optional algorithm id Set optional algorithm ID in the show isis commands. Signed-off-by: Louis Scalbert --- doc/user/isisd.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/user/isisd.rst b/doc/user/isisd.rst index d37dfa64c673..6e4e42b81138 100644 --- a/doc/user/isisd.rst +++ b/doc/user/isisd.rst @@ -320,12 +320,12 @@ Showing ISIS information Show the ISIS database globally, for a specific LSP id without or with details. -.. clicmd:: show isis topology [level-1|level-2] [algorithm (128-255)] +.. clicmd:: show isis topology [level-1|level-2] [algorithm [(128-255)]] Show topology IS-IS paths to Intermediate Systems, globally, in area (level-1) or domain (level-2). -.. clicmd:: show isis route [level-1|level-2] [prefix-sid|backup] [algorithm (128-255)] +.. clicmd:: show isis route [level-1|level-2] [prefix-sid|backup] [algorithm [(128-255)]] Show the ISIS routing table, as determined by the most recent SPF calculation. @@ -435,7 +435,7 @@ Known limitations: clear the Node flag that is set by default for Prefix-SIDs associated to loopback addresses. This option is necessary to configure Anycast-SIDs. -.. clicmd:: show isis segment-routing node [algorithm (128-255)] +.. clicmd:: show isis segment-routing node [algorithm [(128-255)]] Show detailed information about all learned Segment Routing Nodes.