]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pim6d: Adding "show ipv6 pim local-membership"
authorSai Gomathi N <nsaigomathi@vmware.com>
Wed, 2 Mar 2022 06:15:32 +0000 (22:15 -0800)
committerSai Gomathi N <nsaigomathi@vmware.com>
Mon, 4 Apr 2022 07:52:03 +0000 (00:52 -0700)
Adding the new cli to display pim local membership information.
Changing DEFUN to DEPFY for "show ip pim local-membership"

Signed-off-by: Sai Gomathi N <nsaigomathi@vmware.com>
pimd/pim6_cmd.c
pimd/pim_cmd.c
pimd/pim_cmd_common.c

index 636999c4b754437e45fb343d98ac328a2e8dd898..a1a6d9d3f1ffb0cab6a2b7d9d28cf90c30c5bdd0 100644 (file)
@@ -1283,6 +1283,29 @@ DEFPY (show_ipv6_pim_jp_agg,
        return CMD_SUCCESS;
 }
 
+DEFPY (show_ipv6_pim_local_membership,
+       show_ipv6_pim_local_membership_cmd,
+       "show ipv6 pim [vrf NAME] local-membership [json$json]",
+       SHOW_STR
+       IPV6_STR
+       PIM_STR
+       VRF_CMD_HELP_STR
+       "PIM interface local-membership\n"
+       JSON_STR)
+{
+       struct vrf *v;
+       bool uj = !!json;
+
+       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+       if (!v)
+               return CMD_WARNING;
+
+       pim_show_membership(v->info, vty, uj);
+
+       return CMD_SUCCESS;
+}
+
 void pim_cmd_init(void)
 {
        if_cmd_init(pim_interface_config_write);
@@ -1353,4 +1376,5 @@ void pim_cmd_init(void)
        install_element(VIEW_NODE, &show_ipv6_pim_join_cmd);
        install_element(VIEW_NODE, &show_ipv6_pim_join_vrf_all_cmd);
        install_element(VIEW_NODE, &show_ipv6_pim_jp_agg_cmd);
+       install_element(VIEW_NODE, &show_ipv6_pim_local_membership_cmd);
 }
index c064be159f449d8cd900c5528845d3d3a12c101f..bd7e24bd0a3221b000a10ba0a3d94f13426620c7 100644 (file)
@@ -2693,9 +2693,9 @@ DEFPY (show_ip_pim_jp_agg,
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_pim_local_membership,
+DEFPY (show_ip_pim_local_membership,
        show_ip_pim_local_membership_cmd,
-       "show ip pim [vrf NAME] local-membership [json]",
+       "show ip pim [vrf NAME] local-membership [json$json]",
        SHOW_STR
        IP_STR
        PIM_STR
@@ -2703,14 +2703,15 @@ DEFUN (show_ip_pim_local_membership,
        "PIM interface local-membership\n"
        JSON_STR)
 {
-       int idx = 2;
-       struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
-       bool uj = use_json(argc, argv);
+       struct vrf *v;
+       bool uj = !!json;
 
-       if (!vrf)
+       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+       if (!v)
                return CMD_WARNING;
 
-       pim_show_membership(vrf->info, vty, uj);
+       pim_show_membership(v->info, vty, uj);
 
        return CMD_SUCCESS;
 }
index b859e4a4720a03c49a6f062e5bef6e08e9761696..441a00816568932ec49dd9c75f1545cf3b794152 100644 (file)
@@ -1728,7 +1728,6 @@ static void pim_show_membership_helper(struct vty *vty,
                                       struct pim_ifchannel *ch,
                                       struct json_object *json)
 {
-       char ch_grp_str[PIM_ADDRSTRLEN];
        json_object *json_iface = NULL;
        json_object *json_row = NULL;
 
@@ -1739,16 +1738,14 @@ static void pim_show_membership_helper(struct vty *vty,
                json_object_object_add(json, ch->interface->name, json_iface);
        }
 
-       snprintfrr(ch_grp_str, sizeof(ch_grp_str), "%pPAs", &ch->sg.grp);
-
        json_row = json_object_new_object();
        json_object_string_addf(json_row, "source", "%pPAs", &ch->sg.src);
-       json_object_string_add(json_row, "group", ch_grp_str);
+       json_object_string_addf(json_row, "group", "%pPAs", &ch->sg.grp);
        json_object_string_add(json_row, "localMembership",
                               ch->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO
-                                          ? "NOINFO"
-                                          : "INCLUDE");
-       json_object_object_add(json_iface, ch_grp_str, json_row);
+                                      ? "NOINFO"
+                                      : "INCLUDE");
+       json_object_object_addf(json_iface, json_row, "%pPAs", &ch->sg.grp);
 }
 
 void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
@@ -1773,8 +1770,7 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
        }
 
        if (uj) {
-               vty_out(vty, "%s\n", json_object_to_json_string_ext(
-                               json, JSON_C_TO_STRING_PRETTY));
+               vty_json(vty, json);
        } else {
                vty_out(vty,
                        "Interface         Address          Source           Group            Membership\n");
@@ -1841,9 +1837,8 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
                                }
                        }
                }
+               json_object_free(json);
        }
-
-       json_object_free(json);
 }
 
 static void pim_show_channel_helper(struct pim_instance *pim, struct vty *vty,