diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2023-10-05 09:14:45 +0200 |
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2023-10-18 17:45:29 +0200 |
| commit | 0bd8a160822bf7fe4aafab6eede73b83552f32bc (patch) | |
| tree | c5d50e8bdd1177add15496823f645c05b9525af5 /zebra/label_manager.c | |
| parent | 8a400bb70adddd6b701ec50c10d186322e7ae45d (diff) | |
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 <philippe.guibert@6wind.com>
Diffstat (limited to 'zebra/label_manager.c')
| -rw-r--r-- | zebra/label_manager.c | 29 |
1 files 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; } |
