]>
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.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 from lib
import topotest
41 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
42 from lib
.topolog
import logger
43 from mininet
.topo
import Topo
46 class BgpAggregateAddressTopo1(Topo
):
47 def build(self
, *_args
, **_opts
):
48 tgen
= get_topogen(self
)
50 r1
= tgen
.add_router("r1")
51 r2
= tgen
.add_router("r2")
52 peer1
= tgen
.add_exabgp_peer(
53 "peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1"
56 switch
= tgen
.add_switch("s1")
58 switch
.add_link(peer1
)
60 switch
= tgen
.add_switch("s2")
65 def setup_module(mod
):
66 tgen
= Topogen(BgpAggregateAddressTopo1
, mod
.__name
__)
69 router
= tgen
.gears
["r1"]
70 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
71 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
74 router
= tgen
.gears
["r2"]
75 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r2/zebra.conf"))
76 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r2/bgpd.conf"))
79 peer
= tgen
.gears
["peer1"]
80 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
83 def teardown_module(mod
):
88 def expect_route(router_name
, routes_expected
):
89 "Helper function to avoid repeated code."
91 test_func
= functools
.partial(
92 topotest
.router_json_cmp
,
93 tgen
.gears
[router_name
],
97 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
98 assertmsg
= '"{}" BGP convergence failure'.format(router_name
)
99 assert result
is None, assertmsg
102 def test_expect_convergence():
103 "Test that BGP protocol converged."
106 if tgen
.routers_have_failure():
107 pytest
.skip(tgen
.errors
)
109 logger
.info("waiting for protocols to converge")
111 def expect_loopback_route(router
, iptype
, route
, proto
):
112 "Wait until route is present on RIB for protocol."
113 logger
.info("waiting route {} in {}".format(route
, router
))
114 test_func
= functools
.partial(
115 topotest
.router_json_cmp
,
117 "show {} route json".format(iptype
),
118 {route
: [{"protocol": proto
}]},
120 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
121 assertmsg
= '"{}" BGP convergence failure'.format(router
)
122 assert result
is None, assertmsg
124 expect_loopback_route("r2", "ip", "10.254.254.1/32", "bgp")
125 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
128 def test_bgp_aggregate_address_matching_med_only():
129 "Test that the command matching-MED-only works."
132 if tgen
.routers_have_failure():
133 pytest
.skip(tgen
.errors
)
136 # All MED matches, aggregation must exist.
137 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
138 "192.168.0.1/32": [{"protocol": "bgp", "metric": 10}],
139 "192.168.0.2/32": [{"protocol": "bgp", "metric": 10}],
140 "192.168.0.3/32": [{"protocol": "bgp", "metric": 10}],
141 # Non matching MED: aggregation must not exist.
142 "192.168.1.0/24": None,
143 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
144 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
145 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
148 test_func
= functools
.partial(
149 topotest
.router_json_cmp
,
151 "show ip route json",
154 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
155 assertmsg
= '"r2" BGP convergence failure'
156 assert result
is None, assertmsg
159 def test_bgp_aggregate_address_match_and_supress():
160 "Test that the command matching-MED-only with suppression works."
163 if tgen
.routers_have_failure():
164 pytest
.skip(tgen
.errors
)
166 tgen
.gears
["r1"].vtysh_multicmd(
170 address-family ipv4 unicast
171 no aggregate-address 192.168.0.0/24 matching-MED-only
172 no aggregate-address 192.168.1.0/24 matching-MED-only
173 aggregate-address 192.168.0.0/24 matching-MED-only summary-only
174 aggregate-address 192.168.1.0/24 matching-MED-only summary-only
179 # All MED matches, aggregation must exist.
180 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
181 "192.168.0.1/32": None,
182 "192.168.0.2/32": None,
183 "192.168.0.3/32": None,
184 # Non matching MED: aggregation must not exist.
185 "192.168.1.0/24": None,
186 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
187 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
188 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
191 test_func
= functools
.partial(
192 topotest
.router_json_cmp
,
194 "show ip route json",
197 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
198 assertmsg
= '"r2" BGP convergence failure'
199 assert result
is None, assertmsg
202 def test_bgp_aggregate_address_suppress_map():
203 "Test that the command suppress-map works."
206 if tgen
.routers_have_failure():
207 pytest
.skip(tgen
.errors
)
210 "192.168.2.0/24": [{"protocol": "bgp"}],
211 "192.168.2.1/32": None,
212 "192.168.2.2/32": [{"protocol": "bgp"}],
213 "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
228 "192.168.2.0/24": [{"protocol": "bgp"}],
229 "192.168.2.1/32": [{"protocol": "bgp"}],
230 "192.168.2.2/32": None,
231 "192.168.2.3/32": [{"protocol": "bgp"}],
235 def test_bgp_aggregate_address_suppress_map_update_route_map():
236 "Test that the suppress-map late route map creation works."
238 if tgen
.routers_have_failure():
239 pytest
.skip(tgen
.errors
)
241 tgen
.gears
["r1"].vtysh_multicmd(
245 address-family ipv4 unicast
246 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
247 aggregate-address 192.168.2.0/24 suppress-map rm-sup-three
252 "192.168.2.0/24": [{"protocol": "bgp"}],
253 "192.168.2.1/32": [{"protocol": "bgp"}],
254 "192.168.2.2/32": [{"protocol": "bgp"}],
255 "192.168.2.3/32": [{"protocol": "bgp"}],
258 # Create missing route map and test again.
259 tgen
.gears
["r1"].vtysh_multicmd(
262 route-map rm-sup-three permit 10
263 match ip address acl-sup-three
268 "192.168.2.0/24": [{"protocol": "bgp"}],
269 "192.168.2.1/32": [{"protocol": "bgp"}],
270 "192.168.2.2/32": [{"protocol": "bgp"}],
271 "192.168.2.3/32": None,
275 def test_memory_leak():
276 "Run the memory leak test and report results."
278 if not tgen
.is_memleak_enabled():
279 pytest
.skip("Memory leak test/report is disabled")
281 tgen
.report_memory_leaks()
284 if __name__
== "__main__":
285 args
= ["-s"] + sys
.argv
[1:]
286 sys
.exit(pytest
.main(args
))