Skip to content

Commit

Permalink
pimd,yang: Implement AutoRP CLI and NB config path
Browse files Browse the repository at this point in the history
New CLI commands added:
router pim [vrf NAME]
  autorp discovery
  autorp announce RP-ADDR [GROUP | group-list PREFIX-LIST]
  autorp announce {scope (1-255) | interval (1-65535) | holdtime (0-65535)}

autorp discovery
  Enables Auto RP discovery for learning dynamic RP information using the
  AutoRP protocol.

autorp announce RP-ADDR [GROUP | group-list PREFIX-LIST]
  Enable announcements of a candidate RP with the given group range, or
  prefix list of group ranges, to an AutoRP mapping agent.

autorp announce {scope (1-255) | interval (1-65535) | holdtime (0-65535)}
  Configure the parameters of the AutoRP announcement messages.
  The scope sets the packet TTL.
  The interval sets the time between TX of announcements.
  The holdtime sets the hold time in the message, the time the mapping
  agent should wait before invalidating the candidate RP information.

debug pim autorp
  Enable debug logging of the AutoRP protocol

show ip pim [vrf NAME] autorp [json]
  Show details of the AutoRP protocol.
  To view learned RP info, use the existing command 'show ip pim rp-info'

Extend pim yang for new configuration:
  augment /frr-rt:routing/frr-rt:control-plane-protocols/frr-rt:control-plane-protocol/frr-pim:pim/frr-pim:address-family:
    +--rw rp
       +--rw auto-rp
          +--rw discovery-enabled?   boolean
          +--rw announce-scope?      uint8
          +--rw announce-interval?   uint16
          +--rw announce-holdtime?   uint16
          +--rw candidate-rp-list* [rp-address]
             +--rw rp-address           inet:ip-address
             +--rw (group-or-prefix-list)?
                +--:(group)
                |  +--rw group?         frr-route-types:ip-multicast-group-prefix
                +--:(prefix-list)
                   +--rw prefix-list?   plist-ref

Signed-off-by: Nathan Bahr <[email protected]>
  • Loading branch information
nabahr committed Sep 24, 2024
1 parent f182255 commit 3b323fc
Show file tree
Hide file tree
Showing 9 changed files with 839 additions and 1 deletion.
147 changes: 147 additions & 0 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2820,6 +2820,75 @@ DEFPY (show_ip_pim_rp_vrf_all,
(struct prefix *)group, !!json);
}

DEFPY (show_ip_pim_autorp,
show_ip_pim_autorp_cmd,
"show ip pim [vrf NAME] autorp [json$json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM AutoRP information\n"
JSON_STR)
{
struct vrf *v;
json_object *json_parent = NULL;

v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
if (!v || !v->info) {
if (!json)
vty_out(vty, "%% Unable to find pim instance\n");
return CMD_WARNING;
}

if (json)
json_parent = json_object_new_object();

pim_autorp_show_autorp(vty, v->info, json_parent);

if (json)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}

DEFPY (show_ip_pim_autorp_vrf_all,
show_ip_pim_autorp_vrf_all_cmd,
"show ip pim vrf all autorp [json$json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM AutoRP information\n"
JSON_STR)
{
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 (vrf->info) {
if (!json)
vty_out(vty, "VRF: %s\n", vrf->name);
else
json_vrf = json_object_new_object();

pim_autorp_show_autorp(vty, vrf->info, json_vrf);

if (json)
json_object_object_add(json_parent, vrf->name,
json_vrf);
}
}

if (json)
vty_json(vty, json_parent);

return CMD_SUCCESS;
}

