]> git.proxmox.com Git - mirror_frr.git/commitdiff
pim6d: Moving reusable code to common api for "show ip/ipv6 multicast count" command
authorAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 11:04:14 +0000 (04:04 -0700)
committerAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 11:04:14 +0000 (04:04 -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 e9d90b104d5c6b38449fec12decb575983802a2a..4476b8b103dc66e5c8597e682c7ac513f13a666b 100644 (file)
@@ -1353,31 +1353,7 @@ DEFPY (show_ipv6_multicast_count,
        VRF_CMD_HELP_STR
        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_multicast_interfaces(pim, vty, json_parent);
-
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_multicast_count_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ipv6_multicast_count_vrf_all,
@@ -1390,28 +1366,7 @@ DEFPY (show_ipv6_multicast_count_vrf_all,
        VRF_CMD_HELP_STR
        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_multicast_interfaces(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_multicast_count_vrf_all_helper(vty, !!json);
 }
 
 DEFPY (show_ipv6_mroute,
index 1766bd1fae33b90979e69ca23fc678b21c228343..dc36471f69dab68e0019be0a43ccb2e26c8dbd9b 100644 (file)
@@ -3341,31 +3341,7 @@ DEFPY (show_ip_multicast_count,
        VRF_CMD_HELP_STR
        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_multicast_interfaces(pim, vty, json_parent);
-
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_multicast_count_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ip_multicast_count_vrf_all,
@@ -3378,28 +3354,7 @@ DEFPY (show_ip_multicast_count_vrf_all,
        VRF_CMD_HELP_STR
        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_multicast_interfaces(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_multicast_count_vrf_all_helper(vty, !!json);
 }
 
 DEFPY (show_ip_mroute,
index 7a051186777dc99bb69172bd8eafb17e21d0308b..e5052dfe9a112b12fd9f6dc80484371e2a670a79 100644 (file)
@@ -4115,3 +4115,58 @@ int pim_show_multicast_vrf_all_helper(struct vty *vty)
 
        return CMD_SUCCESS;
 }
+
+int pim_show_multicast_count_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_multicast_interfaces(pim, vty, json_parent);
+
+       if (json)
+               vty_json(vty, json_parent);
+
+       return CMD_SUCCESS;
+}
+
+int pim_show_multicast_count_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_multicast_interfaces(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 ceba2f2b41fa5bb884871460fea3cb44989a80fb..a7fbefb86281ee0d81e640ee8354f4284a76374a 100644 (file)
@@ -152,6 +152,9 @@ int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str,
                                  const char *g_str, bool json);
 int pim_show_multicast_helper(const char *vrf, struct vty *vty);
 int pim_show_multicast_vrf_all_helper(struct vty *vty);
+int pim_show_multicast_count_helper(const char *vrf, struct vty *vty,
+                                   bool json);
+int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json);
 
 /*
  * Special Macro to allow us to get the correct pim_instance;