]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / bgp_comm_list_match / test_bgp_comm_list_match.py
CommitLineData
1b484abc
DA
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2022 by
5# Donatas Abraitis <donatas@opensourcerouting.org>
6#
7# Permission to use, copy, modify, and/or distribute this software
8# for any purpose with or without fee is hereby granted, provided
9# that the above copyright notice and this permission notice appear
10# in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19# OF THIS SOFTWARE.
20#
21
22"""
23Check if BGP community-list works as OR if multiple community entries specified,
24like:
25
26bgp community-list 1 seq 5 permit 65001:1 65002:2
27bgp community-list 1 seq 10 permit 65001:3
28!
29route-map test deny 10
30 match community 1
31route-map test permit 20
32
33Here, we should deny routes in/out if the path has:
34(65001:1 AND 65001:2) OR 65001:3.
35"""
36
37import os
38import sys
39import json
40import pytest
41import functools
42
43CWD = os.path.dirname(os.path.realpath(__file__))
44sys.path.append(os.path.join(CWD, "../"))
45
46# pylint: disable=C0413
47from lib import topotest
48from lib.topogen import Topogen, TopoRouter, get_topogen
49from lib.common_config import step
50
51pytestmark = [pytest.mark.bgpd]
52
53
54def build_topo(tgen):
55 for routern in range(1, 3):
56 tgen.add_router("r{}".format(routern))
57
58 switch = tgen.add_switch("s1")
59 switch.add_link(tgen.gears["r1"])
60 switch.add_link(tgen.gears["r2"])
61
62
63def setup_module(mod):
64 tgen = Topogen(build_topo, mod.__name__)
65 tgen.start_topology()
66
67 router_list = tgen.routers()
68
69 for i, (rname, router) in enumerate(router_list.items(), 1):
70 router.load_config(
71 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
72 )
73 router.load_config(
74 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
75 )
76
77 tgen.start_router()
78
79
80def teardown_module(mod):
81 tgen = get_topogen()
82 tgen.stop_topology()
83
84
85def test_bgp_comm_list_match():
86 tgen = get_topogen()
87
88 if tgen.routers_have_failure():
89 pytest.skip(tgen.errors)
90
91 router = tgen.gears["r2"]
92
93 def _bgp_converge():
94 output = json.loads(
95 router.vtysh_cmd(
96 "show bgp ipv4 unicast neighbors 192.168.0.1 filtered-routes json"
97 )
98 )
99 expected = {
100 "receivedRoutes": {
101 "172.16.255.1/32": {
102 "path": "65001",
103 },
104 "172.16.255.3/32": {
105 "path": "65001",
106 },
107 }
108 }
109 return topotest.json_cmp(output, expected)
110
111 step("Initial BGP converge")
112 test_func = functools.partial(_bgp_converge)
113 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
114 assert result is None, "Failed to filter BGP UPDATES with community-list on R2"
115
116
117if __name__ == "__main__":
118 args = ["-s"] + sys.argv[1:]
119 sys.exit(pytest.main(args))