pim6d: Implementing "show ipv6 multicast" CLI

Signed-off-by: Abhishek N R <abnr@vmware.com>
This commit is contained in:
Abhishek N R 2022-04-13 23:30:28 -07:00
parent be126d919a
commit ca3b5906fc
4 changed files with 92 additions and 36 deletions

View File

@ -1569,6 +1569,52 @@ DEFPY (show_ipv6_pim_nexthop_lookup,
return CMD_SUCCESS;
}
DEFPY (show_ipv6_multicast,
show_ipv6_multicast_cmd,
"show ipv6 multicast [vrf NAME]",
SHOW_STR
IPV6_STR
"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;
}
DEFPY (show_ipv6_multicast_vrf_all,
show_ipv6_multicast_vrf_all_cmd,
"show ipv6 multicast vrf all",
SHOW_STR
IPV6_STR
"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;
}
void pim_cmd_init(void)
{
if_cmd_init(pim_interface_config_write);
@ -1665,4 +1711,6 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ipv6_pim_neighbor_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_nexthop_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_nexthop_lookup_cmd);
install_element(VIEW_NODE, &show_ipv6_multicast_cmd);
install_element(VIEW_NODE, &show_ipv6_multicast_vrf_all_cmd);
}

View File

@ -3649,51 +3649,48 @@ DEFPY (show_ip_pim_statistics,
return CMD_SUCCESS;
}
DEFUN (show_ip_multicast,
DEFPY (show_ip_multicast,
show_ip_multicast_cmd,
"show ip multicast [vrf NAME]",
SHOW_STR
IP_STR
VRF_CMD_HELP_STR
"Multicast global information\n")
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
struct vrf *v;
struct pim_instance *pim;
if (!vrf)
v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
if (!v)
return CMD_WARNING;
pim_cmd_show_ip_multicast_helper(vrf->info, vty);
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;
}
DEFUN (show_ip_multicast_vrf_all,
DEFPY (show_ip_multicast_vrf_all,
show_ip_multicast_vrf_all_cmd,
"show ip multicast vrf all",
SHOW_STR
IP_STR
VRF_CMD_HELP_STR
"Multicast global information\n")
"Multicast global information\n"
VRF_CMD_HELP_STR)
{
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
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
vty_out(vty, "VRF: %s\n", vrf->name);
vty_out(vty, "VRF: %s\n", vrf->name);
pim_cmd_show_ip_multicast_helper(vrf->info, vty);
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}

View File

@ -2858,7 +2858,6 @@ int pim_process_ssmpingd_cmd(struct vty *vty, enum nb_operation operation,
return nb_cli_apply_changes(vty, NULL);
}
#if PIM_IPV == 4
static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty,
time_t now)
{
@ -2886,7 +2885,6 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct interface *ifp;
char buf[PREFIX_STRLEN];
json_object *json = NULL;
json_object *json_row = NULL;
@ -2900,8 +2898,11 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp;
struct in_addr ifaddr;
#if PIM_IPV == 4
struct sioc_vif_req vreq;
#else
struct sioc_mif_req6 vreq;
#endif
pim_ifp = ifp->info;
@ -2909,8 +2910,8 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
continue;
memset(&vreq, 0, sizeof(vreq));
#if PIM_IPV == 4
vreq.vifi = pim_ifp->mroute_vif_index;
if (ioctl(pim->mroute_socket, SIOCGETVIFCNT, &vreq)) {
zlog_warn(
"ioctl(SIOCGETVIFCNT=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
@ -2918,14 +2919,23 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
pim_ifp->mroute_vif_index, errno,
safe_strerror(errno));
}
#else
vreq.mifi = pim_ifp->mroute_vif_index;
if (ioctl(pim->mroute_socket, SIOCGETMIFCNT_IN6, &vreq)) {
zlog_warn(
"ioctl(SIOCGETMIFCNT_IN6=%lu) failure for interface %s vif_index=%d: errno=%d: %s",
(unsigned long)SIOCGETMIFCNT_IN6, ifp->name,
pim_ifp->mroute_vif_index, errno,
safe_strerror(errno));
}
#endif
ifaddr = pim_ifp->primary_address;
if (uj) {
json_row = json_object_new_object();
json_object_string_add(json_row, "name", ifp->name);
json_object_string_add(json_row, "state",
if_is_up(ifp) ? "up" : "down");
json_object_string_addf(json_row, "address", "%pI4",
json_object_string_addf(json_row, "address", "%pPA",
&pim_ifp->primary_address);
json_object_int_add(json_row, "ifIndex", ifp->ifindex);
json_object_int_add(json_row, "vif",
@ -2941,9 +2951,8 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
json_object_object_add(json, ifp->name, json_row);
} else {
vty_out(vty,
"%-16s %-15s %3d %3d %7lu %7lu %10lu %10lu\n",
ifp->name,
inet_ntop(AF_INET, &ifaddr, buf, sizeof(buf)),
"%-16s %-15pPAs %3d %3d %7lu %7lu %10lu %10lu\n",
ifp->name, &pim_ifp->primary_address,
ifp->ifindex, pim_ifp->mroute_vif_index,
(unsigned long)vreq.icount,
(unsigned long)vreq.ocount,
@ -2956,8 +2965,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
vty_json(vty, json);
}
void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
struct vty *vty)
void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
{
struct vrf *vrf = pim->vrf;
time_t now = pim_time_monotonic_sec();
@ -2979,7 +2987,11 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
vty_out(vty, "\n");
pim_zebra_zclient_update(vty);
#if PIM_IPV == 4
pim_zlookup_show_ip_multicast(vty);
#else
/* TBD */
#endif
vty_out(vty, "\n");
vty_out(vty, "Maximum highest VifIndex: %d\n", PIM_MAX_USABLE_VIFS);
@ -3001,4 +3013,3 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
show_multicast_interfaces(pim, vty, false);
}
#endif /* PIM_IPV == 4 */

View File

@ -105,7 +105,7 @@ int gm_process_no_last_member_query_interval_cmd(struct vty *vty);
int pim_process_ssmpingd_cmd(struct vty *vty, enum nb_operation operation,
const char *src_str);
void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
struct vty *vty);
struct vty *vty);
void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
bool uj);