summaryrefslogtreecommitdiff
path: root/pimd/pim_cmd_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'pimd/pim_cmd_common.c')
-rw-r--r--pimd/pim_cmd_common.c1186
1 files changed, 1180 insertions, 6 deletions
diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c
index 51cacfdf19..03689bea8d 100644
--- a/pimd/pim_cmd_common.c
+++ b/pimd/pim_cmd_common.c
@@ -55,6 +55,7 @@
#include "pim_static.h"
#include "pim_addr.h"
#include "pim_static.h"
+#include "pim_util.h"
/**
* Get current node VRF name.
@@ -1664,6 +1665,73 @@ static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp,
}
}
+int pim_show_join_cmd_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, const char *json)
+{
+ pim_sgaddr sg = {};
+ struct vrf *v;
+ struct pim_instance *pim;
+ json_object *json_parent = NULL;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v) {
+ vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
+ 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 (!pim_addr_is_any(s_or_g)) {
+ if (!pim_addr_is_any(g)) {
+ sg.src = s_or_g;
+ sg.grp = g;
+ } else
+ sg.grp = s_or_g;
+ }
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ pim_show_join(pim, vty, &sg, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_join_vrf_all_cmd_helper(struct vty *vty, const char *json)
+{
+ pim_sgaddr sg = {0};
+ struct vrf *vrf_struct;
+ json_object *json_parent = NULL;
+ json_object *json_vrf = NULL;
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ RB_FOREACH (vrf_struct, vrf_name_head, &vrfs_by_name) {
+ if (!json_parent)
+ vty_out(vty, "VRF: %s\n", vrf_struct->name);
+ else
+ json_vrf = json_object_new_object();
+ pim_show_join(vrf_struct->info, vty, &sg, json_vrf);
+
+ if (json)
+ json_object_object_add(json_parent, vrf_struct->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_WARNING;
+}
+
void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
json_object *json)
{
@@ -1701,6 +1769,29 @@ static void pim_show_jp_agg_helper(struct vty *vty, struct interface *ifp,
is_join ? "J" : "P");
}
+int pim_show_jp_agg_list_cmd_helper(const char *vrf, struct vty *vty)
+{
+ struct vrf *v;
+ struct pim_instance *pim;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v) {
+ vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
+ 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_show_jp_agg_list(pim, vty);
+
+ return CMD_SUCCESS;
+}
+
void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty)
{
struct interface *ifp;
@@ -1735,6 +1826,20 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty)
}
}
+int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj)
+{
+ struct vrf *v;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+ pim_show_membership(v->info, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
static void pim_show_membership_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch,
@@ -1945,6 +2050,77 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj)
vty_json(vty, json);
}
+int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj)
+{
+ struct vrf *v;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+ pim_show_channel(v->info, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_interface_cmd_helper(const char *vrf, struct vty *vty, bool uj,
+ bool mlag, const char *interface)
+{
+ struct vrf *v;
+ 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, mlag,
+ json_parent);
+ else
+ pim_show_interfaces(v->info, vty, mlag, json_parent);
+
+ if (uj)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_interface_vrf_all_cmd_helper(struct vty *vty, bool uj, bool mlag,
+ const char *interface)
+{
+ 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,
+ mlag, json_vrf);
+ else
+ pim_show_interfaces(v->info, vty, mlag, 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_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag,
json_object *json)
{
@@ -1989,8 +2165,8 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag,
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))
+ if (!pim_addr_cmp(pim_ifp->pim_dr_addr,
+ pim_ifp->primary_address))
json_object_boolean_true_add(
json_row, "pimDesignatedRouterLocal");
@@ -2489,6 +2665,73 @@ static int pim_print_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
return CMD_SUCCESS;
}
+int pim_show_nexthop_lookup_cmd_helper(const char *vrf, struct vty *vty,
+ pim_addr source, pim_addr group)
+{
+ struct prefix nht_p;
+ int result = 0;
+ pim_addr vif_source;
+ struct prefix grp;
+ struct pim_nexthop nexthop;
+ struct vrf *v;
+ char grp_str[PREFIX_STRLEN];
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+#if PIM_IPV == 4
+ if (pim_is_group_224_4(source)) {
+ vty_out(vty,
+ "Invalid argument. Expected Valid Source Address.\n");
+ return CMD_WARNING;
+ }
+
+ if (!pim_is_group_224_4(group)) {
+ vty_out(vty,
+ "Invalid argument. Expected Valid Multicast Group Address.\n");
+ return CMD_WARNING;
+ }
+#endif
+
+ if (!pim_rp_set_upstream_addr(v->info, &vif_source, source, group))
+ return CMD_SUCCESS;
+
+ pim_addr_to_prefix(&nht_p, vif_source);
+ pim_addr_to_prefix(&grp, group);
+ memset(&nexthop, 0, sizeof(nexthop));
+
+ result = pim_ecmp_nexthop_lookup(v->info, &nexthop, &nht_p, &grp, 0);
+
+ if (!result) {
+ vty_out(vty,
+ "Nexthop Lookup failed, no usable routes returned.\n");
+ return CMD_SUCCESS;
+ }
+
+ pim_addr_dump("<grp?>", &grp, grp_str, sizeof(grp_str));
+
+ vty_out(vty, "Group %s --- Nexthop %pPAs Interface %s\n", grp_str,
+ &nexthop.mrib_nexthop_addr, nexthop.interface->name);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_nexthop_cmd_helper(const char *vrf, struct vty *vty)
+{
+ struct vrf *v;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+ pim_show_nexthop(v->info, vty);
+
+ return CMD_SUCCESS;
+}
+
void pim_show_nexthop(struct pim_instance *pim, struct vty *vty)
{
struct pnc_cache_walk_data cwd;
@@ -2503,6 +2746,61 @@ void pim_show_nexthop(struct pim_instance *pim, struct vty *vty)
hash_walk(pim->rpf_hash, pim_print_pnc_cache_walkcb, &cwd);
}
+int pim_show_neighbors_cmd_helper(const char *vrf, struct vty *vty,
+ const char *json, const char *interface)
+{
+ struct vrf *v;
+ json_object *json_parent = NULL;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v)
+ return CMD_WARNING;
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ if (interface)
+ pim_show_neighbors_single(v->info, vty, interface, json_parent);
+ else
+ pim_show_neighbors(v->info, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_neighbors_vrf_all_cmd_helper(struct vty *vty, const char *json,
+ const char *interface)
+{
+ struct vrf *v;
+ json_object *json_parent = NULL;
+ json_object *json_vrf = NULL;
+
+ if (json)
+ json_parent = json_object_new_object();
+ RB_FOREACH (v, vrf_name_head, &vrfs_by_name) {
+ if (!json)
+ vty_out(vty, "VRF: %s\n", v->name);
+ else
+ json_vrf = json_object_new_object();
+
+ if (interface)
+ pim_show_neighbors_single(v->info, vty, interface,
+ json_vrf);
+ else
+ pim_show_neighbors(v->info, vty, json_vrf);
+
+ if (json)
+ json_object_object_add(json_parent, v->name, json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty,
const char *neighbor, json_object *json)
{
@@ -3007,11 +3305,7 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
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);
@@ -3673,3 +3967,883 @@ void clear_pim_statistics(struct pim_instance *pim)
pim_ifp->pim_ifstat_bsm_invalid_sz = 0;
}
}
+
+int pim_debug_pim_cmd(void)
+{
+ PIM_DO_DEBUG_PIM_EVENTS;
+ PIM_DO_DEBUG_PIM_PACKETS;
+ PIM_DO_DEBUG_PIM_TRACE;
+ PIM_DO_DEBUG_MSDP_EVENTS;
+ PIM_DO_DEBUG_MSDP_PACKETS;
+ PIM_DO_DEBUG_BSM;
+ PIM_DO_DEBUG_VXLAN;
+ return CMD_SUCCESS;
+}
+
+int pim_no_debug_pim_cmd(void)
+{
+ PIM_DONT_DEBUG_PIM_EVENTS;
+ PIM_DONT_DEBUG_PIM_PACKETS;
+ PIM_DONT_DEBUG_PIM_TRACE;
+ PIM_DONT_DEBUG_MSDP_EVENTS;
+ PIM_DONT_DEBUG_MSDP_PACKETS;
+
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND;
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV;
+ return CMD_SUCCESS;
+}
+
+int pim_debug_pim_packets_cmd(const char *hello, const char *joins,
+ const char *registers, struct vty *vty)
+{
+ if (hello) {
+ PIM_DO_DEBUG_PIM_HELLO;
+ vty_out(vty, "PIM Hello debugging is on\n");
+ } else if (joins) {
+ PIM_DO_DEBUG_PIM_J_P;
+ vty_out(vty, "PIM Join/Prune debugging is on\n");
+ } else if (registers) {
+ PIM_DO_DEBUG_PIM_REG;
+ vty_out(vty, "PIM Register debugging is on\n");
+ } else {
+ PIM_DO_DEBUG_PIM_PACKETS;
+ vty_out(vty, "PIM Packet debugging is on\n");
+ }
+ return CMD_SUCCESS;
+}
+
+int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins,
+ const char *registers, struct vty *vty)
+{
+ if (hello) {
+ PIM_DONT_DEBUG_PIM_HELLO;
+ vty_out(vty, "PIM Hello debugging is off\n");
+ } else if (joins) {
+ PIM_DONT_DEBUG_PIM_J_P;
+ vty_out(vty, "PIM Join/Prune debugging is off\n");
+ } else if (registers) {
+ PIM_DONT_DEBUG_PIM_REG;
+ vty_out(vty, "PIM Register debugging is off\n");
+ } else {
+ PIM_DONT_DEBUG_PIM_PACKETS;
+ vty_out(vty, "PIM Packet debugging is off\n");
+ }
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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_rpf(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_rpf(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;
+}
+
+int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+ json_object *json_parent = NULL;
+ struct prefix *range = 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 (group_str) {
+ range = prefix_new();
+ prefix_copy(range, group);
+ apply_mask(range);
+ }
+
+ if (json)
+ json_parent = json_object_new_object();
+
+ pim_rp_show_information(pim, range, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ prefix_free(&range);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str,
+ const struct prefix *group, bool json)
+{
+ struct vrf *vrf;
+ json_object *json_parent = NULL;
+ json_object *json_vrf = NULL;
+ struct prefix *range = NULL;
+
+ if (group_str) {
+ range = prefix_new();
+ prefix_copy(range, group);
+ apply_mask(range);
+ }
+
+ 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_rp_show_information(vrf->info, range, vty, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ prefix_free(&range);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_secondary_helper(const char *vrf, struct vty *vty)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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_show_neighbors_secondary(pim, vty);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_statistics_helper(const char *vrf, struct vty *vty,
+ const char *word, bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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 (word)
+ pim_show_statistics(pim, vty, word, uj);
+ else
+ pim_show_statistics(pim, vty, NULL, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool json)
+{
+ pim_sgaddr sg = {0};
+ struct vrf *v;
+ struct pim_instance *pim;
+ json_object *json_parent = NULL;
+
+ v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+ if (!v) {
+ vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf);
+ 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();
+
+ if (!pim_addr_is_any(s_or_g)) {
+ if (!pim_addr_is_any(g)) {
+ sg.src = s_or_g;
+ sg.grp = g;
+ } else
+ sg.grp = s_or_g;
+ }
+
+ pim_show_upstream(pim, vty, &sg, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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_upstream(vrf->info, vty, &sg, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty,
+ bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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_show_join_desired(pim, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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_show_upstream_rpf(pim, vty, uj);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_state_helper(const char *vrf, struct vty *vty,
+ const char *s_or_g_str, const char *g_str, bool json)
+{
+ 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;
+}
+
+int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str,
+ const char *g_str, bool json)
+{
+ 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;
+}
+
+int pim_show_multicast_helper(const char *vrf, struct vty *vty)
+{
+ 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;
+}
+
+int pim_show_multicast_vrf_all_helper(struct vty *vty)
+{
+ 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;
+}
+
+int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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_multicast_interfaces(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_multicast_interfaces(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;
+}
+
+int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool fill, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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();
+
+ if (!pim_addr_is_any(s_or_g)) {
+ if (!pim_addr_is_any(g)) {
+ sg.src = s_or_g;
+ sg.grp = g;
+ } else
+ sg.grp = s_or_g;
+ }
+
+ show_mroute(pim, vty, &sg, fill, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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(vrf->info, vty, &sg, fill, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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_count(pim, vty, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_count(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;
+}
+
+int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json)
+{
+ 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;
+}
+
+int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json)
+{
+ 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_show_interface_traffic(struct pim_instance *pim, struct vty *vty,
+ bool uj)
+{
+ struct interface *ifp = NULL;
+ struct pim_interface *pim_ifp = NULL;
+ json_object *json = NULL;
+ json_object *json_row = NULL;
+
+ if (uj)
+ json = json_object_new_object();
+ else {
+ vty_out(vty, "\n");
+ vty_out(vty, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
+ "Interface", " HELLO", " JOIN",
+ " PRUNE", " REGISTER", "REGISTER-STOP",
+ " ASSERT", " BSM");
+ vty_out(vty, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
+ " Rx/Tx", " Rx/Tx", " Rx/Tx",
+ " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
+ vty_out(vty,
+ "---------------------------------------------------------------------------------------------------------------\n");
+ }
+
+ FOR_ALL_INTERFACES (pim->vrf, ifp) {
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (uj) {
+ json_row = json_object_new_object();
+ json_object_pim_ifp_add(json_row, ifp);
+ json_object_int_add(json_row, "helloRx",
+ pim_ifp->pim_ifstat_hello_recv);
+ json_object_int_add(json_row, "helloTx",
+ pim_ifp->pim_ifstat_hello_sent);
+ json_object_int_add(json_row, "joinRx",
+ pim_ifp->pim_ifstat_join_recv);
+ json_object_int_add(json_row, "joinTx",
+ pim_ifp->pim_ifstat_join_send);
+ json_object_int_add(json_row, "pruneTx",
+ pim_ifp->pim_ifstat_prune_send);
+ json_object_int_add(json_row, "pruneRx",
+ pim_ifp->pim_ifstat_prune_recv);
+ json_object_int_add(json_row, "registerRx",
+ pim_ifp->pim_ifstat_reg_recv);
+ json_object_int_add(json_row, "registerTx",
+ pim_ifp->pim_ifstat_reg_send);
+ json_object_int_add(json_row, "registerStopRx",
+ pim_ifp->pim_ifstat_reg_stop_recv);
+ json_object_int_add(json_row, "registerStopTx",
+ pim_ifp->pim_ifstat_reg_stop_send);
+ json_object_int_add(json_row, "assertRx",
+ pim_ifp->pim_ifstat_assert_recv);
+ json_object_int_add(json_row, "assertTx",
+ pim_ifp->pim_ifstat_assert_send);
+ json_object_int_add(json_row, "bsmRx",
+ pim_ifp->pim_ifstat_bsm_rx);
+ json_object_int_add(json_row, "bsmTx",
+ pim_ifp->pim_ifstat_bsm_tx);
+ json_object_object_add(json, ifp->name, json_row);
+ } else {
+ vty_out(vty,
+ "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
+ "/%-7" PRIu64 "\n",
+ ifp->name, pim_ifp->pim_ifstat_hello_recv,
+ pim_ifp->pim_ifstat_hello_sent,
+ pim_ifp->pim_ifstat_join_recv,
+ pim_ifp->pim_ifstat_join_send,
+ pim_ifp->pim_ifstat_prune_recv,
+ pim_ifp->pim_ifstat_prune_send,
+ pim_ifp->pim_ifstat_reg_recv,
+ pim_ifp->pim_ifstat_reg_send,
+ pim_ifp->pim_ifstat_reg_stop_recv,
+ pim_ifp->pim_ifstat_reg_stop_send,
+ pim_ifp->pim_ifstat_assert_recv,
+ pim_ifp->pim_ifstat_assert_send,
+ pim_ifp->pim_ifstat_bsm_rx,
+ pim_ifp->pim_ifstat_bsm_tx);
+ }
+ }
+ if (uj)
+ vty_json(vty, json);
+}
+
+void pim_show_interface_traffic_single(struct pim_instance *pim,
+ struct vty *vty, const char *ifname,
+ bool uj)
+{
+ struct interface *ifp = NULL;
+ struct pim_interface *pim_ifp = NULL;
+ json_object *json = NULL;
+ json_object *json_row = NULL;
+ uint8_t found_ifname = 0;
+
+ if (uj)
+ json = json_object_new_object();
+ else {
+ vty_out(vty, "\n");
+ vty_out(vty, "%-16s%-17s%-17s%-17s%-17s%-17s%-17s%-17s\n",
+ "Interface", " HELLO", " JOIN", " PRUNE",
+ " REGISTER", " REGISTER-STOP", " ASSERT",
+ " BSM");
+ vty_out(vty, "%-14s%-18s%-17s%-17s%-17s%-17s%-17s%-17s\n", "",
+ " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
+ " Rx/Tx", " Rx/Tx", " Rx/Tx");
+ vty_out(vty,
+ "-------------------------------------------------------------------------------------------------------------------------------\n");
+ }
+
+ FOR_ALL_INTERFACES (pim->vrf, ifp) {
+ if (strcmp(ifname, ifp->name))
+ continue;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ found_ifname = 1;
+ if (uj) {
+ json_row = json_object_new_object();
+ json_object_pim_ifp_add(json_row, ifp);
+ json_object_int_add(json_row, "helloRx",
+ pim_ifp->pim_ifstat_hello_recv);
+ json_object_int_add(json_row, "helloTx",
+ pim_ifp->pim_ifstat_hello_sent);
+ json_object_int_add(json_row, "joinRx",
+ pim_ifp->pim_ifstat_join_recv);
+ json_object_int_add(json_row, "joinTx",
+ pim_ifp->pim_ifstat_join_send);
+ json_object_int_add(json_row, "pruneRx",
+ pim_ifp->pim_ifstat_prune_recv);
+ json_object_int_add(json_row, "pruneTx",
+ pim_ifp->pim_ifstat_prune_send);
+ json_object_int_add(json_row, "registerRx",
+ pim_ifp->pim_ifstat_reg_recv);
+ json_object_int_add(json_row, "registerTx",
+ pim_ifp->pim_ifstat_reg_send);
+ json_object_int_add(json_row, "registerStopRx",
+ pim_ifp->pim_ifstat_reg_stop_recv);
+ json_object_int_add(json_row, "registerStopTx",
+ pim_ifp->pim_ifstat_reg_stop_send);
+ json_object_int_add(json_row, "assertRx",
+ pim_ifp->pim_ifstat_assert_recv);
+ json_object_int_add(json_row, "assertTx",
+ pim_ifp->pim_ifstat_assert_send);
+ json_object_int_add(json_row, "bsmRx",
+ pim_ifp->pim_ifstat_bsm_rx);
+ json_object_int_add(json_row, "bsmTx",
+ pim_ifp->pim_ifstat_bsm_tx);
+
+ json_object_object_add(json, ifp->name, json_row);
+ } else {
+ vty_out(vty,
+ "%-16s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7" PRIu64
+ "/%-7" PRIu64 "\n",
+ ifp->name, pim_ifp->pim_ifstat_hello_recv,
+ pim_ifp->pim_ifstat_hello_sent,
+ pim_ifp->pim_ifstat_join_recv,
+ pim_ifp->pim_ifstat_join_send,
+ pim_ifp->pim_ifstat_prune_recv,
+ pim_ifp->pim_ifstat_prune_send,
+ pim_ifp->pim_ifstat_reg_recv,
+ pim_ifp->pim_ifstat_reg_send,
+ pim_ifp->pim_ifstat_reg_stop_recv,
+ pim_ifp->pim_ifstat_reg_stop_send,
+ pim_ifp->pim_ifstat_assert_recv,
+ pim_ifp->pim_ifstat_assert_send,
+ pim_ifp->pim_ifstat_bsm_rx,
+ pim_ifp->pim_ifstat_bsm_tx);
+ }
+ }
+ if (uj)
+ vty_json(vty, json);
+ else if (!found_ifname)
+ vty_out(vty, "%% No such interface\n");
+}
+
+int pim_show_interface_traffic_helper(const char *vrf, const char *if_name,
+ struct vty *vty, bool uj)
+{
+ struct pim_instance *pim;
+ struct vrf *v;
+
+ 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 (if_name)
+ pim_show_interface_traffic_single(v->info, vty, if_name, uj);
+ else
+ pim_show_interface_traffic(v->info, vty, uj);
+
+ return CMD_SUCCESS;
+}