]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py
tests: micronet: adapt tests
[mirror_frr.git] / tests / topotests / bgp_conditional_advertisement / test_bgp_conditional_advertisement.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_conditional_advertisement.py
5 #
6 # Copyright (c) 2020 by
7 # Samsung R&D Institute India - Bangalore.
8 # Madhurilatha Kuruganti
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.
41
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.
46 TC31: non-exist-map routes not present in R2's BGP table
47 advertise-map routes present in R2's BGP table are advertised to R3.
48 TC32: non-exist-map routes present in R2's BGP table
49 advertise-map routes present in R2's BGP table are withdrawn from R3.
50
51 TC41: non-exist-map route-map configuration removed in R2.
52 advertise-map routes present in R2's BGP table are advertised to R3.
53 TC42: exist-map route-map configuration removed in R2
54 advertise-map routes present in R2's BGP table are withdrawn from R3.
55
56 Conditional advertisement(received routes) along with Route-map Filter
57 ----------------------------------------------------------------------
58 TC51: exist-map routes present in R2's BGP table, with route-map filter.
59 All routes are withdrawn from R3 except advertise-map routes.
60 TC52: exist-map routes present in R2's BGP table, without route-map filter.
61 All routes are advertised to R3 including advertise-map routes.
62 TC53: non-exist-map routes present in R2's BGP table, with route-map filter.
63 All routes are withdrawn from R3 including advertise-map routes.
64 TC54: non-exist-map routes present in R2's BGP table, without route-map filter.
65 All routes are advertised to R3 except advertise-map routes.
66
67 TC61: exist-map routes not present in R2's BGP table, with route-map filter.
68 All routes are withdrawn from R3 including advertise-map routes.
69 TC62: exist-map routes not present in R2's BGP table, without route-map filter.
70 All routes are advertised to R3 except advertise-map routes.
71 TC63: non-exist-map routes not present in R2's BGP table, with route-map filter.
72 All routes are withdrawn from R3 except advertise-map routes.
73 TC64: non-exist-map routes not present in R2's BGP table, without route-map filter.
74 All routes are advertised to R3 including advertise-map routes.
75
76 Conditional advertisement(attached routes) along with Route-map Filter
77 -----------------------------------------------------------------
78 TC71: exist-map routes present in R2's BGP table, with route-map filter.
79 All routes are withdrawn from R3 except advertise-map routes.
80 TC72: exist-map routes present in R2's BGP table, without route-map filter.
81 All routes are advertised to R3 including advertise-map routes.
82 TC73: non-exist-map routes present in R2's BGP table, with route-map filter.
83 All routes are withdrawn from R3 including advertise-map routes.
84 TC74: non-exist-map routes present in R2's BGP table, without route-map filter.
85 All routes are advertised to R3 except advertise-map routes.
86
87 TC81: exist-map routes not present in R2's BGP table, with route-map filter.
88 All routes are withdrawn from R3 including advertise-map routes.
89 TC82: exist-map routes not present in R2's BGP table, without route-map filter.
90 All routes are advertised to R3 except advertise-map routes.
91 TC83: non-exist-map routes not present in R2's BGP table, with route-map filter.
92 All routes are withdrawn from R3 except advertise-map routes.
93 TC84: non-exist-map routes not present in R2's BGP table, without route-map filter.
94 All routes are advertised to R3 including advertise-map routes.
95
96 TC91: exist-map routes present in R2's BGP table, with route-map filter and network.
97 All routes are advertised to R3 including advertise-map routes.
98 TC92: exist-map routes present in R2's BGP table, with route-map filter and no network.
99 All routes are advertised to R3 except advertise-map routes.
100 TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network.
101 All routes are advertised to R3 including advertise-map routes.
102 TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network.
103 All routes are advertised to R3 except advertise-map routes.
104
105 i.e.
106 +----------------+-------------------------+------------------------+
107 | Routes in | exist-map status | advertise-map status |
108 | BGP table | | |
109 +----------------+-------------------------+------------------------+
110 | Present | Condition matched | Advertise |
111 +----------------+-------------------------+------------------------+
112 | Not Present | Condition not matched | Withdrawn |
113 +----------------+-------------------------+------------------------+
114 | | non-exist-map status | advertise-map status |
115 | | | |
116 +----------------+-------------------------+------------------------+
117 | Present | Condition matched | Withdrawn |
118 +----------------+-------------------------+------------------------+
119 | Not Present | Condition not matched | Advertise |
120 +----------------+-------------------------+------------------------+
121 Here in this topology, based on the default route presence in R2 and
122 the configured condition-map (exist-map/non-exist-map) 10.139.224.0/20
123 will be either advertised/withdrawn to/from R3.
124 """
125
126 import os
127 import sys
128 import json
129 import time
130 import pytest
131 import functools
132
133 CWD = os.path.dirname(os.path.realpath(__file__))
134 sys.path.append(os.path.join(CWD, "../"))
135
136 # pylint: disable=C0413
137 from lib import topotest
138 from lib.topogen import Topogen, TopoRouter, get_topogen
139 from lib.topolog import logger
140 from lib.micronet_compat import Topo
141
142 pytestmark = [pytest.mark.bgpd]
143
144
145 class BgpConditionalAdvertisementTopo(Topo):
146 def build(self, *_args, **_opts):
147 tgen = get_topogen(self)
148
149 r1 = tgen.add_router("r1")
150 r2 = tgen.add_router("r2")
151 r3 = tgen.add_router("r3")
152
153 switch = tgen.add_switch("s1")
154 switch.add_link(r1)
155 switch.add_link(r2)
156
157 switch = tgen.add_switch("s2")
158 switch.add_link(r2)
159 switch.add_link(r3)
160
161
162 def setup_module(mod):
163 testsuite_run_time = time.asctime(time.localtime(time.time()))
164 logger.info("Testsuite start time: {}".format(testsuite_run_time))
165 logger.info("=" * 40)
166
167 logger.info("Running setup_module to create topology")
168
169 tgen = Topogen(BgpConditionalAdvertisementTopo, mod.__name__)
170 tgen.start_topology()
171
172 router_list = tgen.routers()
173
174 for i, (rname, router) in enumerate(router_list.items(), 1):
175 router.load_config(
176 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
177 )
178 router.load_config(
179 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
180 )
181
182 tgen.start_router()
183
184 logger.info("Running setup_module() done")
185
186
187 def teardown_module(mod):
188 """
189 Teardown the pytest environment
190 * `mod`: module name
191 """
192
193 logger.info("Running teardown_module to delete topology")
194
195 tgen = get_topogen()
196 tgen.stop_topology()
197
198 logger.info(
199 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
200 )
201 logger.info("=" * 40)
202
203
204 def test_bgp_conditional_advertisement():
205 """
206 Test BGP conditional advertisement functionality.
207 """
208
209 tgen = get_topogen()
210 if tgen.routers_have_failure():
211 pytest.skip(tgen.errors)
212
213 router1 = tgen.gears["r1"]
214 router2 = tgen.gears["r2"]
215 router3 = tgen.gears["r3"]
216
217 passed = "PASSED!!!"
218 failed = "FAILED!!!"
219
220 def _all_routes_advertised(router):
221 output = json.loads(router.vtysh_cmd("show ip route json"))
222 expected = {
223 "0.0.0.0/0": [{"protocol": "bgp"}],
224 "192.0.2.1/32": [{"protocol": "bgp"}],
225 "192.0.2.5/32": [{"protocol": "bgp"}],
226 "10.139.224.0/20": [{"protocol": "bgp"}],
227 "203.0.113.1/32": [{"protocol": "bgp"}],
228 }
229 return topotest.json_cmp(output, expected)
230
231 def _all_routes_withdrawn(router):
232 output = json.loads(router.vtysh_cmd("show ip route json"))
233 expected = {
234 "0.0.0.0/0": None,
235 "192.0.2.1/32": None,
236 "192.0.2.5/32": None,
237 "10.139.224.0/20": None,
238 "203.0.113.1/32": None,
239 }
240 return topotest.json_cmp(output, expected)
241
242 # BGP conditional advertisement with route-maps
243 # EXIST-MAP, ADV-MAP-1 and RMAP-1
244 def _exist_map_routes_present(router):
245 return _all_routes_advertised(router)
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 def _non_exist_map_routes_present(router):
259 output = json.loads(router.vtysh_cmd("show ip route json"))
260 expected = {
261 "0.0.0.0/0": [{"protocol": "bgp"}],
262 "192.0.2.1/32": None,
263 "192.0.2.5/32": [{"protocol": "bgp"}],
264 "10.139.224.0/20": None,
265 "203.0.113.1/32": [{"protocol": "bgp"}],
266 }
267 return topotest.json_cmp(output, expected)
268
269 def _non_exist_map_routes_not_present(router):
270 output = json.loads(router.vtysh_cmd("show ip route json"))
271 expected = {
272 "0.0.0.0/0": None,
273 "192.0.2.1/32": [{"protocol": "bgp"}],
274 "192.0.2.5/32": [{"protocol": "bgp"}],
275 "10.139.224.0/20": [{"protocol": "bgp"}],
276 "203.0.113.1/32": [{"protocol": "bgp"}],
277 }
278 return topotest.json_cmp(output, expected)
279
280 def _exist_map_no_condition_route_map(router):
281 return _non_exist_map_routes_present(router)
282
283 def _non_exist_map_no_condition_route_map(router):
284 return _all_routes_advertised(router)
285
286 def _exist_map_routes_present_rmap_filter(router):
287 output = json.loads(router.vtysh_cmd("show ip route json"))
288 expected = {
289 "0.0.0.0/0": None,
290 "192.0.2.1/32": [{"protocol": "bgp"}],
291 "192.0.2.5/32": None,
292 "10.139.224.0/20": [{"protocol": "bgp"}],
293 "203.0.113.1/32": None,
294 }
295 return topotest.json_cmp(output, expected)
296
297 def _exist_map_routes_present_no_rmap_filter(router):
298 return _all_routes_advertised(router)
299
300 def _non_exist_map_routes_present_rmap_filter(router):
301 return _all_routes_withdrawn(router)
302
303 def _non_exist_map_routes_present_no_rmap_filter(router):
304 return _non_exist_map_routes_present(router)
305
306 def _exist_map_routes_not_present_rmap_filter(router):
307 return _all_routes_withdrawn(router)
308
309 def _exist_map_routes_not_present_no_rmap_filter(router):
310 return _exist_map_routes_not_present(router)
311
312 def _non_exist_map_routes_not_present_rmap_filter(router):
313 return _exist_map_routes_present_rmap_filter(router)
314
315 def _non_exist_map_routes_not_present_no_rmap_filter(router):
316 return _non_exist_map_routes_not_present(router)
317
318 # BGP conditional advertisement with route-maps
319 # EXIST-MAP, ADV-MAP-2 and RMAP-2
320 def _exist_map_routes_not_present_rmap2_filter(router):
321 return _all_routes_withdrawn(router)
322
323 def _exist_map_routes_not_present_no_rmap2_filter(router):
324 output = json.loads(router.vtysh_cmd("show ip route json"))
325 expected = {
326 "0.0.0.0/0": None,
327 "192.0.2.1/32": [{"protocol": "bgp"}],
328 "192.0.2.5/32": [{"protocol": "bgp"}],
329 "10.139.224.0/20": [{"protocol": "bgp"}],
330 "203.0.113.1/32": None,
331 }
332 return topotest.json_cmp(output, expected)
333
334 def _non_exist_map_routes_not_present_rmap2_filter(router):
335 output = json.loads(router.vtysh_cmd("show ip route json"))
336 expected = {
337 "0.0.0.0/0": None,
338 "192.0.2.1/32": None,
339 "192.0.2.5/32": None,
340 "10.139.224.0/20": None,
341 "203.0.113.1/32": [{"protocol": "bgp"}],
342 }
343 return topotest.json_cmp(output, expected)
344
345 def _non_exist_map_routes_not_present_no_rmap2_filter(router):
346 return _non_exist_map_routes_not_present(router)
347
348 def _exist_map_routes_present_rmap2_filter(router):
349 return _non_exist_map_routes_not_present_rmap2_filter(router)
350
351 def _exist_map_routes_present_no_rmap2_filter(router):
352 return _all_routes_advertised(router)
353
354 def _non_exist_map_routes_present_rmap2_filter(router):
355 return _all_routes_withdrawn(router)
356
357 def _non_exist_map_routes_present_no_rmap2_filter(router):
358 output = json.loads(router.vtysh_cmd("show ip route json"))
359 expected = {
360 "0.0.0.0/0": [{"protocol": "bgp"}],
361 "192.0.2.1/32": [{"protocol": "bgp"}],
362 "192.0.2.5/32": [{"protocol": "bgp"}],
363 "10.139.224.0/20": [{"protocol": "bgp"}],
364 "203.0.113.1/32": None,
365 }
366 return topotest.json_cmp(output, expected)
367
368 def _exist_map_routes_present_rmap2_network(router):
369 return _non_exist_map_routes_not_present_rmap2_filter(router)
370
371 def _exist_map_routes_present_rmap2_no_network(router):
372 return _all_routes_withdrawn(router)
373
374 def _non_exist_map_routes_not_present_rmap2_network(router):
375 return _non_exist_map_routes_not_present_rmap2_filter(router)
376
377 def _non_exist_map_routes_not_present_rmap2_no_network(router):
378 return _all_routes_withdrawn(router)
379
380 # TC11: R3 BGP convergence, without advertise-map configuration.
381 # All routes are advertised to R3.
382 test_func = functools.partial(_all_routes_advertised, router3)
383 success, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
384
385 msg = 'TC11: "router3" BGP convergence - '
386 assert result is None, msg + failed
387
388 logger.info(msg + passed)
389
390 # TC21: exist-map routes present in R2's BGP table.
391 # advertise-map routes present in R2's BGP table are advertised to R3.
392 router2.vtysh_cmd(
393 """
394 configure terminal
395 router bgp 2
396 address-family ipv4 unicast
397 neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
398 """
399 )
400
401 test_func = functools.partial(_exist_map_routes_present, router3)
402 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
403
404 msg = 'TC21: exist-map routes present in "router2" BGP table - '
405 assert result is None, msg + failed
406
407 logger.info(msg + passed)
408
409 # TC22: exist-map routes not present in R2's BGP table
410 # advertise-map routes present in R2's BGP table are withdrawn from R3.
411 router1.vtysh_cmd(
412 """
413 configure terminal
414 router bgp 1
415 address-family ipv4 unicast
416 no network 0.0.0.0/0 route-map DEF
417 """
418 )
419
420 test_func = functools.partial(_exist_map_routes_not_present, router3)
421 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
422
423 msg = 'TC22: exist-map routes not present in "router2" BGP table - '
424 assert result is None, msg + failed
425
426 logger.info(msg + passed)
427
428 # TC31: non-exist-map routes not present in R2's BGP table
429 # advertise-map routes present in R2's BGP table are advertised to R3.
430 router2.vtysh_cmd(
431 """
432 configure terminal
433 router bgp 2
434 address-family ipv4 unicast
435 neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
436 """
437 )
438
439 test_func = functools.partial(_non_exist_map_routes_not_present, router3)
440 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
441
442 msg = 'TC31: non-exist-map routes not present in "router2" BGP table - '
443 assert result is None, msg + failed
444
445 logger.info(msg + passed)
446
447 # TC32: non-exist-map routes present in R2's BGP table
448 # advertise-map routes present in R2's BGP table are withdrawn from R3.
449 router1.vtysh_cmd(
450 """
451 configure terminal
452 router bgp 1
453 address-family ipv4 unicast
454 network 0.0.0.0/0 route-map DEF
455 """
456 )
457
458 test_func = functools.partial(_non_exist_map_routes_present, router3)
459 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
460
461 msg = 'TC32: non-exist-map routes present in "router2" BGP table - '
462 assert result is None, msg + failed
463
464 logger.info(msg + passed)
465
466 # TC41: non-exist-map route-map configuration removed in R2.
467 # advertise-map routes present in R2's BGP table are advertised to R3.
468 router2.vtysh_cmd(
469 """
470 configure terminal
471 no route-map EXIST-MAP permit 10
472 """
473 )
474
475 test_func = functools.partial(_non_exist_map_no_condition_route_map, router3)
476 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
477
478 msg = 'TC41: non-exist-map route-map removed in "router2" - '
479 assert result is None, msg + failed
480
481 logger.info(msg + passed)
482
483 # TC42: exist-map route-map configuration removed in R2
484 # advertise-map routes present in R2's BGP table are withdrawn from R3.
485 router2.vtysh_cmd(
486 """
487 configure terminal
488 router bgp 2
489 address-family ipv4 unicast
490 neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
491 """
492 )
493
494 test_func = functools.partial(_exist_map_no_condition_route_map, router3)
495 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
496
497 msg = 'TC42: exist-map route-map removed in "router2" - '
498 assert result is None, msg + failed
499
500 logger.info(msg + passed)
501
502 # TC51: exist-map routes present in R2's BGP table, with route-map filter.
503 # All routes are withdrawn from R3 except advertise-map routes.
504 router2.vtysh_cmd(
505 """
506 configure terminal
507 route-map EXIST-MAP permit 10
508 match community DEFAULT-ROUTE
509 match ip address prefix-list DEFAULT-ROUTE
510 !
511 router bgp 2
512 address-family ipv4 unicast
513 neighbor 10.10.20.3 route-map RMAP-1 out
514 """
515 )
516
517 test_func = functools.partial(_exist_map_routes_present_rmap_filter, router3)
518 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
519
520 msg = "TC51: exist-map routes present with route-map filter - "
521 assert result is None, msg + failed
522
523 logger.info(msg + passed)
524
525 # TC52: exist-map routes present in R2's BGP table, no route-map filter.
526 # All routes are advertised to R3 including advertise-map routes.
527 router2.vtysh_cmd(
528 """
529 configure terminal
530 router bgp 2
531 address-family ipv4 unicast
532 no neighbor 10.10.20.3 route-map RMAP-1 out
533 """
534 )
535
536 test_func = functools.partial(_exist_map_routes_present_no_rmap_filter, router3)
537 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
538
539 msg = "TC52: exist-map routes present, no route-map filter - "
540 assert result is None, msg + failed
541
542 logger.info(msg + passed)
543
544 # TC53: non-exist-map routes present in R2's BGP table, with route-map filter.
545 # All routes are withdrawn from R3 including advertise-map routes.
546 router2.vtysh_cmd(
547 """
548 configure terminal
549 router bgp 2
550 address-family ipv4 unicast
551 neighbor 10.10.20.3 route-map RMAP-1 out
552 neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
553 """
554 )
555
556 test_func = functools.partial(_non_exist_map_routes_present_rmap_filter, router3)
557 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
558
559 msg = "TC53: non-exist-map routes present, with route-map filter - "
560 assert result is None, msg + failed
561
562 logger.info(msg + passed)
563
564 # TC54: non-exist-map routes present in R2's BGP table, no route-map filter.
565 # All routes are advertised to R3 except advertise-map routes.
566 router2.vtysh_cmd(
567 """
568 configure terminal
569 router bgp 2
570 address-family ipv4 unicast
571 no neighbor 10.10.20.3 route-map RMAP-1 out
572 """
573 )
574
575 test_func = functools.partial(_non_exist_map_routes_present_no_rmap_filter, router3)
576 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
577
578 msg = "TC54: non-exist-map routes present, no route-map filter - "
579 assert result is None, msg + failed
580
581 logger.info(msg + passed)
582
583 # TC61: exist-map routes not present in R2's BGP table, with route-map filter.
584 # All routes are withdrawn from R3 including advertise-map routes.
585 router1.vtysh_cmd(
586 """
587 configure terminal
588 router bgp 1
589 address-family ipv4 unicast
590 no network 0.0.0.0/0 route-map DEF
591 """
592 )
593 router2.vtysh_cmd(
594 """
595 configure terminal
596 router bgp 2
597 address-family ipv4 unicast
598 neighbor 10.10.20.3 route-map RMAP-1 out
599 neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
600 """
601 )
602
603 test_func = functools.partial(_exist_map_routes_not_present_rmap_filter, router3)
604 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
605
606 msg = "TC61: exist-map routes not present, route-map filter - "
607 assert result is None, msg + failed
608
609 logger.info(msg + passed)
610
611 # TC62: exist-map routes not present in R2's BGP table, without route-map filter.
612 # All routes are advertised to R3 except advertise-map routes.
613 router2.vtysh_cmd(
614 """
615 configure terminal
616 router bgp 2
617 address-family ipv4 unicast
618 no neighbor 10.10.20.3 route-map RMAP-1 out
619 """
620 )
621
622 test_func = functools.partial(_exist_map_routes_not_present_no_rmap_filter, router3)
623 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
624
625 msg = "TC62: exist-map routes not present, no route-map filter - "
626 assert result is None, msg + failed
627
628 logger.info(msg + passed)
629
630 # TC63: non-exist-map routes not present in R2's BGP table, with route-map filter.
631 # All routes are withdrawn from R3 except advertise-map routes.
632 router2.vtysh_cmd(
633 """
634 configure terminal
635 router bgp 2
636 address-family ipv4 unicast
637 neighbor 10.10.20.3 route-map RMAP-1 out
638 neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
639 """
640 )
641
642 test_func = functools.partial(
643 _non_exist_map_routes_not_present_rmap_filter, router3
644 )
645 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
646
647 msg = "TC63: non-exist-map routes not present, route-map filter - "
648 assert result is None, msg + failed
649
650 logger.info(msg + passed)
651
652 # TC64: non-exist-map routes not present in R2's BGP table, without route-map filter.
653 # All routes are advertised to R3 including advertise-map routes.
654 router2.vtysh_cmd(
655 """
656 configure terminal
657 router bgp 2
658 address-family ipv4 unicast
659 no neighbor 10.10.20.3 route-map RMAP-1 out
660 """
661 )
662
663 test_func = functools.partial(
664 _non_exist_map_routes_not_present_no_rmap_filter, router3
665 )
666 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
667
668 msg = "TC64: non-exist-map routes not present, no route-map filter - "
669 assert result is None, msg + failed
670
671 logger.info(msg + passed)
672
673 # TC71: exist-map routes present in R2's BGP table, with route-map filter.
674 # All routes are withdrawn from R3 except advertise-map routes.
675 router1.vtysh_cmd(
676 """
677 configure terminal
678 router bgp 1
679 address-family ipv4 unicast
680 network 0.0.0.0/0 route-map DEF
681 """
682 )
683 router2.vtysh_cmd(
684 """
685 configure terminal
686 router bgp 2
687 address-family ipv4 unicast
688 neighbor 10.10.20.3 route-map RMAP-2 out
689 neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
690 """
691 )
692
693 test_func = functools.partial(_exist_map_routes_present_rmap2_filter, router3)
694 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
695
696 msg = "TC71: exist-map routes present, route-map filter - "
697 assert result is None, msg + failed
698
699 logger.info(msg + passed)
700
701 # TC72: exist-map routes present in R2's BGP table, without route-map filter.
702 # All routes are advertised to R3 including advertise-map routes.
703 router2.vtysh_cmd(
704 """
705 configure terminal
706 router bgp 2
707 address-family ipv4 unicast
708 no neighbor 10.10.20.3 route-map RMAP-2 out
709 """
710 )
711
712 test_func = functools.partial(_exist_map_routes_present_no_rmap2_filter, router3)
713 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
714
715 msg = "TC72: exist-map routes present, no route-map filter - "
716 assert result is None, msg + failed
717
718 logger.info(msg + passed)
719
720 # TC73: non-exist-map routes present in R2's BGP table, with route-map filter.
721 # All routes are advertised to R3 including advertise-map routes.
722 router2.vtysh_cmd(
723 """
724 configure terminal
725 router bgp 2
726 address-family ipv4 unicast
727 neighbor 10.10.20.3 route-map RMAP-2 out
728 neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
729 """
730 )
731
732 test_func = functools.partial(_non_exist_map_routes_present_rmap2_filter, router3)
733 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
734
735 msg = "TC73: non-exist-map routes present, route-map filter - "
736 assert result is None, msg + failed
737
738 logger.info(msg + passed)
739
740 # TC74: non-exist-map routes present in R2's BGP table, without route-map filter.
741 # All routes are advertised to R3 including advertise-map routes.
742 router2.vtysh_cmd(
743 """
744 configure terminal
745 router bgp 2
746 address-family ipv4 unicast
747 no neighbor 10.10.20.3 route-map RMAP-2 out
748 """
749 )
750
751 test_func = functools.partial(
752 _non_exist_map_routes_present_no_rmap2_filter, router3
753 )
754 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
755
756 msg = "TC74: non-exist-map routes present, no route-map filter - "
757 assert result is None, msg + failed
758
759 logger.info(msg + passed)
760
761 # TC81: exist-map routes not present in R2's BGP table, with route-map filter.
762 # All routes are withdrawn from R3 including advertise-map routes.
763 router1.vtysh_cmd(
764 """
765 configure terminal
766 router bgp 1
767 address-family ipv4 unicast
768 no network 0.0.0.0/0 route-map DEF
769 """
770 )
771 router2.vtysh_cmd(
772 """
773 configure terminal
774 router bgp 2
775 address-family ipv4 unicast
776 neighbor 10.10.20.3 route-map RMAP-2 out
777 neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
778 """
779 )
780
781 test_func = functools.partial(_exist_map_routes_not_present_rmap2_filter, router3)
782 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
783
784 msg = "TC81: exist-map routes not present, route-map filter - "
785 assert result is None, msg + failed
786
787 logger.info(msg + passed)
788
789 # TC82: exist-map routes not present in R2's BGP table, without route-map filter.
790 # All routes are advertised to R3 except advertise-map routes.
791 router2.vtysh_cmd(
792 """
793 configure terminal
794 router bgp 2
795 address-family ipv4 unicast
796 no neighbor 10.10.20.3 route-map RMAP-2 out
797 """
798 )
799
800 test_func = functools.partial(
801 _exist_map_routes_not_present_no_rmap2_filter, router3
802 )
803 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
804
805 msg = "TC82: exist-map routes not present, no route-map filter - "
806 assert result is None, msg + failed
807
808 logger.info(msg + passed)
809
810 # TC83: non-exist-map routes not present in R2's BGP table, with route-map filter.
811 # All routes are advertised to R3 including advertise-map routes.
812 router2.vtysh_cmd(
813 """
814 configure terminal
815 router bgp 2
816 address-family ipv4 unicast
817 neighbor 10.10.20.3 route-map RMAP-2 out
818 neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
819 """
820 )
821
822 test_func = functools.partial(
823 _non_exist_map_routes_not_present_rmap2_filter, router3
824 )
825 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
826
827 msg = "TC83: non-exist-map routes not present, route-map filter - "
828 assert result is None, msg + failed
829
830 logger.info(msg + passed)
831
832 # TC84: non-exist-map routes not present in R2's BGP table, without route-map filter.
833 # All routes are advertised to R3 including advertise-map routes.
834 router2.vtysh_cmd(
835 """
836 configure terminal
837 router bgp 2
838 address-family ipv4 unicast
839 no neighbor 10.10.20.3 route-map RMAP-2 out
840 """
841 )
842
843 test_func = functools.partial(
844 _non_exist_map_routes_not_present_no_rmap2_filter, router3
845 )
846 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
847
848 msg = "TC84: non-exist-map routes not present, no route-map filter - "
849 assert result is None, msg + failed
850
851 logger.info(msg + passed)
852
853 # TC91: exist-map routes present in R2's BGP table, with route-map filter and network.
854 # All routes are advertised to R3 including advertise-map routes.
855 router1.vtysh_cmd(
856 """
857 configure terminal
858 router bgp 1
859 address-family ipv4 unicast
860 network 0.0.0.0/0 route-map DEF
861 """
862 )
863 router2.vtysh_cmd(
864 """
865 configure terminal
866 router bgp 2
867 address-family ipv4 unicast
868 neighbor 10.10.20.3 route-map RMAP-2 out
869 neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
870 """
871 )
872
873 test_func = functools.partial(_exist_map_routes_present_rmap2_network, router3)
874 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
875
876 msg = "TC91: exist-map routes present, route-map filter and network - "
877 assert result is None, msg + failed
878
879 logger.info(msg + passed)
880
881 # TC92: exist-map routes present in R2's BGP table, with route-map filter and no network.
882 # All routes are advertised to R3 except advertise-map routes.
883 router2.vtysh_cmd(
884 """
885 configure terminal
886 router bgp 2
887 address-family ipv4 unicast
888 no network 203.0.113.1/32
889 """
890 )
891
892 test_func = functools.partial(_exist_map_routes_present_rmap2_no_network, router3)
893 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
894
895 msg = "TC92: exist-map routes present, route-map filter and no network - "
896 assert result is None, msg + failed
897
898 logger.info(msg + passed)
899
900 # TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network.
901 # All routes are advertised to R3 including advertise-map routes.
902 router1.vtysh_cmd(
903 """
904 configure terminal
905 router bgp 1
906 address-family ipv4 unicast
907 no network 0.0.0.0/0 route-map DEF
908 """
909 )
910 router2.vtysh_cmd(
911 """
912 configure terminal
913 router bgp 2
914 address-family ipv4 unicast
915 network 203.0.113.1/32
916 neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
917 """
918 )
919
920 test_func = functools.partial(
921 _non_exist_map_routes_not_present_rmap2_network, router3
922 )
923 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
924
925 msg = "TC93: non-exist-map routes not present, route-map filter and network - "
926 assert result is None, msg + failed
927
928 logger.info(msg + passed)
929
930 # TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network.
931 # All routes are advertised to R3 except advertise-map routes.
932 router2.vtysh_cmd(
933 """
934 configure terminal
935 router bgp 2
936 address-family ipv4 unicast
937 no network 203.0.113.1/32
938 """
939 )
940
941 test_func = functools.partial(
942 _non_exist_map_routes_not_present_rmap2_no_network, router3
943 )
944 success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
945
946 msg = "TC94: non-exist-map routes not present, route-map filter and no network - "
947 assert result is None, msg + failed
948
949 logger.info(msg + passed)
950
951
952 def test_memory_leak():
953 "Run the memory leak test and report results."
954 tgen = get_topogen()
955 if not tgen.is_memleak_enabled():
956 pytest.skip("Memory leak test/report is disabled")
957
958 tgen.report_memory_leaks()
959
960
961 if __name__ == "__main__":
962 args = ["-s"] + sys.argv[1:]
963 sys.exit(pytest.main(args))