]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pim6d: Moving reusable code to common api for "show mroute summary" command
authorAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 11:53:12 +0000 (04:53 -0700)
committerAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 11:53:12 +0000 (04:53 -0700)
Signed-off-by: Abhishek N R <abnr@vmware.com>
pimd/pim6_cmd.c
pimd/pim_cmd.c
pimd/pim_cmd_common.c
pimd/pim_cmd_common.h

index 192c62044b12a299edce092972231823cb4323f2..0cf7a2f347319ec46306647e52d70f69a3af0d2a 100644 (file)
@@ -1433,31 +1433,7 @@ DEFPY (show_ipv6_mroute_summary,
        "Summary of all mroutes\n"
        JSON_STR)
 {
-       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;
+       return pim_show_mroute_summary_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ipv6_mroute_summary_vrf_all,
@@ -1470,30 +1446,7 @@ DEFPY (show_ipv6_mroute_summary_vrf_all,
        "Summary of all mroutes\n"
        JSON_STR)
 {
-       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;
+       return pim_show_mroute_summary_vrf_all_helper(vty, !!json);
 }
 
 DEFPY (clear_ipv6_pim_statistics,
index 3442f831562562999e32e828786a546deedb02d8..9abd5a3b761b5ad3fa92756ffc32ba3758d636ce 100644 (file)
@@ -3433,31 +3433,7 @@ DEFPY (show_ip_mroute_summary,
        "Summary of all mroutes\n"
        JSON_STR)
 {
-       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;
+       return pim_show_mroute_summary_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ip_mroute_summary_vrf_all,
@@ -3470,30 +3446,7 @@ DEFPY (show_ip_mroute_summary_vrf_all,
        "Summary of all mroutes\n"
        JSON_STR)
 {
-       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;
+       return pim_show_mroute_summary_vrf_all_helper(vty, !!json);
 }
 
 DEFUN (show_ip_rib,
index c298c60c75d925403b0fae4ce8229ee752dc6502..bc3d8d0fca7c40f5aacc46ffae998e2f84242ec5 100644 (file)
@@ -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;
+}
index 79783ca40917624a51ab3cbf18332e221f66e7eb..437d92897fb710e6127317152a1e9f0c241cc27e 100644 (file)
@@ -160,6 +160,8 @@ int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
 int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json);
 int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json);
 int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json);
+int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json);
+int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json);
 
 /*
  * Special Macro to allow us to get the correct pim_instance;