]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: add json support to display spf paths in 'show isis route'
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 6 Jun 2024 15:08:56 +0000 (17:08 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 21 Jun 2024 13:40:23 +0000 (15:40 +0200)
The 'show isis route json' command never displays the list of
paths. Add the json support for this sub-part.

> # show isis route json
> [..]
> "ipv6-paths":[
>  {
>   "Vertex":"rt1",
>   "Type":"",
>   "Metric":0,
>   "Next-Hop":"",
>   "Interface":"",
>   "Parent":""
>  },
>  {
>    "Vertex":"2001:db8:1000::1\/128",
>    "Type":"IP6 internal",
>    "Metric":0,
>    "Next-Hop":"",
>    "Interface":"",
>    "Parent":"rt1(4)"
>  },

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
isisd/isis_spf.c
isisd/isis_spf.h
tests/isisd/test_isis_spf.c

index 4892479ac2d0a0cf51a7c2ee6d51ac61e0a663ae..c64bf67df5616e4b96820d2ba0ad4597babb4b52 100644 (file)
@@ -2227,7 +2227,7 @@ int _isis_spf_schedule(struct isis_area *area, int level,
 }
 
 static void isis_print_paths(struct vty *vty, struct isis_vertex_queue *queue,
-                            uint8_t *root_sysid)
+                            uint8_t *root_sysid, struct json_object **json)
 {
        struct listnode *node;
        struct isis_vertex *vertex;
@@ -2331,13 +2331,17 @@ static void isis_print_paths(struct vty *vty, struct isis_vertex_queue *queue,
                               vertex_typestr, vertex_metricstr, vertex_nexthop,
                               vertex_interface, vertex_parent);
        }
-       table = ttable_dump(tt, "\n");
-       vty_out(vty, "%s\n", table);
-       XFREE(MTYPE_TMP, table);
+       if (json == NULL) {
+               table = ttable_dump(tt, "\n");
+               vty_out(vty, "%s\n", table);
+               XFREE(MTYPE_TMP, table);
+       } else
+               *json = ttable_json(tt, "ssdsss");
        ttable_del(tt);
 }
 
-void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree)
+void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree,
+                       struct json_object **json)
 {
        const char *tree_id_text = NULL;
 
@@ -2359,10 +2363,13 @@ void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree)
                return;
        }
 
-       vty_out(vty, "IS-IS paths to level-%d routers %s\n", spftree->level,
-               tree_id_text);
-       isis_print_paths(vty, &spftree->paths, spftree->sysid);
-       vty_out(vty, "\n");
+       if (!json)
+               vty_out(vty, "IS-IS paths to level-%d routers %s\n",
+                       spftree->level, tree_id_text);
+
+       isis_print_paths(vty, &spftree->paths, spftree->sysid, json);
+       if (!json)
+               vty_out(vty, "\n");
 }
 
 static void show_isis_topology_common(struct vty *vty, int levels,
@@ -2420,7 +2427,7 @@ static void show_isis_topology_common(struct vty *vty, int levels,
                                        spftree = area->spftree[SPFTREE_IPV4]
                                                               [level - 1];
 
-                               isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree, NULL);
                        }
                        if (area->ipv6_circuits > 0) {
 #ifndef FABRICD
@@ -2431,7 +2438,7 @@ static void show_isis_topology_common(struct vty *vty, int levels,
 #endif /* ifndef FABRICD */
                                        spftree = area->spftree[SPFTREE_IPV6]
                                                               [level - 1];
-                               isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree, NULL);
                        }
                        if (isis_area_ipv6_dstsrc_enabled(area)) {
 #ifndef FABRICD
@@ -2443,14 +2450,15 @@ static void show_isis_topology_common(struct vty *vty, int levels,
 #endif /* ifndef FABRICD */
                                        spftree = area->spftree[SPFTREE_DSTSRC]
                                                               [level - 1];
-                               isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree, NULL);
                        }
                }
 
                if (fabricd_spftree(area)) {
                        vty_out(vty,
                                "IS-IS paths to level-2 routers with hop-by-hop metric\n");
-                       isis_print_paths(vty, &fabricd_spftree(area)->paths, isis->sysid);
+                       isis_print_paths(vty, &fabricd_spftree(area)->paths,
+                                        isis->sysid, NULL);
                        vty_out(vty, "\n");
                }
 
