Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pim6d: Adding PIMv6 show CLIs #10710

Merged
merged 8 commits into from
Apr 4, 2022
Prev Previous commit
Next Next commit
pim6d: Adding "show ipv6 pim [vrf|vrf all] interface" command
Adding show ipv6 pim interface and show ipv6 pim vrf all interface
CLIs to display pim enabled interface informations and
formatted the json output for "show ip pim interface" and
"show ip pim vrf all interface" commands.

Signed-off-by: Sai Gomathi N <nsaigomathi@vmware.com>
  • Loading branch information
SaiGomathiN committed Apr 4, 2022
commit 44f99d22320439947f31283309af512ddb205ef1
79 changes: 79 additions & 0 deletions pimd/pim6_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,83 @@ DEFPY (show_ipv6_pim_channel,
return CMD_SUCCESS;
}

DEFPY (show_ipv6_pim_interface,
show_ipv6_pim_interface_cmd,
"show ipv6 pim [vrf NAME] interface [detail|WORD]$interface [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
struct vrf *v;
bool uj = !!json;
json_object *json_parent = NULL;

v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);

if (!v)
return CMD_WARNING;

if (uj)
json_parent = json_object_new_object();

if (interface)
pim_show_interfaces_single(v->info, vty, interface, false,
json_parent);
else
pim_show_interfaces(v->info, vty, false, json_parent);

if (uj)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}

DEFPY (show_ipv6_pim_interface_vrf_all,
show_ipv6_pim_interface_vrf_all_cmd,
"show ipv6 pim vrf all interface [detail|WORD]$interface [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
bool uj = !!json;
struct vrf *v;
json_object *json_parent = NULL;
json_object *json_vrf = NULL;

if (uj)
json_parent = json_object_new_object();

RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
if (!uj)
vty_out(vty, "VRF: %s\n", v->name);
else
json_vrf = json_object_new_object();

if (interface)
pim_show_interfaces_single(v->info, vty, interface,
false, json_vrf);
else
pim_show_interfaces(v->info, vty, false, json_vrf);

if (uj)
json_object_object_add(json_parent, v->name, json_vrf);
}
if (uj)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}

void pim_cmd_init(void)
{
if_cmd_init(pim_interface_config_write);
Expand Down Expand Up @@ -1156,4 +1233,6 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ipv6_pim_state_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_state_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_channel_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_interface_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_interface_vrf_all_cmd);
}
81 changes: 41 additions & 40 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2498,9 +2498,9 @@ DEFUN (show_ip_pim_assert_winner_metric,
return CMD_SUCCESS;
}

DEFUN (show_ip_pim_interface,
DEFPY (show_ip_pim_interface,
show_ip_pim_interface_cmd,
"show ip pim [mlag] [vrf NAME] interface [detail|WORD] [json]",
"show ip pim [mlag$mlag] [vrf NAME] interface [detail|WORD]$interface [json$json]",
SHOW_STR
IP_STR
PIM_STR
Expand All @@ -2511,30 +2511,34 @@ DEFUN (show_ip_pim_interface,
"interface name\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
bool mlag = false;
struct vrf *v;
bool uj = !!json;
bool is_mlag = !!mlag;
json_object *json_parent = NULL;

if (!vrf)
v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);

if (!v)
return CMD_WARNING;

if (argv_find(argv, argc, "mlag", &idx))
mlag = true;
if (uj)
json_parent = json_object_new_object();

if (argv_find(argv, argc, "WORD", &idx)
|| argv_find(argv, argc, "detail", &idx))
pim_show_interfaces_single(vrf->info, vty, argv[idx]->arg, mlag,
uj);
if (interface)
pim_show_interfaces_single(v->info, vty, interface, is_mlag,
json_parent);
else
pim_show_interfaces(vrf->info, vty, mlag, uj);
pim_show_interfaces(v->info, vty, is_mlag, json_parent);

if (uj)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}

DEFUN (show_ip_pim_interface_vrf_all,
DEFPY (show_ip_pim_interface_vrf_all,
show_ip_pim_interface_vrf_all_cmd,
"show ip pim [mlag] vrf all interface [detail|WORD] [json]",
"show ip pim [mlag$mlag] vrf all interface [detail|WORD]$interface [json$json]",
SHOW_STR
IP_STR
PIM_STR
Expand All @@ -2545,35 +2549,32 @@ DEFUN (show_ip_pim_interface_vrf_all,
"interface name\n"
JSON_STR)
{
int idx = 2;
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
bool mlag = false;

if (argv_find(argv, argc, "mlag", &idx))
mlag = true;
bool uj = !!json;
bool is_mlag = !!mlag;
struct vrf *v;
json_object *json_parent = NULL;
json_object *json_vrf = NULL;

idx = 6;
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);
if (argv_find(argv, argc, "WORD", &idx)
|| argv_find(argv, argc, "detail", &idx))
pim_show_interfaces_single(vrf->info, vty,
argv[idx]->arg, mlag, uj);
json_parent = json_object_new_object();

RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
if (!uj)
vty_out(vty, "VRF: %s\n", v->name);
else
json_vrf = json_object_new_object();

if (interface)
pim_show_interfaces_single(v->info, vty, interface,
is_mlag, json_vrf);
else
pim_show_interfaces(vrf->info, vty, mlag, uj);
pim_show_interfaces(v->info, vty, is_mlag, json_vrf);

if (uj)
json_object_object_add(json_parent, v->name, json_vrf);
}
if (uj)
vty_out(vty, "}\n");
vty_json(vty, json_parent);

return CMD_SUCCESS;
}
Expand Down
Loading