]>
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
45 pytestmark
= [pytest
.mark
.bgpd
]
48 class BgpAggregateAddressTopo1(Topo
):
49 def build(self
, *_args
, **_opts
):
50 tgen
= get_topogen(self
)
52 r1
= tgen
.add_router("r1")
53 r2
= tgen
.add_router("r2")
54 peer1
= tgen
.add_exabgp_peer(
55 "peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1"
58 switch
= tgen
.add_switch("s1")
60 switch
.add_link(peer1
)
62 switch
= tgen
.add_switch("s2")
67 def setup_module(mod
):
68 tgen
= Topogen(BgpAggregateAddressTopo1
, mod
.__name
__)
71 router
= tgen
.gears
["r1"]
72 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
73 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
76 router
= tgen
.gears
["r2"]
77 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r2/zebra.conf"))
78 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r2/bgpd.conf"))
81 peer
= tgen
.gears
["peer1"]
82 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
85 def teardown_module(mod
):
90 def expect_route(router_name
, routes_expected
):
91 "Helper function to avoid repeated code."
93 test_func
= functools
.partial(
94 topotest
.router_json_cmp
,
95 tgen
.gears
[router_name
],
99 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
100 assertmsg
= '"{}" BGP convergence failure'.format(router_name
)
101 assert result
is None, assertmsg
104 def test_expect_convergence():
105 "Test that BGP protocol converged."
108 if tgen
.routers_have_failure():
109 pytest
.skip(tgen
.errors
)
111 logger
.info("waiting for protocols to converge")
113 def expect_loopback_route(router
, iptype
, route
, proto
):
114 "Wait until route is present on RIB for protocol."
115 logger
.info("waiting route {} in {}".format(route
, router
))
116 test_func
= functools
.partial(
117 topotest
.router_json_cmp
,
119 "show {} route json".format(iptype
),
120 {route
: [{"protocol": proto
}]},
122 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
123 assertmsg
= '"{}" BGP convergence failure'.format(router
)
124 assert result
is None, assertmsg
126 expect_loopback_route("r2", "ip", "10.254.254.1/32", "bgp")
127 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
130 def test_bgp_aggregate_address_matching_med_only():
131 "Test that the command matching-MED-only works."
134 if tgen
.routers_have_failure():
135 pytest
.skip(tgen
.errors
)
138 # All MED matches, aggregation must exist.
139 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
140 "192.168.0.1/32": [{"protocol": "bgp", "metric": 10}],
141 "192.168.0.2/32": [{"protocol": "bgp", "metric": 10}],
142 "192.168.0.3/32": [{"protocol": "bgp", "metric": 10}],
143 # Non matching MED: aggregation must not exist.
144 "192.168.1.0/24": None,
145 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
146 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
147 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
150 test_func
= functools
.partial(
151 topotest
.router_json_cmp
,
153 "show ip route json",
156 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
157 assertmsg
= '"r2" BGP convergence failure'
158 assert result
is None, assertmsg
161 def test_bgp_aggregate_address_match_and_suppress():
162 "Test that the command matching-MED-only with suppression works."
165 if tgen
.routers_have_failure():
166 pytest
.skip(tgen
.errors
)
168 tgen
.gears
["r1"].vtysh_multicmd(
172 address-family ipv4 unicast
173 no aggregate-address 192.168.0.0/24 matching-MED-only
174 no aggregate-address 192.168.1.0/24 matching-MED-only
175 aggregate-address 192.168.0.0/24 matching-MED-only summary-only
176 aggregate-address 192.168.1.0/24 matching-MED-only summary-only
181 # All MED matches, aggregation must exist.
182 "192.168.0.0/24": [{"protocol": "bgp", "metric": 0}],
183 "192.168.0.1/32": None,
184 "192.168.0.2/32": None,
185 "192.168.0.3/32": None,
186 # Non matching MED: aggregation must not exist.
187 "192.168.1.0/24": None,
188 "192.168.1.1/32": [{"protocol": "bgp", "metric": 10}],
189 "192.168.1.2/32": [{"protocol": "bgp", "metric": 10}],
190 "192.168.1.3/32": [{"protocol": "bgp", "metric": 20}],
193 test_func
= functools
.partial(
194 topotest
.router_json_cmp
,
196 "show ip route json",
199 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=1)
200 assertmsg
= '"r2" BGP convergence failure'
201 assert result
is None, assertmsg
204 def test_bgp_aggregate_address_suppress_map():
205 "Test that the command suppress-map works."
208 if tgen
.routers_have_failure():
209 pytest
.skip(tgen
.errors
)
214 "192.168.2.0/24": [{"protocol": "bgp"}],
215 "192.168.2.1/32": None,
216 "192.168.2.2/32": [{"protocol": "bgp"}],
217 "192.168.2.3/32": [{"protocol": "bgp"}],
221 # Change route map and test again.
222 tgen
.gears
["r1"].vtysh_multicmd(
226 address-family ipv4 unicast
227 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-one
228 aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
235 "192.168.2.0/24": [{"protocol": "bgp"}],
236 "192.168.2.1/32": [{"protocol": "bgp"}],
237 "192.168.2.2/32": None,
238 "192.168.2.3/32": [{"protocol": "bgp"}],
243 def test_bgp_aggregate_address_suppress_map_update_route_map():
244 "Test that the suppress-map late route map creation works."
246 if tgen
.routers_have_failure():
247 pytest
.skip(tgen
.errors
)
249 tgen
.gears
["r1"].vtysh_multicmd(
253 address-family ipv4 unicast
254 no aggregate-address 192.168.2.0/24 suppress-map rm-sup-two
255 aggregate-address 192.168.2.0/24 suppress-map rm-sup-three
262 "192.168.2.0/24": [{"protocol": "bgp"}],
263 "192.168.2.1/32": [{"protocol": "bgp"}],
264 "192.168.2.2/32": [{"protocol": "bgp"}],
265 "192.168.2.3/32": [{"protocol": "bgp"}],
269 # Create missing route map and test again.
270 tgen
.gears
["r1"].vtysh_multicmd(
273 route-map rm-sup-three permit 10
274 match ip address acl-sup-three
281 "192.168.2.0/24": [{"protocol": "bgp"}],
282 "192.168.2.1/32": [{"protocol": "bgp"}],
283 "192.168.2.2/32": [{"protocol": "bgp"}],
284 "192.168.2.3/32": None,
289 def test_memory_leak():
290 "Run the memory leak test and report results."
292 if not tgen
.is_memleak_enabled():
293 pytest
.skip("Memory leak test/report is disabled")
295 tgen
.report_memory_leaks()
298 if __name__
== "__main__":
299 args
= ["-s"] + sys
.argv
[1:]
300 sys
.exit(pytest
.main(args
))