summaryrefslogtreecommitdiff
path: root/pimd/pim_cmd.c
diff options
context:
space:
mode:
authorAbhishek N R <abnr@vmware.com>2022-04-08 00:20:53 -0700
committerAbhishek N R <abnr@vmware.com>2022-04-28 02:14:49 -0700
commitc41a9dcfa2b71657533f72084b66a80b285a02b2 (patch)
tree0156ad8d7363c5c122932175ee61faff2aaa35fd /pimd/pim_cmd.c
parent50ba39bf4c3a454320b8ef383ac59fdfb610e385 (diff)
pim6d: Implementing "show ipv6 mroute count" CLI
Adding new show CLI to display ipv6 mroute count information. Signed-off-by: Abhishek N R <abnr@vmware.com>
Diffstat (limited to 'pimd/pim_cmd.c')
-rw-r--r--pimd/pim_cmd.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 6f862c74f6..db6945a624 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -3891,9 +3891,9 @@ DEFUN (clear_ip_mroute_count,
return CMD_SUCCESS;
}
-DEFUN (show_ip_mroute_count,
+DEFPY (show_ip_mroute_count,
show_ip_mroute_count_cmd,
- "show ip mroute [vrf NAME] count [json]",
+ "show ip mroute [vrf NAME] count [json$json]",
SHOW_STR
IP_STR
MROUTE_STR
@@ -3901,20 +3901,36 @@ DEFUN (show_ip_mroute_count,
"Route and packet count data\n"
JSON_STR)
{
- int idx = 2;
- bool uj = use_json(argc, argv);
- struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
+ struct pim_instance *pim;
+ struct vrf *v;
+ json_object *json_parent = NULL;
- if (!vrf)
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+ pim = pim_get_pim_instance(v->vrf_id);
+
+ if (!pim) {
+ vty_out(vty, "%% Unable to find pim instance\n");
return CMD_WARNING;
+ }
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ show_mroute_count(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
- show_mroute_count(vrf->info, vty, uj);
return CMD_SUCCESS;
}
-DEFUN (show_ip_mroute_count_vrf_all,
+DEFPY (show_ip_mroute_count_vrf_all,
show_ip_mroute_count_vrf_all_cmd,
- "show ip mroute vrf all count [json]",
+ "show ip mroute vrf all count [json$json]",
SHOW_STR
IP_STR
MROUTE_STR
@@ -3922,24 +3938,27 @@ DEFUN (show_ip_mroute_count_vrf_all,
"Route and packet count data\n"
JSON_STR)
{
- bool uj = use_json(argc, argv);
struct vrf *vrf;
- bool first = true;
+ json_object *json_parent = NULL;
+ json_object *json_vrf = NULL;
+
+ if (json)
+ json_parent = json_object_new_object();
- if (uj)
- vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
- if (uj) {
- if (!first)
- vty_out(vty, ", ");
- vty_out(vty, " \"%s\": ", vrf->name);
- first = false;
- } else
+ if (!json)
vty_out(vty, "VRF: %s\n", vrf->name);
- show_mroute_count(vrf->info, vty, uj);
+ else
+ json_vrf = json_object_new_object();
+
+ show_mroute_count(vrf->info, vty, json_vrf);
+
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
}
- if (uj)
- vty_out(vty, "}\n");
+ if (json)
+ vty_json(vty, json_parent);
return CMD_SUCCESS;
}