]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pim6d: Adding "show ipv6 [vrf|vrf ALL] pim neighbor" command
authorSai Gomathi N <nsaigomathi@vmware.com>
Wed, 2 Mar 2022 09:22:13 +0000 (01:22 -0800)
committerSai Gomathi N <nsaigomathi@vmware.com>
Mon, 4 Apr 2022 07:52:03 +0000 (00:52 -0700)
Adding new show CLI to display regarding pim neighbors.
Changing DEFUN to DEFPY for "show ip pim neighbor" command.

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

index a1a6d9d3f1ffb0cab6a2b7d9d28cf90c30c5bdd0..aa264c4752dbbb36294003d1a36916fe7fd8dc26 100644 (file)
@@ -1306,6 +1306,79 @@ DEFPY (show_ipv6_pim_local_membership,
        return CMD_SUCCESS;
 }
 
+DEFPY (show_ipv6_pim_neighbor,
+       show_ipv6_pim_neighbor_cmd,
+       "show ipv6 pim [vrf NAME] neighbor [detail|WORD]$interface [json$json]",
+       SHOW_STR
+       IPV6_STR
+       PIM_STR
+       VRF_CMD_HELP_STR
+       "PIM neighbor information\n"
+       "Detailed output\n"
+       "Name of interface or neighbor\n"
+       JSON_STR)
+{
+       struct vrf *v;
+       json_object *json_parent = NULL;
+
+       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+       if (!v)
+               return CMD_WARNING;
+
+       if (json)
+               json_parent = json_object_new_object();
+
+       if (interface)
+               pim_show_neighbors_single(v->info, vty, interface, json_parent);
+       else
+               pim_show_neighbors(v->info, vty, json_parent);
+
+       if (json)
+               vty_json(vty, json_parent);
+
+       return CMD_SUCCESS;
+}
+
+DEFPY (show_ipv6_pim_neighbor_vrf_all,
+       show_ipv6_pim_neighbor_vrf_all_cmd,
+       "show ipv6 pim vrf all neighbor [detail|WORD]$interface [json$json]",
+       SHOW_STR
+       IPV6_STR
+       PIM_STR
+       VRF_CMD_HELP_STR
+       "PIM neighbor information\n"
+       "Detailed output\n"
+       "Name of interface or neighbor\n"
+       JSON_STR)
+{
+       struct vrf *v;
+       json_object *json_parent = NULL;
+       json_object *json_vrf = NULL;
+
+       if (json)
+               json_parent = json_object_new_object();
+       RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
+               if (!json)
+                       vty_out(vty, "VRF: %s\n", v->name);
+               else
+                       json_vrf = json_object_new_object();
+
+               if (interface)
+                       pim_show_neighbors_single(v->info, vty, interface,
+                                                 json_vrf);
+               else
+                       pim_show_neighbors(v->info, vty, json_vrf);
+
+               if (json)
+                       json_object_object_add(json_parent, v->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);
@@ -1377,4 +1450,6 @@ void pim_cmd_init(void)
        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);
+       install_element(VIEW_NODE, &show_ipv6_pim_neighbor_cmd);
+       install_element(VIEW_NODE, &show_ipv6_pim_neighbor_vrf_all_cmd);
 }
