]> git.puffer.fish Git - mirror/frr.git/commitdiff
pim6d: Implementing "show ipv6 pim rpf" CLI
authorAbhishek N R <abnr@vmware.com>
Fri, 4 Mar 2022 07:56:19 +0000 (23:56 -0800)
committerAbhishek N R <abnr@vmware.com>
Tue, 29 Mar 2022 06:53:24 +0000 (23:53 -0700)
Adding new show CLI to display pim RPF information.

Also corrected ipv4 json object.

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 251d62058bf68e925756c5496e94888f24638773..7cbd949286e00d95b008ad8e6ada8da3cf7beafe 100644 (file)
@@ -712,6 +712,76 @@ DEFPY (show_ipv6_pim_rp_vrf_all,
        return CMD_SUCCESS;
 }
 
+DEFPY (show_ipv6_pim_rpf,
+       show_ipv6_pim_rpf_cmd,
+       "show ipv6 pim [vrf NAME] rpf [json$json]",
+       SHOW_STR
+       IPV6_STR
+       PIM_STR
+       VRF_CMD_HELP_STR
+       "PIM cached source rpf information\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();
+
+       pim_show_rpf(pim, vty, json_parent);
+
+       if (json)
+               vty_json(vty, json_parent);
+
+       return CMD_SUCCESS;
+}
+
+DEFPY (show_ipv6_pim_rpf_vrf_all,
+       show_ipv6_pim_rpf_vrf_all_cmd,
+       "show ipv6 pim vrf all rpf [json$json]",
+       SHOW_STR
+       IPV6_STR
+       PIM_STR
+       VRF_CMD_HELP_STR
+       "PIM cached source rpf information\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();
+               pim_show_rpf(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);
@@ -766,4 +836,6 @@ void pim_cmd_init(void)
                        &interface_no_ipv6_mld_query_interval_cmd);
        install_element(VIEW_NODE, &show_ipv6_pim_rp_cmd);
        install_element(VIEW_NODE, &show_ipv6_pim_rp_vrf_all_cmd);
+       install_element(VIEW_NODE, &show_ipv6_pim_rpf_cmd);
+       install_element(VIEW_NODE, &show_ipv6_pim_rpf_vrf_all_cmd);
 }
