]>
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
]
46 r1
= tgen
.add_router("r1")
47 r2
= tgen
.add_router("r2")
48 peer1
= tgen
.add_exabgp_peer("peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1")
50 switch
= tgen
.add_switch("s1")
52 switch
.add_link(peer1
)
54 switch
= tgen
.add_switch("s2")
59 def setup_module(mod
):
60 tgen
= Topogen(build_topo
, mod
.__name
__)
63 router
= tgen
.gears
["r1"]
64 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
65 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
68 router
= tgen
.gears
["r2"]
69 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r2/zebra.conf"))
70 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r2/bgpd.conf"))
73 peer
= tgen
.gears
["peer1"]
74 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
77 def teardown_module(mod
):
82 def expect_route(router_name
, routes_expected
):
83 "Helper function to avoid repeated code."
85 test_func
= functools
.partial(
86 topotest
.router_json_cmp
,
87 tgen
.gears
[router_name
],
91 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
92 assertmsg
= '"{}" BGP convergence failure'.format(router_name
)
93 assert result
is None, assertmsg
96 def test_expect_convergence():
97 "Test that BGP protocol converged."
100 if tgen
.routers_have_failure():
101 pytest
.skip(tgen
.errors
)
103 logger
.info("waiting for protocols to converge")
105 def expect_loopback_route(router
, iptype
, route
, proto
):
106 "Wait until route is present on RIB for protocol."
107 logger
.info("waiting route {} in {}".format(route
, router
))
108 test_func
= functools
.partial(
109 topotest
.router_json_cmp
,
111 "show {} route json".format(iptype
),
112 {route
: [{"protocol": proto
}]},
114 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
115 assertmsg
= '"{}" BGP convergence failure'.format(router
)
116 assert result
is None, assertmsg
118 expect_loopback_route("r2", "ip", "10.254.254.1/32", "bgp")
119 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
122 def test_bgp_aggregate_address_matching_med_only():
123 "Test that the command matching-MED-only works."
126 if tgen
.routers_have_failure():
127 pytest
.skip(tgen
.errors
)
130 # All MED matches, aggregation must exist.
131 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
132 "192.168.0.1/32": [{"protocol": "bgp", "metric": 10}],
133 "192.168.0.2/32": [{"protocol": "bgp", "metric": 10}],
134 "192.168.0.3/32": [{"protocol": "bgp", "metric": 10}],
135 # Non matching MED: aggregation must not exist.
136 "192.168.1.0/24": None,
137 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
138 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
139 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
142 test_func
= functools
.partial(
143 topotest
.router_json_cmp
,
145 "show ip route json",
148 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
149 assertmsg
= '"r2" BGP convergence failure'
150 assert result
is None, assertmsg
153 def test_bgp_aggregate_address_match_and_suppress():
154 "Test that the command matching-MED-only with suppression works."
157 if tgen
.routers_have_failure():
158 pytest
.skip(tgen
.errors
)
160 tgen
.gears
["r1"].vtysh_multicmd(
164 address-family ipv4 unicast
165 no aggregate-address 192.168.0.0/24 matching-MED-only
166 no aggregate-address 192.168.1.0/24 matching-MED-only
167 aggregate-address 192.168.0.0/24 matching-MED-only summary-only
168 aggregate-address 192.168.1.0/24 matching-MED-only summary-only
173 # All MED matches, aggregation must exist.
174 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
175 "192.168.0.1/32": None,
176 "192.168.0.2/32": None,
177 "192.168.0.3/32": None,
178 # Non matching MED: aggregation must not exist.
179 "192.168.1.0/24": None,
180 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
181 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
182 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
185 test_func
= functools
.partial(
186 topotest
.router_json_cmp
,
188 "show ip route json",
191 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
192 assertmsg
= '"r2" BGP convergence failure'
193 assert result
is None, assertmsg
196 def test_bgp_aggregate_address_suppress_map():
197 "Test that the command suppress-map works."
200 if tgen
.routers_have_failure():
201 pytest
.skip(tgen
.errors
)
206 "192.168.2.0/24": [{"protocol": "bgp"}],
207 "192.168.2.1/32": None,
208 "192.168.2.2/32": [{"protocol": "bgp"}],
209 "192.168.2.3/32": [{"protocol": "bgp"}],
213 # Change route map and test again.
214 tgen
.gears
["r1"].vtysh_multicmd(
218 address-family ipv4 unicast
219 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-one
220 aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
227 "192.168.2.0/24": [{"protocol": "bgp"}],
228 "192.168.2.1/32": [{"protocol": "bgp"}],
229 "192.168.2.2/32": None,
230 "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
254 "192.168.2.0/24": [{"protocol": "bgp"}],
255 "192.168.2.1/32": [{"protocol": "bgp"}],
256 "192.168.2.2/32": [{"protocol": "bgp"}],
257 "192.168.2.3/32": [{"protocol": "bgp"}],
261 # Create missing route map and test again.
262 tgen
.gears
["r1"].vtysh_multicmd(
265 route-map rm-sup-three permit 10
266 match ip address acl-sup-three
273 "192.168.2.0/24": [{"protocol": "bgp"}],
274 "192.168.2.1/32": [{"protocol": "bgp"}],
275 "192.168.2.2/32": [{"protocol": "bgp"}],
276 "192.168.2.3/32": None,
281 def test_memory_leak():
282 "Run the memory leak test and report results."
284 if not tgen
.is_memleak_enabled():
285 pytest
.skip("Memory leak test/report is disabled")
287 tgen
.report_memory_leaks()
290 if __name__
== "__main__":
291 args
= ["-s"] + sys
.argv
[1:]
292 sys
.exit(pytest
.main(args
))