Merge pull request #12456 from opensourcerouting/fix/bgpd_labeled_unicast_rr_addpath

bgpd: Labeled unicast fixes for addpath capability
This commit is contained in:
Donald Sharp 2022-12-07 08:03:59 -05:00 committed by GitHub
commit 1b97fa9976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 294 additions and 9 deletions

View File

@ -111,6 +111,9 @@ void bgp_addpath_free_info_data(struct bgp_addpath_info_data *d,
uint32_t bgp_addpath_id_for_peer(struct peer *peer, afi_t afi, safi_t safi,
struct bgp_addpath_info_data *d)
{
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
if (peer->addpath_type[afi][safi] < BGP_ADDPATH_MAX)
return d->addpath_tx_id[peer->addpath_type[afi][safi]];
else
@ -182,6 +185,9 @@ static void bgp_addpath_flush_type_rn(struct bgp *bgp, afi_t afi, safi_t safi,
{
struct bgp_path_info *pi;
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
idalloc_drain_pool(
bgp->tx_addpath.id_allocators[afi][safi][addpath_type],
&(dest->tx_addpath.free_ids[addpath_type]));
@ -210,6 +216,9 @@ static void bgp_addpath_flush_type(struct bgp *bgp, afi_t afi, safi_t safi,
{
struct bgp_dest *dest, *ndest;
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
if (safi == SAFI_MPLS_VPN) {
@ -251,6 +260,7 @@ static void bgp_addpath_populate_path(struct id_alloc *allocator,
* and afi/safi combination. Since we won't waste the time computing addpath IDs
* for unused strategies, the first time a peer is configured to use a strategy,
* we have to backfill the data.
* In labeled-unicast, addpath allocations SHOULD be done in unicast SAFI.
*/
static void bgp_addpath_populate_type(struct bgp *bgp, afi_t afi, safi_t safi,
enum bgp_addpath_strat addpath_type)
@ -259,6 +269,9 @@ static void bgp_addpath_populate_type(struct bgp *bgp, afi_t afi, safi_t safi,
char buf[200];
struct id_alloc *allocator;
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
snprintf(buf, sizeof(buf), "Addpath ID Allocator %s:%d/%d",
bgp_addpath_names(addpath_type)->config_name, (int)afi,
(int)safi);
@ -357,11 +370,15 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
enum bgp_addpath_strat addpath_type)
{
struct bgp *bgp = peer->bgp;
enum bgp_addpath_strat old_type = peer->addpath_type[afi][safi];
enum bgp_addpath_strat old_type;
struct listnode *node, *nnode;
struct peer *tmp_peer;
struct peer_group *group;
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
old_type = peer->addpath_type[afi][safi];
if (addpath_type == old_type)
return;
@ -431,6 +448,9 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *bn, afi_t afi,
struct bgp_path_info *pi;
struct id_alloc_pool **pool_ptr;
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
for (i = 0; i < BGP_ADDPATH_MAX; i++) {
struct id_alloc *alloc =
bgp->tx_addpath.id_allocators[afi][safi][i];

View File

@ -1658,7 +1658,7 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer,
iana_safi_t pkt_safi = IANA_SAFI_UNICAST;
as_t local_as;
uint8_t afi_safi_count = 0;
int adv_addpath_tx = 0;
bool adv_addpath_tx = false;
/* Non-Ext OP Len. */
cp = stream_get_endp(s);
@ -1797,7 +1797,17 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer,
* will use it is
* configured */
if (peer->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
adv_addpath_tx = 1;
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;
}
}
@ -1838,6 +1848,10 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer,
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);

View File

@ -2086,11 +2086,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
/* If this is not the bestpath then check to see if there is an enabled
* addpath
* feature that requires us to advertise it */
if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
if (!bgp_addpath_tx_path(peer->addpath_type[afi][safi], pi)) {
if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
if (!bgp_addpath_capable(pi, peer, afi, safi))
return false;
}
}
/* Aggregate-address suppress check. */
if (bgp_path_suppressed(pi) && !UNSUPPRESS_MAP_NAME(filter))
@ -9736,8 +9734,13 @@ void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
}
}
if (use_json) {
struct bgp_path_info *bpi = bgp_dest_get_bgp_path_info(dest);
json_object_boolean_true_add(json_status, "*");
json_object_boolean_true_add(json_status, ">");
if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_MULTIPATH))
json_object_boolean_true_add(json_status, "=");
json_object_object_add(json_net, "appliedStatusSymbols",
json_status);
json_object_object_addf(json_ar, json_net, "%pFX", p);

View File

@ -2230,10 +2230,18 @@ bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi)
PEER_CAP_ADDPATH_AF_RX_RCV));
}
bool bgp_addpath_capable(struct bgp_path_info *bpi, struct peer *peer,
afi_t afi, safi_t safi)
{
return (bgp_addpath_tx_path(peer->addpath_type[afi][safi], bpi) ||
(safi == SAFI_LABELED_UNICAST &&
bgp_addpath_tx_path(peer->addpath_type[afi][SAFI_UNICAST],
bpi)));
}
bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer,
bool addpath_capable, afi_t afi, safi_t safi)
{
return (CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED) ||
(addpath_capable &&
bgp_addpath_tx_path(peer->addpath_type[afi][safi], bpi)));
(addpath_capable && bgp_addpath_capable(bpi, peer, afi, safi)));
}

View File

