Merge pull request #12618 from pguibert6WIND/vpnv4_ecmp

Vpnv4 ecmp
This commit is contained in:
Russ White 2023-02-28 15:49:05 -05:00 committed by GitHub
commit 516444e6b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 255 additions and 57 deletions

View File

@ -581,6 +581,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
bool new_proxy; bool new_proxy;
bool new_origin, exist_origin; bool new_origin, exist_origin;
struct bgp_path_info *bpi_ultimate; struct bgp_path_info *bpi_ultimate;
struct peer *peer_new, *peer_exist;
*paths_eq = 0; *paths_eq = 0;
@ -1397,16 +1398,25 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
} }
/* locally configured routes to advertise do not have su_remote */ /* locally configured routes to advertise do not have su_remote */
if (new->peer->su_remote == NULL) { if (new->sub_type == BGP_ROUTE_IMPORTED) {
bpi_ultimate = bgp_get_imported_bpi_ultimate(new);
peer_new = bpi_ultimate->peer;
} else if (new->peer->su_remote == NULL) {
*reason = bgp_path_selection_local_configured; *reason = bgp_path_selection_local_configured;
return 0; return 0;
} } else
if (exist->peer->su_remote == NULL) { peer_new = new->peer;
if (exist->sub_type == BGP_ROUTE_IMPORTED) {
bpi_ultimate = bgp_get_imported_bpi_ultimate(exist);
peer_exist = bpi_ultimate->peer;
} else if (exist->peer->su_remote == NULL) {
*reason = bgp_path_selection_local_configured; *reason = bgp_path_selection_local_configured;
return 1; return 1;
} } else
peer_exist = exist->peer;
ret = sockunion_cmp(new->peer->su_remote, exist->peer->su_remote); ret = sockunion_cmp(peer_new->su_remote, peer_exist->su_remote);
if (ret == 1) { if (ret == 1) {
*reason = bgp_path_selection_neighbor_ip; *reason = bgp_path_selection_neighbor_ip;

View File

@ -0,0 +1,49 @@
{
"vrfName": "vrf1",
"localAS": 65500,
"routes":
{
"172.31.0.10/32": [
{
"prefix": "172.31.0.10",
"prefixLen": 32,
"network": "172.31.0.10\/32",
"nhVrfName": "default",
"nexthops": [
{
"ip": "192.168.0.3",
"afi": "ipv4",
"used": true
}
]
},
{
"prefix": "172.31.0.10",
"prefixLen": 32,
"network": "172.31.0.10\/32",
"nhVrfName": "default",
"nexthops": [
{
"ip": "192.168.0.2",
"afi": "ipv4",
"used": true
}
]
}
],
"172.31.0.1/32": [
{
"prefix": "172.31.0.1",
"prefixLen": 32,
"network": "172.31.0.1\/32",
"nexthops": [
{
"ip": "0.0.0.0",
"afi": "ipv4",
"used": true
}
]
}
]
}
}

View File

@ -1,16 +1,19 @@
router bgp 65500 router bgp 65500
bgp router-id 1.1.1.1 bgp router-id 192.0.2.1
no bgp ebgp-requires-policy no bgp ebgp-requires-policy
neighbor 10.125.0.2 remote-as 65501 neighbor 192.168.0.2 remote-as 65501
neighbor 192.168.0.3 remote-as 65501
address-family ipv4 unicast address-family ipv4 unicast
no neighbor 10.125.0.2 activate no neighbor 192.168.0.3 activate
no neighbor 192.168.0.2 activate
exit-address-family exit-address-family
address-family ipv4 vpn address-family ipv4 vpn
neighbor 10.125.0.2 activate neighbor 192.168.0.2 activate
neighbor 192.168.0.3 activate
exit-address-family exit-address-family
! !
router bgp 65500 vrf vrf1 router bgp 65500 vrf vrf1
bgp router-id 1.1.1.1 bgp router-id 192.0.2.1
address-family ipv4 unicast address-family ipv4 unicast
redistribute connected redistribute connected
label vpn export 101 label vpn export 101

View File

@ -1,8 +1,8 @@
{ {
"10.200.0.0/24": [ "172.31.0.10/32": [
{ {
"prefix": "10.200.0.0/24", "prefix": "172.31.0.10/32",
"prefixLen": 24, "prefixLen": 32,
"protocol": "bgp", "protocol": "bgp",
"vrfName": "vrf1", "vrfName": "vrf1",
"selected": true, "selected": true,
@ -13,7 +13,19 @@
{ {
"flags": 3, "flags": 3,
"fib": true, "fib": true,
"ip": "10.125.0.2", "ip": "192.168.0.2",
"afi": "ipv4",
"interfaceName": "r1-eth0",
"vrf": "default",
"active": true,
"labels":[
102
]
},
{
"flags": 3,
"fib": true,
"ip": "192.168.0.3",
"afi": "ipv4", "afi": "ipv4",
"interfaceName": "r1-eth0", "interfaceName": "r1-eth0",
"vrf": "default", "vrf": "default",
@ -25,10 +37,10 @@
] ]
} }
], ],
"10.201.0.0/24": [ "172.31.0.1/32": [
{ {
"prefix": "10.201.0.0/24", "prefix": "172.31.0.1/32",
"prefixLen": 24, "prefixLen": 32,
"protocol": "connected", "protocol": "connected",
"vrfName": "vrf1", "vrfName": "vrf1",
"selected": true, "selected": true,

View File

@ -1,7 +1,7 @@
log stdout log stdout
interface r1-eth1 vrf vrf1 interface r1-eth1 vrf vrf1
ip address 10.201.0.1/24 ip address 172.31.0.1/32
! !
interface r1-eth0 interface r1-eth0
ip address 10.125.0.1/24 ip address 192.168.0.1/24
! !

View File

@ -3,28 +3,28 @@
"localAS": 65501, "localAS": 65501,
"routes": "routes":
{ {
"10.201.0.0/24": [ "172.31.0.1/32": [
{ {
"prefix": "10.201.0.0", "prefix": "172.31.0.1",
"prefixLen": 24, "prefixLen": 32,
"network": "10.201.0.0\/24", "network": "172.31.0.1\/32",
"nhVrfName": "default", "nhVrfName": "default",
"nexthops": [ "nexthops": [
{ {
"ip": "10.125.0.1", "ip": "192.168.0.1",
"afi": "ipv4", "afi": "ipv4",
"used": true "used": true
} }
] ]
} }
], ],
"10.200.0.0/24": [ "172.31.0.10/32": [
{ {
"valid": true, "valid": true,
"bestpath": true, "bestpath": true,
"prefix": "10.200.0.0", "prefix": "172.31.0.10",
"prefixLen": 24, "prefixLen": 32,
"network": "10.200.0.0\/24", "network": "172.31.0.10\/32",
"nexthops": [ "nexthops": [
{ {
"ip": "0.0.0.0", "ip": "0.0.0.0",

View File

@ -1,16 +1,16 @@
router bgp 65501 router bgp 65501
bgp router-id 2.2.2.2 bgp router-id 192.0.2.2
no bgp ebgp-requires-policy no bgp ebgp-requires-policy
neighbor 10.125.0.1 remote-as 65500 neighbor 192.168.0.1 remote-as 65500
address-family ipv4 unicast address-family ipv4 unicast
no neighbor 10.125.0.1 activate no neighbor 192.168.0.1 activate
exit-address-family exit-address-family
address-family ipv4 vpn address-family ipv4 vpn
neighbor 10.125.0.1 activate neighbor 192.168.0.1 activate
exit-address-family exit-address-family
! !
router bgp 65501 vrf vrf1 router bgp 65501 vrf vrf1
bgp router-id 2.2.2.2 bgp router-id 192.0.2.2
address-family ipv4 unicast address-family ipv4 unicast
redistribute connected redistribute connected
label vpn export 102 label vpn export 102

View File

@ -1,7 +1,7 @@
log stdout log stdout
interface r2-eth1 vrf vrf1 interface r2-eth1 vrf vrf1
ip address 10.200.0.2/24 ip address 172.31.0.10/32
! !
interface r2-eth0 interface r2-eth0
ip address 10.125.0.2/24 ip address 192.168.0.2/24
! !

View File

@ -0,0 +1,38 @@
{
"vrfName": "vrf1",
"localAS": 65501,
"routes":
{
"10.201.0.0/24": [
{
"prefix": "10.201.0.0",
"prefixLen": 24,
"network": "10.201.0.0\/24",
"nhVrfName": "default",
"nexthops": [
{
"ip": "10.125.0.1",
"afi": "ipv4",
"used": true
}
]
}
],
"10.200.0.0/24": [
{
"valid": true,
"bestpath": true,
"prefix": "10.200.0.0",
"prefixLen": 24,
"network": "10.200.0.0\/24",
"nexthops": [
{
"ip": "0.0.0.0",
"afi": "ipv4",
"used": true
}
]
}
]
}
}

View File

@ -0,0 +1,25 @@
router bgp 65501
bgp router-id 192.0.2.3
no bgp ebgp-requires-policy
neighbor 192.168.0.1 remote-as 65500
address-family ipv4 unicast
no neighbor 192.168.0.1 activate
exit-address-family
address-family ipv4 vpn
neighbor 192.168.0.1 activate
exit-address-family
!
router bgp 65502 vrf vrf1
bgp router-id 192.0.2.3
address-family ipv4 unicast
redistribute connected
label vpn export 102
rd vpn export 444:3
rt vpn both 52:100
export vpn
import vpn
exit-address-family
!
interface r3-eth0
mpls bgp forwarding
!

View File

@ -0,0 +1,7 @@
log stdout
interface r3-eth1 vrf vrf1
ip address 172.31.0.10/32
!
interface r3-eth0
ip address 192.168.0.3/24
!

View File

@ -40,10 +40,12 @@ def build_topo(tgen):
# Create 2 routers. # Create 2 routers.
tgen.add_router("r1") tgen.add_router("r1")
tgen.add_router("r2") tgen.add_router("r2")
tgen.add_router("r3")
switch = tgen.add_switch("s1") switch = tgen.add_switch("s1")
switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"]) switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
switch = tgen.add_switch("s2") switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r1"])
@ -51,27 +53,38 @@ def build_topo(tgen):
switch = tgen.add_switch("s3") switch = tgen.add_switch("s3")
switch.add_link(tgen.gears["r2"]) switch.add_link(tgen.gears["r2"])
switch = tgen.add_switch("s4")
switch.add_link(tgen.gears["r3"])
def _populate_iface(): def _populate_iface():
tgen = get_topogen() tgen = get_topogen()
cmds_list = [ cmds_list = [
'ip link add vrf1 type vrf table 10', "ip link add vrf1 type vrf table 10",
'echo 100000 > /proc/sys/net/mpls/platform_labels', "echo 100000 > /proc/sys/net/mpls/platform_labels",
'ip link set dev vrf1 up', "ip link set dev vrf1 up",
'ip link set dev {0}-eth1 master vrf1', "ip link set dev {0}-eth1 master vrf1",
'echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input', "echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input",
] ]
for cmd in cmds_list: for cmd in cmds_list:
input = cmd.format('r1', '1', '2') input = cmd.format("r1")
logger.info('input: ' + cmd) logger.info("input: " + cmd)
output = tgen.net['r1'].cmd(cmd.format('r1', '1', '2')) output = tgen.net["r1"].cmd(cmd.format("r1"))
logger.info('output: ' + output) logger.info("output: " + output)
for cmd in cmds_list: for cmd in cmds_list:
input = cmd.format('r2', '2', '1') input = cmd.format("r2")
logger.info('input: ' + cmd) logger.info("input: " + cmd)
output = tgen.net['r2'].cmd(cmd.format('r2', '2', '1')) output = tgen.net["r2"].cmd(cmd.format("r2"))
logger.info('output: ' + output) logger.info("output: " + output)
for cmd in cmds_list:
input = cmd.format("r3")
logger.info("input: " + cmd)
output = tgen.net["r3"].cmd(cmd.format("r3"))
logger.info("output: " + output)
def setup_module(mod): def setup_module(mod):
"Sets up the pytest environment" "Sets up the pytest environment"
@ -109,13 +122,13 @@ def test_protocols_convergence():
if tgen.routers_have_failure(): if tgen.routers_have_failure():
pytest.skip(tgen.errors) pytest.skip(tgen.errors)
router = tgen.gears['r1'] router = tgen.gears["r1"]
logger.info("Dump some context for r1") logger.info("Dump some context for r1")
router.vtysh_cmd("show bgp ipv4 vpn") router.vtysh_cmd("show bgp ipv4 vpn")
router.vtysh_cmd("show bgp summary") router.vtysh_cmd("show bgp summary")
router.vtysh_cmd("show bgp vrf vrf1 ipv4") router.vtysh_cmd("show bgp vrf vrf1 ipv4")
router.vtysh_cmd("show running-config") router.vtysh_cmd("show running-config")
router = tgen.gears['r2'] router = tgen.gears["r2"]
logger.info("Dump some context for r2") logger.info("Dump some context for r2")
router.vtysh_cmd("show bgp ipv4 vpn") router.vtysh_cmd("show bgp ipv4 vpn")
router.vtysh_cmd("show bgp summary") router.vtysh_cmd("show bgp summary")
@ -124,11 +137,11 @@ def test_protocols_convergence():
# Check IPv4 routing tables on r1 # Check IPv4 routing tables on r1
logger.info("Checking IPv4 routes for convergence on r1") logger.info("Checking IPv4 routes for convergence on r1")
router = tgen.gears['r1'] router = tgen.gears["r1"]
json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name) json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file): if not os.path.isfile(json_file):
logger.info("skipping file {}".format(json_file)) logger.info("skipping file {}".format(json_file))
assert 0, 'ipv4_routes.json file not found' assert 0, "ipv4_routes.json file not found"
return return
expected = json.loads(open(json_file).read()) expected = json.loads(open(json_file).read())
@ -142,12 +155,12 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name) assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg assert result is None, assertmsg
# Check BGP IPv4 routing tables on r2 not installed # Check BGP IPv4 routing tables on r1
logger.info("Checking BGP IPv4 routes for convergence on r2") logger.info("Checking BGP IPv4 routes for convergence on r1")
router = tgen.gears['r2'] router = tgen.gears["r1"]
json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name) json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file): if not os.path.isfile(json_file):
assert 0, 'bgp_ipv4_routes.json file not found' assert 0, "bgp_ipv4_routes.json file not found"
expected = json.loads(open(json_file).read()) expected = json.loads(open(json_file).read())
test_func = partial( test_func = partial(
@ -160,6 +173,47 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name) assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg assert result is None, assertmsg
# Check BGP IPv4 imported entry is not detected as local
# "selectionReason": "Locally configured route"
donna = tgen.gears["r1"].vtysh_cmd(
"show bgp vrf vrf1 ipv4 172.31.0.10/32 json", isjson=True
)
routes = donna["paths"]
selectionReasonFound = False
for route in routes:
if "bestpath" not in route.keys():
continue
if "selectionReason" not in route["bestpath"].keys():
continue
if "Locally configured route" == route["bestpath"]["selectionReason"]:
assert 0, "imported prefix has wrong reason detected"
selectionReasonFound = True
if not selectionReasonFound:
assertmsg = '"{}" imported prefix has wrong reason detected'.format(router.name)
assert False, assertmsg
# Check BGP IPv4 routing tables on r2 not installed
logger.info("Checking BGP IPv4 routes for convergence on r2")
router = tgen.gears["r2"]
json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file):
assert 0, "bgp_ipv4_routes.json file not found"
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp,
router,
"show bgp vrf vrf1 ipv4 json",
expected,
)
_, result = topotest.run_and_expect(test_func, None, count=40, wait=2)
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg
def test_memory_leak(): def test_memory_leak():
"Run the memory leak test and report results." "Run the memory leak test and report results."
tgen = get_topogen() tgen = get_topogen()