@@ -3006,8 +3014,14 @@ static void show_isis_route_common(struct vty *vty, int levels,
                                        spftree = area->spftree[SPFTREE_IPV4]
                                                               [level - 1];
 
-                               if (!json)
-                                       isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree,
+                                                  json ? &json_val : NULL);
+                               if (json && json_val) {
+                                       json_object_object_add(json_level,
+                                                              "ipv4-paths",
+                                                              json_val);
+                                       json_val = NULL;
+                               }
 
                                isis_print_routes(vty, spftree,
                                                  json ? &json_val : NULL,
@@ -3028,8 +3042,14 @@ static void show_isis_route_common(struct vty *vty, int levels,
                                        spftree = area->spftree[SPFTREE_IPV6]
                                                               [level - 1];
 
-                               if (!json)
-                                       isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree,
+                                                  json ? &json_val : NULL);
+                               if (json && json_val) {
+                                       json_object_object_add(json_level,
+                                                              "ipv6-paths",
+                                                              json_val);
+                                       json_val = NULL;
+                               }
 
                                isis_print_routes(vty, spftree,
                                                  json ? &json_val : NULL,
@@ -3051,8 +3071,14 @@ static void show_isis_route_common(struct vty *vty, int levels,
                                        spftree = area->spftree[SPFTREE_DSTSRC]
                                                               [level - 1];
 
-                               if (!json)
-                                       isis_print_spftree(vty, spftree);
+                               isis_print_spftree(vty, spftree,
+                                                  json ? &json_val : NULL);
+                               if (json && json_val) {
+                                       json_object_object_add(json_level,
+                                                              "ipv6-dstsrc-paths",
+                                                              json_val);
+                                       json_val = NULL;
+                               }
                                isis_print_routes(vty, spftree,
                                                  json ? &json_val : NULL,
                                                  prefix_sid, backup);
index 7e9754d9bfa5175d225c3b2028e10d13cf5acbd0..ee2d29abe3ba317fc6b71d19f0aceb0924cd1915 100644 (file)
@@ -61,7 +61,8 @@ struct isis_lsp *isis_root_system_lsp(struct lspdb_head *lspdb,
                           __FILE__, __LINE__)
 int _isis_spf_schedule(struct isis_area *area, int level,
                       const char *func, const char *file, int line);
-void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree);
+void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree,
+                       struct json_object **json);
 void isis_print_routes(struct vty *vty, struct isis_spftree *spftree,
                       json_object **json, bool prefix_sid, bool backup);
 void isis_spf_init(void);
index 4ea28cda2ff8bc45c8f9ddef599915f5debb2944..6fe6993fdfd866253c6bf3ca2ec4a29c37f852ff 100644 (file)
@@ -55,7 +55,7 @@ static void test_run_spf(struct vty *vty, const struct isis_topology *topology,
        isis_run_spf(spftree);
 
        /* Print the SPT and the corresponding routing table. */
-       isis_print_spftree(vty, spftree);
+       isis_print_spftree(vty, spftree, NULL);
        isis_print_routes(vty, spftree, NULL, false, false);
 
        /* Cleanup SPF tree. */
@@ -85,7 +85,7 @@ static void test_run_lfa(struct vty *vty, const struct isis_topology *topology,
        isis_lfa_compute(area, NULL, spftree_self, protected_resource);
 
        /* Print the SPT and the corresponding main/backup routing tables. */
-       isis_print_spftree(vty, spftree_self);
+       isis_print_spftree(vty, spftree_self, NULL);
        vty_out(vty, "Main:\n");
        isis_print_routes(vty, spftree_self, NULL, false, false);
        vty_out(vty, "Backup:\n");
@@ -148,7 +148,7 @@ static void test_run_rlfa(struct vty *vty, const struct isis_topology *topology,
        vty_out(vty, "\n");
 
        /* Print the post-convergence SPT. */
-       isis_print_spftree(vty, spftree_pc);
+       isis_print_spftree(vty, spftree_pc, NULL);
 
        /*
         * Activate the computed RLFAs (if any) using artificial LDP labels for
@@ -164,7 +164,7 @@ static void test_run_rlfa(struct vty *vty, const struct isis_topology *topology,
        }
 
        /* Print the SPT and the corresponding main/backup routing tables. */
-       isis_print_spftree(vty, spftree_self);
+       isis_print_spftree(vty, spftree_self, NULL);
        vty_out(vty, "Main:\n");
        isis_print_routes(vty, spftree_self, NULL, false, false);
        vty_out(vty, "Backup:\n");
@@ -228,7 +228,7 @@ static void test_run_ti_lfa(struct vty *vty,
        /*
         * Print the post-convergence SPT and the corresponding routing table.
         */
-       isis_print_spftree(vty, spftree_pc);
+       isis_print_spftree(vty, spftree_pc, NULL);
        isis_print_routes(vty, spftree_self, NULL, false, true);
 
        /* Cleanup everything. */