]> git.proxmox.com Git - mirror_frr.git/commitdiff
pim6d: Implementing "show ipv6 multicast count" CLI
authorAbhishek N R <abnr@vmware.com>
Thu, 14 Apr 2022 07:07:41 +0000 (00:07 -0700)
committerAbhishek N R <abnr@vmware.com>
Wed, 27 Apr 2022 11:26:35 +0000 (04:26 -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 7f7c3979c73fd2713dc103f2f8e01cc1e8fab552..185ec33f9c55cb45b8ff7f2aa69357f1cfe343b3 100644 (file)
@@ -1615,6 +1615,77 @@ DEFPY (show_ipv6_multicast_vrf_all,
        return CMD_SUCCESS;
 }
 
+DEFPY (show_ipv6_multicast_count,
+       show_ipv6_multicast_count_cmd,
+       "show ipv6 multicast count [vrf NAME] [json$json]",
+       SHOW_STR
+       IPV6_STR
+       "Multicast global information\n"
+       "Data packet count\n"
+       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;
+}
+
+DEFPY (show_ipv6_multicast_count_vrf_all,
+       show_ipv6_multicast_count_vrf_all_cmd,
+       "show ipv6 multicast count vrf all [json$json]",
+       SHOW_STR
+       IPV6_STR
+       "Multicast global information\n"
+       "Data packet count\n"
+       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;
+}
+
 void pim_cmd_init(void)
 {
        if_cmd_init(pim_interface_config_write);
@@ -1713,4 +1784,6 @@ void pim_cmd_init(void)
        install_element(VIEW_NODE, &show_ipv6_pim_nexthop_lookup_cmd);
        install_element(VIEW_NODE, &show_ipv6_multicast_cmd);
        install_element(VIEW_NODE, &show_ipv6_multicast_vrf_all_cmd);
+       install_element(VIEW_NODE, &show_ipv6_multicast_count_cmd);
+       install_element(VIEW_NODE, &show_ipv6_multicast_count_vrf_all_cmd);
 }
index f72353646946987861fefcacc572025aa4baf6b1..0a90d625c219aa11fd77f6899dd55f0817374475 100644 (file)
@@ -3695,56 +3695,73 @@ DEFPY (show_ip_multicast_vrf_all,
        return CMD_SUCCESS;
 }
 
-DEFUN(show_ip_multicast_count,
-      show_ip_multicast_count_cmd,
-      "show ip multicast count [vrf NAME] [json]",
-      SHOW_STR IP_STR
-      "Multicast global information\n"
-      "Data packet count\n"
-      VRF_CMD_HELP_STR JSON_STR)
-{
-       int idx = 3;
-       struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
-       bool uj = use_json(argc, argv);
+DEFPY (show_ip_multicast_count,
+       show_ip_multicast_count_cmd,
+       "show ip multicast count [vrf NAME] [json$json]",
+       SHOW_STR
+       IP_STR
+       "Multicast global information\n"
+       "Data packet count\n"
+       VRF_CMD_HELP_STR
+       JSON_STR)
+{
+       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;
 
-       show_multicast_interfaces(vrf->info, vty, uj);
+       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;
 }
 
-DEFUN(show_ip_multicast_count_vrf_all,
-      show_ip_multicast_count_vrf_all_cmd,
-      "show ip multicast count vrf all [json]",
-      SHOW_STR IP_STR
-      "Multicast global information\n"
-      "Data packet count\n"
-      VRF_CMD_HELP_STR JSON_STR)
+DEFPY (show_ip_multicast_count_vrf_all,
+       show_ip_multicast_count_vrf_all_cmd,
+       "show ip multicast count vrf all [json$json]",
+       SHOW_STR
+       IP_STR
+       "Multicast global information\n"
+       "Data packet count\n"
+       VRF_CMD_HELP_STR
+       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 (uj)
-               vty_out(vty, "{ ");
+       if (json)
+               json_parent = json_object_new_object();
 
        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);
+               else
+                       json_vrf = json_object_new_object();
 
-               show_multicast_interfaces(vrf->info, vty, uj);
+               show_multicast_interfaces(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;
 }
index 784ef2e311fa19375ce7022471780064a1958817..5bcde48e2ede1358e87f88c352a8c8af1f50231d 100644 (file)
@@ -2882,17 +2882,14 @@ static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty,
 }
 
 void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
-                                     bool uj)
+                              json_object *json)
 {
        struct interface *ifp;
-       json_object *json = NULL;
        json_object *json_row = NULL;
 
        vty_out(vty, "\n");
 
-       if (uj)
-               json = json_object_new_object();
-       else
+       if (!json)
                vty_out(vty,
                        "Interface        Address            ifi Vif  PktsIn PktsOut    BytesIn   BytesOut\n");
 
@@ -2930,7 +2927,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
                }
 #endif
 
-               if (uj) {
+               if (json) {
                        json_row = json_object_new_object();
                        json_object_string_add(json_row, "name", ifp->name);
                        json_object_string_add(json_row, "state",
@@ -2960,9 +2957,6 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
                                (unsigned long)vreq.obytes);
                }
        }
-
-       if (uj)
-               vty_json(vty, json);
 }
 
 void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
@@ -3011,5 +3005,5 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
 
        show_scan_oil_stats(pim, vty, now);
 
-       show_multicast_interfaces(pim, vty, false);
+       show_multicast_interfaces(pim, vty, NULL);
 }
index 5f7021280edd8a9ceb9f1f88629e4595527d562d..9fac2c111b7dc5e14bb20ac3da1658230707fa66 100644 (file)
@@ -107,7 +107,7 @@ int pim_process_ssmpingd_cmd(struct vty *vty, enum nb_operation operation,
 void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
                                      struct vty *vty);
 void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
-                                     bool uj);
+                              json_object *json);
 
 /*
  * Special Macro to allow us to get the correct pim_instance;