From 789d0ec4def92ec1fe6a0d24d5eefe7ba8f0fd0f Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 04:53:12 -0700 Subject: pim6d: Moving reusable code to common api for "show mroute summary" command Signed-off-by: Abhishek N R --- pimd/pim_cmd_common.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'pimd/pim_cmd_common.c') diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index c298c60c75..bc3d8d0fca 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4291,3 +4291,60 @@ int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json) return CMD_SUCCESS; } + +int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + 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_summary(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + + show_mroute_summary(vrf->info, vty, json_vrf); + + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} -- cgit v1.2.3