pimd: candidate BSR/RP show commands, move under ip pim bsr

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
This commit is contained in:
Jafar Al-Gharaibeh 2024-07-23 00:57:08 -05:00
parent 2d0812373c
commit 865bae9657
7 changed files with 218 additions and 156 deletions

View File

@ -1775,69 +1775,53 @@ DEFPY (show_ipv6_pim_secondary,
return pim_show_secondary_helper(vrf, vty);
}
DEFPY (show_ipv6_pim_cand_rp,
show_ipv6_pim_cand_rp_cmd,
"show ipv6 pim candidate-rp [vrf VRF_NAME] [json$uj]",
DEFPY (show_ipv6_pim_bsr_cand_bsr,
show_ipv6_pim_bsr_cand_bsr_cmd,
"show ipv6 pim bsr candidate-bsr [vrf NAME$vrfname] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
"PIM Candidate RP state\n"
BSR_STR
"Current PIM router candidate BSR state\n"
VRF_CMD_HELP_STR
JSON_STR)
{
struct vrf *vrf = pim_cmd_lookup(vty, vrf_name);
struct pim_instance *pim;
struct bsm_scope *scope;
json_object *json = NULL;
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, !!json);
if (!vrf || !vrf->info)
return CMD_WARNING;
pim = (struct pim_instance *)vrf->info;
scope = &pim->global_scope;
return pim_show_bsr_cand_bsr(vrf, vty, !!json);
}
if (!scope->cand_rp_addrsel.run) {
if (uj)
vty_out(vty, "{}\n");
else
vty_out(vty,
"This router is not currently operating as Candidate RP\n");
return CMD_SUCCESS;
}
DEFPY (show_ipv6_pim_bsr_cand_rp,
show_ipv6_pim_bsr_cand_rp_cmd,
"show ipv6 pim bsr candidate-rp [vrf VRF_NAME] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
BSR_STR
"Current PIM router candidate RP state\n"
VRF_CMD_HELP_STR
JSON_STR)
{
struct vrf *vrf = pim_cmd_lookup(vty, vrf_name);
if (uj) {
json = json_object_new_object();
json_object_string_addf(json, "address", "%pPA",
&scope->cand_rp_addrsel.run_addr);
json_object_int_add(json, "priority", scope->cand_rp_prio);
json_object_int_add(json, "nextAdvertisementMsec",
event_timer_remain_msec(
scope->cand_rp_adv_timer));
if (!vrf || !vrf->info)
return CMD_WARNING;
vty_out(vty, "%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_PRETTY));
json_object_free(json);
return CMD_SUCCESS;
}
vty_out(vty, "Candidate-RP\nAddress: %pPA\nPriority: %u\n\n",
&scope->cand_rp_addrsel.run_addr, scope->cand_rp_prio);
vty_out(vty, "Next adv.: %lu msec\n",
event_timer_remain_msec(scope->cand_rp_adv_timer));
return CMD_SUCCESS;
return pim_show_bsr_cand_rp(vrf, vty, !!json);
}
DEFPY (show_ipv6_pim_bsr_rpdb,
show_ipv6_pim_bsr_rpdb_cmd,
"show ipv6 pim bsr candidate-rps [vrf VRF_NAME] [json$uj]",
"show ipv6 pim bsr candidate-rp-database [vrf VRF_NAME] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
"boot-strap router information\n"
"Candidate RPs\n"
BSR_STR
"Candidate RPs database on this router (if it is the BSR)\n"
VRF_CMD_HELP_STR
JSON_STR)
{
@ -1849,12 +1833,12 @@ DEFPY (show_ipv6_pim_bsr_rpdb,
struct pim_instance *pim = vrf->info;
struct bsm_scope *scope = &pim->global_scope;
return pim_crp_db_show(vty, scope);
return pim_crp_db_show(vty, scope, !!json);
}
DEFPY (show_ipv6_pim_bsr_groups,
show_ipv6_pim_bsr_groups_cmd,
"show ipv6 pim bsr groups [vrf VRF_NAME] [json$uj]",
"show ipv6 pim bsr groups [vrf VRF_NAME] [json$json]",
SHOW_STR
IPV6_STR
PIM_STR
@ -1871,7 +1855,7 @@ DEFPY (show_ipv6_pim_bsr_groups,
struct pim_instance *pim = vrf->info;
struct bsm_scope *scope = &pim->global_scope;
return pim_crp_groups_show(vty, scope);
return pim_crp_groups_show(vty, scope, !!json);
}
@ -2864,7 +2848,8 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ipv6_pim_rpf_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_rpf_vrf_all_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_secondary_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_cand_rp_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_bsr_cand_bsr_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_bsr_cand_rp_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_bsr_rpdb_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_bsr_groups_cmd);
install_element(VIEW_NODE, &show_ipv6_pim_statistics_cmd);

View File

@ -378,28 +378,8 @@ struct pim_nexthop_cache;
void pim_crp_nht_update(struct pim_instance *pim, struct pim_nexthop_cache *pnc);
void pim_crp_db_clear(struct bsm_scope *scope);
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,
uint32_t buf_size);
struct pim_nexthop_cache;
void pim_crp_nht_update(struct pim_instance *pim, struct pim_nexthop_cache *pnc);
void pim_crp_db_clear(struct bsm_scope *scope);
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,
uint32_t buf_size);
struct pim_nexthop_cache;
void pim_crp_nht_update(struct pim_instance *pim, struct pim_nexthop_cache *pnc);
void pim_crp_db_clear(struct bsm_scope *scope);
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope);
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope, bool json);
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope, bool json);
int pim_cand_config_write(struct pim_instance *pim, struct vty *vty);

