summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <donaldsharp72@gmail.com>2022-06-12 08:06:01 -0400
committerGitHub <noreply@github.com>2022-06-12 08:06:01 -0400
commitdb28205528db7b67c53c437c4a0c8f52f492225e (patch)
treec09faa7fbb43ac08dac8cb2ba0e1f6c7e0424489
parentf52dd7f9eed66340072bb582b3f4750e754c72bb (diff)
parent789d0ec4def92ec1fe6a0d24d5eefe7ba8f0fd0f (diff)
Merge pull request #11385 from AbhishekNR/show_cli
pimd, pim6d: Moving reusable code to common api for show CLI's.
-rw-r--r--pimd/pim6_cmd.c543
-rw-r--r--pimd/pim_cmd.c542
-rw-r--r--pimd/pim_cmd_common.c611
-rw-r--r--pimd/pim_cmd_common.h31
4 files changed, 690 insertions, 1037 deletions
diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c
index 5adeb51c19..fea83f37b6 100644
--- a/pimd/pim6_cmd.c
+++ b/pimd/pim6_cmd.c
@@ -790,40 +790,8 @@ DEFPY (show_ipv6_pim_rp,
"Multicast Group range\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- json_object *json_parent = NULL;
- struct prefix *range = 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 (group_str) {
- range = prefix_new();
- prefix_copy(range, group);
- apply_mask(range);
- }
-
- if (json)
- json_parent = json_object_new_object();
-
- pim_rp_show_information(pim, range, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- prefix_free(&range);
-
- return CMD_SUCCESS;
+ return pim_show_rp_helper(vrf, vty, group_str, (struct prefix *)group,
+ !!json);
}
DEFPY (show_ipv6_pim_rp_vrf_all,
@@ -837,36 +805,8 @@ DEFPY (show_ipv6_pim_rp_vrf_all,
"Multicast Group range\n"
JSON_STR)
{
- struct vrf *vrf;
- json_object *json_parent = NULL;
- json_object *json_vrf = NULL;
- struct prefix *range = NULL;
-
- if (group_str) {
- range = prefix_new();
- prefix_copy(range, group);
- apply_mask(range);
- }
-
- 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_rp_show_information(vrf->info, range, vty, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- prefix_free(&range);
-
- return CMD_SUCCESS;
+ return pim_show_rp_vrf_all_helper(vty, group_str,
+ (struct prefix *)group, !!json);
}
DEFPY (show_ipv6_pim_rpf,
@@ -879,31 +819,7 @@ DEFPY (show_ipv6_pim_rpf,
"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;
+ return pim_show_rpf_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_pim_rpf_vrf_all,
@@ -916,27 +832,7 @@ DEFPY (show_ipv6_pim_rpf_vrf_all,
"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;
+ return pim_show_rpf_vrf_all_helper(vty, !!json);
}
DEFPY (show_ipv6_pim_secondary,
@@ -948,24 +844,7 @@ DEFPY (show_ipv6_pim_secondary,
VRF_CMD_HELP_STR
"PIM neighbor addresses\n")
{
- struct pim_instance *pim;
- struct vrf *v;
-
- 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;
- }
-
- pim_show_neighbors_secondary(pim, vty);
-
- return CMD_SUCCESS;
+ return pim_show_secondary_helper(vrf, vty);
}
DEFPY (show_ipv6_pim_statistics,
@@ -980,28 +859,7 @@ DEFPY (show_ipv6_pim_statistics,
"PIM interface\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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 (word)
- pim_show_statistics(pim, vty, word, uj);
- else
- pim_show_statistics(pim, vty, NULL, uj);
-
- return CMD_SUCCESS;
+ return pim_show_statistics_helper(vrf, vty, word, !!json);
}
DEFPY (show_ipv6_pim_upstream,
@@ -1016,42 +874,7 @@ DEFPY (show_ipv6_pim_upstream,
"The Group\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- struct vrf *v;
- bool uj = !!json;
- struct pim_instance *pim;
- json_object *json_parent = NULL;
-
- v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
-
- if (!v) {
- vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
- 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 (uj)
- json_parent = json_object_new_object();
-
- if (!pim_addr_is_any(s_or_g)) {
- if (!pim_addr_is_any(g)) {
- sg.src = s_or_g;
- sg.grp = g;
- } else
- sg.grp = s_or_g;
- }
-
- pim_show_upstream(pim, vty, &sg, json_parent);
-
- if (uj)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json);
}
DEFPY (show_ipv6_pim_upstream_vrf_all,
@@ -1064,29 +887,7 @@ DEFPY (show_ipv6_pim_upstream_vrf_all,
"PIM upstream information\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_upstream(vrf->info, vty, &sg, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_vrf_all_helper(vty, !!json);
}
DEFPY (show_ipv6_pim_upstream_join_desired,
@@ -1099,25 +900,7 @@ DEFPY (show_ipv6_pim_upstream_join_desired,
"PIM upstream join-desired\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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;
- }
-
- pim_show_join_desired(pim, vty, uj);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_join_desired_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_pim_upstream_rpf,
@@ -1130,25 +913,7 @@ DEFPY (show_ipv6_pim_upstream_rpf,
"PIM upstream source rpf\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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;
- }
-
- pim_show_upstream_rpf(pim, vty, uj);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_rpf_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_pim_state,
@@ -1163,31 +928,7 @@ DEFPY (show_ipv6_pim_state,
"Multicast address\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_state(pim, vty, s_or_g_str, g_str, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_state_helper(vrf, vty, s_or_g_str, g_str, !!json);
}
DEFPY (show_ipv6_pim_state_vrf_all,
@@ -1202,27 +943,7 @@ DEFPY (show_ipv6_pim_state_vrf_all,
"Multicast address\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_state(vrf->info, vty, s_or_g_str, g_str, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_state_vrf_all_helper(vty, s_or_g_str, g_str, !!json);
}
DEFPY (show_ipv6_pim_channel,
@@ -1387,24 +1108,7 @@ DEFPY (show_ipv6_multicast,
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
- struct vrf *v;
- struct pim_instance *pim;
-
- 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;
- }
-
- pim_cmd_show_ip_multicast_helper(pim, vty);
-
- return CMD_SUCCESS;
+ return pim_show_multicast_helper(vrf, vty);
}
DEFPY (show_ipv6_multicast_vrf_all,
@@ -1415,14 +1119,7 @@ DEFPY (show_ipv6_multicast_vrf_all,
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
- struct vrf *vrf;
-
- RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
- vty_out(vty, "VRF: %s\n", vrf->name);
- pim_cmd_show_ip_multicast_helper(vrf->info, vty);
- }
-
- return CMD_SUCCESS;
+ return pim_show_multicast_vrf_all_helper(vty);
}
DEFPY (show_ipv6_multicast_count,
@@ -1435,31 +1132,7 @@ DEFPY (show_ipv6_multicast_count,
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;
+ return pim_show_multicast_count_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_multicast_count_vrf_all,
@@ -1472,28 +1145,7 @@ DEFPY (show_ipv6_multicast_count_vrf_all,
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;
+ return pim_show_multicast_count_vrf_all_helper(vty, !!json);
}
DEFPY (show_ipv6_mroute,
@@ -1508,40 +1160,7 @@ DEFPY (show_ipv6_mroute,
"Fill in Assumed data\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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();
-
- if (!pim_addr_is_any(s_or_g)) {
- if (!pim_addr_is_any(g)) {
- sg.src = s_or_g;
- sg.grp = g;
- } else
- sg.grp = s_or_g;
- }
-
- show_mroute(pim, vty, &sg, !!fill, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!json);
}
DEFPY (show_ipv6_mroute_vrf_all,
@@ -1554,28 +1173,7 @@ DEFPY (show_ipv6_mroute_vrf_all,
"Fill in Assumed data\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_mroute(vrf->info, vty, &sg, !!fill, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_vrf_all_helper(vty, !!fill, !!json);
}
DEFPY (show_ipv6_mroute_count,
@@ -1588,31 +1186,7 @@ DEFPY (show_ipv6_mroute_count,
"Route and packet count data\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();
-
- show_mroute_count(pim, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_count_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_mroute_count_vrf_all,
@@ -1625,29 +1199,7 @@ DEFPY (show_ipv6_mroute_count_vrf_all,
"Route and packet count data\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();
- show_mroute_count(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;
+ return pim_show_mroute_count_vrf_all_helper(vty, !!json);
}
DEFPY (show_ipv6_mroute_summary,
@@ -1660,31 +1212,7 @@ DEFPY (show_ipv6_mroute_summary,
"Summary of all mroutes\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();
-
- show_mroute_summary(pim, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_summary_helper(vrf, vty, !!json);
}
DEFPY (show_ipv6_mroute_summary_vrf_all,
@@ -1697,30 +1225,7 @@ DEFPY (show_ipv6_mroute_summary_vrf_all,
"Summary of all mroutes\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();
-
- show_mroute_summary(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;
+ return pim_show_mroute_summary_vrf_all_helper(vty, !!json);
}
DEFPY (clear_ipv6_pim_statistics,
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 9766a38c15..b387783e85 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -2802,24 +2802,7 @@ DEFPY (show_ip_pim_secondary,
VRF_CMD_HELP_STR
"PIM neighbor addresses\n")
{
- struct pim_instance *pim;
- struct vrf *v;
-
- 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;
- }
-
- pim_show_neighbors_secondary(pim, vty);
-
- return CMD_SUCCESS;
+ return pim_show_secondary_helper(vrf, vty);
}
DEFPY (show_ip_pim_state,
@@ -2834,31 +2817,7 @@ DEFPY (show_ip_pim_state,
"Multicast address\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_state(pim, vty, s_or_g_str, g_str, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_state_helper(vrf, vty, s_or_g_str, g_str, !!json);
}
DEFPY (show_ip_pim_state_vrf_all,
@@ -2873,27 +2832,7 @@ DEFPY (show_ip_pim_state_vrf_all,
"Multicast address\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_state(vrf->info, vty, s_or_g_str, g_str, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_state_vrf_all_helper(vty, s_or_g_str, g_str, !!json);
}
DEFPY (show_ip_pim_upstream,
@@ -2908,41 +2847,7 @@ DEFPY (show_ip_pim_upstream,
"The Group\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- struct vrf *v;
- bool uj = !!json;
- struct pim_instance *pim;
- json_object *json_parent = NULL;
-
- v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
-
- if (!v) {
- vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
- 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 (uj)
- json_parent = json_object_new_object();
-
- if (s_or_g.s_addr != INADDR_ANY) {
- if (g.s_addr != INADDR_ANY) {
- sg.src = s_or_g;
- sg.grp = g;
- } else
- sg.grp = s_or_g;
- }
- pim_show_upstream(pim, vty, &sg, json_parent);
-
- if (uj)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json);
}
DEFPY (show_ip_pim_upstream_vrf_all,
@@ -2955,29 +2860,7 @@ DEFPY (show_ip_pim_upstream_vrf_all,
"PIM upstream information\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_upstream(vrf->info, vty, &sg, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_vrf_all_helper(vty, !!json);
}
DEFPY (show_ip_pim_channel,
@@ -3003,25 +2886,7 @@ DEFPY (show_ip_pim_upstream_join_desired,
"PIM upstream join-desired\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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;
- }
-
- pim_show_join_desired(pim, vty, uj);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_join_desired_helper(vrf, vty, !!json);
}
DEFPY (show_ip_pim_upstream_rpf,
@@ -3034,25 +2899,7 @@ DEFPY (show_ip_pim_upstream_rpf,
"PIM upstream source rpf\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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;
- }
-
- pim_show_upstream_rpf(pim, vty, uj);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_rpf_helper(vrf, vty, !!json);
}
DEFPY (show_ip_pim_rp,
@@ -3066,40 +2913,8 @@ DEFPY (show_ip_pim_rp,
"Multicast Group range\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- json_object *json_parent = NULL;
- struct prefix *range = 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 (group_str) {
- range = prefix_new();
- prefix_copy(range, group);
- apply_mask(range);
- }
-
- if (json)
- json_parent = json_object_new_object();
-
- pim_rp_show_information(pim, range, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- prefix_free(&range);
-
- return CMD_SUCCESS;
+ return pim_show_rp_helper(vrf, vty, group_str, (struct prefix *)group,
+ !!json);
}
DEFPY (show_ip_pim_rp_vrf_all,
@@ -3113,36 +2928,8 @@ DEFPY (show_ip_pim_rp_vrf_all,
"Multicast Group range\n"
JSON_STR)
{
- struct vrf *vrf;
- json_object *json_parent = NULL;
- json_object *json_vrf = NULL;
- struct prefix *range = NULL;
-
- if (group_str) {
- range = prefix_new();
- prefix_copy(range, group);
- apply_mask(range);
- }
-
- 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_rp_show_information(vrf->info, range, vty, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- prefix_free(&range);
-
- return CMD_SUCCESS;
+ return pim_show_rp_vrf_all_helper(vty, group_str,
+ (struct prefix *)group, !!json);
}
DEFPY (show_ip_pim_rpf,
@@ -3155,31 +2942,7 @@ DEFPY (show_ip_pim_rpf,
"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;
+ return pim_show_rpf_helper(vrf, vty, !!json);
}
DEFPY (show_ip_pim_rpf_vrf_all,
@@ -3192,27 +2955,7 @@ DEFPY (show_ip_pim_rpf_vrf_all,
"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;
+ return pim_show_rpf_vrf_all_helper(vty, !!json);
}
DEFPY (show_ip_pim_nexthop,
@@ -3324,28 +3067,7 @@ DEFPY (show_ip_pim_statistics,
"PIM interface\n"
JSON_STR)
{
- struct pim_instance *pim;
- struct vrf *v;
- bool uj = !!json;
-
- 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 (word)
- pim_show_statistics(pim, vty, word, uj);
- else
- pim_show_statistics(pim, vty, NULL, uj);
-
- return CMD_SUCCESS;
+ return pim_show_statistics_helper(vrf, vty, word, !!json);
}
DEFPY (show_ip_multicast,
@@ -3356,24 +3078,7 @@ DEFPY (show_ip_multicast,
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
- struct vrf *v;
- struct pim_instance *pim;
-
- 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;
- }
-
- pim_cmd_show_ip_multicast_helper(pim, vty);
-
- return CMD_SUCCESS;
+ return pim_show_multicast_helper(vrf, vty);
}
DEFPY (show_ip_multicast_vrf_all,
@@ -3384,14 +3089,7 @@ DEFPY (show_ip_multicast_vrf_all,
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
- struct vrf *vrf;
-
- RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
- vty_out(vty, "VRF: %s\n", vrf->name);
- pim_cmd_show_ip_multicast_helper(vrf->info, vty);
- }
-
- return CMD_SUCCESS;
+ return pim_show_multicast_vrf_all_helper(vty);
}
DEFPY (show_ip_multicast_count,
@@ -3404,31 +3102,7 @@ DEFPY (show_ip_multicast_count,
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;
+ return pim_show_multicast_count_helper(vrf, vty, !!json);
}
DEFPY (show_ip_multicast_count_vrf_all,
@@ -3441,28 +3115,7 @@ DEFPY (show_ip_multicast_count_vrf_all,
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;
+ return pim_show_multicast_count_vrf_all_helper(vty, !!json);
}
DEFPY (show_ip_mroute,
@@ -3477,40 +3130,7 @@ DEFPY (show_ip_mroute,
"Fill in Assumed data\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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();
-
- if (s_or_g.s_addr != INADDR_ANY) {
- if (g.s_addr != INADDR_ANY) {
- sg.src = s_or_g;
- sg.grp = g;
- } else
- sg.grp = s_or_g;
- }
-
- show_mroute(pim, vty, &sg, !!fill, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!json);
}
DEFPY (show_ip_mroute_vrf_all,
@@ -3523,28 +3143,7 @@ DEFPY (show_ip_mroute_vrf_all,
"Fill in Assumed data\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_mroute(vrf->info, vty, &sg, !!fill, json_vrf);
- if (json)
- json_object_object_add(json_parent, vrf->name,
- json_vrf);
- }
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_vrf_all_helper(vty, !!fill, !!json);
}
DEFPY (clear_ip_mroute_count,
@@ -3569,31 +3168,7 @@ DEFPY (show_ip_mroute_count,
"Route and packet count data\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();
-
- show_mroute_count(pim, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_count_helper(vrf, vty, !!json);
}
DEFPY (show_ip_mroute_count_vrf_all,
@@ -3606,29 +3181,7 @@ DEFPY (show_ip_mroute_count_vrf_all,
"Route and packet count data\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();
-
- show_mroute_count(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;
+ return pim_show_mroute_count_vrf_all_helper(vty, !!json);
}
DEFPY (show_ip_mroute_summary,
@@ -3641,31 +3194,7 @@ DEFPY (show_ip_mroute_summary,
"Summary of all mroutes\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();
-
- show_mroute_summary(pim, vty, json_parent);
-
- if (json)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_mroute_summary_helper(vrf, vty, !!json);
}
DEFPY (show_ip_mroute_summary_vrf_all,
@@ -3678,30 +3207,7 @@ DEFPY (show_ip_mroute_summary_vrf_all,
"Summary of all mroutes\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();
-
- show_mroute_summary(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;
+ return pim_show_mroute_summary_vrf_all_helper(vty, !!json);
}
DEFUN (show_ip_rib,
diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c
index 8e93597118..559aa7ec03 100644
--- a/pimd/pim_cmd_common.c
+++ b/pimd/pim_cmd_common.c
@@ -4035,3 +4035,614 @@ int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins,
return CMD_SUCCESS;
}
+
+int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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;
+}
+
+int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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;
+}
+
+int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+ json_object *json_parent = NULL;
+ struct prefix *range = 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 (group_str) {
+ range = prefix_new();
+ prefix_copy(range, group);
+ apply_mask(range);
+ }
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ pim_rp_show_information(pim, range, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ prefix_free(&range);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json)
+{
+ struct vrf *vrf;
+ json_object *json_parent = NULL;
+ json_object *json_vrf = NULL;
+ struct prefix *range = NULL;
+
+ if (group_str) {
+ range = prefix_new();
+ prefix_copy(range, group);
+ apply_mask(range);
+ }
+
+ 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_rp_show_information(vrf->info, range, vty, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ prefix_free(&range);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_secondary_helper(const char *vrf, struct vty *vty)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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;
+ }
+
+ pim_show_neighbors_secondary(pim, vty);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_statistics_helper(const char *vrf, struct vty *vty,
+ const char *word, bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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 (word)
+ pim_show_statistics(pim, vty, word, uj);
+ else
+ pim_show_statistics(pim, vty, NULL, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool json)
+{
+ pim_sgaddr sg = {0};
+ struct vrf *v;
+ struct pim_instance *pim;
+ json_object *json_parent = NULL;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v) {
+ vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
+ 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();
+
+ if (!pim_addr_is_any(s_or_g)) {
+ if (!pim_addr_is_any(g)) {
+ sg.src = s_or_g;
+ sg.grp = g;
+ } else
+ sg.grp = s_or_g;
+ }
+
+ pim_show_upstream(pim, vty, &sg, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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_upstream(vrf->info, vty, &sg, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty,
+ bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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;
+ }
+
+ pim_show_join_desired(pim, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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;
+ }
+
+ pim_show_upstream_rpf(pim, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_state_helper(const char *vrf, struct vty *vty,
+ const char *s_or_g_str, const char *g_str, bool json)
+{
+ 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_state(pim, vty, s_or_g_str, g_str, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str,
+ const char *g_str, bool json)
+{
+ 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_state(vrf->info, vty, s_or_g_str, g_str, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_multicast_helper(const char *vrf, struct vty *vty)
+{
+ struct vrf *v;
+ struct pim_instance *pim;
+
+ 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;
+ }
+
+ pim_cmd_show_ip_multicast_helper(pim, vty);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_multicast_vrf_all_helper(struct vty *vty)
+{
+ struct vrf *vrf;
+
+ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+ vty_out(vty, "VRF: %s\n", vrf->name);
+ pim_cmd_show_ip_multicast_helper(vrf->info, vty);
+ }
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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;
+}
+
+int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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;
+}
+
+int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool fill, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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();
+
+ if (!pim_addr_is_any(s_or_g)) {
+ if (!pim_addr_is_any(g)) {
+ sg.src = s_or_g;
+ sg.grp = g;
+ } else
+ sg.grp = s_or_g;
+ }
+
+ show_mroute(pim, vty, &sg, fill, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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_mroute(vrf->info, vty, &sg, fill, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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_mroute_count(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_mroute_count(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;
+}
+
+int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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_mroute_summary(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_mroute_summary(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;
+}
diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h
index e3d1a68652..e1e48dd24a 100644
--- a/pimd/pim_cmd_common.h
+++ b/pimd/pim_cmd_common.h
@@ -148,6 +148,37 @@ int pim_debug_pim_packets_cmd(const char *hello, const char *joins,
const char *registers, struct vty *vty);
int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins,
const char *registers, struct vty *vty);
+int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json);
+int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json);
+int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json);
+int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json);
+int pim_show_secondary_helper(const char *vrf, struct vty *vty);
+int pim_show_statistics_helper(const char *vrf, struct vty *vty,
+ const char *word, bool uj);
+int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool json);
+int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json);
+int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty,
+ bool uj);
+int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj);
+int pim_show_state_helper(const char *vrf, struct vty *vty,
+ const char *s_or_g_str, const char *g_str, bool json);
+int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str,
+ const char *g_str, bool json);
+int pim_show_multicast_helper(const char *vrf, struct vty *vty);
+int pim_show_multicast_vrf_all_helper(struct vty *vty);
+int pim_show_multicast_count_helper(const char *vrf, struct vty *vty,
+ bool json);
+int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json);
+int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool fill, bool json);
+int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json);
+int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json);
+int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json);
+int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json);
+int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json);
/*
* Special Macro to allow us to get the correct pim_instance;