pim6d: Implementing "show ipv6 pim state" CLI

Adding new show CLI to display pim internal state related to groups.

Signed-off-by: Abhishek N R <abnr@vmware.com>
This commit is contained in:
Abhishek N R 2022-02-15 02:19:39 -08:00
parent b1a419baef
commit 2d85c67144
4 changed files with 135 additions and 74 deletions

View File

@ -994,6 +994,80 @@ DEFPY (show_ipv6_pim_upstream_rpf,
return CMD_SUCCESS;
}
DEFPY (show_ipv6_pim_state,
show_ipv6_pim_state_cmd,
"show ipv6 pim [vrf NAME] state [X:X::X:X$s_or_g [X:X::X:X$g]] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM state information\n"
"Unicast or Multicast address\n"
"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;
}
DEFPY (show_ipv6_pim_state_vrf_all,
show_ipv6_pim_state_vrf_all_cmd,
"show ipv6 pim vrf all state [X:X::X:X$s_or_g [X:X::X:X$g]] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM state information\n"
"Unicast or Multicast address\n"
"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;
}
void pim_cmd_init(void)
{
if_cmd_init(pim_interface_config_write);
@ -1056,4 +1130,6 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ipv6_pim_upstream_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_upstream_join_desired_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_upstream_rpf_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_state_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_state_vrf_all_cmd);
}

View File

