tests: Check if routes are not sent back from the sender

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2023-01-05 10:24:47 +02:00
parent 329dc20704
commit c7fe4786dc
5 changed files with 51 additions and 42 deletions

View File

@ -9,6 +9,11 @@ router bgp 65001
exit-address-family exit-address-family
! !
! !
ip prefix-list p1 seq 5 permit 172.16.255.253/32
!
route-map prepend permit 10 route-map prepend permit 10
match ip address prefix-list p1
set as-path prepend 65003 set as-path prepend 65003
! !
route-map prepend permit 20
!

View File

@ -1,5 +1,6 @@
! exit1 ! exit1
interface lo interface lo
ip address 172.16.255.253/32
ip address 172.16.255.254/32 ip address 172.16.255.254/32
! !
interface r1-eth0 interface r1-eth0

View File

@ -3,9 +3,8 @@ router bgp 65002
no bgp ebgp-requires-policy no bgp ebgp-requires-policy
neighbor 192.168.255.2 remote-as 65001 neighbor 192.168.255.2 remote-as 65001
neighbor 192.168.255.2 timers 3 10 neighbor 192.168.255.2 timers 3 10
neighbor 192.168.255.2 solo neighbor 192.168.255.2 sender-as-path-loop-detection
neighbor 192.168.254.2 remote-as 65003 neighbor 192.168.254.2 remote-as 65003
neighbor 192.168.254.2 timers 3 10 neighbor 192.168.254.2 timers 3 10
neighbor 192.168.254.2 solo
neighbor 192.168.254.2 sender-as-path-loop-detection neighbor 192.168.254.2 sender-as-path-loop-detection
! !

View File

@ -85,20 +85,20 @@ def test_bgp_sender_as_path_loop_detection():
if tgen.routers_have_failure(): if tgen.routers_have_failure():
pytest.skip(tgen.errors) pytest.skip(tgen.errors)
router = tgen.gears["r2"] r2 = tgen.gears["r2"]
def _bgp_converge(router): def _bgp_converge():
output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")) output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
expected = { expected = {
"192.168.255.2": { "192.168.255.2": {
"bgpState": "Established", "bgpState": "Established",
"addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
} }
} }
return topotest.json_cmp(output, expected) return topotest.json_cmp(output, expected)
def _bgp_has_route_from_r1(router): def _bgp_has_route_from_r1():
output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) output = json.loads(r2.vtysh_cmd("show ip bgp 172.16.255.253/32 json"))
expected = { expected = {
"paths": [ "paths": [
{ {
@ -111,31 +111,35 @@ def test_bgp_sender_as_path_loop_detection():
} }
return topotest.json_cmp(output, expected) return topotest.json_cmp(output, expected)
def _bgp_suppress_route_to_r3(router): def _bgp_suppress_route_to_r1():
output = json.loads( output = json.loads(
router.vtysh_cmd( r2.vtysh_cmd("show ip bgp neighbor 192.168.255.2 advertised-routes json")
"show ip bgp neighbor 192.168.254.2 advertised-routes json"
)
) )
expected = {"totalPrefixCounter": 0} expected = {"totalPrefixCounter": 0}
return topotest.json_cmp(output, expected) return topotest.json_cmp(output, expected)
test_func = functools.partial(_bgp_converge, router) def _bgp_suppress_route_to_r3():
success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) 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)
assert result is None, 'Failed bgp convergence in "{}"'.format(router) 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"
test_func = functools.partial(_bgp_has_route_from_r1, router) test_func = functools.partial(_bgp_has_route_from_r1)
success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
assert result is None, "Failed to see a route from r1"
assert result is None, 'Failed to see a route from r1 in "{}"'.format(router) 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"
test_func = functools.partial(_bgp_suppress_route_to_r3, router) test_func = functools.partial(_bgp_suppress_route_to_r1)
success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) _, 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"
assert (
result is None
), 'Route 172.16.255.254/32 should not be sent to r3 "{}"'.format(router)
if __name__ == "__main__": if __name__ == "__main__":