pim6d: Moving reusable code to common api for "show ip/ipv6 mroute" command

Signed-off-by: Abhishek N R <abnr@vmware.com>
This commit is contained in:
Abhishek N R 2022-06-09 04:27:20 -07:00
parent 334d2f8c3d
commit 4f1f8ff9aa
4 changed files with 72 additions and 112 deletions

View file

@ -1381,40 +1381,7 @@ DEFPY (show_ipv6_mroute,
"Fill in Assumed data\n" "Fill in Assumed data\n"
JSON_STR) JSON_STR)
{ {
pim_sgaddr sg = {0}; return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!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();
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;
} }
DEFPY (show_ipv6_mroute_vrf_all, DEFPY (show_ipv6_mroute_vrf_all,
@ -1427,28 +1394,7 @@ DEFPY (show_ipv6_mroute_vrf_all,
"Fill in Assumed data\n" "Fill in Assumed data\n"
JSON_STR) JSON_STR)
{ {
pim_sgaddr sg = {0}; return pim_show_mroute_vrf_all_helper(vty, !!fill, !!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(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;
} }
DEFPY (show_ipv6_mroute_count, DEFPY (show_ipv6_mroute_count,

View file

@ -3369,40 +3369,7 @@ DEFPY (show_ip_mroute,
"Fill in Assumed data\n" "Fill in Assumed data\n"
JSON_STR) JSON_STR)
{ {
pim_sgaddr sg = {0}; return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!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();
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;
} }
DEFPY (show_ip_mroute_vrf_all, DEFPY (show_ip_mroute_vrf_all,
@ -3415,28 +3382,7 @@ DEFPY (show_ip_mroute_vrf_all,
"Fill in Assumed data\n" "Fill in Assumed data\n"
JSON_STR) JSON_STR)
{ {
pim_sgaddr sg = {0}; return pim_show_mroute_vrf_all_helper(vty, !!fill, !!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(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;
} }
DEFPY (clear_ip_mroute_count, DEFPY (clear_ip_mroute_count,

View file

@ -4170,3 +4170,68 @@ int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json)
return CMD_SUCCESS; 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;
}

View file

@ -155,6 +155,9 @@ int pim_show_multicast_vrf_all_helper(struct vty *vty);
int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, int pim_show_multicast_count_helper(const char *vrf, struct vty *vty,
bool json); bool json);
int pim_show_multicast_count_vrf_all_helper(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);
/* /*
* Special Macro to allow us to get the correct pim_instance; * Special Macro to allow us to get the correct pim_instance;