]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_comm_list_match / test_bgp_comm_list_match.py
CommitLineData
1b484abc 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
1b484abc
DA
3
4#
5# Copyright (c) 2022 by
6# Donatas Abraitis <donatas@opensourcerouting.org>
7#
1b484abc
DA
8
9"""
10Check if BGP community-list works as OR if multiple community entries specified,
11like:
12
13bgp community-list 1 seq 5 permit 65001:1 65002:2
14bgp community-list 1 seq 10 permit 65001:3
15!
16route-map test deny 10
17 match community 1
18route-map test permit 20
19
20Here, we should deny routes in/out if the path has:
21(65001:1 AND 65001:2) OR 65001:3.
22"""
23
24import os
25import sys
26import json
27import pytest
28import functools
29
30CWD = os.path.dirname(os.path.realpath(__file__))
31sys.path.append(os.path.join(CWD, "../"))
32
33# pylint: disable=C0413
34from lib import topotest
35from lib.topogen import Topogen, TopoRouter, get_topogen
36from lib.common_config import step
37
38pytestmark = [pytest.mark.bgpd]
39
40
41def build_topo(tgen):
42 for routern in range(1, 3):
43 tgen.add_router("r{}".format(routern))
44
45 switch = tgen.add_switch("s1")
46 switch.add_link(tgen.gears["r1"])
47 switch.add_link(tgen.gears["r2"])
48
49
50def setup_module(mod):
51 tgen = Topogen(build_topo, mod.__name__)
52 tgen.start_topology()
53
54 router_list = tgen.routers()
55
56 for i, (rname, router) in enumerate(router_list.items(), 1):
57 router.load_config(
58 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
59 )
60 router.load_config(
61 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
62 )
63
64 tgen.start_router()
65
66
67def teardown_module(mod):
68 tgen = get_topogen()
69 tgen.stop_topology()
70
71
72def test_bgp_comm_list_match():
73 tgen = get_topogen()
74
75 if tgen.routers_have_failure():
76 pytest.skip(tgen.errors)
77
78 router = tgen.gears["r2"]
79
80 def _bgp_converge():
81 output = json.loads(
82 router.vtysh_cmd(
83 "show bgp ipv4 unicast neighbors 192.168.0.1 filtered-routes json"
84 )
85 )
86 expected = {
87 "receivedRoutes": {
88 "172.16.255.1/32": {
89 "path": "65001",
90 },
91 "172.16.255.3/32": {
92 "path": "65001",
93 },
94 }
95 }
96 return topotest.json_cmp(output, expected)
97
98 step("Initial BGP converge")
99 test_func = functools.partial(_bgp_converge)
100 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
101 assert result is None, "Failed to filter BGP UPDATES with community-list on R2"
102
103
104if __name__ == "__main__":
105 args = ["-s"] + sys.argv[1:]
106 sys.exit(pytest.main(args))