Skip to content

Commit

Permalink
pimd: candidate BSR/RP show commands, move under ip pim bsr
Browse files Browse the repository at this point in the history
Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
  • Loading branch information
Jafaral committed Sep 9, 2024
1 parent 2d08123 commit 865bae9
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 149 deletions.
79 changes: 32 additions & 47 deletions pimd/pim6_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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) {
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));

vty_out(vty, "%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_PRETTY));
json_object_free(json);
return CMD_SUCCESS;
}
return pim_show_bsr_cand_bsr(vrf, vty, !!json);
}

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));
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 (!vrf || !vrf->info)
return CMD_WARNING;

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)
{
Expand All @@ -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
Expand All @@ -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);
}


Expand Down Expand Up @@ -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);
Expand Down
24 changes: 2 additions & 22 deletions pimd/pim_bsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions pimd/pim_bsr_rpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
126 changes: 51 additions & 75 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -2877,93 +2856,89 @@ 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;
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;
}

if (uj) {
char buf[INET_ADDRSTRLEN];
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
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);

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));
if (!vrf || !vrf->info)
return CMD_WARNING;


return CMD_SUCCESS;
return pim_show_bsr_cand_rp(vrf, vty, !!json);
}

DEFUN (show_ip_pim_bsr_rpdb,
DEFPY (show_ip_pim_bsr_rpdb,
show_ip_pim_bsr_rpdb_cmd,
"show ip pim bsr candidate-rps [vrf NAME] [json]",
"show ip pim bsr candidate-rp-database [vrf NAME$vrfname] [json$json]",
SHOW_STR
IP_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)
{
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;

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
Expand All @@ -2974,15 +2949,14 @@ 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;

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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 865bae9

Please sign in to comment.