@ -476,6 +476,8 @@ extern void update_bgp_group_free(struct bgp *bgp);
extern bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi);
extern bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer,
bool addpath_capable, afi_t afi, safi_t safi);
extern bool bgp_addpath_capable(struct bgp_path_info *bpi, struct peer *peer,
afi_t afi, safi_t safi);
/*
* Inline functions

View File

@ -0,0 +1,14 @@
router bgp 65001
no bgp ebgp-requires-policy
no bgp default ipv4-unicast
neighbor 192.168.31.3 remote-as external
neighbor 192.168.31.3 timers 1 3
neighbor 192.168.31.3 timers connect 1
address-family ipv4 unicast
redistribute connected
exit-address-family
!
address-family ipv4 labeled-unicast
neighbor 192.168.31.3 activate
exit-address-family
!

View File

@ -0,0 +1,7 @@
!
interface lo
ip address 10.0.0.1/32
!
interface r1-eth0
ip address 192.168.31.1/24
!

View File

@ -0,0 +1,14 @@
router bgp 65002
no bgp ebgp-requires-policy
no bgp default ipv4-unicast
neighbor 192.168.32.3 remote-as external
neighbor 192.168.32.3 timers 1 3
neighbor 192.168.32.3 timers connect 1
address-family ipv4 unicast
redistribute connected
exit-address-family
!
address-family ipv4 labeled-unicast
neighbor 192.168.32.3 activate
exit-address-family
!

View File

@ -0,0 +1,7 @@
!
interface lo
ip address 10.0.0.1/32
!
interface r2-eth0
ip address 192.168.32.2/24
!

View File

@ -0,0 +1,30 @@
!
router bgp 65003
no bgp default ipv4-unicast
no bgp ebgp-requires-policy
no bgp suppress-duplicates
bgp bestpath as-path multipath-relax
neighbor 192.168.31.1 remote-as external
neighbor 192.168.31.1 timers 1 3
neighbor 192.168.31.1 timers connect 1
neighbor 192.168.32.2 remote-as external
neighbor 192.168.32.2 timers 1 3
neighbor 192.168.32.2 timers connect 1
neighbor 192.168.34.4 remote-as external
neighbor 192.168.34.4 timers 1 3
neighbor 192.168.34.4 timers connect 1
address-family ipv4 labeled-unicast
neighbor 192.168.31.1 activate
neighbor 192.168.32.2 activate
neighbor 192.168.34.4 activate
neighbor 192.168.34.4 route-map r4 out
neighbor 192.168.34.4 addpath-tx-all-paths
exit-address-family
!
!
ip prefix-list r4 seq 5 permit 10.0.0.1/32
!
route-map r4 permit 10
match ip address prefix-list r4
exit
!

View File

@ -0,0 +1,10 @@
!
interface r3-eth0
ip address 192.168.31.3/24
!
interface r3-eth1
ip address 192.168.32.3/24
!
interface r3-eth2
ip address 192.168.34.3/24
!

View File

@ -0,0 +1,10 @@
router bgp 65004
no bgp ebgp-requires-policy
no bgp default ipv4-unicast
neighbor 192.168.34.3 remote-as external
neighbor 192.168.34.3 timers 1 3
neighbor 192.168.34.3 timers connect 1
address-family ipv4 labeled-unicast
neighbor 192.168.34.3 activate
exit-address-family
!

View File

@ -0,0 +1,4 @@
!
interface r4-eth0
ip address 192.168.34.4/24
!

View File

@ -0,0 +1,142 @@
#!/usr/bin/env python
#
# Copyright (c) 2022 by
# Donatas Abraitis <donatas@opensourcerouting.org>
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice appear
# in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#
"""
Check if labeled-unicast works correctly with addpath capability.
"""
import os
import sys
import json
import pytest
import functools
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 build_topo(tgen):
for routern in range(1, 5):
tgen.add_router("r{}".format(routern))
switch = tgen.add_switch("s1")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r3"])
switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
switch = tgen.add_switch("s3")
switch.add_link(tgen.gears["r3"])
switch.add_link(tgen.gears["r4"])
def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
tgen.start_topology()
router_list = tgen.routers()
for i, (rname, router) in enumerate(router_list.items(), 1):
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
)
tgen.start_router()
def teardown_module(mod):
tgen = get_topogen()
tgen.stop_topology()
def test_bgp_addpath_labeled_unicast():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
r3 = tgen.gears["r3"]
r4 = tgen.gears["r4"]
def _bgp_check_advertised_routes():
output = json.loads(
r3.vtysh_cmd(
"show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json"
)
)
expected = {
"advertisedRoutes": {
"10.0.0.1/32": {
"appliedStatusSymbols": {
"*": True,
">": True,
"=": True,
}
}
},
"totalPrefixCounter": 2,
}
return topotest.json_cmp(output, expected)
test_func = functools.partial(_bgp_check_advertised_routes)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert (
result is None
), "Failed to advertise labeled-unicast with addpath (multipath)"
def _bgp_check_received_routes():
output = json.loads(r4.vtysh_cmd("show bgp ipv4 labeled-unicast json"))
expected = {
"routes": {
"10.0.0.1/32": [
{
"valid": True,
"path": "65003 65001",
},
{
"valid": True,
"path": "65003 65002",
},
]
}
}
return topotest.json_cmp(output, expected)
test_func = functools.partial(_bgp_check_received_routes)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed to receive labeled-unicast with addpath (multipath)"
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))