From c7fe4786dc09fbb27a57e9fdac67b60df6565f52 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 5 Jan 2023 10:24:47 +0200 Subject: [PATCH] tests: Check if routes are not sent back from the sender Signed-off-by: Donatas Abraitis --- .../r1/bgpd.conf | 23 +++++---- .../r1/zebra.conf | 1 + .../r2/bgpd.conf | 15 +++--- .../r3/bgpd.conf | 6 +-- .../test_bgp_sender-as-path-loop-detection.py | 48 ++++++++++--------- 5 files changed, 51 insertions(+), 42 deletions(-) diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/r1/bgpd.conf b/tests/topotests/bgp_sender_as_path_loop_detection/r1/bgpd.conf index 719d76392d..409be74740 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/r1/bgpd.conf +++ b/tests/topotests/bgp_sender_as_path_loop_detection/r1/bgpd.conf @@ -1,14 +1,19 @@ ! exit1 router bgp 65001 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65002 - neighbor 192.168.255.1 timers 3 10 - address-family ipv4 unicast - neighbor 192.168.255.1 route-map prepend out - redistribute connected - exit-address-family - ! + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65002 + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 unicast + neighbor 192.168.255.1 route-map prepend out + redistribute connected + exit-address-family + ! +! +ip prefix-list p1 seq 5 permit 172.16.255.253/32 ! route-map prepend permit 10 - set as-path prepend 65003 + match ip address prefix-list p1 + set as-path prepend 65003 +! +route-map prepend permit 20 ! diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/r1/zebra.conf b/tests/topotests/bgp_sender_as_path_loop_detection/r1/zebra.conf index 9904bb4e16..74489a0571 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/r1/zebra.conf +++ b/tests/topotests/bgp_sender_as_path_loop_detection/r1/zebra.conf @@ -1,5 +1,6 @@ ! exit1 interface lo + ip address 172.16.255.253/32 ip address 172.16.255.254/32 ! interface r1-eth0 diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/r2/bgpd.conf b/tests/topotests/bgp_sender_as_path_loop_detection/r2/bgpd.conf index a4a654d7b5..dcb52a2e7d 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/r2/bgpd.conf +++ b/tests/topotests/bgp_sender_as_path_loop_detection/r2/bgpd.conf @@ -1,11 +1,10 @@ ! spine router bgp 65002 - no bgp ebgp-requires-policy - neighbor 192.168.255.2 remote-as 65001 - neighbor 192.168.255.2 timers 3 10 - neighbor 192.168.255.2 solo - neighbor 192.168.254.2 remote-as 65003 - neighbor 192.168.254.2 timers 3 10 - neighbor 192.168.254.2 solo - neighbor 192.168.254.2 sender-as-path-loop-detection + no bgp ebgp-requires-policy + neighbor 192.168.255.2 remote-as 65001 + neighbor 192.168.255.2 timers 3 10 + neighbor 192.168.255.2 sender-as-path-loop-detection + neighbor 192.168.254.2 remote-as 65003 + neighbor 192.168.254.2 timers 3 10 + neighbor 192.168.254.2 sender-as-path-loop-detection ! diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/r3/bgpd.conf b/tests/topotests/bgp_sender_as_path_loop_detection/r3/bgpd.conf index 2e24de0b2d..519273d30d 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/r3/bgpd.conf +++ b/tests/topotests/bgp_sender_as_path_loop_detection/r3/bgpd.conf @@ -1,6 +1,6 @@ ! exit2 router bgp 65003 - no bgp ebgp-requires-policy - neighbor 192.168.254.1 remote-as 65002 - neighbor 192.168.254.1 timers 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.254.1 remote-as 65002 + neighbor 192.168.254.1 timers 3 10 ! diff --git a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py index b5c33f359b..ebeab05648 100644 --- a/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender_as_path_loop_detection/test_bgp_sender-as-path-loop-detection.py @@ -85,20 +85,20 @@ def test_bgp_sender_as_path_loop_detection(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears["r2"] + r2 = tgen.gears["r2"] - def _bgp_converge(router): - output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) expected = { "192.168.255.2": { "bgpState": "Established", - "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}}, } } return topotest.json_cmp(output, expected) - def _bgp_has_route_from_r1(router): - output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) + def _bgp_has_route_from_r1(): + output = json.loads(r2.vtysh_cmd("show ip bgp 172.16.255.253/32 json")) expected = { "paths": [ { @@ -111,31 +111,35 @@ def test_bgp_sender_as_path_loop_detection(): } return topotest.json_cmp(output, expected) - def _bgp_suppress_route_to_r3(router): + def _bgp_suppress_route_to_r1(): output = json.loads( - router.vtysh_cmd( - "show ip bgp neighbor 192.168.254.2 advertised-routes json" - ) + r2.vtysh_cmd("show ip bgp neighbor 192.168.255.2 advertised-routes json") ) expected = {"totalPrefixCounter": 0} return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_converge, router) - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - - assert result is None, 'Failed bgp convergence in "{}"'.format(router) + def _bgp_suppress_route_to_r3(): + output = json.loads( + r2.vtysh_cmd("show ip bgp neighbor 192.168.254.2 advertised-routes json") + ) + expected = {"totalPrefixCounter": 2} + return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_has_route_from_r1, router) - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Failed bgp to convergence" - assert result is None, 'Failed to see a route from r1 in "{}"'.format(router) + test_func = functools.partial(_bgp_has_route_from_r1) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Failed to see a route from r1" - test_func = functools.partial(_bgp_suppress_route_to_r3, router) - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + test_func = functools.partial(_bgp_suppress_route_to_r3) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Route 172.16.255.253/32 should not be sent to r3 from r2" - assert ( - result is None - ), 'Route 172.16.255.254/32 should not be sent to r3 "{}"'.format(router) + test_func = functools.partial(_bgp_suppress_route_to_r1) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Routes should not be sent to r1 from r2" if __name__ == "__main__": -- 2.39.5