Skip to content

Commit

Permalink
topotest: add a test to control the community-list count
Browse files Browse the repository at this point in the history
Add a test to control the community-list count.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Jan 13, 2025
1 parent 20cbeec commit e2b0e12
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/topotests/bgp_comm_list_match/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ router bgp 65001
ip prefix-list p1 seq 5 permit 172.16.255.1/32
ip prefix-list p3 seq 5 permit 172.16.255.3/32
ip prefix-list p4 seq 5 permit 172.16.255.4/32
ip prefix-list p5 seq 5 permit 172.16.255.5/32
ip prefix-list p6 seq 5 permit 172.16.255.6/32
!
route-map r2 permit 10
match ip address prefix-list p1
Expand All @@ -24,5 +26,13 @@ route-map r2 permit 30
set community 65001:10 65001:12 65001:13
exit
route-map r2 permit 40
match ip address prefix-list p5
set community 65001:13 65001:14
exit
route-map r2 permit 50
match ip address prefix-list p6
set community 65001:16 65001:17 65001:18 65001:19
exit
route-map r2 permit 60
exit
!
2 changes: 2 additions & 0 deletions tests/topotests/bgp_comm_list_match/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ interface lo
ip address 172.16.255.2/32
ip address 172.16.255.3/32
ip address 172.16.255.4/32
ip address 172.16.255.5/32
ip address 172.16.255.6/32
!
interface r1-eth0
ip address 192.168.0.1/24
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/bgp_comm_list_match/r3/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ router bgp 65003
neighbor 192.168.1.2 soft-reconfiguration inbound
exit-address-family
!
bgp route-map delay-timer 5
bgp community-list 2 seq 10 permit 65001:12
!
route-map r1 deny 10
Expand Down
64 changes: 64 additions & 0 deletions tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,70 @@ def _bgp_converge():
assert result is None, "Failed to filter BGP UPDATES with community-list on R3"


def test_bgp_comm_list_limit_match():
tgen = get_topogen()

if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r3"]
router.vtysh_cmd(
"""
configure terminal
route-map r1 permit 20
match community-limit 3
"""
)

def _bgp_count():
output = json.loads(router.vtysh_cmd("show bgp ipv4 json"))
expected = {
"vrfName": "default",
"routerId": "192.168.1.3",
"localAS": 65003,
"totalRoutes": 3,
"totalPaths": 3,
}
return topotest.json_cmp(output, expected)

step("Check that 3 routes have been received on R3")
test_func = functools.partial(_bgp_count)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed to check that 3 routes have been received on R3"


def test_bgp_comm_list_reset_limit_match():
tgen = get_topogen()

if tgen.routers_have_failure():
pytest.skip(tgen.errors)

router = tgen.gears["r3"]
router.vtysh_cmd(
"""
configure terminal
route-map r1 permit 20
no match community-limit
"""
)

def _bgp_count_two():
output = json.loads(router.vtysh_cmd("show bgp ipv4 json"))
expected = {
"vrfName": "default",
"routerId": "192.168.1.3",
"localAS": 65003,
"totalRoutes": 4,
"totalPaths": 4,
}
return topotest.json_cmp(output, expected)

step("Check that 4 routes have been received on R3")
test_func = functools.partial(_bgp_count_two)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed to check that 4 routes have been received on R3"


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
6 changes: 6 additions & 0 deletions yang/frr-bgp-route-map.yang
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ module frr-bgp-route-map {
"Match BGP community list";
}

identity match-community-limit {
base frr-route-map:rmap-match-type;
description
"Match BGP community limit count";
}

identity match-large-community {
base frr-route-map:rmap-match-type;
description
Expand Down

0 comments on commit e2b0e12

Please sign in to comment.