index aa1ff5c925e39f5180aeebd09d7c269a7db5cc60..866be774040f1de0425dbec754d342c4fe4273fd 100644 (file)
@@ -4631,9 +4631,9 @@ DEFPY (show_ip_pim_rp_vrf_all,
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_pim_rpf,
+DEFPY (show_ip_pim_rpf,
        show_ip_pim_rpf_cmd,
-       "show ip pim [vrf NAME] rpf [json]",
+       "show ip pim [vrf NAME] rpf [json$json]",
        SHOW_STR
        IP_STR
        PIM_STR
@@ -4641,21 +4641,36 @@ DEFUN (show_ip_pim_rpf,
        "PIM cached source rpf information\n"
        JSON_STR)
 {
-       int idx = 2;
-       struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
-       bool uj = use_json(argc, argv);
+       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;
+
+       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();
+
+       pim_show_rpf(pim, vty, json_parent);
 
-       pim_show_rpf(vrf->info, vty, uj);
+       if (json)
+               vty_json(vty, json_parent);
 
        return CMD_SUCCESS;
 }
 
-DEFUN (show_ip_pim_rpf_vrf_all,
+DEFPY (show_ip_pim_rpf_vrf_all,
        show_ip_pim_rpf_vrf_all_cmd,
-       "show ip pim vrf all rpf [json]",
+       "show ip pim vrf all rpf [json$json]",
        SHOW_STR
        IP_STR
        PIM_STR
@@ -4663,24 +4678,25 @@ DEFUN (show_ip_pim_rpf_vrf_all,
        "PIM cached source rpf information\n"
        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 (json)
+               json_parent = json_object_new_object();
 
-       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
+               if (!json)
                        vty_out(vty, "VRF: %s\n", vrf->name);
-               pim_show_rpf(vrf->info, vty, uj);
+               else
+                       json_vrf = json_object_new_object();
+               pim_show_rpf(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;
 }
@@ -4998,7 +5014,7 @@ static void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
 
        vty_out(vty, "\n");
 
-       show_rpf_refresh_stats(vty, pim, now, NULL);
+       pim_show_rpf_refresh_stats(vty, pim, now, NULL);
 
        vty_out(vty, "\n");
 
index 6894556bfab3c5339e4675318d383f9ff6d1b460..b8c4ef155279cd1462dc760f0bcbdd2706422dc2 100644 (file)
@@ -760,8 +760,8 @@ static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state,
        return state_str;
 }
 
-void show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
-                           time_t now, json_object *json)
+void pim_show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
+                               time_t now, json_object *json)
 {
        char refresh_uptime[10];
 
@@ -802,19 +802,16 @@ void show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
        }
 }
 
-void pim_show_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
+void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json)
 {
        struct pim_upstream *up;
        time_t now = pim_time_monotonic_sec();
-       json_object *json = NULL;
        json_object *json_group = NULL;
        json_object *json_row = NULL;
 
-       if (uj) {
-               json = json_object_new_object();
-               show_rpf_refresh_stats(vty, pim, now, json);
-       } else {
-               show_rpf_refresh_stats(vty, pim, now, json);
+       pim_show_rpf_refresh_stats(vty, pim, now, json);
+
+       if (!json) {
                vty_out(vty, "\n");
                vty_out(vty,
                        "Source          Group           RpfIface         RpfAddress      RibNextHop      Metric Pref\n");
@@ -832,9 +829,12 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
                              &rpf->source_nexthop.mrib_nexthop_addr,
                              rib_nexthop_str, sizeof(rib_nexthop_str));
 
-               rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
+               rpf_ifname =
+                       rpf->source_nexthop.interface ? rpf->source_nexthop
+                                                               .interface->name
+                                                     : "<ifname?>";
 
-               if (uj) {
+               if (json) {
                        char grp_str[PIM_ADDRSTRLEN];
                        char src_str[PIM_ADDRSTRLEN];
 
@@ -869,16 +869,14 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
                        json_object_object_add(json_group, src_str, json_row);
 
                } else {
-                       vty_out(vty, "%-15pPAs %-15pPAs %-16s %-15s %-15s %6d %4d\n",
+                       vty_out(vty,
+                               "%-15pPAs %-15pPAs %-16s %-15s %-15s %6d %4d\n",
                                &up->sg.src, &up->sg.grp, rpf_ifname,
                                rpf_addr_str, rib_nexthop_str,
                                rpf->source_nexthop.mrib_route_metric,
                                rpf->source_nexthop.mrib_metric_preference);
                }
        }
-
-       if (uj)
-               vty_json(vty, json);
 }
 
 void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty)
index 6034df68283ee8c479af565597e8d358d43c90e6..4d80e24329144833a9e7877191877c40ef8f5db7 100644 (file)
@@ -59,7 +59,7 @@ int pim_process_ip_mroute_cmd(struct vty *vty, const char *interface,
 int pim_process_no_ip_mroute_cmd(struct vty *vty, const char *interface,
                                 const char *group_str, const char *src_str);
 void json_object_pim_upstream_add(json_object *json, struct pim_upstream *up);
-void pim_show_rpf(struct pim_instance *pim, struct vty *vty, bool uj);
+void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json);
 void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty);
 void pim_show_state(struct pim_instance *pim, struct vty *vty,
                    const char *src_or_group, const char *group, bool uj);
@@ -69,8 +69,8 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty,
                       pim_sgaddr *sg, bool uj);
 void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj);
 void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj);
-void show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
-                           time_t now, json_object *json);
+void pim_show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
+                               time_t now, json_object *json);
 
 /*
  * Special Macro to allow us to get the correct pim_instance;