View File

@ -588,7 +588,7 @@ void pim_crp_db_clear(struct bsm_scope *scope)
}
}
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope)
int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope, bool json)
{
struct bsr_crp_rp *rp;
struct bsr_crp_item *item;
@ -609,7 +609,7 @@ int pim_crp_db_show(struct vty *vty, struct bsm_scope *scope)
return CMD_SUCCESS;
}
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope)
int pim_crp_groups_show(struct vty *vty, struct bsm_scope *scope, bool json)
{
struct bsr_crp_group *group;
struct bsr_crp_item *item;

View File

@ -66,27 +66,6 @@ static struct cmd_node debug_node = {
.config_write = pim_debug_config_write,
};
static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
const int argc, int *idx, bool uj)
{
struct vrf *vrf;
if (argv_find(argv, argc, "NAME", idx))
vrf = vrf_lookup_by_name(argv[*idx]->arg);
else
vrf = vrf_lookup_by_id(VRF_DEFAULT);
if (!vrf) {
if (uj)
vty_json_empty(vty, NULL);
else
vty_out(vty, "Specified VRF: %s does not exist\n",
argv[*idx]->arg);
}
return vrf;
}
static void pim_show_assert_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch, time_t now)
@ -2864,7 +2843,7 @@ DEFPY (show_ip_pim_bsm_db,
return pim_show_bsm_db_helper(vrf, vty, !!json);
}
DEFPY (show_ip_pim_bsrp,
DEFPY_HIDDEN (show_ip_pim_bsrp,
show_ip_pim_bsrp_cmd,
"show ip pim bsrp-info [vrf NAME] [json$json]",
SHOW_STR
@ -2877,80 +2856,76 @@ DEFPY (show_ip_pim_bsrp,
return pim_show_group_rp_mappings_info_helper(vrf, vty, !!json);
}
DEFUN (show_ip_pim_cand_rp,
show_ip_pim_cand_rp_cmd,
"show ip pim candidate-rp [vrf NAME] [json]",
DEFPY (show_ip_pim_bsr_rpinfo,
show_ip_pim_bsr_rpinfo_cmd,
"show ip pim bsr rp-info [vrf NAME] [json$json]",
SHOW_STR
IP_STR
PIM_STR
"PIM Candidate RP state\n"
BSR_STR
"PIM cached group-rp mappings information received from BSR\n"
VRF_CMD_HELP_STR
JSON_STR)
{
return pim_show_group_rp_mappings_info_helper(vrf, vty, !!json);
}
DEFPY (show_ip_pim_bsr_cand_bsr,
show_ip_pim_bsr_cand_bsr_cmd,
"show ip pim bsr candidate-bsr [vrf NAME$vrfname] [json$json]",
SHOW_STR
IP_STR
PIM_STR
BSR_STR
"Current PIM router candidate BSR state\n"
VRF_CMD_HELP_STR
JSON_STR)
{
bool uj = use_json(argc, argv);
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, uj);
struct pim_instance *pim;
struct bsm_scope *scope;
json_object *json = NULL;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, !!json);
if (!vrf || !vrf->info)
return CMD_WARNING;
pim = (struct pim_instance *)vrf->info;
scope = &pim->global_scope;
if (!scope->cand_rp_addrsel.run) {
if (uj)
vty_out(vty, "{}\n");
else
vty_out(vty,
"This router is not currently operating as Candidate RP\n");
return CMD_SUCCESS;
}
if (uj) {
char buf[INET_ADDRSTRLEN];
json = json_object_new_object();
inet_ntop(AF_INET, &scope->cand_rp_addrsel.run_addr, buf,
sizeof(buf));
json_object_string_add(json, "address", buf);
json_object_int_add(json, "priority", scope->cand_rp_prio);
json_object_int_add(json, "nextAdvertisementMsec",
pim_time_timer_remain_msec(
scope->cand_rp_adv_timer));
vty_out(vty, "%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_PRETTY));
json_object_free(json);
return CMD_SUCCESS;
}
vty_out(vty, "Candidate-RP\nAddress: %pI4\nPriority: %u\n\n",
&scope->cand_rp_addrsel.run_addr, scope->cand_rp_prio);
vty_out(vty, "Next adv.: %lu msec\n",
pim_time_timer_remain_msec(scope->cand_rp_adv_timer));
return CMD_SUCCESS;
return pim_show_bsr_cand_bsr(vrf, vty, !!json);
}
DEFUN (show_ip_pim_bsr_rpdb,
show_ip_pim_bsr_rpdb_cmd,
"show ip pim bsr candidate-rps [vrf NAME] [json]",
DEFPY (show_ip_pim_bsr_cand_rp,
show_ip_pim_bsr_cand_rp_cmd,
"show ip pim bsr candidate-rp [vrf NAME$vrfname] [json$json]",
SHOW_STR
IP_STR
PIM_STR
"boot-strap router information\n"
"Candidate RPs\n"
BSR_STR
"Current PIM router candidate RP state\n"
VRF_CMD_HELP_STR
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, !!json);
if (!vrf || !vrf->info)
return CMD_WARNING;
return pim_show_bsr_cand_rp(vrf, vty, !!json);
}
DEFPY (show_ip_pim_bsr_rpdb,
show_ip_pim_bsr_rpdb_cmd,
"show ip pim bsr candidate-rp-database [vrf NAME$vrfname] [json$json]",
SHOW_STR
IP_STR
PIM_STR
BSR_STR
"Candidate RPs database on this router (if it is the BSR)\n"
VRF_CMD_HELP_STR
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, false);
//bool uj = use_json(argc, argv);
if (!vrf || !vrf->info)
return CMD_WARNING;
@ -2958,12 +2933,12 @@ DEFUN (show_ip_pim_bsr_rpdb,
struct pim_instance *pim = vrf->info;
struct bsm_scope *scope = &pim->global_scope;
return pim_crp_db_show(vty, scope);
return pim_crp_db_show(vty, scope, !!json);
}
DEFUN (show_ip_pim_bsr_groups,
DEFPY (show_ip_pim_bsr_groups,
show_ip_pim_bsr_groups_cmd,
"show ip pim bsr groups [vrf NAME] [json]",
"show ip pim bsr groups [vrf NAME$vrfname] [json$json]",
SHOW_STR
IP_STR
PIM_STR
@ -2974,7 +2949,6 @@ DEFUN (show_ip_pim_bsr_groups,
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx, false);
//bool uj = use_json(argc, argv);
if (!vrf || !vrf->info)
return CMD_WARNING;
@ -2982,7 +2956,7 @@ DEFUN (show_ip_pim_bsr_groups,
struct pim_instance *pim = vrf->info;
struct bsm_scope *scope = &pim->global_scope;
return pim_crp_groups_show(vty, scope);
return pim_crp_groups_show(vty, scope, !!json);
}
DEFPY (show_ip_pim_statistics,
@ -4534,7 +4508,7 @@ DEFPY (pim_bsr_candidate_rp_group,
NO_STR
BSR_STR
"Make this router a Candidate RP\n"
"Configure groups to become candidate RP for\n"
"Configure groups to become candidate RP for (At least one group must be configured)\n"
"Multicast group prefix\n")
{
return pim_process_bsr_crp_grp_cmd(vty, group_str, no);
@ -8838,7 +8812,9 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ip_pim_nexthop_lookup_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsrp_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsm_db_cmd);
install_element(VIEW_NODE, &show_ip_pim_cand_rp_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_rpinfo_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_cand_bsr_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_cand_rp_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_rpdb_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_groups_cmd);
install_element(VIEW_NODE, &show_ip_pim_statistics_cmd);

View File

@ -4207,6 +4207,27 @@ struct vrf *pim_cmd_lookup(struct vty *vty, const char *name)
return vrf;
}
struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
const int argc, int *idx, bool uj)
{
struct vrf *vrf;
if (argv_find(argv, argc, "NAME", idx))
vrf = vrf_lookup_by_name(argv[*idx]->arg);
else
vrf = vrf_lookup_by_id(VRF_DEFAULT);
if (!vrf) {
if (uj)
vty_json_empty(vty, NULL);
else
vty_out(vty, "Specified VRF: %s does not exist\n",
argv[*idx]->arg);
}
return vrf;
}
void clear_mroute(struct pim_instance *pim)
{
struct pim_upstream *up;
@ -5262,7 +5283,7 @@ void pim_show_bsr(struct pim_instance *pim, struct vty *vty, bool uj)
}
else {
vty_out(vty, "PIMv2 Bootstrap information\n");
vty_out(vty, "PIMv2 Bootstrap Router information\n");
vty_out(vty, "Current preferred BSR address: %pPA\n",
&pim->global_scope.current_bsr);
vty_out(vty,
@ -5471,6 +5492,101 @@ int pim_show_group_rp_mappings_info_helper(const char *vrf, struct vty *vty,
return CMD_SUCCESS;
}
int pim_show_bsr_cand_rp(const struct vrf *vrf, struct vty *vty, bool uj)
{
struct pim_instance *pim;
struct bsm_scope *scope;
json_object *jsondata = NULL;
if (!vrf || !vrf->info)
return CMD_WARNING;
pim = (struct pim_instance *)vrf->info;
scope = &pim->global_scope;
if (!scope->cand_rp_addrsel.run) {
if (!!uj)
vty_out(vty, "{}\n");
else
vty_out(vty,
"This router is not currently operating as Candidate RP\n");
return CMD_SUCCESS;
}
if (!!uj) {
jsondata = json_object_new_object();
json_object_string_addf(jsondata, "address", "%pPA",
&scope->cand_rp_addrsel.run_addr);
json_object_int_add(jsondata, "priority", scope->cand_rp_prio);
json_object_int_add(jsondata, "nextAdvertisementMsec",
event_timer_remain_msec(
scope->cand_rp_adv_timer));
vty_json(vty, jsondata);
return CMD_SUCCESS;
}
vty_out(vty, "Candidate-RP\nAddress: %pPA\nPriority: %u\n\n",
&scope->cand_rp_addrsel.run_addr, scope->cand_rp_prio);
vty_out(vty, "Next adv.: %lu msec\n",
event_timer_remain_msec(scope->cand_rp_adv_timer));
return CMD_SUCCESS;
}
int pim_show_bsr_cand_bsr(const struct vrf *vrf, struct vty *vty, bool uj)
{
struct pim_instance *pim;
struct bsm_scope *scope;
json_object *jsondata = NULL;
if (!vrf || !vrf->info)
return CMD_WARNING;
pim = (struct pim_instance *)vrf->info;
scope = &pim->global_scope;
if (!scope->bsr_addrsel.cfg_enable) {
if (!!uj)
vty_out(vty, "{}\n");
else
vty_out(vty,
"This router is not currently operating as Candidate BSR\n");
return CMD_SUCCESS;
}
if (uj) {
char buf[INET_ADDRSTRLEN];
jsondata = json_object_new_object();
inet_ntop(AF_INET, &scope->bsr_addrsel.run_addr, buf,
sizeof(buf));
json_object_string_add(jsondata, "address", buf);
json_object_int_add(jsondata, "priority", scope->cand_bsr_prio);
json_object_boolean_add(jsondata, "elected",
pim->global_scope.state == BSR_ELECTED);
vty_out(vty, "%s\n",
json_object_to_json_string_ext(jsondata,
JSON_C_TO_STRING_PRETTY));
json_object_free(jsondata);
return CMD_SUCCESS;
}
vty_out(vty,
"Candidate-BSR\nAddress: %pPA\nPriority: %u\nElected: %s\n",
&scope->bsr_addrsel.run_addr, scope->cand_bsr_prio,
(pim->global_scope.state == BSR_ELECTED) ? " Yes" : " No");
if (!pim_addr_cmp(scope->bsr_addrsel.run_addr, PIMADDR_ANY))
vty_out(vty,
"\nThis router is not currently operating as Candidate BSR\n"
"Configure a BSR address to enable this feature\n\n");
return CMD_SUCCESS;
}
/* Display the bsm database details */
static void pim_show_bsm_db(struct pim_instance *pim, struct vty *vty, bool uj)
{

View File

@ -140,6 +140,8 @@ void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
json_object *json);
int clear_ip_mroute_count_command(struct vty *vty, const char *name);
struct vrf *pim_cmd_lookup(struct vty *vty, const char *name);
struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
const int argc, int *idx, bool uj);
void clear_mroute(struct pim_instance *pim);
void clear_pim_statistics(struct pim_instance *pim);
int clear_pim_interface_traffic(const char *vrf, struct vty *vty);
@ -191,6 +193,8 @@ int pim_show_interface_traffic_helper(const char *vrf, const char *if_name,
void clear_pim_interfaces(struct pim_instance *pim);
void pim_show_bsr(struct pim_instance *pim, struct vty *vty, bool uj);
int pim_show_bsr_helper(const char *vrf, struct vty *vty, bool uj);
int pim_show_bsr_cand_bsr(const struct vrf *vrf, struct vty *vty, bool uj);
int pim_show_bsr_cand_rp(const struct vrf *vrf, struct vty *vty, bool uj);
int pim_router_config_write(struct vty *vty);
/*

View File

@ -277,8 +277,9 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
if (!is_mcast) {
if (header->type == PIM_MSG_TYPE_CANDIDATE) {
if (PIM_DEBUG_PIM_PACKETS)
zlog_debug( "%s %s: Candidate RP PIM message from %pPA on %s",
__FILE__, __func__, &sg.src, ifp->name);
zlog_debug("%s %s: Candidate RP PIM message from %pPA on %s",
__FILE__, __func__, &sg.src,
ifp->name);
return pim_crp_process(ifp, &sg, pim_msg, pim_msg_len);
}