]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: add json support to 'show debugging label-table'
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 5 Oct 2023 07:14:45 +0000 (09:14 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 18 Oct 2023 15:45:29 +0000 (17:45 +0200)
Add the json keyword to dump the label chunks of
the zebra label manager in json format.

>dut# show debugging label-table json
> {
>   "chunks":[
>     {
>       "protocol":"bgp",
>       "instance":0,
>       "sessionId":1,
>       "start":16,
>       "end":16,
>       "dynamic":true
>     },
>     {
>       "protocol":"ldp",
>       "instance":0,
>       "sessionId":1,
>       "start":17,
>       "end":80,
>       "dynamic":true
>     }
>   ]
> }

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
zebra/label_manager.c

index 24968f6509a89504ddf661a570db950df2764293..c0564d65402775a941411d5af835949d409a3c10 100644 (file)
@@ -162,19 +162,42 @@ void lm_hooks_unregister(void)
                        label_manager_write_label_block_config);
 }
 
-DEFPY(show_label_table, show_label_table_cmd, "show debugging label-table",
+static json_object *lmc_json(struct label_manager_chunk *lmc)
+{
+       json_object *json = json_object_new_object();
+
+       json_object_string_add(json, "protocol", zebra_route_string(lmc->proto));
+       json_object_int_add(json, "instance", lmc->instance);
+       json_object_int_add(json, "sessionId", lmc->session_id);
+       json_object_int_add(json, "start", lmc->start);
+       json_object_int_add(json, "end", lmc->end);
+       json_object_boolean_add(json, "dynamic", lmc->is_dynamic);
+       return json;
+}
+
+DEFPY(show_label_table, show_label_table_cmd, "show debugging label-table [json$uj]",
       SHOW_STR
       DEBUG_STR
-      "Display allocated label chunks\n")
+      "Display allocated label chunks\n"
+      JSON_STR)
 {
        struct label_manager_chunk *lmc;
        struct listnode *node;
+       json_object *json_array = NULL;
+
+       if (uj)
+               json_array = json_object_new_array();
 
        for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) {
+               if (uj) {
+                       json_object_array_add(json_array, lmc_json(lmc));
+                       continue;
+               }
                vty_out(vty, "Proto %s: [%u/%u]\n",
                        zebra_route_string(lmc->proto), lmc->start, lmc->end);
        }
-
+       if (uj)
+               vty_json(vty, json_array);
        return CMD_SUCCESS;
 }