DEFPY (show_ip_pim_rpf,
show_ip_pim_rpf_cmd,
"show ip pim [vrf NAME] rpf [json$json]",
Expand Down Expand Up @@ -4516,6 +4585,52 @@ DEFPY_ATTR(no_ip_pim_rp_prefix_list,
return ret;
}

DEFPY (pim_autorp_discovery,
pim_autorp_discovery_cmd,
"[no] autorp discovery",
NO_STR
"AutoRP\n"
"Enable AutoRP discovery\n")
{
if (no)
return pim_process_no_autorp_cmd(vty);
else
return pim_process_autorp_cmd(vty);
}

DEFPY (pim_autorp_announce_rp,
pim_autorp_announce_rp_cmd,
"[no] autorp announce A.B.C.D$rpaddr ![A.B.C.D/M$grp|group-list PREFIX_LIST$plist]",
NO_STR
"AutoRP\n"
"AutoRP Candidate RP announcement\n"
"AutoRP Candidate RP address\n"
"Group prefix\n"
"Prefix list\n"
"List name\n")
{
return pim_process_autorp_candidate_rp_cmd(vty, no, rpaddr_str, grp,
plist);
}

DEFPY (pim_autorp_announce_scope_int,
pim_autorp_announce_scope_int_cmd,
"[no] autorp announce ![{scope (1-255) | interval (1-65535) | holdtime (0-65535)}]",
NO_STR
"AutoRP\n"
"AutoRP Candidate RP announcement\n"
"Packet scope (TTL)\n"
"TTL value\n"
"Announcement interval\n"
"Time in seconds\n"
"Announcement holdtime\n"
"Time in seconds\n")
{
return pim_process_autorp_announce_scope_int_cmd(vty, no, scope_str,
interval_str,
holdtime_str);
}

DEFPY (pim_bsr_candidate_bsr,
pim_bsr_candidate_bsr_cmd,
"[no] bsr candidate-bsr [{priority (0-255)|source <address A.B.C.D|interface IFNAME|loopback$loopback|any$any>}]",
Expand Down Expand Up @@ -6377,6 +6492,29 @@ DEFUN (no_debug_bsm,
return CMD_SUCCESS;
}

DEFUN (debug_autorp,
debug_autorp_cmd,
"debug pim autorp",
DEBUG_STR
DEBUG_PIM_STR
DEBUG_PIM_AUTORP_STR)
{
PIM_DO_DEBUG_AUTORP;
return CMD_SUCCESS;
}

DEFUN (no_debug_autorp,
no_debug_autorp_cmd,
"no debug pim autorp",
NO_STR
DEBUG_STR
DEBUG_PIM_STR
DEBUG_PIM_AUTORP_STR)
{
PIM_DONT_DEBUG_AUTORP;
return CMD_SUCCESS;
}


DEFUN_NOSH (show_debugging_pim,
show_debugging_pim_cmd,
Expand Down Expand Up @@ -8714,6 +8852,9 @@ void pim_cmd_init(void)
install_element(PIM_NODE, &no_pim_rp_cmd);
install_element(PIM_NODE, &pim_rp_prefix_list_cmd);
install_element(PIM_NODE, &no_pim_rp_prefix_list_cmd);
install_element(PIM_NODE, &pim_autorp_discovery_cmd);
install_element(PIM_NODE, &pim_autorp_announce_rp_cmd);
install_element(PIM_NODE, &pim_autorp_announce_scope_int_cmd);
install_element(PIM_NODE, &no_pim_ssm_prefix_list_cmd);
install_element(PIM_NODE, &no_pim_ssm_prefix_list_name_cmd);
install_element(PIM_NODE, &pim_ssm_prefix_list_cmd);
Expand Down Expand Up @@ -8868,6 +9009,8 @@ void pim_cmd_init(void)
install_element(VIEW_NODE, &show_ip_pim_upstream_rpf_cmd);
install_element(VIEW_NODE, &show_ip_pim_rp_cmd);
install_element(VIEW_NODE, &show_ip_pim_rp_vrf_all_cmd);
install_element(VIEW_NODE, &show_ip_pim_autorp_cmd);
install_element(VIEW_NODE, &show_ip_pim_autorp_vrf_all_cmd);
install_element(VIEW_NODE, &show_ip_pim_bsr_cmd);
install_element(VIEW_NODE, &show_ip_multicast_cmd);
install_element(VIEW_NODE, &show_ip_multicast_vrf_all_cmd);
Expand Down Expand Up @@ -8975,6 +9118,8 @@ void pim_cmd_init(void)
install_element(CONFIG_NODE, &debug_pim_trace_detail_cmd);
install_element(ENABLE_NODE, &debug_ssmpingd_cmd);
install_element(CONFIG_NODE, &debug_ssmpingd_cmd);
install_element(ENABLE_NODE, &debug_autorp_cmd);
install_element(ENABLE_NODE, &no_debug_autorp_cmd);
install_element(ENABLE_NODE, &no_debug_ssmpingd_cmd);
install_element(CONFIG_NODE, &no_debug_ssmpingd_cmd);
install_element(ENABLE_NODE, &debug_pim_zebra_cmd);
Expand Down Expand Up @@ -9007,6 +9152,8 @@ void pim_cmd_init(void)
install_element(CONFIG_NODE, &debug_bsm_cmd);
install_element(ENABLE_NODE, &no_debug_bsm_cmd);
install_element(CONFIG_NODE, &no_debug_bsm_cmd);
install_element(CONFIG_NODE, &debug_autorp_cmd);
install_element(CONFIG_NODE, &no_debug_autorp_cmd);

install_element(CONFIG_NODE, &ip_igmp_group_watermark_cmd);
install_element(VRF_NODE, &ip_igmp_group_watermark_cmd);
Expand Down
1 change: 1 addition & 0 deletions pimd/pim_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define DEBUG_MSDP_PACKETS_STR "MSDP protocol packets\n"
#define DEBUG_MTRACE_STR "Mtrace protocol activity\n"
#define DEBUG_PIM_BSM_STR "BSR message processing activity\n"
#define DEBUG_PIM_AUTORP_STR "AutoRP message processing activity\n"


void pim_cmd_init(void);
Expand Down
159 changes: 159 additions & 0 deletions pimd/pim_cmd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,165 @@ int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
return nb_cli_apply_changes(vty, NULL);
}

int pim_process_autorp_cmd(struct vty *vty)
{
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath), "%s/%s", FRR_PIM_AUTORP_XPATH,
"discovery-enabled");

nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, "true");

