From 387a5ffe5a221437dc23edd68457c5520300c21f Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 9 Dec 2022 14:12:32 +0200 Subject: [PATCH] tests: Add more tests for labeled-unicast and addpath Check if we advertise more routes when an additional path comes up, and if we withdraw if dissapears. Signed-off-by: Donatas Abraitis --- .../bgp_labeled_unicast_addpath/r3/bgpd.conf | 5 +++ .../bgp_labeled_unicast_addpath/r3/zebra.conf | 3 ++ .../bgp_labeled_unicast_addpath/r5/bgpd.conf | 14 ++++++ .../bgp_labeled_unicast_addpath/r5/zebra.conf | 7 +++ .../test_bgp_labeled_unicast_addpath.py | 45 +++++++++++++++++-- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tests/topotests/bgp_labeled_unicast_addpath/r5/bgpd.conf create mode 100644 tests/topotests/bgp_labeled_unicast_addpath/r5/zebra.conf diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf index c38ed7ef6f..6dd8f7f67e 100644 --- a/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf +++ b/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf @@ -13,9 +13,14 @@ router bgp 65003 neighbor 192.168.34.4 remote-as external neighbor 192.168.34.4 timers 1 3 neighbor 192.168.34.4 timers connect 1 + neighbor 192.168.35.5 remote-as external + neighbor 192.168.35.5 timers 1 3 + neighbor 192.168.35.5 timers connect 1 + neighbor 192.168.35.5 shutdown address-family ipv4 labeled-unicast neighbor 192.168.31.1 activate neighbor 192.168.32.2 activate + neighbor 192.168.35.5 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 diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf index 1cc2ca2edf..838413ac6f 100644 --- a/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf +++ b/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf @@ -8,3 +8,6 @@ interface r3-eth1 interface r3-eth2 ip address 192.168.34.3/24 ! +interface r3-eth3 + ip address 192.168.35.3/24 +! diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r5/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r5/bgpd.conf new file mode 100644 index 0000000000..5b38b5a0d2 --- /dev/null +++ b/tests/topotests/bgp_labeled_unicast_addpath/r5/bgpd.conf @@ -0,0 +1,14 @@ +router bgp 65005 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 192.168.35.3 remote-as external + neighbor 192.168.35.3 timers 1 3 + neighbor 192.168.35.3 timers connect 1 + address-family ipv4 unicast + redistribute connected + exit-address-family + ! + address-family ipv4 labeled-unicast + neighbor 192.168.35.3 activate + exit-address-family +! diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r5/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r5/zebra.conf new file mode 100644 index 0000000000..6289e4ffc5 --- /dev/null +++ b/tests/topotests/bgp_labeled_unicast_addpath/r5/zebra.conf @@ -0,0 +1,7 @@ +! +interface lo + ip address 10.0.0.1/32 +! +interface r5-eth0 + ip address 192.168.35.5/24 +! diff --git a/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py b/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py index 9e7dd403f5..aae901eabe 100644 --- a/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py +++ b/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py @@ -21,6 +21,9 @@ """ Check if labeled-unicast works correctly with addpath capability. +Initially R3 MUST announce 10.0.0.1/32 multipath(2) from R1 + R2. +Later, we enable R5 and 10.0.0.1/32 multipath(3) MUST be announced, +R1 + R2 + R5. """ import os @@ -41,7 +44,7 @@ pytestmark = [pytest.mark.bgpd] def build_topo(tgen): - for routern in range(1, 5): + for routern in range(1, 6): tgen.add_router("r{}".format(routern)) switch = tgen.add_switch("s1") @@ -56,6 +59,10 @@ def build_topo(tgen): switch.add_link(tgen.gears["r3"]) switch.add_link(tgen.gears["r4"]) + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r5"]) + def setup_module(mod): tgen = Topogen(build_topo, mod.__name__) @@ -88,7 +95,7 @@ def test_bgp_addpath_labeled_unicast(): r3 = tgen.gears["r3"] r4 = tgen.gears["r4"] - def _bgp_check_advertised_routes(): + def _bgp_check_advertised_routes(prefix_num): output = json.loads( r3.vtysh_cmd( "show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json" @@ -104,11 +111,11 @@ def test_bgp_addpath_labeled_unicast(): } } }, - "totalPrefixCounter": 2, + "totalPrefixCounter": prefix_num, } return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_check_advertised_routes) + test_func = functools.partial(_bgp_check_advertised_routes, 2) _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert ( result is None @@ -136,6 +143,36 @@ def test_bgp_addpath_labeled_unicast(): _, 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)" + step("Enable BGP session for R5") + r3.vtysh_cmd( + """ + configure terminal + router bgp 65003 + no neighbor 192.168.35.5 shutdown + """ + ) + + test_func = functools.partial(_bgp_check_advertised_routes, 3) + _, 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)" + + step("Disable BGP session for R5") + r3.vtysh_cmd( + """ + configure terminal + router bgp 65003 + neighbor 192.168.35.5 shutdown + """ + ) + + test_func = functools.partial(_bgp_check_advertised_routes, 2) + _, 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)" + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] -- 2.39.5