mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-02 13:18:52 +00:00
tests: add a bgp path selection topotest
Add a bgp path selection topotest to the IGP metric path selection. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
parent
6f27419975
commit
e577535f15
0
tests/topotests/bgp_path_selection/__init__.py
Normal file
0
tests/topotests/bgp_path_selection/__init__.py
Normal file
28
tests/topotests/bgp_path_selection/r1/bgpd.conf
Normal file
28
tests/topotests/bgp_path_selection/r1/bgpd.conf
Normal file
@ -0,0 +1,28 @@
|
||||
router bgp 65001
|
||||
no bgp ebgp-requires-policy
|
||||
neighbor 192.0.2.2 remote-as 65002
|
||||
neighbor 192.0.2.2 timers 1 3
|
||||
neighbor 192.0.2.2 timers connect 1
|
||||
neighbor 192.0.2.2 ebgp-multihop 2
|
||||
neighbor 192.0.2.3 remote-as 65002
|
||||
neighbor 192.0.2.3 timers 1 3
|
||||
neighbor 192.0.2.3 timers connect 1
|
||||
neighbor 192.0.2.3 ebgp-multihop 2
|
||||
address-family ipv4
|
||||
redistribute connected
|
||||
exit-address-family
|
||||
address-family ipv4 vpn
|
||||
neighbor 192.0.2.2 activate
|
||||
neighbor 192.0.2.3 activate
|
||||
exit-address-family
|
||||
!
|
||||
router bgp 65001 vrf vrf1
|
||||
bgp router-id 192.0.2.1
|
||||
address-family ipv4 unicast
|
||||
label vpn export 101
|
||||
rd vpn export 101:1
|
||||
rt vpn both 52:100
|
||||
import vpn
|
||||
export vpn
|
||||
exit-address-family
|
||||
!
|
26
tests/topotests/bgp_path_selection/r1/ldpd.conf
Normal file
26
tests/topotests/bgp_path_selection/r1/ldpd.conf
Normal file
@ -0,0 +1,26 @@
|
||||
hostname r1
|
||||
log file ldpd.log
|
||||
password zebra
|
||||
!
|
||||
! debug mpls ldp zebra
|
||||
! debug mpls ldp event
|
||||
! debug mpls ldp errors
|
||||
! debug mpls ldp messages recv
|
||||
! debug mpls ldp messages sent
|
||||
! debug mpls ldp discovery hello recv
|
||||
! debug mpls ldp discovery hello sent
|
||||
!
|
||||
mpls ldp
|
||||
router-id 192.0.2.1
|
||||
!
|
||||
address-family ipv4
|
||||
discovery transport-address 192.0.2.1
|
||||
!
|
||||
interface r1-eth0
|
||||
!
|
||||
interface r1-eth1
|
||||
!
|
||||
!
|
||||
!
|
||||
line vty
|
||||
!
|
2
tests/topotests/bgp_path_selection/r1/staticd.conf
Normal file
2
tests/topotests/bgp_path_selection/r1/staticd.conf
Normal file
@ -0,0 +1,2 @@
|
||||
ip route 192.0.2.2/32 192.168.1.2
|
||||
ip route 192.0.2.3/32 192.168.2.2
|
11
tests/topotests/bgp_path_selection/r1/zebra.conf
Normal file
11
tests/topotests/bgp_path_selection/r1/zebra.conf
Normal file
@ -0,0 +1,11 @@
|
||||
!
|
||||
interface lo
|
||||
ip address 192.0.2.1/32
|
||||
ip address 172.16.255.1/32
|
||||
!
|
||||
interface r1-eth0
|
||||
ip address 192.168.1.1/24
|
||||
!
|
||||
interface r1-eth1
|
||||
ip address 192.168.2.1/24
|
||||
!
|
25
tests/topotests/bgp_path_selection/r2/bgpd.conf
Normal file
25
tests/topotests/bgp_path_selection/r2/bgpd.conf
Normal file
@ -0,0 +1,25 @@
|
||||
router bgp 65002
|
||||
no bgp network import-check
|
||||
network 192.0.2.8/32
|
||||
no bgp ebgp-requires-policy
|
||||
neighbor 192.168.1.1 remote-as 65001
|
||||
neighbor 192.168.1.1 timers 1 3
|
||||
neighbor 192.168.1.1 timers connect 1
|
||||
neighbor 192.168.1.1 ebgp-multihop 2
|
||||
neighbor 192.168.1.1 update-source 192.0.2.2
|
||||
address-family ipv4 vpn
|
||||
neighbor 192.168.1.1 activate
|
||||
exit-address-family
|
||||
!
|
||||
router bgp 65002 vrf vrf1
|
||||
bgp router-id 192.0.2.2
|
||||
no bgp ebgp-requires-policy
|
||||
address-family ipv4 unicast
|
||||
redistribute connected
|
||||
label vpn export 102
|
||||
rd vpn export 102:1
|
||||
rt vpn both 52:100
|
||||
import vpn
|
||||
export vpn
|
||||
exit-address-family
|
||||
!
|
26
tests/topotests/bgp_path_selection/r2/ldpd.conf
Normal file
26
tests/topotests/bgp_path_selection/r2/ldpd.conf
Normal file
@ -0,0 +1,26 @@
|
||||
hostname r2
|
||||
log file ldpd.log
|
||||
password zebra
|
||||
!
|
||||
! debug mpls ldp zebra
|
||||
! debug mpls ldp event
|
||||
! debug mpls ldp errors
|
||||
! debug mpls ldp messages recv
|
||||
! debug mpls ldp messages sent
|
||||
! debug mpls ldp discovery hello recv
|
||||
! debug mpls ldp discovery hello sent
|
||||
!
|
||||
mpls ldp
|
||||
router-id 192.0.2.2
|
||||
!
|
||||
address-family ipv4
|
||||
discovery transport-address 192.0.2.2
|
||||
!
|
||||
interface r2-eth0
|
||||
!
|
||||
interface r2-eth1
|
||||
!
|
||||
!
|
||||
!
|
||||
line vty
|
||||
!
|
0
tests/topotests/bgp_path_selection/r2/staticd.conf
Normal file
0
tests/topotests/bgp_path_selection/r2/staticd.conf
Normal file
7
tests/topotests/bgp_path_selection/r2/zebra.conf
Normal file
7
tests/topotests/bgp_path_selection/r2/zebra.conf
Normal file
@ -0,0 +1,7 @@
|
||||
!
|
||||
int lo
|
||||
ip address 192.0.2.2/32
|
||||
!
|
||||
interface r2-eth0
|
||||
ip address 192.168.1.2/24
|
||||
!
|
25
tests/topotests/bgp_path_selection/r3/bgpd.conf
Normal file
25
tests/topotests/bgp_path_selection/r3/bgpd.conf
Normal file
@ -0,0 +1,25 @@
|
||||
router bgp 65002
|
||||
no bgp network import-check
|
||||
network 192.0.2.8/32
|
||||
no bgp ebgp-requires-policy
|
||||
neighbor 192.168.2.1 remote-as 65001
|
||||
neighbor 192.168.2.1 timers 1 3
|
||||
neighbor 192.168.2.1 timers connect 1
|
||||
neighbor 192.168.2.1 ebgp-multihop 2
|
||||
neighbor 192.168.1.1 update-source 192.0.2.3
|
||||
address-family ipv4 vpn
|
||||
neighbor 192.168.2.1 activate
|
||||
exit-address-family
|
||||
!
|
||||
router bgp 65002 vrf vrf1
|
||||
bgp router-id 192.0.2.3
|
||||
no bgp ebgp-requires-policy
|
||||
address-family ipv4 unicast
|
||||
redistribute connected
|
||||
label vpn export 103
|
||||
rd vpn export 102:1
|
||||
rt vpn both 52:100
|
||||
import vpn
|
||||
export vpn
|
||||
exit-address-family
|
||||
!
|
24
tests/topotests/bgp_path_selection/r3/ldpd.conf
Normal file
24
tests/topotests/bgp_path_selection/r3/ldpd.conf
Normal file
@ -0,0 +1,24 @@
|
||||
hostname r3
|
||||
password zebra
|
||||
log file ldpd.log
|
||||
!
|
||||
! debug mpls ldp zebra
|
||||
! debug mpls ldp event
|
||||
! debug mpls ldp errors
|
||||
! debug mpls ldp messages recv
|
||||
! debug mpls ldp messages sent
|
||||
! debug mpls ldp discovery hello recv
|
||||
! debug mpls ldp discovery hello sent
|
||||
!
|
||||
mpls ldp
|
||||
router-id 192.0.2.3
|
||||
!
|
||||
address-family ipv4
|
||||
discovery transport-address 192.0.2.3
|
||||
!
|
||||
interface r3-eth0
|
||||
!
|
||||
!
|
||||
!
|
||||
line vty
|
||||
!
|
0
tests/topotests/bgp_path_selection/r3/staticd.conf
Normal file
0
tests/topotests/bgp_path_selection/r3/staticd.conf
Normal file
7
tests/topotests/bgp_path_selection/r3/zebra.conf
Normal file
7
tests/topotests/bgp_path_selection/r3/zebra.conf
Normal file
@ -0,0 +1,7 @@
|
||||
!
|
||||
int lo
|
||||
ip address 192.0.2.3/32
|
||||
!
|
||||
interface r3-eth0
|
||||
ip address 192.168.2.2/24
|
||||
!
|
233
tests/topotests/bgp_path_selection/test_bgp_path_selection.py
Normal file
233
tests/topotests/bgp_path_selection/test_bgp_path_selection.py
Normal file
@ -0,0 +1,233 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# Copyright (c) 2022 by
|
||||
# Louis Scalbert <louis.scalbert@6wind.com>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
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, 4):
|
||||
tgen.add_router("r{}".format(routern))
|
||||
|
||||
switch = tgen.add_switch("s1")
|
||||
switch.add_link(tgen.gears["r1"])
|
||||
switch.add_link(tgen.gears["r2"])
|
||||
|
||||
switch = tgen.add_switch("s2")
|
||||
switch.add_link(tgen.gears["r1"])
|
||||
switch.add_link(tgen.gears["r3"])
|
||||
|
||||
|
||||
def setup_module(mod):
|
||||
tgen = Topogen(build_topo, mod.__name__)
|
||||
tgen.start_topology()
|
||||
|
||||
router_list = tgen.routers()
|
||||
|
||||
for routern in range(1, 4):
|
||||
tgen.gears["r{}".format(routern)].cmd("ip link add vrf1 type vrf table 10")
|
||||
tgen.gears["r{}".format(routern)].cmd("ip link set vrf1 up")
|
||||
tgen.gears["r{}".format(routern)].cmd("ip address add dev vrf1 {}.{}.{}.{}/32".format(routern, routern, routern,routern))
|
||||
tgen.gears["r2"].cmd("ip address add dev vrf1 192.0.2.8/32")
|
||||
tgen.gears["r3"].cmd("ip address add dev vrf1 192.0.2.8/32")
|
||||
|
||||
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))
|
||||
)
|
||||
router.load_config(
|
||||
TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname))
|
||||
)
|
||||
|
||||
tgen.start_router()
|
||||
|
||||
tgen.gears["r1"].cmd("ip route add 192.0.2.2 via 192.168.1.2 metric 20")
|
||||
tgen.gears["r1"].cmd("ip route add 192.0.2.3 via 192.168.2.2 metric 20")
|
||||
|
||||
|
||||
def teardown_module(mod):
|
||||
tgen = get_topogen()
|
||||
tgen.stop_topology()
|
||||
|
||||
def test_bgp_path_selection_ecmp():
|
||||
tgen = get_topogen()
|
||||
|
||||
if tgen.routers_have_failure():
|
||||
pytest.skip(tgen.errors)
|
||||
|
||||
def _bgp_check_path_selection_ecmp():
|
||||
output = json.loads(
|
||||
tgen.gears["r1"].vtysh_cmd("show bgp ipv4 unicast 192.0.2.8/32 json")
|
||||
)
|
||||
expected = {
|
||||
"paths": [
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"multipath": True,
|
||||
"nexthops": [{"ip": "192.0.2.2", "metric": 20}],
|
||||
},
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"multipath": True,
|
||||
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return topotest.json_cmp(output, expected)
|
||||
|
||||
step("Check if two ECMP paths are present")
|
||||
test_func = functools.partial(_bgp_check_path_selection_ecmp)
|
||||
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
|
||||
assert result is None, "Failed to see BGP prefixes on R1"
|
||||
|
||||
|
||||
def test_bgp_path_selection_vpn_ecmp():
|
||||
tgen = get_topogen()
|
||||
|
||||
if tgen.routers_have_failure():
|
||||
pytest.skip(tgen.errors)
|
||||
|
||||
def _bgp_check_path_selection_vpn_ecmp():
|
||||
output = json.loads(
|
||||
tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json")
|
||||
)
|
||||
expected = {
|
||||
"paths": [
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"multipath": True,
|
||||
"nexthops": [{"ip": "192.0.2.2", "metric": 20}],
|
||||
},
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"multipath": True,
|
||||
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return topotest.json_cmp(output, expected)
|
||||
|
||||
step("Check if two ECMP paths are present")
|
||||
test_func = functools.partial(_bgp_check_path_selection_vpn_ecmp)
|
||||
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
|
||||
assert result is None, "Failed to see BGP prefixes on R1"
|
||||
|
||||
|
||||
def test_bgp_path_selection_metric():
|
||||
tgen = get_topogen()
|
||||
|
||||
if tgen.routers_have_failure():
|
||||
pytest.skip(tgen.errors)
|
||||
|
||||
def _bgp_check_path_selection_metric():
|
||||
output = json.loads(
|
||||
tgen.gears["r1"].vtysh_cmd("show bgp ipv4 unicast 192.0.2.8/32 json")
|
||||
)
|
||||
expected = {
|
||||
"paths": [
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"nexthops": [{"ip": "192.0.2.2", "metric": 10}],
|
||||
"bestpath":{ "selectionReason":"IGP Metric"},
|
||||
},
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return topotest.json_cmp(output, expected)
|
||||
|
||||
tgen.gears["r1"].cmd("ip route add 192.0.2.2 via 192.168.1.2 metric 10")
|
||||
tgen.gears["r1"].cmd("ip route del 192.0.2.2 via 192.168.1.2 metric 20")
|
||||
|
||||
step("Check if IGP metric best path is selected")
|
||||
test_func = functools.partial(_bgp_check_path_selection_metric)
|
||||
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
|
||||
assert result is None, "Failed to see BGP prefixes on R1"
|
||||
|
||||
|
||||
def test_bgp_path_selection_vpn_metric():
|
||||
tgen = get_topogen()
|
||||
|
||||
if tgen.routers_have_failure():
|
||||
pytest.skip(tgen.errors)
|
||||
|
||||
def _bgp_check_path_selection_vpn_metric():
|
||||
output = json.loads(
|
||||
tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json")
|
||||
)
|
||||
expected = {
|
||||
"paths": [
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"nexthops": [{"ip": "192.0.2.2", "metric": 10}],
|
||||
"bestpath":{ "selectionReason":"IGP Metric"},
|
||||
},
|
||||
{
|
||||
"valid": True,
|
||||
"aspath": {"string": "65002"},
|
||||
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return topotest.json_cmp(output, expected)
|
||||
|
||||
step("Check if IGP metric best path is selected")
|
||||
test_func = functools.partial(_bgp_check_path_selection_vpn_metric)
|
||||
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
|
||||
assert result is None, "Failed to see BGP prefixes on R1"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = ["-s"] + sys.argv[1:]
|
||||
sys.exit(pytest.main(args))
|
Loading…
Reference in New Issue
Block a user