index bd7e24bd0a3221b000a10ba0a3d94f13426620c7..3b6a62d65b5aca822624b57b0dd54211917a498f 100644 (file)
@@ -2983,9 +2983,9 @@ DEFUN(show_ip_pim_mlag_up_vrf_all, show_ip_pim_mlag_up_vrf_all_cmd,
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_pim_neighbor,
+DEFPY (show_ip_pim_neighbor,
        show_ip_pim_neighbor_cmd,
-       "show ip pim [vrf NAME] neighbor [detail|WORD] [json]",
+       "show ip pim [vrf NAME] neighbor [detail|WORD]$interface [json$json]",
        SHOW_STR
        IP_STR
        PIM_STR
@@ -2995,25 +2995,31 @@ DEFUN (show_ip_pim_neighbor,
        "Name of interface or neighbor\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;
+       json_object *json_parent = NULL;
 
-       if (!vrf)
+       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+       if (!v)
                return CMD_WARNING;
 
-       if (argv_find(argv, argc, "detail", &idx)
-           || argv_find(argv, argc, "WORD", &idx))
-               pim_show_neighbors_single(vrf->info, vty, argv[idx]->arg, uj);
+       if (json)
+               json_parent = json_object_new_object();
+
+       if (interface)
+               pim_show_neighbors_single(v->info, vty, interface, json_parent);
        else
-               pim_show_neighbors(vrf->info, vty, uj);
+               pim_show_neighbors(v->info, vty, json_parent);
+
+       if (json)
+               vty_json(vty, json_parent);
 
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_pim_neighbor_vrf_all,
+DEFPY (show_ip_pim_neighbor_vrf_all,
        show_ip_pim_neighbor_vrf_all_cmd,
-       "show ip pim vrf all neighbor [detail|WORD] [json]",
+       "show ip pim vrf all neighbor [detail|WORD]$interface [json$json]",
        SHOW_STR
        IP_STR
        PIM_STR
@@ -3023,30 +3029,29 @@ DEFUN (show_ip_pim_neighbor_vrf_all,
        "Name of interface or neighbor\n"
        JSON_STR)
 {
-       int idx = 2;
-       bool uj = use_json(argc, argv);
-       struct vrf *vrf;
-       bool first = true;
+       struct vrf *v;
+       json_object *json_parent = NULL;
+       json_object *json_vrf = NULL;
 
-       if (uj)
-               vty_out(vty, "{ ");
-       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
-                       vty_out(vty, "VRF: %s\n", vrf->name);
-               if (argv_find(argv, argc, "detail", &idx)
-                   || argv_find(argv, argc, "WORD", &idx))
-                       pim_show_neighbors_single(vrf->info, vty,
-                                                 argv[idx]->arg, uj);
+       if (json)
+               json_parent = json_object_new_object();
+       RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
+               if (!json)
+                       vty_out(vty, "VRF: %s\n", v->name);
                else
-                       pim_show_neighbors(vrf->info, vty, uj);
+                       json_vrf = json_object_new_object();
+
+               if (interface)
+                       pim_show_neighbors_single(v->info, vty, interface,
+                                                 json_vrf);
+               else
+                       pim_show_neighbors(v->info, vty, json_vrf);
+
+               if (json)
+                       json_object_object_add(json_parent, v->name, json_vrf);
        }
-       if (uj)
-               vty_out(vty, "}\n");
+       if (json)
+               vty_json(vty, json_parent);
 
        return CMD_SUCCESS;
 }
index 441a00816568932ec49dd9c75f1545cf3b794152..0d575a1456d664bd037d839d8680c81a3d1a51cd 100644 (file)
@@ -2677,7 +2677,8 @@ void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty,
                vty_out(vty, "%% No such interface or neighbor\n");
 }
 
-void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj)
+void pim_show_neighbors(struct pim_instance *pim, struct vty *vty,
+                       json_object *json)
 {
        struct listnode *neighnode;
        struct interface *ifp;
@@ -2686,16 +2687,13 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj)
        time_t now;
        char uptime[10];
        char expire[10];
-       char neigh_src_str[INET_ADDRSTRLEN];
-       json_object *json = NULL;
+       char neigh_src_str[PIM_ADDRSTRLEN];
        json_object *json_ifp_rows = NULL;
        json_object *json_row = NULL;
 
        now = pim_time_monotonic_sec();
 
-       if (uj) {
-               json = json_object_new_object();
-       } else {
+       if (!json) {
                vty_out(vty,
                        "Interface                Neighbor    Uptime  Holdtime  DR Pri\n");
        }
@@ -2709,19 +2707,19 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj)
                if (pim_ifp->pim_sock_fd < 0)
                        continue;
 
-               if (uj)
+               if (json)
                        json_ifp_rows = json_object_new_object();
 
                for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
                                          neigh)) {
-                       pim_inet4_dump("<src?>", neigh->source_addr,
-                                      neigh_src_str, sizeof(neigh_src_str));
+                       snprintfrr(neigh_src_str, sizeof(neigh_src_str),
+                                  "%pPAs", &neigh->source_addr);
                        pim_time_uptime(uptime, sizeof(uptime),
                                        now - neigh->creation);
                        pim_time_timer_to_hhmmss(expire, sizeof(expire),
                                                 neigh->t_expire_timer);
 
-                       if (uj) {
+                       if (json) {
                                json_row = json_object_new_object();
                                json_object_string_add(json_row, "interface",
                                                       ifp->name);
@@ -2745,12 +2743,9 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj)
                        }
                }
 
-               if (uj) {
+               if (json) {
                        json_object_object_add(json, ifp->name, json_ifp_rows);
                        json_ifp_rows = NULL;
                }
        }
-
-       if (uj)
-               vty_json(vty, json);
 }
index 13fd40b99bfbf97ce94a05f4df28e320eb27af18..00a9a5673873bf1fc12729729de1de266f99f195 100644 (file)
@@ -90,8 +90,9 @@ void ip_pim_ssm_show_group_range(struct pim_instance *pim, struct vty *vty,
                                 bool uj);
 void pim_show_nexthop(struct pim_instance *pim, struct vty *vty);
 void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty,
-                              const char *neighbor, bool uj);
-void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj);
+                              const char *neighbor, json_object *json);
+void pim_show_neighbors(struct pim_instance *pim, struct vty *vty,
+                       json_object *json);
 /*
  * Special Macro to allow us to get the correct pim_instance
  */