Adding new show CLI to display pim RPF information.
Also corrected ipv4 json object.
Signed-off-by: Abhishek N R <abnr@vmware.com>
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);
&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);
}
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
"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
"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;
}
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");
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];
}
}
-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");
&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];
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)
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);
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;