mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-16 00:25:01 +00:00
Merge pull request #14528 from opensourcerouting/feature/bgpd_handle_addpath_capability_via_dynamic_capability
bgpd: Handle Addpath capability using dynamic capabilities
This commit is contained in:
commit
9ff1a8c550
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "bgp_addpath.h"
|
#include "bgp_addpath.h"
|
||||||
#include "bgp_route.h"
|
#include "bgp_route.h"
|
||||||
|
#include "bgp_open.h"
|
||||||
|
#include "bgp_packet.h"
|
||||||
|
|
||||||
static const struct bgp_addpath_strategy_names strat_names[BGP_ADDPATH_MAX] = {
|
static const struct bgp_addpath_strategy_names strat_names[BGP_ADDPATH_MAX] = {
|
||||||
{
|
{
|
||||||
@ -359,6 +361,31 @@ void bgp_addpath_type_changed(struct bgp *bgp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type,
|
||||||
|
uint8_t paths)
|
||||||
|
{
|
||||||
|
int action = CAPABILITY_ACTION_UNSET;
|
||||||
|
|
||||||
|
switch (addpath_type) {
|
||||||
|
case BGP_ADDPATH_ALL:
|
||||||
|
case BGP_ADDPATH_BEST_PER_AS:
|
||||||
|
action = CAPABILITY_ACTION_SET;
|
||||||
|
break;
|
||||||
|
case BGP_ADDPATH_BEST_SELECTED:
|
||||||
|
if (paths)
|
||||||
|
action = CAPABILITY_ACTION_SET;
|
||||||
|
else
|
||||||
|
action = CAPABILITY_ACTION_UNSET;
|
||||||
|
break;
|
||||||
|
case BGP_ADDPATH_NONE:
|
||||||
|
case BGP_ADDPATH_MAX:
|
||||||
|
action = CAPABILITY_ACTION_UNSET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Change the addpath type assigned to a peer, or peer group. In addition to
|
* Change the addpath type assigned to a peer, or peer group. In addition to
|
||||||
* adjusting the counts, peer sessions will be reset as needed to make the
|
* adjusting the counts, peer sessions will be reset as needed to make the
|
||||||
@ -373,6 +400,7 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
|
|||||||
struct listnode *node, *nnode;
|
struct listnode *node, *nnode;
|
||||||
struct peer *tmp_peer;
|
struct peer *tmp_peer;
|
||||||
struct peer_group *group;
|
struct peer_group *group;
|
||||||
|
int action = bgp_addpath_capability_action(addpath_type, paths);
|
||||||
|
|
||||||
if (safi == SAFI_LABELED_UNICAST)
|
if (safi == SAFI_LABELED_UNICAST)
|
||||||
safi = SAFI_UNICAST;
|
safi = SAFI_UNICAST;
|
||||||
@ -430,9 +458,12 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
peer_change_action(peer, afi, safi, peer_change_reset);
|
if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV) &&
|
||||||
|
!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV))
|
||||||
|
peer_change_action(peer, afi, safi, peer_change_reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
#include "bgpd/bgp_table.h"
|
#include "bgpd/bgp_table.h"
|
||||||
#include "lib/json.h"
|
#include "lib/json.h"
|
||||||
|
|
||||||
|
struct bgp_addpath_capability {
|
||||||
|
uint16_t afi;
|
||||||
|
uint8_t safi;
|
||||||
|
uint8_t flags;
|
||||||
|
};
|
||||||
|
|
||||||
#define BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE 1
|
#define BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE 1
|
||||||
|
|
||||||
void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d);
|
void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d);
|
||||||
@ -57,4 +63,6 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *dest, afi_t afi,
|
|||||||
safi_t safi);
|
safi_t safi);
|
||||||
|
|
||||||
void bgp_addpath_type_changed(struct bgp *bgp);
|
void bgp_addpath_type_changed(struct bgp *bgp);
|
||||||
|
extern int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type,
|
||||||
|
uint8_t paths);
|
||||||
#endif
|
#endif
|
||||||
|
@ -682,15 +682,17 @@ static int bgp_capability_addpath(struct peer *peer,
|
|||||||
uint8_t send_receive = stream_getc(s);
|
uint8_t send_receive = stream_getc(s);
|
||||||
|
|
||||||
if (bgp_debug_neighbor_events(peer))
|
if (bgp_debug_neighbor_events(peer))
|
||||||
zlog_debug(
|
zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s",
|
||||||
"%s OPEN has %s capability for afi/safi: %s/%s%s%s",
|
peer->host,
|
||||||
peer->host,
|
lookup_msg(capcode_str, hdr->code, NULL),
|
||||||
lookup_msg(capcode_str, hdr->code, NULL),
|
iana_afi2str(pkt_afi),
|
||||||
iana_afi2str(pkt_afi), iana_safi2str(pkt_safi),
|
iana_safi2str(pkt_safi),
|
||||||
(send_receive & BGP_ADDPATH_RX) ? ", receive"
|
CHECK_FLAG(send_receive, BGP_ADDPATH_RX)
|
||||||
: "",
|
? ", receive"
|
||||||
(send_receive & BGP_ADDPATH_TX) ? ", transmit"
|
: "",
|
||||||
: "");
|
CHECK_FLAG(send_receive, BGP_ADDPATH_TX)
|
||||||
|
? ", transmit"
|
||||||
|
: "");
|
||||||
|
|
||||||
/* Convert AFI, SAFI to internal values, check. */
|
/* Convert AFI, SAFI to internal values, check. */
|
||||||
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) {
|
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) {
|
||||||
@ -709,13 +711,19 @@ static int bgp_capability_addpath(struct peer *peer,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (send_receive & BGP_ADDPATH_RX)
|
if (CHECK_FLAG(send_receive, BGP_ADDPATH_RX))
|
||||||
SET_FLAG(peer->af_cap[afi][safi],
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
PEER_CAP_ADDPATH_AF_RX_RCV);
|
PEER_CAP_ADDPATH_AF_RX_RCV);
|
||||||
|
else
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_RCV);
|
||||||
|
|
||||||
if (send_receive & BGP_ADDPATH_TX)
|
if (CHECK_FLAG(send_receive, BGP_ADDPATH_TX))
|
||||||
SET_FLAG(peer->af_cap[afi][safi],
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
PEER_CAP_ADDPATH_AF_TX_RCV);
|
PEER_CAP_ADDPATH_AF_TX_RCV);
|
||||||
|
else
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_RCV);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "lib_errors.h"
|
#include "lib_errors.h"
|
||||||
|
|
||||||
#include "bgpd/bgpd.h"
|
#include "bgpd/bgpd.h"
|
||||||
|
#include "bgpd/bgp_addpath.h"
|
||||||
#include "bgpd/bgp_table.h"
|
#include "bgpd/bgp_table.h"
|
||||||
#include "bgpd/bgp_dump.h"
|
#include "bgpd/bgp_dump.h"
|
||||||
#include "bgpd/bgp_bmp.h"
|
#include "bgpd/bgp_bmp.h"
|
||||||
@ -1211,6 +1212,8 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
|
|||||||
unsigned long cap_len;
|
unsigned long cap_len;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint32_t gr_restart_time;
|
uint32_t gr_restart_time;
|
||||||
|
uint8_t addpath_afi_safi_count = 0;
|
||||||
|
bool adv_addpath_tx = false;
|
||||||
const char *capability = lookup_msg(capcode_str, capability_code,
|
const char *capability = lookup_msg(capcode_str, capability_code,
|
||||||
"Unknown");
|
"Unknown");
|
||||||
|
|
||||||
@ -1374,11 +1377,91 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
|
|||||||
capability, iana_afi2str(pkt_afi),
|
capability, iana_afi2str(pkt_afi),
|
||||||
iana_safi2str(pkt_safi));
|
iana_safi2str(pkt_safi));
|
||||||
break;
|
break;
|
||||||
|
case CAPABILITY_CODE_ADDPATH:
|
||||||
|
SET_FLAG(peer->cap, PEER_CAP_ADDPATH_ADV);
|
||||||
|
|
||||||
|
FOREACH_AFI_SAFI (afi, safi) {
|
||||||
|
if (peer->afc[afi][safi]) {
|
||||||
|
addpath_afi_safi_count++;
|
||||||
|
|
||||||
|
/* Only advertise addpath TX if a feature that
|
||||||
|
* will use it is
|
||||||
|
* configured */
|
||||||
|
if (peer->addpath_type[afi][safi] !=
|
||||||
|
BGP_ADDPATH_NONE)
|
||||||
|
adv_addpath_tx = true;
|
||||||
|
|
||||||
|
/* If we have enabled labeled unicast, we MUST check
|
||||||
|
* against unicast SAFI because addpath IDs are
|
||||||
|
* allocated under unicast SAFI, the same as the RIB
|
||||||
|
* is managed in unicast SAFI.
|
||||||
|
*/
|
||||||
|
if (safi == SAFI_LABELED_UNICAST)
|
||||||
|
if (peer->addpath_type[afi][SAFI_UNICAST] !=
|
||||||
|
BGP_ADDPATH_NONE)
|
||||||
|
adv_addpath_tx = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_putc(s, action);
|
||||||
|
stream_putc(s, CAPABILITY_CODE_ADDPATH);
|
||||||
|
stream_putc(s, CAPABILITY_CODE_ADDPATH_LEN *
|
||||||
|
addpath_afi_safi_count);
|
||||||
|
|
||||||
|
FOREACH_AFI_SAFI (afi, safi) {
|
||||||
|
if (peer->afc[afi][safi]) {
|
||||||
|
bool adv_addpath_rx =
|
||||||
|
!CHECK_FLAG(peer->af_flags[afi][safi],
|
||||||
|
PEER_FLAG_DISABLE_ADDPATH_RX);
|
||||||
|
uint8_t flags = 0;
|
||||||
|
|
||||||
|
/* Convert AFI, SAFI to values for packet. */
|
||||||
|
bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
|
||||||
|
&pkt_safi);
|
||||||
|
|
||||||
|
stream_putw(s, pkt_afi);
|
||||||
|
stream_putc(s, pkt_safi);
|
||||||
|
|
||||||
|
if (adv_addpath_rx) {
|
||||||
|
SET_FLAG(flags, BGP_ADDPATH_RX);
|
||||||
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_ADV);
|
||||||
|
} else {
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_ADV);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adv_addpath_tx) {
|
||||||
|
SET_FLAG(flags, BGP_ADDPATH_TX);
|
||||||
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_ADV);
|
||||||
|
if (safi == SAFI_LABELED_UNICAST)
|
||||||
|
SET_FLAG(peer->af_cap[afi]
|
||||||
|
[SAFI_UNICAST],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_ADV);
|
||||||
|
} else {
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_ADV);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_putc(s, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bgp_debug_neighbor_events(peer))
|
||||||
|
zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s",
|
||||||
|
peer,
|
||||||
|
action == CAPABILITY_ACTION_SET
|
||||||
|
? "Advertising"
|
||||||
|
: "Removing",
|
||||||
|
capability, iana_afi2str(pkt_afi),
|
||||||
|
iana_safi2str(pkt_safi));
|
||||||
|
|
||||||
|
break;
|
||||||
case CAPABILITY_CODE_REFRESH:
|
case CAPABILITY_CODE_REFRESH:
|
||||||
case CAPABILITY_CODE_ORF:
|
case CAPABILITY_CODE_ORF:
|
||||||
case CAPABILITY_CODE_AS4:
|
case CAPABILITY_CODE_AS4:
|
||||||
case CAPABILITY_CODE_DYNAMIC:
|
case CAPABILITY_CODE_DYNAMIC:
|
||||||
case CAPABILITY_CODE_ADDPATH:
|
|
||||||
case CAPABILITY_CODE_ENHANCED_RR:
|
case CAPABILITY_CODE_ENHANCED_RR:
|
||||||
case CAPABILITY_CODE_FQDN:
|
case CAPABILITY_CODE_FQDN:
|
||||||
case CAPABILITY_CODE_ENHE:
|
case CAPABILITY_CODE_ENHE:
|
||||||
@ -2871,6 +2954,96 @@ static int bgp_route_refresh_receive(struct peer_connection *connection,
|
|||||||
return BGP_PACKET_NOOP;
|
return BGP_PACKET_NOOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bgp_dynamic_capability_addpath(uint8_t *pnt, int action,
|
||||||
|
struct capability_header *hdr,
|
||||||
|
struct peer *peer)
|
||||||
|
{
|
||||||
|
uint8_t *data = pnt + 3;
|
||||||
|
uint8_t *end = data + hdr->length;
|
||||||
|
size_t len = end - data;
|
||||||
|
afi_t afi;
|
||||||
|
safi_t safi;
|
||||||
|
|
||||||
|
if (action == CAPABILITY_ACTION_SET) {
|
||||||
|
if (len % CAPABILITY_CODE_ADDPATH_LEN) {
|
||||||
|
flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH,
|
||||||
|
"Add Path: Received invalid length %zu, non-multiple of 4",
|
||||||
|
len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SET_FLAG(peer->cap, PEER_CAP_ADDPATH_RCV);
|
||||||
|
|
||||||
|
while (data + CAPABILITY_CODE_ADDPATH_LEN <= end) {
|
||||||
|
afi_t afi;
|
||||||
|
safi_t safi;
|
||||||
|
iana_afi_t pkt_afi;
|
||||||
|
iana_safi_t pkt_safi;
|
||||||
|
struct bgp_addpath_capability bac;
|
||||||
|
|
||||||
|
memcpy(&bac, data, sizeof(bac));
|
||||||
|
pkt_afi = ntohs(bac.afi);
|
||||||
|
pkt_safi = safi_int2iana(bac.safi);
|
||||||
|
|
||||||
|
if (bgp_debug_neighbor_events(peer))
|
||||||
|
zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s",
|
||||||
|
peer->host,
|
||||||
|
lookup_msg(capcode_str, hdr->code,
|
||||||
|
NULL),
|
||||||
|
iana_afi2str(pkt_afi),
|
||||||
|
iana_safi2str(pkt_safi),
|
||||||
|
(bac.flags & BGP_ADDPATH_RX)
|
||||||
|
? ", receive"
|
||||||
|
: "",
|
||||||
|
(bac.flags & BGP_ADDPATH_TX)
|
||||||
|
? ", transmit"
|
||||||
|
: "");
|
||||||
|
|
||||||
|
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi,
|
||||||
|
&safi)) {
|
||||||
|
if (bgp_debug_neighbor_events(peer))
|
||||||
|
zlog_debug("%s Addr-family %s/%s(afi/safi) not supported. Ignore the Addpath Attribute for this AFI/SAFI",
|
||||||
|
peer->host,
|
||||||
|
iana_afi2str(pkt_afi),
|
||||||
|
iana_safi2str(pkt_safi));
|
||||||
|
continue;
|
||||||
|
} else if (!peer->afc[afi][safi]) {
|
||||||
|
if (bgp_debug_neighbor_events(peer))
|
||||||
|
zlog_debug("%s Addr-family %s/%s(afi/safi) not enabled. Ignore the AddPath capability for this AFI/SAFI",
|
||||||
|
peer->host,
|
||||||
|
iana_afi2str(pkt_afi),
|
||||||
|
iana_safi2str(pkt_safi));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CHECK_FLAG(bac.flags, BGP_ADDPATH_RX))
|
||||||
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_RCV);
|
||||||
|
else
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_RCV);
|
||||||
|
|
||||||
|
if (CHECK_FLAG(bac.flags, BGP_ADDPATH_TX))
|
||||||
|
SET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_RCV);
|
||||||
|
else
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_RCV);
|
||||||
|
|
||||||
|
data += CAPABILITY_CODE_ADDPATH_LEN;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FOREACH_AFI_SAFI (afi, safi) {
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_RX_RCV);
|
||||||
|
UNSET_FLAG(peer->af_cap[afi][safi],
|
||||||
|
PEER_CAP_ADDPATH_AF_TX_RCV);
|
||||||
|
}
|
||||||
|
|
||||||
|
UNSET_FLAG(peer->cap, PEER_CAP_ADDPATH_RCV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void bgp_dynamic_capability_llgr(uint8_t *pnt, int action,
|
static void bgp_dynamic_capability_llgr(uint8_t *pnt, int action,
|
||||||
struct capability_header *hdr,
|
struct capability_header *hdr,
|
||||||
struct peer *peer)
|
struct peer *peer)
|
||||||
@ -3225,11 +3398,13 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt,
|
|||||||
case CAPABILITY_CODE_LLGR:
|
case CAPABILITY_CODE_LLGR:
|
||||||
bgp_dynamic_capability_llgr(pnt, action, hdr, peer);
|
bgp_dynamic_capability_llgr(pnt, action, hdr, peer);
|
||||||
break;
|
break;
|
||||||
|
case CAPABILITY_CODE_ADDPATH:
|
||||||
|
bgp_dynamic_capability_addpath(pnt, action, hdr, peer);
|
||||||
|
break;
|
||||||
case CAPABILITY_CODE_REFRESH:
|
case CAPABILITY_CODE_REFRESH:
|
||||||
case CAPABILITY_CODE_ORF:
|
case CAPABILITY_CODE_ORF:
|
||||||
case CAPABILITY_CODE_AS4:
|
case CAPABILITY_CODE_AS4:
|
||||||
case CAPABILITY_CODE_DYNAMIC:
|
case CAPABILITY_CODE_DYNAMIC:
|
||||||
case CAPABILITY_CODE_ADDPATH:
|
|
||||||
case CAPABILITY_CODE_ENHANCED_RR:
|
case CAPABILITY_CODE_ENHANCED_RR:
|
||||||
case CAPABILITY_CODE_FQDN:
|
case CAPABILITY_CODE_FQDN:
|
||||||
case CAPABILITY_CODE_ENHE:
|
case CAPABILITY_CODE_ENHE:
|
||||||
|
@ -8840,13 +8840,21 @@ DEFUN(neighbor_disable_addpath_rx,
|
|||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
afi_t afi = bgp_node_afi(vty);
|
afi_t afi = bgp_node_afi(vty);
|
||||||
safi_t safi = bgp_node_safi(vty);
|
safi_t safi = bgp_node_safi(vty);
|
||||||
|
int ret;
|
||||||
|
int action;
|
||||||
|
|
||||||
peer = peer_and_group_lookup_vty(vty, peer_str);
|
peer = peer_and_group_lookup_vty(vty, peer_str);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
|
||||||
return peer_af_flag_set_vty(vty, peer_str, afi, safi,
|
action = bgp_addpath_capability_action(peer->addpath_type[afi][safi], 0);
|
||||||
PEER_FLAG_DISABLE_ADDPATH_RX);
|
|
||||||
|
ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
|
||||||
|
PEER_FLAG_DISABLE_ADDPATH_RX);
|
||||||
|
|
||||||
|
bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFUN(no_neighbor_disable_addpath_rx,
|
DEFUN(no_neighbor_disable_addpath_rx,
|
||||||
@ -8861,13 +8869,21 @@ DEFUN(no_neighbor_disable_addpath_rx,
|
|||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
afi_t afi = bgp_node_afi(vty);
|
afi_t afi = bgp_node_afi(vty);
|
||||||
safi_t safi = bgp_node_safi(vty);
|
safi_t safi = bgp_node_safi(vty);
|
||||||
|
int ret;
|
||||||
|
int action;
|
||||||
|
|
||||||
peer = peer_and_group_lookup_vty(vty, peer_str);
|
peer = peer_and_group_lookup_vty(vty, peer_str);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
|
||||||
return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
|
action = bgp_addpath_capability_action(peer->addpath_type[afi][safi], 0);
|
||||||
PEER_FLAG_DISABLE_ADDPATH_RX);
|
|
||||||
|
ret = peer_af_flag_unset_vty(vty, peer_str, afi, safi,
|
||||||
|
PEER_FLAG_DISABLE_ADDPATH_RX);
|
||||||
|
|
||||||
|
bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFUN (neighbor_addpath_tx_all_paths,
|
DEFUN (neighbor_addpath_tx_all_paths,
|
||||||
@ -8879,13 +8895,15 @@ DEFUN (neighbor_addpath_tx_all_paths,
|
|||||||
{
|
{
|
||||||
int idx_peer = 1;
|
int idx_peer = 1;
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
|
afi_t afi = bgp_node_afi(vty);
|
||||||
|
safi_t safi = bgp_node_safi(vty);
|
||||||
|
|
||||||
peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
|
peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
|
||||||
bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
|
bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_ALL, 0);
|
||||||
BGP_ADDPATH_ALL, 0);
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8905,20 +8923,20 @@ DEFUN (no_neighbor_addpath_tx_all_paths,
|
|||||||
{
|
{
|
||||||
int idx_peer = 2;
|
int idx_peer = 2;
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
|
afi_t afi = bgp_node_afi(vty);
|
||||||
|
safi_t safi = bgp_node_safi(vty);
|
||||||
|
|
||||||
peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
|
peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
|
|
||||||
if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
|
if (peer->addpath_type[afi][safi] != BGP_ADDPATH_ALL) {
|
||||||
!= BGP_ADDPATH_ALL) {
|
|
||||||
vty_out(vty,
|
vty_out(vty,
|
||||||
"%% Peer not currently configured to transmit all paths.");
|
"%% Peer not currently configured to transmit all paths.");
|
||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
|
bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE, 0);
|
||||||
BGP_ADDPATH_NONE, 0);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -4552,7 +4552,7 @@ static const struct peer_flag_action peer_af_flag_action_list[] = {
|
|||||||
{PEER_FLAG_AS_OVERRIDE, 1, peer_change_reset_out},
|
{PEER_FLAG_AS_OVERRIDE, 1, peer_change_reset_out},
|
||||||
{PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE, 1, peer_change_reset_out},
|
{PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE, 1, peer_change_reset_out},
|
||||||
{PEER_FLAG_WEIGHT, 0, peer_change_reset_in},
|
{PEER_FLAG_WEIGHT, 0, peer_change_reset_in},
|
||||||
{PEER_FLAG_DISABLE_ADDPATH_RX, 0, peer_change_reset},
|
{PEER_FLAG_DISABLE_ADDPATH_RX, 0, peer_change_none},
|
||||||
{PEER_FLAG_SOO, 0, peer_change_reset},
|
{PEER_FLAG_SOO, 0, peer_change_reset},
|
||||||
{PEER_FLAG_ACCEPT_OWN, 0, peer_change_reset},
|
{PEER_FLAG_ACCEPT_OWN, 0, peer_change_reset},
|
||||||
{0, 0, 0}};
|
{0, 0, 0}};
|
||||||
|
@ -12,4 +12,8 @@ router bgp 65001
|
|||||||
neighbor 192.168.1.2 timers 1 3
|
neighbor 192.168.1.2 timers 1 3
|
||||||
neighbor 192.168.1.2 timers connect 1
|
neighbor 192.168.1.2 timers connect 1
|
||||||
neighbor 192.168.1.2 capability dynamic
|
neighbor 192.168.1.2 capability dynamic
|
||||||
|
!
|
||||||
|
address-family ipv4 unicast
|
||||||
|
neighbor 192.168.1.2 addpath-tx-all-paths
|
||||||
|
exit-address-family
|
||||||
!
|
!
|
||||||
|
@ -0,0 +1,170 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# SPDX-License-Identifier: ISC
|
||||||
|
|
||||||
|
# Copyright (c) 2023 by
|
||||||
|
# Donatas Abraitis <donatas@opensourcerouting.org>
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test if Addpath capability is adjusted dynamically.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
import functools
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.bgpd
|
||||||
|
|
||||||
|
CWD = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
sys.path.append(os.path.join(CWD, "../"))
|
||||||
|
|
||||||
|
# pylint: disable=C0413
|
||||||
|
from lib import topotest
|
||||||
|
from lib.topogen import Topogen, TopoRouter, get_topogen
|
||||||
|
from lib.common_config import step
|
||||||
|
|
||||||
|
pytestmark = [pytest.mark.bgpd]
|
||||||
|
|
||||||
|
|
||||||
|
def setup_module(mod):
|
||||||
|
topodef = {"s1": ("r1", "r2")}
|
||||||
|
tgen = Topogen(topodef, mod.__name__)
|
||||||
|
tgen.start_topology()
|
||||||
|
|
||||||
|
router_list = tgen.routers()
|
||||||
|
|
||||||
|
for _, (rname, router) in enumerate(router_list.items(), 1):
|
||||||
|
router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
|
||||||
|
|
||||||
|
tgen.start_router()
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_module(mod):
|
||||||
|
tgen = get_topogen()
|
||||||
|
tgen.stop_topology()
|
||||||
|
|
||||||
|
|
||||||
|
def test_bgp_dynamic_capability_role():
|
||||||
|
tgen = get_topogen()
|
||||||
|
|
||||||
|
if tgen.routers_have_failure():
|
||||||
|
pytest.skip(tgen.errors)
|
||||||
|
|
||||||
|
r1 = tgen.gears["r1"]
|
||||||
|
r2 = tgen.gears["r2"]
|
||||||
|
|
||||||
|
def _bgp_converge():
|
||||||
|
output = json.loads(r1.vtysh_cmd("show bgp neighbor json"))
|
||||||
|
expected = {
|
||||||
|
"192.168.1.2": {
|
||||||
|
"bgpState": "Established",
|
||||||
|
"neighborCapabilities": {
|
||||||
|
"dynamic": "advertisedAndReceived",
|
||||||
|
"addPath": {
|
||||||
|
"ipv4Unicast": {
|
||||||
|
"txAdvertised": True,
|
||||||
|
"rxAdvertisedAndReceived": True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return topotest.json_cmp(output, expected)
|
||||||
|
|
||||||
|
test_func = functools.partial(
|
||||||
|
_bgp_converge,
|
||||||
|
)
|
||||||
|
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
|
||||||
|
assert result is None, "Can't converge"
|
||||||
|
|
||||||
|
step("Enable Addpath capability and check if it's exchanged dynamically")
|
||||||
|
|
||||||
|
# Clear message stats to check if we receive a notification or not after we
|
||||||
|
# change the settings fo LLGR.
|
||||||
|
r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats")
|
||||||
|
r2.vtysh_cmd(
|
||||||
|
"""
|
||||||
|
configure terminal
|
||||||
|
router bgp
|
||||||
|
address-family ipv4 unicast
|
||||||
|
neighbor 192.168.1.1 addpath-tx-all-paths
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
def _bgp_check_if_addpath_rx_tx_and_session_not_reset():
|
||||||
|
output = json.loads(r1.vtysh_cmd("show bgp neighbor json"))
|
||||||
|
expected = {
|
||||||
|
"192.168.1.2": {
|
||||||
|
"bgpState": "Established",
|
||||||
|
"neighborCapabilities": {
|
||||||
|
"dynamic": "advertisedAndReceived",
|
||||||
|
"addPath": {
|
||||||
|
"ipv4Unicast": {
|
||||||
|
"txAdvertisedAndReceived": True,
|
||||||
|
"rxAdvertisedAndReceived": True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"messageStats": {
|
||||||
|
"notificationsRecv": 0,
|
||||||
|
"capabilityRecv": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return topotest.json_cmp(output, expected)
|
||||||
|
|
||||||
|
test_func = functools.partial(
|
||||||
|
_bgp_check_if_addpath_rx_tx_and_session_not_reset,
|
||||||
|
)
|
||||||
|
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
|
||||||
|
assert result is None, "Session was reset after enabling Addpath capability"
|
||||||
|
|
||||||
|
step("Disable Addpath capability RX and check if it's exchanged dynamically")
|
||||||
|
|
||||||
|
# Clear message stats to check if we receive a notification or not after we
|
||||||
|
# change the settings fo LLGR.
|
||||||
|
r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats")
|
||||||
|
r2.vtysh_cmd(
|
||||||
|
"""
|
||||||
|
configure terminal
|
||||||
|
router bgp
|
||||||
|
address-family ipv4 unicast
|
||||||
|
neighbor 192.168.1.1 disable-addpath-rx
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
def _bgp_check_if_addpath_tx_and_session_not_reset():
|
||||||
|
output = json.loads(r1.vtysh_cmd("show bgp neighbor json"))
|
||||||
|
expected = {
|
||||||
|
"192.168.1.2": {
|
||||||
|
"bgpState": "Established",
|
||||||
|
"neighborCapabilities": {
|
||||||
|
"dynamic": "advertisedAndReceived",
|
||||||
|
"addPath": {
|
||||||
|
"ipv4Unicast": {
|
||||||
|
"txAdvertisedAndReceived": True,
|
||||||
|
"rxAdvertised": True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"messageStats": {
|
||||||
|
"notificationsRecv": 0,
|
||||||
|
"capabilityRecv": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return topotest.json_cmp(output, expected)
|
||||||
|
|
||||||
|
test_func = functools.partial(
|
||||||
|
_bgp_check_if_addpath_tx_and_session_not_reset,
|
||||||
|
)
|
||||||
|
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
|
||||||
|
assert result is None, "Session was reset after disabling Addpath RX flags"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = ["-s"] + sys.argv[1:]
|
||||||
|
sys.exit(pytest.main(args))
|
Loading…
Reference in New Issue
Block a user