From b15be1605afa5d14c7794d0dd7db49c0b147905f Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 19 May 2021 17:47:23 +0300 Subject: [PATCH] tests: Show BGP prefixes by community alias Signed-off-by: Donatas Abraitis --- .../bgp_community_alias/r1/bgpd.conf | 4 +-- .../bgp_community_alias/r2/bgpd.conf | 9 ++++++- .../bgp_community_alias/r2/zebra.conf | 4 +++ .../test_bgp-community-alias.py | 26 ++++++++++++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/tests/topotests/bgp_community_alias/r1/bgpd.conf b/tests/topotests/bgp_community_alias/r1/bgpd.conf index 2cf84d0b70..06113bdd2a 100644 --- a/tests/topotests/bgp_community_alias/r1/bgpd.conf +++ b/tests/topotests/bgp_community_alias/r1/bgpd.conf @@ -1,7 +1,7 @@ ! -bgp community alias 65002:1 community-r2-1 +bgp community alias 65001:1 community-r2-1 bgp community alias 65002:2 community-r2-2 -bgp community alias 65002:1:1 large-community-r2-1 +bgp community alias 65001:1:1 large-community-r2-1 ! router bgp 65001 no bgp ebgp-requires-policy diff --git a/tests/topotests/bgp_community_alias/r2/bgpd.conf b/tests/topotests/bgp_community_alias/r2/bgpd.conf index 517ef70f2a..fc67ff2ad2 100644 --- a/tests/topotests/bgp_community_alias/r2/bgpd.conf +++ b/tests/topotests/bgp_community_alias/r2/bgpd.conf @@ -6,7 +6,14 @@ router bgp 65002 neighbor 192.168.1.1 route-map r1 out exit-address-family ! +ip prefix-list p1 permit 172.16.16.1/32 +ip prefix-list p2 permit 172.16.16.2/32 +! route-map r1 permit 10 + match ip address prefix-list p1 + set community 65001:1 65001:2 + set large-community 65001:1:1 65001:1:2 +route-map r1 permit 20 + match ip address prefix-list p2 set community 65002:1 65002:2 - set large-community 65002:1:1 65002:2:1 ! diff --git a/tests/topotests/bgp_community_alias/r2/zebra.conf b/tests/topotests/bgp_community_alias/r2/zebra.conf index cffe827363..a806628a8e 100644 --- a/tests/topotests/bgp_community_alias/r2/zebra.conf +++ b/tests/topotests/bgp_community_alias/r2/zebra.conf @@ -1,4 +1,8 @@ ! +int lo + ip address 172.16.16.1/32 + ip address 172.16.16.2/32 +! int r2-eth0 ip address 192.168.1.2/24 ! diff --git a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py index a43e5f937e..90eeaaa731 100644 --- a/tests/topotests/bgp_community_alias/test_bgp-community-alias.py +++ b/tests/topotests/bgp_community_alias/test_bgp-community-alias.py @@ -84,12 +84,14 @@ def test_bgp_community_alias(): router = tgen.gears["r1"] def _bgp_converge(router): - output = json.loads(router.vtysh_cmd("show ip bgp 192.168.1.0/24 json")) + output = json.loads( + router.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json") + ) expected = { "paths": [ { - "community": {"string": "community-r2-1 community-r2-2"}, - "largeCommunity": {"string": "large-community-r2-1 65002:2:1"}, + "community": {"string": "community-r2-1 65001:2"}, + "largeCommunity": {"string": "large-community-r2-1 65001:1:2"}, } ] } @@ -97,9 +99,25 @@ def test_bgp_community_alias(): 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, 'Cannot see BGP community aliases "{}"'.format(router) + def _bgp_show_prefixes_by_alias(router): + output = json.loads( + router.vtysh_cmd("show bgp ipv4 unicast alias community-r2-2 json detail") + ) + expected = { + "routes": { + "172.16.16.2/32": [{"community": {"string": "65002:1 community-r2-2"}}] + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_show_prefixes_by_alias, router) + success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, 'Cannot see BGP prefixes by community alias "{}"'.format( + router + ) + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] -- 2.39.5