From 0bd8a160822bf7fe4aafab6eede73b83552f32bc Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 5 Oct 2023 09:14:45 +0200 Subject: [PATCH] zebra: add json support to 'show debugging label-table' 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 --- zebra/label_manager.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/zebra/label_manager.c b/zebra/label_manager.c index 24968f6509..c0564d6540 100644 --- a/zebra/label_manager.c +++ b/zebra/label_manager.c @@ -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; } -- 2.39.5