bgpd: convert nbr rmap transactional cli

- Move vtysh handler to DEFPY
- Convert neighbor route-map command to transactional cli.
- After nb conversion, remove not used apis.
- Implement NB callbacks for afi-safis

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-12-21 17:11:50 -08:00
parent f4eac84c5a
commit c668557533
2 changed files with 474 additions and 314 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7733,7 +7733,7 @@ DEFPY_YANG(
{
char base_xpath[XPATH_MAXLEN];
char af_xpath[XPATH_MAXLEN];
char plist_xpath[80];
char plist_xpath[XPATH_MAXLEN];
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
@ -7930,70 +7930,52 @@ ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
"Name of the exist or non exist map\n")
/* Set route-map to the peer. */
static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
afi_t afi, safi_t safi, const char *name_str,
const char *direct_str)
DEFPY_YANG(
neighbor_route_map, neighbor_route_map_cmd,
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
"Apply route map to neighbor\n"
"Name of route map\n"
"Apply map to incoming routes\n"
"Apply map to outbound routes\n")
{
int ret;
struct peer *peer;
int direct = RMAP_IN;
struct route_map *route_map;
char base_xpath[XPATH_MAXLEN];
char af_xpath[XPATH_MAXLEN];
char rmap_xpath[XPATH_MAXLEN];
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
peer = peer_and_group_lookup_vty(vty, ip_str);
if (!peer)
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
sizeof(base_xpath), af_xpath)
< 0)
return CMD_WARNING_CONFIG_FAILED;
/* Check filter direction. */
if (strncmp(direct_str, "in", 2) == 0)
direct = RMAP_IN;
else if (strncmp(direct_str, "o", 1) == 0)
direct = RMAP_OUT;
if (strmatch(direction, "in"))
snprintf(rmap_xpath, sizeof(rmap_xpath),
"./%s/filter-config/rmap-import",
bgp_afi_safi_get_container_str(afi, safi));
else if (strmatch(direction, "out"))
snprintf(rmap_xpath, sizeof(rmap_xpath),
"./%s/filter-config/rmap-export",
bgp_afi_safi_get_container_str(afi, safi));
route_map = route_map_lookup_warn_noexist(vty, name_str);
ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
if (!no) {
if (!yang_dnode_exists(
vty->candidate_config->dnode,
"/frr-route-map:lib/route-map[name='%s']",
rmap_str)) {
if (vty_shell_serv(vty))
vty_out(vty,
"The route-map '%s' does not exist.\n",
rmap_str);
}
nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
} else
nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
return bgp_vty_return(vty, ret);
}
static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
afi_t afi, safi_t safi,
const char *direct_str)
{
int ret;
struct peer *peer;
int direct = RMAP_IN;
peer = peer_and_group_lookup_vty(vty, ip_str);
if (!peer)
return CMD_WARNING_CONFIG_FAILED;
/* Check filter direction. */
if (strncmp(direct_str, "in", 2) == 0)
direct = RMAP_IN;
else if (strncmp(direct_str, "o", 1) == 0)
direct = RMAP_OUT;
ret = peer_route_map_unset(peer, afi, safi, direct);
return bgp_vty_return(vty, ret);
}
DEFUN (neighbor_route_map,
neighbor_route_map_cmd,
"neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Apply route map to neighbor\n"
"Name of route map\n"
"Apply map to incoming routes\n"
"Apply map to outbound routes\n")
{
int idx_peer = 1;
int idx_word = 3;
int idx_in_out = 4;
return peer_route_map_set_vty(
vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
argv[idx_word]->arg, argv[idx_in_out]->arg);
return nb_cli_apply_changes(vty, base_xpath);
}
ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
@ -8004,25 +7986,7 @@ ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
"Apply map to incoming routes\n"
"Apply map to outbound routes\n")
DEFUN (no_neighbor_route_map,
no_neighbor_route_map_cmd,
"no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
NO_STR
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Apply route map to neighbor\n"
"Name of route map\n"
"Apply map to incoming routes\n"
"Apply map to outbound routes\n")
{
int idx_peer = 2;
int idx_in_out = 5;
return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
bgp_node_afi(vty), bgp_node_safi(vty),
argv[idx_in_out]->arg);
}
ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
ALIAS_HIDDEN(neighbor_route_map, no_neighbor_route_map_hidden_cmd,
"no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
"Apply route map to neighbor\n"
@ -18461,27 +18425,16 @@ void bgp_vty_init(void)
install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
/* "neighbor unsuppress-map" commands. */
install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);