diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
commit | e2bbf175a2184bd76f6c54ccf8456babeb1a46fc (patch) | |
tree | f0b76550d6e6f500ada964a3a4ee933a45e5a6f1 /tests/topotests/bgp_path_selection | |
parent | Initial commit. (diff) | |
download | frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.tar.xz frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.zip |
Adding upstream version 9.1.upstream/9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/topotests/bgp_path_selection')
-rw-r--r-- | tests/topotests/bgp_path_selection/__init__.py | 0 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r1/bgpd.conf | 28 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r1/ldpd.conf | 26 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r1/staticd.conf | 2 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r1/zebra.conf | 11 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r2/bgpd.conf | 25 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r2/ldpd.conf | 26 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r2/staticd.conf | 0 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r2/zebra.conf | 7 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r3/bgpd.conf | 25 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r3/ldpd.conf | 24 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r3/staticd.conf | 0 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/r3/zebra.conf | 7 | ||||
-rw-r--r-- | tests/topotests/bgp_path_selection/test_bgp_path_selection.py | 220 |
14 files changed, 401 insertions, 0 deletions
diff --git a/tests/topotests/bgp_path_selection/__init__.py b/tests/topotests/bgp_path_selection/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/topotests/bgp_path_selection/__init__.py diff --git a/tests/topotests/bgp_path_selection/r1/bgpd.conf b/tests/topotests/bgp_path_selection/r1/bgpd.conf new file mode 100644 index 0000000..08eb867 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r1/bgpd.conf @@ -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 +!
\ No newline at end of file diff --git a/tests/topotests/bgp_path_selection/r1/ldpd.conf b/tests/topotests/bgp_path_selection/r1/ldpd.conf new file mode 100644 index 0000000..04ae068 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r1/ldpd.conf @@ -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 +! diff --git a/tests/topotests/bgp_path_selection/r1/staticd.conf b/tests/topotests/bgp_path_selection/r1/staticd.conf new file mode 100644 index 0000000..a37f60a --- /dev/null +++ b/tests/topotests/bgp_path_selection/r1/staticd.conf @@ -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
\ No newline at end of file diff --git a/tests/topotests/bgp_path_selection/r1/zebra.conf b/tests/topotests/bgp_path_selection/r1/zebra.conf new file mode 100644 index 0000000..e860d6e --- /dev/null +++ b/tests/topotests/bgp_path_selection/r1/zebra.conf @@ -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 +! diff --git a/tests/topotests/bgp_path_selection/r2/bgpd.conf b/tests/topotests/bgp_path_selection/r2/bgpd.conf new file mode 100644 index 0000000..cc878d8 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r2/bgpd.conf @@ -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 +!
\ No newline at end of file diff --git a/tests/topotests/bgp_path_selection/r2/ldpd.conf b/tests/topotests/bgp_path_selection/r2/ldpd.conf new file mode 100644 index 0000000..67973ab --- /dev/null +++ b/tests/topotests/bgp_path_selection/r2/ldpd.conf @@ -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 +! diff --git a/tests/topotests/bgp_path_selection/r2/staticd.conf b/tests/topotests/bgp_path_selection/r2/staticd.conf new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r2/staticd.conf diff --git a/tests/topotests/bgp_path_selection/r2/zebra.conf b/tests/topotests/bgp_path_selection/r2/zebra.conf new file mode 100644 index 0000000..40dfa98 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r2/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 192.0.2.2/32 +! +interface r2-eth0 + ip address 192.168.1.2/24 +! diff --git a/tests/topotests/bgp_path_selection/r3/bgpd.conf b/tests/topotests/bgp_path_selection/r3/bgpd.conf new file mode 100644 index 0000000..ca8d27a --- /dev/null +++ b/tests/topotests/bgp_path_selection/r3/bgpd.conf @@ -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 +!
\ No newline at end of file diff --git a/tests/topotests/bgp_path_selection/r3/ldpd.conf b/tests/topotests/bgp_path_selection/r3/ldpd.conf new file mode 100644 index 0000000..b282b08 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r3/ldpd.conf @@ -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 +! diff --git a/tests/topotests/bgp_path_selection/r3/staticd.conf b/tests/topotests/bgp_path_selection/r3/staticd.conf new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r3/staticd.conf diff --git a/tests/topotests/bgp_path_selection/r3/zebra.conf b/tests/topotests/bgp_path_selection/r3/zebra.conf new file mode 100644 index 0000000..a0473b6 --- /dev/null +++ b/tests/topotests/bgp_path_selection/r3/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 192.0.2.3/32 +! +interface r3-eth0 + ip address 192.168.2.2/24 +! diff --git a/tests/topotests/bgp_path_selection/test_bgp_path_selection.py b/tests/topotests/bgp_path_selection/test_bgp_path_selection.py new file mode 100644 index 0000000..bf5737b --- /dev/null +++ b/tests/topotests/bgp_path_selection/test_bgp_path_selection.py @@ -0,0 +1,220 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2022 by +# Louis Scalbert <louis.scalbert@6wind.com> +# + +""" + +""" + +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)) |