]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_topo1/test_bgp_aggregate_address_topo1.py
4 # test_bgp_aggregate_address_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 Test BGP aggregate address features.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
40 from lib
.topolog
import logger
42 pytestmark
= [pytest
.mark
.bgpd
]
47 r1
= tgen
.add_router("r1")
48 r2
= tgen
.add_router("r2")
49 peer1
= tgen
.add_exabgp_peer(
50 "peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1"
53 switch
= tgen
.add_switch("s1")
55 switch
.add_link(peer1
)
57 switch
= tgen
.add_switch("s2")
62 def setup_module(mod
):
63 tgen
= Topogen(build_topo
, mod
.__name
__)
66 router
= tgen
.gears
["r1"]
67 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
68 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
71 router
= tgen
.gears
["r2"]
72 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r2/zebra.conf"))
73 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r2/bgpd.conf"))
76 peer
= tgen
.gears
["peer1"]
77 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
80 def teardown_module(mod
):
85 def expect_route(router_name
, routes_expected
):
86 "Helper function to avoid repeated code."
88 test_func
= functools
.partial(
89 topotest
.router_json_cmp
,
90 tgen
.gears
[router_name
],
94 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
95 assertmsg
= '"{}" BGP convergence failure'.format(router_name
)
96 assert result
is None, assertmsg
99 def test_expect_convergence():
100 "Test that BGP protocol converged."
103 if tgen
.routers_have_failure():
104 pytest
.skip(tgen
.errors
)
106 logger
.info("waiting for protocols to converge")
108 def expect_loopback_route(router
, iptype
, route
, proto
):
109 "Wait until route is present on RIB for protocol."
110 logger
.info("waiting route {} in {}".format(route
, router
))
111 test_func
= functools
.partial(
112 topotest
.router_json_cmp
,
114 "show {} route json".format(iptype
),
115 {route
: [{"protocol": proto
}]},
117 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
118 assertmsg
= '"{}" BGP convergence failure'.format(router
)
119 assert result
is None, assertmsg
121 expect_loopback_route("r2", "ip", "10.254.254.1/32", "bgp")
122 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
125 def test_bgp_aggregate_address_matching_med_only():
126 "Test that the command matching-MED-only works."
129 if tgen
.routers_have_failure():
130 pytest
.skip(tgen
.errors
)
133 # All MED matches, aggregation must exist.
134 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
135 "192.168.0.1/32": [{"protocol": "bgp", "metric": 10}],
136 "192.168.0.2/32": [{"protocol": "bgp", "metric": 10}],
137 "192.168.0.3/32": [{"protocol": "bgp", "metric": 10}],
138 # Non matching MED: aggregation must not exist.
139 "192.168.1.0/24": None,
140 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
141 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
142 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
145 test_func
= functools
.partial(
146 topotest
.router_json_cmp
,
148 "show ip route json",
151 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
152 assertmsg
= '"r2" BGP convergence failure'
153 assert result
is None, assertmsg
156 def test_bgp_aggregate_address_match_and_suppress():
157 "Test that the command matching-MED-only with suppression works."
160 if tgen
.routers_have_failure():
161 pytest
.skip(tgen
.errors
)
163 tgen
.gears
["r1"].vtysh_multicmd(
167 address-family ipv4 unicast
168 no aggregate-address 192.168.0.0/24 matching-MED-only
169 no aggregate-address 192.168.1.0/24 matching-MED-only
170 aggregate-address 192.168.0.0/24 matching-MED-only summary-only
171 aggregate-address 192.168.1.0/24 matching-MED-only summary-only
176 # All MED matches, aggregation must exist.
177 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
178 "192.168.0.1/32": None,
179 "192.168.0.2/32": None,
180 "192.168.0.3/32": None,
181 # Non matching MED: aggregation must not exist.
182 "192.168.1.0/24": None,
183 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
184 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
185 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
188 test_func
= functools
.partial(
189 topotest
.router_json_cmp
,
191 "show ip route json",
194 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
195 assertmsg
= '"r2" BGP convergence failure'
196 assert result
is None, assertmsg
199 def test_bgp_aggregate_address_suppress_map():
200 "Test that the command suppress-map works."
203 if tgen
.routers_have_failure():
204 pytest
.skip(tgen
.errors
)
209 "192.168.2.0/24": [{"protocol": "bgp"}],
210 "192.168.2.1/32": None,
211 "192.168.2.2/32": [{"protocol": "bgp"}],
212 "192.168.2.3/32": [{"protocol": "bgp"}],
216 # Change route map and test again.
217 tgen
.gears
["r1"].vtysh_multicmd(
221 address-family ipv4 unicast
222 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-one
223 aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
230 "192.168.2.0/24": [{"protocol": "bgp"}],
231 "192.168.2.1/32": [{"protocol": "bgp"}],
232 "192.168.2.2/32": None,
233 "192.168.2.3/32": [{"protocol": "bgp"}],
238 def test_bgp_aggregate_address_suppress_map_update_route_map():
239 "Test that the suppress-map late route map creation works."
241 if tgen
.routers_have_failure():
242 pytest
.skip(tgen
.errors
)
244 tgen
.gears
["r1"].vtysh_multicmd(
248 address-family ipv4 unicast
249 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
250 aggregate-address 192.168.2.0/24 suppress-map rm-sup-three
257 "192.168.2.0/24": [{"protocol": "bgp"}],
258 "192.168.2.1/32": [{"protocol": "bgp"}],
259 "192.168.2.2/32": [{"protocol": "bgp"}],
260 "192.168.2.3/32": [{"protocol": "bgp"}],
264 # Create missing route map and test again.
265 tgen
.gears
["r1"].vtysh_multicmd(
268 route-map rm-sup-three permit 10
269 match ip address acl-sup-three
276 "192.168.2.0/24": [{"protocol": "bgp"}],
277 "192.168.2.1/32": [{"protocol": "bgp"}],
278 "192.168.2.2/32": [{"protocol": "bgp"}],
279 "192.168.2.3/32": None,
284 def test_memory_leak():
285 "Run the memory leak test and report results."
287 if not tgen
.is_memleak_enabled():
288 pytest
.skip("Memory leak test/report is disabled")
290 tgen
.report_memory_leaks()
293 if __name__
== "__main__":
294 args
= ["-s"] + sys
.argv
[1:]
295 sys
.exit(pytest
.main(args
))