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);
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);
}
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
"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
"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;
}
}
void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag,
- bool uj)
+ json_object *json)
{
struct interface *ifp;
struct pim_interface *pim_ifp;
int fhr = 0;
int pim_nbrs = 0;
int pim_ifchannels = 0;
- json_object *json = NULL;
+ bool uj = true;
json_object *json_row = NULL;
json_object *json_tmp;
- json = json_object_new_object();
+ if (!json) {
+ uj = false;
+ json = json_object_new_object();
+ }
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
json_object_int_add(json_row, "pimNeighbors", pim_nbrs);
json_object_int_add(json_row, "pimIfChannels", pim_ifchannels);
json_object_int_add(json_row, "firstHopRouterCount", fhr);
- json_object_string_addf(json_row, "pimDesignatedRouter", "%pPAs",
- &pim_ifp->pim_dr_addr);
+ json_object_string_addf(json_row, "pimDesignatedRouter",
+ "%pPAs", &pim_ifp->pim_dr_addr);
if (pim_addr_cmp(pim_ifp->pim_dr_addr,
- pim_ifp->primary_address))
+ pim_ifp->primary_address))
json_object_boolean_true_add(
json_row, "pimDesignatedRouterLocal");
json_object_object_add(json, ifp->name, json_row);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- } else {
+ if (!uj) {
vty_out(vty,
"Interface State Address PIM Nbrs PIM DR FHR IfChannels\n");
vty_out(vty, "%9d\n", json_object_get_int(json_tmp));
}
}
-
- json_object_free(json);
}
-void pim_show_interfaces_single(struct pim_instance *pim,
- struct vty *vty, const char *ifname,
- bool mlag, bool uj)
+void pim_show_interfaces_single(struct pim_instance *pim, struct vty *vty,
+ const char *ifname, bool mlag,
+ json_object *json)
{
pim_addr ifaddr;
struct interface *ifp;
struct pim_neighbor *neigh;
struct pim_upstream *up;
time_t now;
- char dr_str[INET_ADDRSTRLEN];
+ char dr_str[PIM_ADDRSTRLEN];
char dr_uptime[10];
char expire[10];
- char grp_str[INET_ADDRSTRLEN];
+ char grp_str[PIM_ADDRSTRLEN];
char hello_period[10];
char hello_timer[10];
- char neigh_src_str[INET_ADDRSTRLEN];
- char src_str[INET_ADDRSTRLEN];
+ char neigh_src_str[PIM_ADDRSTRLEN];
+ char src_str[PIM_ADDRSTRLEN];
char stat_uptime[10];
char uptime[10];
int found_ifname = 0;
int print_header;
- json_object *json = NULL;
json_object *json_row = NULL;
json_object *json_pim_neighbor = NULL;
json_object *json_pim_neighbors = NULL;
now = pim_time_monotonic_sec();
- if (uj)
- json = json_object_new_object();
-
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
found_ifname = 1;
ifaddr = pim_ifp->primary_address;
- pim_inet4_dump("<dr?>", pim_ifp->pim_dr_addr, dr_str,
- sizeof(dr_str));
+ snprintfrr(dr_str, sizeof(dr_str), "%pPAs",
+ &pim_ifp->pim_dr_addr);
pim_time_uptime_begin(dr_uptime, sizeof(dr_uptime), now,
pim_ifp->pim_dr_election_last);
pim_time_timer_to_hhmmss(hello_timer, sizeof(hello_timer),
pim_time_uptime(stat_uptime, sizeof(stat_uptime),
now - pim_ifp->pim_ifstat_start);
- if (uj) {
- char pbuf[PREFIX2STR_BUFFER];
-
+ if (json) {
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
- if (pim_ifp->update_source.s_addr != INADDR_ANY) {
+ if (!pim_addr_is_any(pim_ifp->update_source)) {
json_object_string_addf(
- json_row, "useSource", "%pI4",
+ json_row, "useSource", "%pPAs",
&pim_ifp->update_source);
}
if (pim_ifp->sec_addr_list) {
sec_addr)) {
json_object_array_add(
sec_list,
- json_object_new_string(
- prefix2str(
- &sec_addr->addr,
- pbuf,
- sizeof(pbuf))));
+ json_object_new_stringf(
+ "%pFXh",
+ &sec_addr->addr));
}
json_object_object_add(json_row,
"secondaryAddressList",
neighnode, neigh)) {
json_pim_neighbor =
json_object_new_object();
- pim_inet4_dump("<src?>",
- neigh->source_addr,
- neigh_src_str,
- sizeof(neigh_src_str));
+ snprintfrr(neigh_src_str,
+ sizeof(neigh_src_str),
+ "%pPAs",
+ &neigh->source_addr);
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(
vty_out(vty, "Interface : %s\n", ifp->name);
vty_out(vty, "State : %s\n",
if_is_up(ifp) ? "up" : "down");
- if (pim_ifp->update_source.s_addr != INADDR_ANY) {
- vty_out(vty, "Use Source : %pI4\n",
+ if (!pim_addr_is_any(pim_ifp->update_source)) {
+ vty_out(vty, "Use Source : %pPAs\n",
&pim_ifp->update_source);
}
if (pim_ifp->sec_addr_list) {
- vty_out(vty, "Address : %pI4 (primary)\n",
+ vty_out(vty, "Address : %pPAs (primary)\n",
&ifaddr);
for (ALL_LIST_ELEMENTS_RO(
pim_ifp->sec_addr_list, sec_node,
vty_out(vty, " %pFX\n",
&sec_addr->addr);
} else {
- vty_out(vty, "Address : %pI4\n",
- &ifaddr);
+ vty_out(vty, "Address : %pPAs\n", &ifaddr);
}
vty_out(vty, "\n");
print_header = 0;
}
- pim_inet4_dump("<src?>", neigh->source_addr,
- neigh_src_str,
- sizeof(neigh_src_str));
+ snprintfrr(neigh_src_str, sizeof(neigh_src_str),
+ "%pPAs", &neigh->source_addr);
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(expire, sizeof(expire),
if (strcmp(ifp->name,
up->rpf.source_nexthop
- .interface->name) != 0)
+ .interface->name) != 0)
continue;
if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR))
}
}
- if (uj)
- vty_json(vty, json);
- else if (!found_ifname)
+ if (!found_ifname)
vty_out(vty, "%% No such interface\n");
}
void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj);
void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj);
void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag,
- bool uj);
+ json_object *json);
void pim_show_interfaces_single(struct pim_instance *pim, struct vty *vty,
- const char *ifname, bool mlag, bool uj);
+ const char *ifname, bool mlag,
+ json_object *json);
void ip_pim_ssm_show_group_range(struct pim_instance *pim, struct vty *vty,
bool uj);
void pim_show_nexthop(struct pim_instance *pim, struct vty *vty);