return nb_cli_apply_changes(vty, NULL);
}

int pim_process_no_autorp_cmd(struct vty *vty)
{
char xpath[XPATH_MAXLEN];

snprintf(xpath, sizeof(xpath), "%s/%s", FRR_PIM_AUTORP_XPATH,
"discovery-enabled");

nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);

return nb_cli_apply_changes(vty, NULL);
}

int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no,
const char *rpaddr_str,
const struct prefix_ipv4 *grp,
const char *plist)
{
char xpath[XPATH_MAXLEN];
char grpstr[64];

if (no) {
if (!is_default_prefix((const struct prefix *)grp) || plist) {
/* If any single values are set, only destroy those */
if (!is_default_prefix((const struct prefix *)grp)) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/group",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
if (plist) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/prefix-list",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
} else {
/* No values set, remove the entire RP */
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
}
} else {
if (!is_default_prefix((const struct prefix *)grp) || plist) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
if (!is_default_prefix((const struct prefix *)grp)) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/group",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
prefix2str(grp, grpstr,
sizeof(grpstr)));
}
if (plist) {
snprintfrr(xpath, sizeof(xpath),
"%s/candidate-rp-list[rp-address='%s']/prefix-list",
FRR_PIM_AUTORP_XPATH, rpaddr_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
plist);
}
} else {
return CMD_WARNING_CONFIG_FAILED;
}
}

return nb_cli_apply_changes(vty, NULL);
}

int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no,
const char *scope,
const char *interval,
const char *holdtime)
{
char xpath[XPATH_MAXLEN];

if (no) {
if (scope || interval || holdtime) {
/* If any single values are set, only destroy those */
if (scope) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-scope");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
if (interval) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
if (holdtime) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY,
NULL);
}
} else {
/* No values set, remove all */
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-scope");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH, "announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
}
} else {
if (scope || interval || holdtime) {
if (scope) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-scope");
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
scope);
}
if (interval) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-interval");
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
interval);
}
if (holdtime) {
snprintfrr(xpath, sizeof(xpath), "%s/%s",
FRR_PIM_AUTORP_XPATH,
"announce-holdtime");
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY,
holdtime);
}
} else {
return CMD_WARNING_CONFIG_FAILED;
}
}

return nb_cli_apply_changes(vty, NULL);
}

bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match)
{
return (pim_addr_is_any(match.grp) ||
Expand Down
11 changes: 10 additions & 1 deletion pimd/pim_cmd_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ int pim_process_rp_plist_cmd(struct vty *vty, const char *rp_str,
const char *prefix_list);
int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
const char *prefix_list);

int pim_process_autorp_cmd(struct vty *vty);
int pim_process_no_autorp_cmd(struct vty *vty);
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no,
const char *rpaddr_str,
const struct prefix_ipv4 *grp,
const char *plist);
int pim_process_autorp_announce_scope_int_cmd(struct vty *vty, bool no,
const char *scope,
const char *interval,
const char *holdtime);
int pim_process_ip_pim_cmd(struct vty *vty);
int pim_process_no_ip_pim_cmd(struct vty *vty);
int pim_process_ip_pim_passive_cmd(struct vty *vty, bool enable);
Expand Down
Loading

0 comments on commit 3b323fc

Please sign in to comment.