Skip to content

Commit

Permalink
pim6d: Implementing "show ipv6 mroute summary" CLI
Browse files Browse the repository at this point in the history
Adding new show CLI to display ipv6 mroute summary information.

Signed-off-by: Abhishek N R <abnr@vmware.com>
  • Loading branch information
AbhishekNR committed Apr 28, 2022
1 parent c41a9dc commit 74e8197
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 38 deletions.
75 changes: 75 additions & 0 deletions pimd/pim6_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,79 @@ DEFPY (show_ipv6_mroute_count_vrf_all,
return CMD_SUCCESS;
}

DEFPY (show_ipv6_mroute_summary,
show_ipv6_mroute_summary_cmd,
"show ipv6 mroute [vrf NAME] summary [json$json]",
SHOW_STR
IPV6_STR
MROUTE_STR
VRF_CMD_HELP_STR
"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;
}

DEFPY (show_ipv6_mroute_summary_vrf_all,
show_ipv6_mroute_summary_vrf_all_cmd,
"show ipv6 mroute vrf all summary [json$json]",
SHOW_STR
IPV6_STR
MROUTE_STR
VRF_CMD_HELP_STR
"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;
}

void pim_cmd_init(void)
{
if_cmd_init(pim_interface_config_write);
Expand Down Expand Up @@ -1944,4 +2017,6 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_mroute_count_cmd);
install_element(VIEW_NODE, &show_ipv6_mroute_count_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_mroute_summary_cmd);
install_element(VIEW_NODE, &show_ipv6_mroute_summary_vrf_all_cmd);
}
59 changes: 34 additions & 25 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3963,37 +3963,46 @@ DEFPY (show_ip_mroute_count_vrf_all,
return CMD_SUCCESS;
}

DEFUN (show_ip_mroute_summary,
DEFPY (show_ip_mroute_summary,
show_ip_mroute_summary_cmd,
"show ip mroute [vrf NAME] summary [json]",
"show ip mroute [vrf NAME] summary [json$json]",
SHOW_STR
IP_STR
MROUTE_STR
VRF_CMD_HELP_STR
"Summary of all mroutes\n"
JSON_STR)
{
int idx = 2;
bool uj = use_json(argc, argv);
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
json_object *json = NULL;
struct pim_instance *pim;
struct vrf *v;
json_object *json_parent = NULL;

if (uj)
json = json_object_new_object();
v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);

if (!vrf)
if (!v)
return CMD_WARNING;

show_mroute_summary(vrf->info, vty, json);
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);

if (uj)
vty_json(vty, json);
return CMD_SUCCESS;
}

DEFUN (show_ip_mroute_summary_vrf_all,
DEFPY (show_ip_mroute_summary_vrf_all,
show_ip_mroute_summary_vrf_all_cmd,
"show ip mroute vrf all summary [json]",
"show ip mroute vrf all summary [json$json]",
SHOW_STR
IP_STR
MROUTE_STR
Expand All @@ -4002,27 +4011,27 @@ DEFUN (show_ip_mroute_summary_vrf_all,
JSON_STR)
{
struct vrf *vrf;
bool uj = use_json(argc, argv);
json_object *json = NULL;
json_object *json_parent = NULL;
json_object *json_vrf = NULL;

if (uj)
json = json_object_new_object();
if (json)
json_parent = json_object_new_object();

RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj)
json_vrf = json_object_new_object();
else
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 (uj)
json_object_object_add(json, vrf->name, json_vrf);
if (json)
json_object_object_add(json_parent, vrf->name,
json_vrf);
}

if (uj)
vty_json(vty, json);
if (json)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}
Expand Down
22 changes: 10 additions & 12 deletions pimd/pim_cmd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3459,9 +3459,8 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty,
show_mroute_count_per_channel_oil(&sr->c_oil, json, vty);
}

#if PIM_IPV == 4
void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
json_object *json)
json_object *json)
{
struct listnode *node;
struct channel_oil *c_oil;
Expand All @@ -3478,12 +3477,12 @@ void show_mroute_summary(struct pim_instance *pim, struct vty *vty,

frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) {
if (!c_oil->installed) {
if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY)
if (pim_addr_is_any(*oil_origin(c_oil)))
starg_sw_mroute_cnt++;
else
sg_sw_mroute_cnt++;
} else {
if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY)
if (pim_addr_is_any(*oil_origin(c_oil)))
starg_hw_mroute_cnt++;
else
sg_hw_mroute_cnt++;
Expand All @@ -3492,12 +3491,12 @@ void show_mroute_summary(struct pim_instance *pim, struct vty *vty,

for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) {
if (!s_route->c_oil.installed) {
if (s_route->c_oil.oil.mfcc_origin.s_addr == INADDR_ANY)
if (pim_addr_is_any(*oil_origin(&s_route->c_oil)))
starg_sw_mroute_cnt++;
else
sg_sw_mroute_cnt++;
} else {
if (s_route->c_oil.oil.mfcc_origin.s_addr == INADDR_ANY)
if (pim_addr_is_any(*oil_origin(&s_route->c_oil)))
starg_hw_mroute_cnt++;
else
sg_hw_mroute_cnt++;
Expand All @@ -3512,8 +3511,8 @@ void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
vty_out(vty, "------\n");
vty_out(vty, "%-20s %u/%u\n", "Total",
(starg_hw_mroute_cnt + sg_hw_mroute_cnt),
(starg_sw_mroute_cnt + starg_hw_mroute_cnt
+ sg_sw_mroute_cnt + sg_hw_mroute_cnt));
(starg_sw_mroute_cnt + starg_hw_mroute_cnt +
sg_sw_mroute_cnt + sg_hw_mroute_cnt));
} else {
/* (*,G) route details */
json_starg = json_object_new_object();
Expand All @@ -3535,9 +3534,8 @@ void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
json_object_int_add(json, "totalNumOfInstalledMroutes",
starg_hw_mroute_cnt + sg_hw_mroute_cnt);
json_object_int_add(json, "totalNumOfMroutes",
starg_sw_mroute_cnt + starg_hw_mroute_cnt
+ sg_sw_mroute_cnt
+ sg_hw_mroute_cnt);
starg_sw_mroute_cnt + starg_hw_mroute_cnt +
sg_sw_mroute_cnt +
sg_hw_mroute_cnt);
}
}
#endif
2 changes: 1 addition & 1 deletion pimd/pim_cmd_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
void show_mroute_count(struct pim_instance *pim, struct vty *vty,
json_object *json);
void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
json_object *json);
json_object *json);

/*
* Special Macro to allow us to get the correct pim_instance;
Expand Down

0 comments on commit 74e8197

Please sign in to comment.