]>
Commit | Line | Data |
---|---|---|
fa36596c MK |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
4 | # test_bgp_conditional_advertisement.py | |
fa36596c MK |
5 | # |
6 | # Copyright (c) 2020 by | |
1a0416bd MK |
7 | # Samsung R&D Institute India - Bangalore. |
8 | # Madhurilatha Kuruganti | |
fa36596c MK |
9 | # |
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 | |
13 | # in all copies. | |
14 | # | |
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 | |
22 | # OF THIS SOFTWARE. | |
23 | # | |
24 | ||
25 | """ | |
26 | Test BGP conditional advertisement functionality. | |
27 | ||
28 | +--------+ +--------+ +--------+ | |
29 | | | | | | | | |
30 | | R1 |------------| R2 |------------| R3 | | |
31 | | | | | | | | |
32 | +--------+ +--------+ +--------+ | |
33 | ||
34 | R2 is DUT and peers with R1 and R3 in default bgp instance. | |
35 | ||
36 | Following tests are covered under BGP conditional advertisement functionality. | |
37 | Conditional advertisement | |
38 | ------------------------- | |
39 | TC11: R3 BGP convergence, without advertise-map configuration. | |
40 | All routes are advertised to R3. | |
e73c112e | 41 | |
fa36596c MK |
42 | TC21: exist-map routes present in R2's BGP table. |
43 | advertise-map routes present in R2's BGP table are advertised to R3. | |
44 | TC22: exist-map routes not present in R2's BGP table | |
45 | advertise-map routes present in R2's BGP table are withdrawn from R3. | |
1285c4ac MK |
46 | TC23: advertise-map with exist-map configuration is removed from a peer |
47 | send normal BGP update to advertise previously withdrawn routes if any. | |
48 | ||
fa36596c MK |
49 | TC31: non-exist-map routes not present in R2's BGP table |
50 | advertise-map routes present in R2's BGP table are advertised to R3. | |
51 | TC32: non-exist-map routes present in R2's BGP table | |
52 | advertise-map routes present in R2's BGP table are withdrawn from R3. | |
1285c4ac MK |
53 | TC33: advertise-map with non-exist-map configuration is removed from a peer |
54 | send normal BGP update to advertisepreviously withdrawn routes if any. | |
e73c112e | 55 | |
fa36596c MK |
56 | TC41: non-exist-map route-map configuration removed in R2. |
57 | advertise-map routes present in R2's BGP table are advertised to R3. | |
58 | TC42: exist-map route-map configuration removed in R2 | |
59 | advertise-map routes present in R2's BGP table are withdrawn from R3. | |
60 | ||
e73c112e MK |
61 | Conditional advertisement(received routes) along with Route-map Filter |
62 | ---------------------------------------------------------------------- | |
fa36596c MK |
63 | TC51: exist-map routes present in R2's BGP table, with route-map filter. |
64 | All routes are withdrawn from R3 except advertise-map routes. | |
65 | TC52: exist-map routes present in R2's BGP table, without route-map filter. | |
66 | All routes are advertised to R3 including advertise-map routes. | |
67 | TC53: non-exist-map routes present in R2's BGP table, with route-map filter. | |
68 | All routes are withdrawn from R3 including advertise-map routes. | |
69 | TC54: non-exist-map routes present in R2's BGP table, without route-map filter. | |
70 | All routes are advertised to R3 except advertise-map routes. | |
e73c112e | 71 | |
fa36596c MK |
72 | TC61: exist-map routes not present in R2's BGP table, with route-map filter. |
73 | All routes are withdrawn from R3 including advertise-map routes. | |
74 | TC62: exist-map routes not present in R2's BGP table, without route-map filter. | |
75 | All routes are advertised to R3 except advertise-map routes. | |
76 | TC63: non-exist-map routes not present in R2's BGP table, with route-map filter. | |
77 | All routes are withdrawn from R3 except advertise-map routes. | |
78 | TC64: non-exist-map routes not present in R2's BGP table, without route-map filter. | |
79 | All routes are advertised to R3 including advertise-map routes. | |
80 | ||
e73c112e MK |
81 | Conditional advertisement(attached routes) along with Route-map Filter |
82 | ----------------------------------------------------------------- | |
83 | TC71: exist-map routes present in R2's BGP table, with route-map filter. | |
84 | All routes are withdrawn from R3 except advertise-map routes. | |
85 | TC72: exist-map routes present in R2's BGP table, without route-map filter. | |
86 | All routes are advertised to R3 including advertise-map routes. | |
87 | TC73: non-exist-map routes present in R2's BGP table, with route-map filter. | |
88 | All routes are withdrawn from R3 including advertise-map routes. | |
89 | TC74: non-exist-map routes present in R2's BGP table, without route-map filter. | |
90 | All routes are advertised to R3 except advertise-map routes. | |
91 | ||
92 | TC81: exist-map routes not present in R2's BGP table, with route-map filter. | |
93 | All routes are withdrawn from R3 including advertise-map routes. | |
94 | TC82: exist-map routes not present in R2's BGP table, without route-map filter. | |
95 | All routes are advertised to R3 except advertise-map routes. | |
96 | TC83: non-exist-map routes not present in R2's BGP table, with route-map filter. | |
97 | All routes are withdrawn from R3 except advertise-map routes. | |
98 | TC84: non-exist-map routes not present in R2's BGP table, without route-map filter. | |
99 | All routes are advertised to R3 including advertise-map routes. | |
100 | ||
101 | TC91: exist-map routes present in R2's BGP table, with route-map filter and network. | |
102 | All routes are advertised to R3 including advertise-map routes. | |
103 | TC92: exist-map routes present in R2's BGP table, with route-map filter and no network. | |
104 | All routes are advertised to R3 except advertise-map routes. | |
105 | TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network. | |
106 | All routes are advertised to R3 including advertise-map routes. | |
107 | TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network. | |
108 | All routes are advertised to R3 except advertise-map routes. | |
fa36596c MK |
109 | |
110 | i.e. | |
111 | +----------------+-------------------------+------------------------+ | |
112 | | Routes in | exist-map status | advertise-map status | | |
113 | | BGP table | | | | |
114 | +----------------+-------------------------+------------------------+ | |
115 | | Present | Condition matched | Advertise | | |
116 | +----------------+-------------------------+------------------------+ | |
117 | | Not Present | Condition not matched | Withdrawn | | |
118 | +----------------+-------------------------+------------------------+ | |
119 | | | non-exist-map status | advertise-map status | | |
120 | | | | | | |
121 | +----------------+-------------------------+------------------------+ | |
122 | | Present | Condition matched | Withdrawn | | |
123 | +----------------+-------------------------+------------------------+ | |
124 | | Not Present | Condition not matched | Advertise | | |
125 | +----------------+-------------------------+------------------------+ | |
126 | Here in this topology, based on the default route presence in R2 and | |
127 | the configured condition-map (exist-map/non-exist-map) 10.139.224.0/20 | |
128 | will be either advertised/withdrawn to/from R3. | |
129 | """ | |
130 | ||
131 | import os | |
132 | import sys | |
133 | import json | |
134 | import time | |
135 | import pytest | |
136 | import functools | |
137 | ||
138 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
139 | sys.path.append(os.path.join(CWD, "../")) | |
140 | ||
141 | # pylint: disable=C0413 | |
142 | from lib import topotest | |
143 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
144 | from lib.topolog import logger | |
fa36596c | 145 | |
bf3a0a9a DS |
146 | pytestmark = [pytest.mark.bgpd] |
147 | ||
fa36596c | 148 | |
e82b531d CH |
149 | def build_topo(tgen): |
150 | r1 = tgen.add_router("r1") | |
151 | r2 = tgen.add_router("r2") | |
152 | r3 = tgen.add_router("r3") | |
fa36596c | 153 | |
e82b531d CH |
154 | switch = tgen.add_switch("s1") |
155 | switch.add_link(r1) | |
156 | switch.add_link(r2) | |
fa36596c | 157 | |
e82b531d CH |
158 | switch = tgen.add_switch("s2") |
159 | switch.add_link(r2) | |
160 | switch.add_link(r3) | |
fa36596c MK |
161 | |
162 | ||
163 | def setup_module(mod): | |
164 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
165 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
166 | logger.info("=" * 40) | |
167 | ||
168 | logger.info("Running setup_module to create topology") | |
169 | ||
e82b531d | 170 | tgen = Topogen(build_topo, mod.__name__) |
fa36596c MK |
171 | tgen.start_topology() |
172 | ||
173 | router_list = tgen.routers() | |
174 | ||
175 | for i, (rname, router) in enumerate(router_list.items(), 1): | |
176 | router.load_config( | |
177 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | |
178 | ) | |
179 | router.load_config( | |
180 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | |
181 | ) | |
182 | ||
183 | tgen.start_router() | |
184 | ||
185 | logger.info("Running setup_module() done") | |
186 | ||
187 | ||
188 | def teardown_module(mod): | |
189 | """ | |
190 | Teardown the pytest environment | |
191 | * `mod`: module name | |
192 | """ | |
193 | ||
194 | logger.info("Running teardown_module to delete topology") | |
195 | ||
196 | tgen = get_topogen() | |
197 | tgen.stop_topology() | |
198 | ||
199 | logger.info( | |
200 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
201 | ) | |
202 | logger.info("=" * 40) | |
203 | ||
204 | ||
90557c3f LS |
205 | def all_routes_advertised(router): |
206 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
207 | expected = { | |
208 | "0.0.0.0/0": [{"protocol": "bgp"}], | |
209 | "192.0.2.1/32": [{"protocol": "bgp"}], | |
210 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
211 | "10.139.224.0/20": [{"protocol": "bgp"}], | |
212 | "203.0.113.1/32": [{"protocol": "bgp"}], | |
213 | } | |
214 | return topotest.json_cmp(output, expected) | |
215 | ||
216 | ||
217 | def all_routes_withdrawn(router): | |
218 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
219 | expected = { | |
220 | "0.0.0.0/0": None, | |
221 | "192.0.2.1/32": None, | |
222 | "192.0.2.5/32": None, | |
223 | "10.139.224.0/20": None, | |
224 | "203.0.113.1/32": None, | |
225 | } | |
226 | return topotest.json_cmp(output, expected) | |
227 | ||
b9fdddb8 | 228 | |
1285c4ac MK |
229 | def default_route_withdrawn(router): |
230 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
231 | expected = { | |
232 | "0.0.0.0/0": None, | |
233 | "192.0.2.1/32": [{"protocol": "bgp"}], | |
234 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
235 | "10.139.224.0/20": [{"protocol": "bgp"}], | |
236 | "203.0.113.1/32": [{"protocol": "bgp"}], | |
b9fdddb8 | 237 | } |
1285c4ac MK |
238 | return topotest.json_cmp(output, expected) |
239 | ||
90557c3f LS |
240 | |
241 | # BGP conditional advertisement with route-maps | |
242 | # EXIST-MAP, ADV-MAP-1 and RMAP-1 | |
243 | def exist_map_routes_present(router): | |
244 | return all_routes_advertised(router) | |
245 | ||
246 | ||
247 | def exist_map_routes_not_present(router): | |
248 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
249 | expected = { | |
250 | "0.0.0.0/0": None, | |
251 | "192.0.2.1/32": None, | |
252 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
253 | "10.139.224.0/20": None, | |
254 | "203.0.113.1/32": [{"protocol": "bgp"}], | |
255 | } | |
256 | return topotest.json_cmp(output, expected) | |
257 | ||
258 | ||
259 | def non_exist_map_routes_present(router): | |
260 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
261 | expected = { | |
262 | "0.0.0.0/0": [{"protocol": "bgp"}], | |
263 | "192.0.2.1/32": None, | |
264 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
265 | "10.139.224.0/20": None, | |
266 | "203.0.113.1/32": [{"protocol": "bgp"}], | |
267 | } | |
268 | return topotest.json_cmp(output, expected) | |
269 | ||
270 | ||
271 | def non_exist_map_routes_not_present(router): | |
b9fdddb8 MK |
272 | return default_route_withdrawn(router) |
273 | ||
90557c3f LS |
274 | |
275 | def exist_map_no_condition_route_map(router): | |
276 | return non_exist_map_routes_present(router) | |
277 | ||
278 | ||
279 | def non_exist_map_no_condition_route_map(router): | |
280 | return all_routes_advertised(router) | |
281 | ||
282 | ||
283 | def exist_map_routes_present_rmap_filter(router): | |
284 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
285 | expected = { | |
286 | "0.0.0.0/0": None, | |
287 | "192.0.2.1/32": [{"protocol": "bgp"}], | |
288 | "192.0.2.5/32": None, | |
289 | "10.139.224.0/20": [{"protocol": "bgp"}], | |
290 | "203.0.113.1/32": None, | |
291 | } | |
292 | return topotest.json_cmp(output, expected) | |
293 | ||
294 | ||
295 | def exist_map_routes_present_no_rmap_filter(router): | |
296 | return all_routes_advertised(router) | |
297 | ||
298 | ||
299 | def non_exist_map_routes_present_rmap_filter(router): | |
300 | return all_routes_withdrawn(router) | |
301 | ||
302 | ||
303 | def non_exist_map_routes_present_no_rmap_filter(router): | |
304 | return non_exist_map_routes_present(router) | |
305 | ||
306 | ||
307 | def exist_map_routes_not_present_rmap_filter(router): | |
308 | return all_routes_withdrawn(router) | |
309 | ||
310 | ||
311 | def exist_map_routes_not_present_no_rmap_filter(router): | |
312 | return exist_map_routes_not_present(router) | |
313 | ||
314 | ||
315 | def non_exist_map_routes_not_present_rmap_filter(router): | |
316 | return exist_map_routes_present_rmap_filter(router) | |
317 | ||
318 | ||
319 | def non_exist_map_routes_not_present_no_rmap_filter(router): | |
320 | return non_exist_map_routes_not_present(router) | |
321 | ||
322 | ||
323 | # BGP conditional advertisement with route-maps | |
324 | # EXIST-MAP, ADV-MAP-2 and RMAP-2 | |
325 | def exist_map_routes_not_present_rmap2_filter(router): | |
326 | return all_routes_withdrawn(router) | |
327 | ||
328 | ||
329 | def exist_map_routes_not_present_no_rmap2_filter(router): | |
330 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
331 | expected = { | |
332 | "0.0.0.0/0": None, | |
333 | "192.0.2.1/32": [{"protocol": "bgp"}], | |
334 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
335 | "10.139.224.0/20": [{"protocol": "bgp"}], | |
336 | "203.0.113.1/32": None, | |
337 | } | |
338 | return topotest.json_cmp(output, expected) | |
339 | ||
340 | ||
341 | def non_exist_map_routes_not_present_rmap2_filter(router): | |
342 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
343 | expected = { | |
344 | "0.0.0.0/0": None, | |
345 | "192.0.2.1/32": None, | |
346 | "192.0.2.5/32": None, | |
347 | "10.139.224.0/20": None, | |
348 | "203.0.113.1/32": [{"protocol": "bgp", "metric": 911}], | |
349 | } | |
350 | return topotest.json_cmp(output, expected) | |
fa36596c | 351 | |
90557c3f LS |
352 | |
353 | def non_exist_map_routes_not_present_no_rmap2_filter(router): | |
354 | return non_exist_map_routes_not_present(router) | |
355 | ||
356 | ||
357 | def exist_map_routes_present_rmap2_filter(router): | |
358 | return non_exist_map_routes_not_present_rmap2_filter(router) | |
359 | ||
360 | ||
361 | def exist_map_routes_present_no_rmap2_filter(router): | |
362 | return all_routes_advertised(router) | |
363 | ||
364 | ||
365 | def non_exist_map_routes_present_rmap2_filter(router): | |
366 | return all_routes_withdrawn(router) | |
367 | ||
368 | ||
369 | def non_exist_map_routes_present_no_rmap2_filter(router): | |
370 | output = json.loads(router.vtysh_cmd("show ip route json")) | |
371 | expected = { | |
372 | "0.0.0.0/0": [{"protocol": "bgp"}], | |
373 | "192.0.2.1/32": [{"protocol": "bgp"}], | |
374 | "192.0.2.5/32": [{"protocol": "bgp"}], | |
375 | "10.139.224.0/20": [{"protocol": "bgp"}], | |
376 | "203.0.113.1/32": None, | |
377 | } | |
378 | return topotest.json_cmp(output, expected) | |
379 | ||
380 | ||
381 | def exist_map_routes_present_rmap2_network(router): | |
382 | return non_exist_map_routes_not_present_rmap2_filter(router) | |
383 | ||
384 | ||
385 | def exist_map_routes_present_rmap2_no_network(router): | |
386 | return all_routes_withdrawn(router) | |
387 | ||
388 | ||
389 | def non_exist_map_routes_not_present_rmap2_network(router): | |
390 | return non_exist_map_routes_not_present_rmap2_filter(router) | |
391 | ||
392 | ||
393 | def non_exist_map_routes_not_present_rmap2_no_network(router): | |
394 | return all_routes_withdrawn(router) | |
395 | ||
396 | ||
397 | passed = "PASSED!!!" | |
398 | failed = "FAILED!!!" | |
399 | ||
400 | ||
1285c4ac | 401 | def test_bgp_conditional_advertisement_tc_1_1(): |
fa36596c MK |
402 | tgen = get_topogen() |
403 | if tgen.routers_have_failure(): | |
404 | pytest.skip(tgen.errors) | |
405 | ||
406 | router1 = tgen.gears["r1"] | |
407 | router2 = tgen.gears["r2"] | |
408 | router3 = tgen.gears["r3"] | |
409 | ||
fa36596c MK |
410 | # TC11: R3 BGP convergence, without advertise-map configuration. |
411 | # All routes are advertised to R3. | |
90557c3f | 412 | test_func = functools.partial(all_routes_advertised, router3) |
fa36596c MK |
413 | success, result = topotest.run_and_expect(test_func, None, count=130, wait=1) |
414 | ||
415 | msg = 'TC11: "router3" BGP convergence - ' | |
416 | assert result is None, msg + failed | |
417 | ||
418 | logger.info(msg + passed) | |
419 | ||
90557c3f | 420 | |
1285c4ac | 421 | def test_bgp_conditional_advertisement_tc_2_1(): |
90557c3f LS |
422 | tgen = get_topogen() |
423 | if tgen.routers_have_failure(): | |
424 | pytest.skip(tgen.errors) | |
425 | ||
426 | router1 = tgen.gears["r1"] | |
427 | router2 = tgen.gears["r2"] | |
428 | router3 = tgen.gears["r3"] | |
429 | ||
fa36596c MK |
430 | # TC21: exist-map routes present in R2's BGP table. |
431 | # advertise-map routes present in R2's BGP table are advertised to R3. | |
432 | router2.vtysh_cmd( | |
433 | """ | |
434 | configure terminal | |
435 | router bgp 2 | |
436 | address-family ipv4 unicast | |
e73c112e | 437 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP |
fa36596c MK |
438 | """ |
439 | ) | |
440 | ||
90557c3f | 441 | test_func = functools.partial(exist_map_routes_present, router3) |
fa36596c MK |
442 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
443 | ||
444 | msg = 'TC21: exist-map routes present in "router2" BGP table - ' | |
445 | assert result is None, msg + failed | |
446 | ||
447 | logger.info(msg + passed) | |
448 | ||
90557c3f | 449 | |
1285c4ac | 450 | def test_bgp_conditional_advertisement_tc_2_2(): |
90557c3f LS |
451 | tgen = get_topogen() |
452 | if tgen.routers_have_failure(): | |
453 | pytest.skip(tgen.errors) | |
454 | ||
455 | router1 = tgen.gears["r1"] | |
456 | router2 = tgen.gears["r2"] | |
457 | router3 = tgen.gears["r3"] | |
458 | ||
fa36596c MK |
459 | # TC22: exist-map routes not present in R2's BGP table |
460 | # advertise-map routes present in R2's BGP table are withdrawn from R3. | |
461 | router1.vtysh_cmd( | |
462 | """ | |
463 | configure terminal | |
464 | router bgp 1 | |
465 | address-family ipv4 unicast | |
466 | no network 0.0.0.0/0 route-map DEF | |
467 | """ | |
468 | ) | |
469 | ||
90557c3f | 470 | test_func = functools.partial(exist_map_routes_not_present, router3) |
fa36596c MK |
471 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
472 | ||
473 | msg = 'TC22: exist-map routes not present in "router2" BGP table - ' | |
474 | assert result is None, msg + failed | |
475 | ||
476 | logger.info(msg + passed) | |
477 | ||
b9fdddb8 | 478 | |
1285c4ac MK |
479 | def test_bgp_conditional_advertisement_tc_2_3(): |
480 | tgen = get_topogen() | |
481 | if tgen.routers_have_failure(): | |
482 | pytest.skip(tgen.errors) | |
90557c3f | 483 | |
1285c4ac MK |
484 | router1 = tgen.gears["r1"] |
485 | router2 = tgen.gears["r2"] | |
486 | router3 = tgen.gears["r3"] | |
487 | ||
488 | # TC23: advertise-map with exist-map configuration is removed from a peer | |
489 | # send normal BGP update to advertise previously withdrawn routes if any. | |
490 | router2.vtysh_cmd( | |
491 | """ | |
492 | configure terminal | |
493 | router bgp 2 | |
494 | address-family ipv4 unicast | |
495 | no neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP | |
496 | """ | |
497 | ) | |
498 | ||
499 | test_func = functools.partial(default_route_withdrawn, router3) | |
500 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
501 | ||
b9fdddb8 | 502 | msg = "TC23: advertise-map with exist-map configuration is removed from peer - " |
1285c4ac MK |
503 | assert result is None, msg + failed |
504 | ||
505 | logger.info(msg + passed) | |
506 | ||
507 | ||
508 | def test_bgp_conditional_advertisement_tc_3_1(): | |
90557c3f LS |
509 | tgen = get_topogen() |
510 | if tgen.routers_have_failure(): | |
511 | pytest.skip(tgen.errors) | |
512 | ||
513 | router1 = tgen.gears["r1"] | |
514 | router2 = tgen.gears["r2"] | |
515 | router3 = tgen.gears["r3"] | |
516 | ||
fa36596c MK |
517 | # TC31: non-exist-map routes not present in R2's BGP table |
518 | # advertise-map routes present in R2's BGP table are advertised to R3. | |
519 | router2.vtysh_cmd( | |
520 | """ | |
521 | configure terminal | |
522 | router bgp 2 | |
523 | address-family ipv4 unicast | |
e73c112e | 524 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP |
fa36596c MK |
525 | """ |
526 | ) | |
527 | ||
90557c3f | 528 | test_func = functools.partial(non_exist_map_routes_not_present, router3) |
fa36596c MK |
529 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
530 | ||
531 | msg = 'TC31: non-exist-map routes not present in "router2" BGP table - ' | |
532 | assert result is None, msg + failed | |
533 | ||
534 | logger.info(msg + passed) | |
535 | ||
90557c3f | 536 | |
1285c4ac | 537 | def test_bgp_conditional_advertisement_tc_3_2(): |
90557c3f LS |
538 | tgen = get_topogen() |
539 | if tgen.routers_have_failure(): | |
540 | pytest.skip(tgen.errors) | |
541 | ||
542 | router1 = tgen.gears["r1"] | |
543 | router2 = tgen.gears["r2"] | |
544 | router3 = tgen.gears["r3"] | |
545 | ||
fa36596c MK |
546 | # TC32: non-exist-map routes present in R2's BGP table |
547 | # advertise-map routes present in R2's BGP table are withdrawn from R3. | |
548 | router1.vtysh_cmd( | |
549 | """ | |
550 | configure terminal | |
551 | router bgp 1 | |
552 | address-family ipv4 unicast | |
553 | network 0.0.0.0/0 route-map DEF | |
554 | """ | |
555 | ) | |
556 | ||
90557c3f | 557 | test_func = functools.partial(non_exist_map_routes_present, router3) |
fa36596c MK |
558 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
559 | ||
560 | msg = 'TC32: non-exist-map routes present in "router2" BGP table - ' | |
561 | assert result is None, msg + failed | |
562 | ||
563 | logger.info(msg + passed) | |
564 | ||
b9fdddb8 | 565 | |
1285c4ac MK |
566 | def test_bgp_conditional_advertisement_tc_3_3(): |
567 | tgen = get_topogen() | |
568 | if tgen.routers_have_failure(): | |
569 | pytest.skip(tgen.errors) | |
570 | ||
571 | router1 = tgen.gears["r1"] | |
572 | router2 = tgen.gears["r2"] | |
573 | router3 = tgen.gears["r3"] | |
90557c3f | 574 | |
1285c4ac MK |
575 | # TC33: advertise-map with non-exist-map configuration is removed from a peer |
576 | # send normal BGP update to advertisepreviously withdrawn routes if any. | |
577 | router2.vtysh_cmd( | |
578 | """ | |
579 | configure terminal | |
580 | router bgp 2 | |
581 | address-family ipv4 unicast | |
582 | no neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP | |
583 | """ | |
584 | ) | |
585 | ||
586 | test_func = functools.partial(all_routes_advertised, router3) | |
587 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
588 | ||
b9fdddb8 MK |
589 | msg = ( |
590 | "TC33: advertise-map with non-exist-map configuration is removed from a peer - " | |
591 | ) | |
1285c4ac MK |
592 | assert result is None, msg + failed |
593 | ||
594 | logger.info(msg + passed) | |
595 | ||
b9fdddb8 | 596 | |
1285c4ac | 597 | def test_bgp_conditional_advertisement_tc_4_1(): |
90557c3f LS |
598 | tgen = get_topogen() |
599 | if tgen.routers_have_failure(): | |
600 | pytest.skip(tgen.errors) | |
601 | ||
602 | router1 = tgen.gears["r1"] | |
603 | router2 = tgen.gears["r2"] | |
604 | router3 = tgen.gears["r3"] | |
605 | ||
fa36596c MK |
606 | # TC41: non-exist-map route-map configuration removed in R2. |
607 | # advertise-map routes present in R2's BGP table are advertised to R3. | |
608 | router2.vtysh_cmd( | |
609 | """ | |
610 | configure terminal | |
1285c4ac MK |
611 | router bgp 2 |
612 | address-family ipv4 unicast | |
613 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP | |
fa36596c MK |
614 | no route-map EXIST-MAP permit 10 |
615 | """ | |
616 | ) | |
617 | ||
90557c3f | 618 | test_func = functools.partial(non_exist_map_no_condition_route_map, router3) |
fa36596c MK |
619 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
620 | ||
621 | msg = 'TC41: non-exist-map route-map removed in "router2" - ' | |
622 | assert result is None, msg + failed | |
623 | ||
624 | logger.info(msg + passed) | |
625 | ||
90557c3f | 626 | |
1285c4ac | 627 | def test_bgp_conditional_advertisement_tc_4_2(): |
90557c3f LS |
628 | tgen = get_topogen() |
629 | if tgen.routers_have_failure(): | |
630 | pytest.skip(tgen.errors) | |
631 | ||
632 | router1 = tgen.gears["r1"] | |
633 | router2 = tgen.gears["r2"] | |
634 | router3 = tgen.gears["r3"] | |
635 | ||
fa36596c MK |
636 | # TC42: exist-map route-map configuration removed in R2 |
637 | # advertise-map routes present in R2's BGP table are withdrawn from R3. | |
638 | router2.vtysh_cmd( | |
639 | """ | |
640 | configure terminal | |
641 | router bgp 2 | |
642 | address-family ipv4 unicast | |
e73c112e | 643 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP |
fa36596c MK |
644 | """ |
645 | ) | |
646 | ||
90557c3f | 647 | test_func = functools.partial(exist_map_no_condition_route_map, router3) |
fa36596c MK |
648 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
649 | ||
650 | msg = 'TC42: exist-map route-map removed in "router2" - ' | |
651 | assert result is None, msg + failed | |
652 | ||
653 | logger.info(msg + passed) | |
654 | ||
90557c3f | 655 | |
1285c4ac | 656 | def test_bgp_conditional_advertisement_tc_5_1(): |
90557c3f LS |
657 | tgen = get_topogen() |
658 | if tgen.routers_have_failure(): | |
659 | pytest.skip(tgen.errors) | |
660 | ||
661 | router1 = tgen.gears["r1"] | |
662 | router2 = tgen.gears["r2"] | |
663 | router3 = tgen.gears["r3"] | |
664 | ||
fa36596c MK |
665 | # TC51: exist-map routes present in R2's BGP table, with route-map filter. |
666 | # All routes are withdrawn from R3 except advertise-map routes. | |
667 | router2.vtysh_cmd( | |
668 | """ | |
669 | configure terminal | |
670 | route-map EXIST-MAP permit 10 | |
671 | match community DEFAULT-ROUTE | |
672 | match ip address prefix-list DEFAULT-ROUTE | |
673 | ! | |
fa36596c MK |
674 | router bgp 2 |
675 | address-family ipv4 unicast | |
e73c112e | 676 | neighbor 10.10.20.3 route-map RMAP-1 out |
fa36596c MK |
677 | """ |
678 | ) | |
679 | ||
90557c3f | 680 | test_func = functools.partial(exist_map_routes_present_rmap_filter, router3) |
fa36596c MK |
681 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
682 | ||
683 | msg = "TC51: exist-map routes present with route-map filter - " | |
684 | assert result is None, msg + failed | |
685 | ||
686 | logger.info(msg + passed) | |
687 | ||
90557c3f | 688 | |
1285c4ac | 689 | def test_bgp_conditional_advertisement_tc_5_2(): |
90557c3f LS |
690 | tgen = get_topogen() |
691 | if tgen.routers_have_failure(): | |
692 | pytest.skip(tgen.errors) | |
693 | ||
694 | router1 = tgen.gears["r1"] | |
695 | router2 = tgen.gears["r2"] | |
696 | router3 = tgen.gears["r3"] | |
697 | ||
fa36596c MK |
698 | # TC52: exist-map routes present in R2's BGP table, no route-map filter. |
699 | # All routes are advertised to R3 including advertise-map routes. | |
700 | router2.vtysh_cmd( | |
701 | """ | |
702 | configure terminal | |
703 | router bgp 2 | |
704 | address-family ipv4 unicast | |
e73c112e | 705 | no neighbor 10.10.20.3 route-map RMAP-1 out |
fa36596c MK |
706 | """ |
707 | ) | |
708 | ||
90557c3f | 709 | test_func = functools.partial(exist_map_routes_present_no_rmap_filter, router3) |
fa36596c MK |
710 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
711 | ||
712 | msg = "TC52: exist-map routes present, no route-map filter - " | |
713 | assert result is None, msg + failed | |
714 | ||
715 | logger.info(msg + passed) | |
716 | ||
90557c3f | 717 | |
1285c4ac | 718 | def test_bgp_conditional_advertisement_tc_5_3(): |
90557c3f LS |
719 | tgen = get_topogen() |
720 | if tgen.routers_have_failure(): | |
721 | pytest.skip(tgen.errors) | |
722 | ||
723 | router1 = tgen.gears["r1"] | |
724 | router2 = tgen.gears["r2"] | |
725 | router3 = tgen.gears["r3"] | |
726 | ||
fa36596c MK |
727 | # TC53: non-exist-map routes present in R2's BGP table, with route-map filter. |
728 | # All routes are withdrawn from R3 including advertise-map routes. | |
729 | router2.vtysh_cmd( | |
730 | """ | |
731 | configure terminal | |
732 | router bgp 2 | |
733 | address-family ipv4 unicast | |
e73c112e MK |
734 | neighbor 10.10.20.3 route-map RMAP-1 out |
735 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP | |
fa36596c MK |
736 | """ |
737 | ) | |
738 | ||
90557c3f | 739 | test_func = functools.partial(non_exist_map_routes_present_rmap_filter, router3) |
fa36596c MK |
740 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
741 | ||
742 | msg = "TC53: non-exist-map routes present, with route-map filter - " | |
743 | assert result is None, msg + failed | |
744 | ||
745 | logger.info(msg + passed) | |
746 | ||
90557c3f | 747 | |
1285c4ac | 748 | def test_bgp_conditional_advertisement_tc_5_4(): |
90557c3f LS |
749 | tgen = get_topogen() |
750 | if tgen.routers_have_failure(): | |
751 | pytest.skip(tgen.errors) | |
752 | ||
753 | router1 = tgen.gears["r1"] | |
754 | router2 = tgen.gears["r2"] | |
755 | router3 = tgen.gears["r3"] | |
756 | ||
fa36596c MK |
757 | # TC54: non-exist-map routes present in R2's BGP table, no route-map filter. |
758 | # All routes are advertised to R3 except advertise-map routes. | |
759 | router2.vtysh_cmd( | |
760 | """ | |
761 | configure terminal | |
762 | router bgp 2 | |
763 | address-family ipv4 unicast | |
e73c112e | 764 | no neighbor 10.10.20.3 route-map RMAP-1 out |
fa36596c MK |
765 | """ |
766 | ) | |
767 | ||
90557c3f | 768 | test_func = functools.partial(non_exist_map_routes_present_no_rmap_filter, router3) |
fa36596c MK |
769 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
770 | ||
771 | msg = "TC54: non-exist-map routes present, no route-map filter - " | |
772 | assert result is None, msg + failed | |
773 | ||
774 | logger.info(msg + passed) | |
775 | ||
90557c3f | 776 | |
1285c4ac | 777 | def test_bgp_conditional_advertisement_tc_6_1(): |
90557c3f LS |
778 | tgen = get_topogen() |
779 | if tgen.routers_have_failure(): | |
780 | pytest.skip(tgen.errors) | |
781 | ||
782 | router1 = tgen.gears["r1"] | |
783 | router2 = tgen.gears["r2"] | |
784 | router3 = tgen.gears["r3"] | |
785 | ||
fa36596c MK |
786 | # TC61: exist-map routes not present in R2's BGP table, with route-map filter. |
787 | # All routes are withdrawn from R3 including advertise-map routes. | |
788 | router1.vtysh_cmd( | |
789 | """ | |
790 | configure terminal | |
791 | router bgp 1 | |
792 | address-family ipv4 unicast | |
793 | no network 0.0.0.0/0 route-map DEF | |
794 | """ | |
795 | ) | |
796 | router2.vtysh_cmd( | |
797 | """ | |
798 | configure terminal | |
799 | router bgp 2 | |
800 | address-family ipv4 unicast | |
e73c112e MK |
801 | neighbor 10.10.20.3 route-map RMAP-1 out |
802 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP | |
fa36596c MK |
803 | """ |
804 | ) | |
805 | ||
90557c3f | 806 | test_func = functools.partial(exist_map_routes_not_present_rmap_filter, router3) |
fa36596c MK |
807 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
808 | ||
809 | msg = "TC61: exist-map routes not present, route-map filter - " | |
810 | assert result is None, msg + failed | |
811 | ||
812 | logger.info(msg + passed) | |
813 | ||
90557c3f | 814 | |
1285c4ac | 815 | def test_bgp_conditional_advertisement_tc_6_2(): |
90557c3f LS |
816 | tgen = get_topogen() |
817 | if tgen.routers_have_failure(): | |
818 | pytest.skip(tgen.errors) | |
819 | ||
820 | router1 = tgen.gears["r1"] | |
821 | router2 = tgen.gears["r2"] | |
822 | router3 = tgen.gears["r3"] | |
823 | ||
fa36596c MK |
824 | # TC62: exist-map routes not present in R2's BGP table, without route-map filter. |
825 | # All routes are advertised to R3 except advertise-map routes. | |
826 | router2.vtysh_cmd( | |
827 | """ | |
828 | configure terminal | |
829 | router bgp 2 | |
830 | address-family ipv4 unicast | |
e73c112e | 831 | no neighbor 10.10.20.3 route-map RMAP-1 out |
fa36596c MK |
832 | """ |
833 | ) | |
834 | ||
90557c3f | 835 | test_func = functools.partial(exist_map_routes_not_present_no_rmap_filter, router3) |
fa36596c MK |
836 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
837 | ||
838 | msg = "TC62: exist-map routes not present, no route-map filter - " | |
839 | assert result is None, msg + failed | |
840 | ||
841 | logger.info(msg + passed) | |
842 | ||
90557c3f | 843 | |
1285c4ac | 844 | def test_bgp_conditional_advertisement_tc_6_3(): |
90557c3f LS |
845 | tgen = get_topogen() |
846 | if tgen.routers_have_failure(): | |
847 | pytest.skip(tgen.errors) | |
848 | ||
849 | router1 = tgen.gears["r1"] | |
850 | router2 = tgen.gears["r2"] | |
851 | router3 = tgen.gears["r3"] | |
852 | ||
fa36596c MK |
853 | # TC63: non-exist-map routes not present in R2's BGP table, with route-map filter. |
854 | # All routes are withdrawn from R3 except advertise-map routes. | |
855 | router2.vtysh_cmd( | |
856 | """ | |
857 | configure terminal | |
858 | router bgp 2 | |
859 | address-family ipv4 unicast | |
e73c112e MK |
860 | neighbor 10.10.20.3 route-map RMAP-1 out |
861 | neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP | |
fa36596c MK |
862 | """ |
863 | ) | |
864 | ||
90557c3f | 865 | test_func = functools.partial(non_exist_map_routes_not_present_rmap_filter, router3) |
fa36596c MK |
866 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
867 | ||
868 | msg = "TC63: non-exist-map routes not present, route-map filter - " | |
869 | assert result is None, msg + failed | |
870 | ||
871 | logger.info(msg + passed) | |
872 | ||
90557c3f | 873 | |
1285c4ac | 874 | def test_bgp_conditional_advertisement_tc_6_4(): |
90557c3f LS |
875 | tgen = get_topogen() |
876 | if tgen.routers_have_failure(): | |
877 | pytest.skip(tgen.errors) | |
878 | ||
879 | router1 = tgen.gears["r1"] | |
880 | router2 = tgen.gears["r2"] | |
881 | router3 = tgen.gears["r3"] | |
882 | ||
fa36596c MK |
883 | # TC64: non-exist-map routes not present in R2's BGP table, without route-map filter. |
884 | # All routes are advertised to R3 including advertise-map routes. | |
885 | router2.vtysh_cmd( | |
886 | """ | |
887 | configure terminal | |
888 | router bgp 2 | |
889 | address-family ipv4 unicast | |
e73c112e | 890 | no neighbor 10.10.20.3 route-map RMAP-1 out |
fa36596c MK |
891 | """ |
892 | ) | |
893 | ||
894 | test_func = functools.partial( | |
90557c3f | 895 | non_exist_map_routes_not_present_no_rmap_filter, router3 |
fa36596c MK |
896 | ) |
897 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
898 | ||
899 | msg = "TC64: non-exist-map routes not present, no route-map filter - " | |
900 | assert result is None, msg + failed | |
901 | ||
902 | logger.info(msg + passed) | |
903 | ||
90557c3f | 904 | |
1285c4ac | 905 | def test_bgp_conditional_advertisement_tc_7_1(): |
90557c3f LS |
906 | tgen = get_topogen() |
907 | if tgen.routers_have_failure(): | |
908 | pytest.skip(tgen.errors) | |
909 | ||
910 | router1 = tgen.gears["r1"] | |
911 | router2 = tgen.gears["r2"] | |
912 | router3 = tgen.gears["r3"] | |
913 | ||
e73c112e MK |
914 | # TC71: exist-map routes present in R2's BGP table, with route-map filter. |
915 | # All routes are withdrawn from R3 except advertise-map routes. | |
916 | router1.vtysh_cmd( | |
917 | """ | |
918 | configure terminal | |
919 | router bgp 1 | |
920 | address-family ipv4 unicast | |
921 | network 0.0.0.0/0 route-map DEF | |
922 | """ | |
923 | ) | |
924 | router2.vtysh_cmd( | |
925 | """ | |
926 | configure terminal | |
927 | router bgp 2 | |
928 | address-family ipv4 unicast | |
929 | neighbor 10.10.20.3 route-map RMAP-2 out | |
930 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP | |
931 | """ | |
932 | ) | |
933 | ||
90557c3f | 934 | test_func = functools.partial(exist_map_routes_present_rmap2_filter, router3) |
e73c112e MK |
935 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
936 | ||
937 | msg = "TC71: exist-map routes present, route-map filter - " | |
938 | assert result is None, msg + failed | |
939 | ||
940 | logger.info(msg + passed) | |
941 | ||
90557c3f | 942 | |
1285c4ac | 943 | def test_bgp_conditional_advertisement_tc_7_2(): |
90557c3f LS |
944 | tgen = get_topogen() |
945 | if tgen.routers_have_failure(): | |
946 | pytest.skip(tgen.errors) | |
947 | ||
948 | router1 = tgen.gears["r1"] | |
949 | router2 = tgen.gears["r2"] | |
950 | router3 = tgen.gears["r3"] | |
951 | ||
e73c112e MK |
952 | # TC72: exist-map routes present in R2's BGP table, without route-map filter. |
953 | # All routes are advertised to R3 including advertise-map routes. | |
954 | router2.vtysh_cmd( | |
955 | """ | |
956 | configure terminal | |
957 | router bgp 2 | |
958 | address-family ipv4 unicast | |
959 | no neighbor 10.10.20.3 route-map RMAP-2 out | |
960 | """ | |
961 | ) | |
962 | ||
90557c3f | 963 | test_func = functools.partial(exist_map_routes_present_no_rmap2_filter, router3) |
e73c112e MK |
964 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
965 | ||
966 | msg = "TC72: exist-map routes present, no route-map filter - " | |
967 | assert result is None, msg + failed | |
968 | ||
969 | logger.info(msg + passed) | |
970 | ||
90557c3f | 971 | |
1285c4ac | 972 | def test_bgp_conditional_advertisement_tc_7_3(): |
90557c3f LS |
973 | tgen = get_topogen() |
974 | if tgen.routers_have_failure(): | |
975 | pytest.skip(tgen.errors) | |
976 | ||
977 | router1 = tgen.gears["r1"] | |
978 | router2 = tgen.gears["r2"] | |
979 | router3 = tgen.gears["r3"] | |
980 | ||
e73c112e MK |
981 | # TC73: non-exist-map routes present in R2's BGP table, with route-map filter. |
982 | # All routes are advertised to R3 including advertise-map routes. | |
983 | router2.vtysh_cmd( | |
984 | """ | |
985 | configure terminal | |
986 | router bgp 2 | |
987 | address-family ipv4 unicast | |
988 | neighbor 10.10.20.3 route-map RMAP-2 out | |
989 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP | |
990 | """ | |
991 | ) | |
992 | ||
90557c3f | 993 | test_func = functools.partial(non_exist_map_routes_present_rmap2_filter, router3) |
e73c112e MK |
994 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
995 | ||
996 | msg = "TC73: non-exist-map routes present, route-map filter - " | |
997 | assert result is None, msg + failed | |
998 | ||
999 | logger.info(msg + passed) | |
1000 | ||
90557c3f | 1001 | |
1285c4ac | 1002 | def test_bgp_conditional_advertisement_tc_7_4(): |
90557c3f LS |
1003 | tgen = get_topogen() |
1004 | if tgen.routers_have_failure(): | |
1005 | pytest.skip(tgen.errors) | |
1006 | ||
1007 | router1 = tgen.gears["r1"] | |
1008 | router2 = tgen.gears["r2"] | |
1009 | router3 = tgen.gears["r3"] | |
1010 | ||
e73c112e MK |
1011 | # TC74: non-exist-map routes present in R2's BGP table, without route-map filter. |
1012 | # All routes are advertised to R3 including advertise-map routes. | |
1013 | router2.vtysh_cmd( | |
1014 | """ | |
1015 | configure terminal | |
1016 | router bgp 2 | |
1017 | address-family ipv4 unicast | |
1018 | no neighbor 10.10.20.3 route-map RMAP-2 out | |
1019 | """ | |
1020 | ) | |
1021 | ||
90557c3f | 1022 | test_func = functools.partial(non_exist_map_routes_present_no_rmap2_filter, router3) |
e73c112e MK |
1023 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
1024 | ||
1025 | msg = "TC74: non-exist-map routes present, no route-map filter - " | |
1026 | assert result is None, msg + failed | |
1027 | ||
1028 | logger.info(msg + passed) | |
1029 | ||
90557c3f | 1030 | |
1285c4ac | 1031 | def test_bgp_conditional_advertisement_tc_8_1(): |
90557c3f LS |
1032 | tgen = get_topogen() |
1033 | if tgen.routers_have_failure(): | |
1034 | pytest.skip(tgen.errors) | |
1035 | ||
1036 | router1 = tgen.gears["r1"] | |
1037 | router2 = tgen.gears["r2"] | |
1038 | router3 = tgen.gears["r3"] | |
1039 | ||
e73c112e MK |
1040 | # TC81: exist-map routes not present in R2's BGP table, with route-map filter. |
1041 | # All routes are withdrawn from R3 including advertise-map routes. | |
1042 | router1.vtysh_cmd( | |
1043 | """ | |
1044 | configure terminal | |
1045 | router bgp 1 | |
1046 | address-family ipv4 unicast | |
1047 | no network 0.0.0.0/0 route-map DEF | |
1048 | """ | |
1049 | ) | |
1050 | router2.vtysh_cmd( | |
1051 | """ | |
1052 | configure terminal | |
1053 | router bgp 2 | |
1054 | address-family ipv4 unicast | |
1055 | neighbor 10.10.20.3 route-map RMAP-2 out | |
1056 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP | |
1057 | """ | |
1058 | ) | |
1059 | ||
90557c3f | 1060 | test_func = functools.partial(exist_map_routes_not_present_rmap2_filter, router3) |
e73c112e MK |
1061 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
1062 | ||
1063 | msg = "TC81: exist-map routes not present, route-map filter - " | |
1064 | assert result is None, msg + failed | |
1065 | ||
1066 | logger.info(msg + passed) | |
1067 | ||
90557c3f | 1068 | |
1285c4ac | 1069 | def test_bgp_conditional_advertisement_tc_8_2(): |
90557c3f LS |
1070 | tgen = get_topogen() |
1071 | if tgen.routers_have_failure(): | |
1072 | pytest.skip(tgen.errors) | |
1073 | ||
1074 | router1 = tgen.gears["r1"] | |
1075 | router2 = tgen.gears["r2"] | |
1076 | router3 = tgen.gears["r3"] | |
1077 | ||
e73c112e MK |
1078 | # TC82: exist-map routes not present in R2's BGP table, without route-map filter. |
1079 | # All routes are advertised to R3 except advertise-map routes. | |
1080 | router2.vtysh_cmd( | |
1081 | """ | |
1082 | configure terminal | |
1083 | router bgp 2 | |
1084 | address-family ipv4 unicast | |
1085 | no neighbor 10.10.20.3 route-map RMAP-2 out | |
1086 | """ | |
1087 | ) | |
1088 | ||
90557c3f | 1089 | test_func = functools.partial(exist_map_routes_not_present_no_rmap2_filter, router3) |
e73c112e MK |
1090 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
1091 | ||
1092 | msg = "TC82: exist-map routes not present, no route-map filter - " | |
1093 | assert result is None, msg + failed | |
1094 | ||
1095 | logger.info(msg + passed) | |
1096 | ||
90557c3f | 1097 | |
1285c4ac | 1098 | def test_bgp_conditional_advertisement_tc_8_3(): |
90557c3f LS |
1099 | tgen = get_topogen() |
1100 | if tgen.routers_have_failure(): | |
1101 | pytest.skip(tgen.errors) | |
1102 | ||
1103 | router1 = tgen.gears["r1"] | |
1104 | router2 = tgen.gears["r2"] | |
1105 | router3 = tgen.gears["r3"] | |
1106 | ||
e73c112e MK |
1107 | # TC83: non-exist-map routes not present in R2's BGP table, with route-map filter. |
1108 | # All routes are advertised to R3 including advertise-map routes. | |
1109 | router2.vtysh_cmd( | |
1110 | """ | |
1111 | configure terminal | |
1112 | router bgp 2 | |
1113 | address-family ipv4 unicast | |
1114 | neighbor 10.10.20.3 route-map RMAP-2 out | |
1115 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP | |
1116 | """ | |
1117 | ) | |
1118 | ||
1119 | test_func = functools.partial( | |
90557c3f | 1120 | non_exist_map_routes_not_present_rmap2_filter, router3 |
e73c112e MK |
1121 | ) |
1122 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
1123 | ||
1124 | msg = "TC83: non-exist-map routes not present, route-map filter - " | |
1125 | assert result is None, msg + failed | |
1126 | ||
1127 | logger.info(msg + passed) | |
1128 | ||
90557c3f | 1129 | |
1285c4ac | 1130 | def test_bgp_conditional_advertisement_tc_8_4(): |
90557c3f LS |
1131 | tgen = get_topogen() |
1132 | if tgen.routers_have_failure(): | |
1133 | pytest.skip(tgen.errors) | |
1134 | ||
1135 | router1 = tgen.gears["r1"] | |
1136 | router2 = tgen.gears["r2"] | |
1137 | router3 = tgen.gears["r3"] | |
1138 | ||
e73c112e MK |
1139 | # TC84: non-exist-map routes not present in R2's BGP table, without route-map filter. |
1140 | # All routes are advertised to R3 including advertise-map routes. | |
1141 | router2.vtysh_cmd( | |
1142 | """ | |
1143 | configure terminal | |
1144 | router bgp 2 | |
1145 | address-family ipv4 unicast | |
1146 | no neighbor 10.10.20.3 route-map RMAP-2 out | |
1147 | """ | |
1148 | ) | |
1149 | ||
1150 | test_func = functools.partial( | |
90557c3f | 1151 | non_exist_map_routes_not_present_no_rmap2_filter, router3 |
e73c112e MK |
1152 | ) |
1153 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
1154 | ||
1155 | msg = "TC84: non-exist-map routes not present, no route-map filter - " | |
1156 | assert result is None, msg + failed | |
1157 | ||
1158 | logger.info(msg + passed) | |
1159 | ||
90557c3f | 1160 | |
1285c4ac | 1161 | def test_bgp_conditional_advertisement_tc_9_1(): |
90557c3f LS |
1162 | tgen = get_topogen() |
1163 | if tgen.routers_have_failure(): | |
1164 | pytest.skip(tgen.errors) | |
1165 | ||
1166 | router1 = tgen.gears["r1"] | |
1167 | router2 = tgen.gears["r2"] | |
1168 | router3 = tgen.gears["r3"] | |
1169 | ||
e73c112e MK |
1170 | # TC91: exist-map routes present in R2's BGP table, with route-map filter and network. |
1171 | # All routes are advertised to R3 including advertise-map routes. | |
1172 | router1.vtysh_cmd( | |
1173 | """ | |
1174 | configure terminal | |
1175 | router bgp 1 | |
1176 | address-family ipv4 unicast | |
1177 | network 0.0.0.0/0 route-map DEF | |
1178 | """ | |
1179 | ) | |
1180 | router2.vtysh_cmd( | |
1181 | """ | |
1182 | configure terminal | |
1183 | router bgp 2 | |
1184 | address-family ipv4 unicast | |
1185 | neighbor 10.10.20.3 route-map RMAP-2 out | |
1186 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP | |
1187 | """ | |
1188 | ) | |
1189 | ||
90557c3f | 1190 | test_func = functools.partial(exist_map_routes_present_rmap2_network, router3) |
e73c112e MK |
1191 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
1192 | ||
1193 | msg = "TC91: exist-map routes present, route-map filter and network - " | |
1194 | assert result is None, msg + failed | |
1195 | ||
1196 | logger.info(msg + passed) | |
1197 | ||
90557c3f | 1198 | |
1285c4ac | 1199 | def test_bgp_conditional_advertisement_tc_9_2(): |
90557c3f LS |
1200 | tgen = get_topogen() |
1201 | if tgen.routers_have_failure(): | |
1202 | pytest.skip(tgen.errors) | |
1203 | ||
1204 | router1 = tgen.gears["r1"] | |
1205 | router2 = tgen.gears["r2"] | |
1206 | router3 = tgen.gears["r3"] | |
1207 | ||
e73c112e MK |
1208 | # TC92: exist-map routes present in R2's BGP table, with route-map filter and no network. |
1209 | # All routes are advertised to R3 except advertise-map routes. | |
1210 | router2.vtysh_cmd( | |
1211 | """ | |
1212 | configure terminal | |
1213 | router bgp 2 | |
1214 | address-family ipv4 unicast | |
1215 | no network 203.0.113.1/32 | |
1216 | """ | |
1217 | ) | |
1218 | ||
90557c3f | 1219 | test_func = functools.partial(exist_map_routes_present_rmap2_no_network, router3) |
e73c112e MK |
1220 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) |
1221 | ||
1222 | msg = "TC92: exist-map routes present, route-map filter and no network - " | |
1223 | assert result is None, msg + failed | |
1224 | ||
1225 | logger.info(msg + passed) | |
1226 | ||
90557c3f | 1227 | |
1285c4ac | 1228 | def test_bgp_conditional_advertisement_tc_9_3(): |
90557c3f LS |
1229 | tgen = get_topogen() |
1230 | if tgen.routers_have_failure(): | |
1231 | pytest.skip(tgen.errors) | |
1232 | ||
1233 | router1 = tgen.gears["r1"] | |
1234 | router2 = tgen.gears["r2"] | |
1235 | router3 = tgen.gears["r3"] | |
1236 | ||
e73c112e MK |
1237 | # TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network. |
1238 | # All routes are advertised to R3 including advertise-map routes. | |
1239 | router1.vtysh_cmd( | |
1240 | """ | |
1241 | configure terminal | |
1242 | router bgp 1 | |
1243 | address-family ipv4 unicast | |
1244 | no network 0.0.0.0/0 route-map DEF | |
1245 | """ | |
1246 | ) | |
1247 | router2.vtysh_cmd( | |
1248 | """ | |
1249 | configure terminal | |
1250 | router bgp 2 | |
1251 | address-family ipv4 unicast | |
1252 | network 203.0.113.1/32 | |
1253 | neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP | |
1254 | """ | |
1255 | ) | |
1256 | ||
1257 | test_func = functools.partial( | |
90557c3f | 1258 | non_exist_map_routes_not_present_rmap2_network, router3 |
e73c112e MK |
1259 | ) |
1260 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
1261 | ||
1262 | msg = "TC93: non-exist-map routes not present, route-map filter and network - " | |
1263 | assert result is None, msg + failed | |
1264 | ||
1265 | logger.info(msg + passed) | |
1266 | ||
90557c3f | 1267 | |
1285c4ac | 1268 | def test_bgp_conditional_advertisement_tc_9_4(): |
90557c3f LS |
1269 | tgen = get_topogen() |
1270 | if tgen.routers_have_failure(): | |
1271 | pytest.skip(tgen.errors) | |
1272 | ||
1273 | router1 = tgen.gears["r1"] | |
1274 | router2 = tgen.gears["r2"] | |
1275 | router3 = tgen.gears["r3"] | |
1276 | ||
e73c112e MK |
1277 | # TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network. |
1278 | # All routes are advertised to R3 except advertise-map routes. | |
1279 | router2.vtysh_cmd( | |
1280 | """ | |
1281 | configure terminal | |
1282 | router bgp 2 | |
1283 | address-family ipv4 unicast | |
1284 | no network 203.0.113.1/32 | |
1285 | """ | |
1286 | ) | |
1287 | ||
1288 | test_func = functools.partial( | |
90557c3f | 1289 | non_exist_map_routes_not_present_rmap2_no_network, router3 |
e73c112e MK |
1290 | ) |
1291 | success, result = topotest.run_and_expect(test_func, None, count=90, wait=1) | |
1292 | ||
1293 | msg = "TC94: non-exist-map routes not present, route-map filter and no network - " | |
1294 | assert result is None, msg + failed | |
1295 | ||
1296 | logger.info(msg + passed) | |
1297 | ||
fa36596c MK |
1298 | |
1299 | def test_memory_leak(): | |
1300 | "Run the memory leak test and report results." | |
1301 | tgen = get_topogen() | |
1302 | if not tgen.is_memleak_enabled(): | |
1303 | pytest.skip("Memory leak test/report is disabled") | |
1304 | ||
1305 | tgen.report_memory_leaks() | |
1306 | ||
1307 | ||
1308 | if __name__ == "__main__": | |
1309 | args = ["-s"] + sys.argv[1:] | |
1310 | sys.exit(pytest.main(args)) |