@ -4322,9 +4322,9 @@ DEFPY (show_ip_pim_secondary,
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_state,
DEFPY (show_ip_pim_state,
show_ip_pim_state_cmd,
"show ip pim [vrf NAME] state [A.B.C.D [A.B.C.D]] [json]",
"show ip pim [vrf NAME] state [A.B.C.D$s_or_g [A.B.C.D$g]] [json$json]",
SHOW_STR
IP_STR
PIM_STR
@ -4334,32 +4334,36 @@ DEFUN (show_ip_pim_state,
"Multicast address\n"
JSON_STR)
{
const char *src_or_group = NULL;
const char *group = NULL;
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;
if (uj)
argc--;
pim = pim_get_pim_instance(v->vrf_id);
if (argv_find(argv, argc, "A.B.C.D", &idx)) {
src_or_group = argv[idx]->arg;
if (idx + 1 < argc)
group = argv[idx + 1]->arg;
if (!pim) {
vty_out(vty, "%% Unable to find pim instance\n");
return CMD_WARNING;
}
pim_show_state(vrf->info, vty, src_or_group, group, uj);
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;
}
DEFUN (show_ip_pim_state_vrf_all,
DEFPY (show_ip_pim_state_vrf_all,
show_ip_pim_state_vrf_all_cmd,
"show ip pim vrf all state [A.B.C.D [A.B.C.D]] [json]",
"show ip pim vrf all state [A.B.C.D$s_or_g [A.B.C.D$g]] [json$json]",
SHOW_STR
IP_STR
PIM_STR
@ -4369,36 +4373,25 @@ DEFUN (show_ip_pim_state_vrf_all,
"Multicast address\n"
JSON_STR)
{
const char *src_or_group = NULL;
const char *group = NULL;
int idx = 2;
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
json_object *json_parent = NULL;
json_object *json_vrf = NULL;
if (uj) {
vty_out(vty, "{ ");
argc--;
}
if (argv_find(argv, argc, "A.B.C.D", &idx)) {
src_or_group = argv[idx]->arg;
if (idx + 1 < argc)
group = argv[idx + 1]->arg;
}
if (json)
json_parent = json_object_new_object();
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_state(vrf->info, vty, src_or_group, group, uj);
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 (uj)
vty_out(vty, "}\n");
if (json)
vty_json(vty, json_parent);
return CMD_SUCCESS;
}

View File

@ -931,10 +931,10 @@ 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)
const char *src_or_group, const char *group,
json_object *json)
{
struct channel_oil *c_oil;
json_object *json = NULL;
json_object *json_group = NULL;
json_object *json_ifp_in = NULL;
json_object *json_ifp_out = NULL;
@ -944,9 +944,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
now = pim_time_monotonic_sec();
if (uj) {
json = json_object_new_object();
} else {
if (!json) {
vty_out(vty,
"Codes: J -> Pim Join, I -> IGMP Report, S -> Source, * -> Inherited from (*,G), V -> VxLAN, M -> Muted");
vty_out(vty,
@ -954,8 +952,8 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
}
frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) {
char grp_str[INET_ADDRSTRLEN];
char src_str[INET_ADDRSTRLEN];
char src_str[PIM_ADDRSTRLEN];
char grp_str[PIM_ADDRSTRLEN];
char in_ifname[INTERFACE_NAMSIZ + 1];
char out_ifname[INTERFACE_NAMSIZ + 1];
int oif_vif_index;
@ -966,16 +964,16 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
if ((c_oil->up &&
PIM_UPSTREAM_FLAG_TEST_USE_RPT(c_oil->up->flags)) ||
c_oil->oil.mfcc_origin.s_addr == INADDR_ANY)
pim_addr_is_any(*oil_origin(c_oil)))
isRpt = true;
else
isRpt = false;
pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, grp_str,
sizeof(grp_str));
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
sizeof(src_str));
ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
snprintfrr(grp_str, sizeof(grp_str), "%pPAs",
oil_mcastgrp(c_oil));
snprintfrr(src_str, sizeof(src_str), "%pPAs",
oil_origin(c_oil));
ifp_in = pim_if_find_by_vif_index(pim, *oil_parent(c_oil));
if (ifp_in)
strlcpy(in_ifname, ifp_in->name, sizeof(in_ifname));
@ -991,7 +989,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
continue;
}
if (uj) {
if (json) {
/* Find the group, create it if it doesn't exist */
json_object_object_get_ex(json, grp_str, &json_group);
@ -1028,12 +1026,8 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
c_oil->installed);
json_object_int_add(json_source, "installed",
c_oil->installed);
if (isRpt)
json_object_boolean_true_add(
json_source, "isRpt");
else
json_object_boolean_false_add(
json_source, "isRpt");
json_object_boolean_add(json_source, "isRpt",
isRpt);
json_object_int_add(json_source, "RefCount",
c_oil->oil_ref_count);
json_object_int_add(json_source, "refCount",
@ -1067,11 +1061,11 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
"wrongInterface",
c_oil->cc.wrong_if);
}
} else {
vty_out(vty, "%-6d %-15s %-15s %-3s %-16s ",
c_oil->installed, src_str, grp_str,
isRpt ? "y" : "n", in_ifname);
}
} else
vty_out(vty, "%-6d %-15pPAs %-15pPAs %-3s %-16s ",
c_oil->installed, oil_origin(c_oil),
oil_mcastgrp(c_oil), isRpt ? "y" : "n",
in_ifname);
for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
++oif_vif_index) {
@ -1079,7 +1073,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
char oif_uptime[10];
int ttl;
ttl = c_oil->oil.mfcc_ttls[oif_vif_index];
ttl = oil_if_has(c_oil, oif_vif_index);
if (ttl < 1)
continue;
@ -1095,7 +1089,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
strlcpy(out_ifname, "<oif?>",
sizeof(out_ifname));
if (uj) {
if (json) {
json_ifp_out = json_object_new_object();
json_object_string_add(json_ifp_out, "source",
src_str);
@ -1173,14 +1167,11 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
}
}
if (!uj)
if (!json)
vty_out(vty, "\n");
}
if (uj)
vty_json(vty, json);
else
if (!json)
vty_out(vty, "\n");
}

View File

@ -62,7 +62,8 @@ void json_object_pim_upstream_add(json_object *json, struct pim_upstream *up);
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);
const char *src_or_group, const char *group,
json_object *json);
void pim_show_statistics(struct pim_instance *pim, struct vty *vty,
const char *ifname, bool uj);
void pim_show_upstream(struct pim_instance *pim, struct vty *vty,