]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: make optional algorithm id in 'show isis route'
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 15 Dec 2022 08:26:45 +0000 (09:26 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Mon, 19 Feb 2024 09:10:54 +0000 (10:10 +0100)
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 <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
isisd/isis_spf.c

index 7a4b45a0de17eb273645fc1c51b556a9547a44d4..8689742a5e87a4fa6cc04b2683553720a88a995a 100644 (file)
@@ -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 <NAME|all>] route"
@@ -3019,7 +3052,7 @@ DEFUN(show_isis_route, show_isis_route_cmd,
 #endif /* ifndef FABRICD */
       " [<prefix-sid|backup>]"
 #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",