]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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 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
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.
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.
55
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
61 Conditional advertisement(received routes) along with Route-map Filter
62 ----------------------------------------------------------------------
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.
71
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
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.
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
145
146 pytestmark = [pytest.mark.bgpd]
147
148
149 def build_topo(tgen):
150 r1 = tgen.add_router("r1")
151 r2 = tgen.add_router("r2")
152 r3 = tgen.add_router("r3")
153
154 switch = tgen.add_switch("s1")
155 switch.add_link(r1)
156 switch.add_link(r2)
157
158 switch = tgen.add_switch("s2")
159 switch.add_link(r2)
160 switch.add_link(r3)
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
170 tgen = Topogen(build_topo, mod.__name__)
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
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
228
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"}],
237 }
238 return topotest.json_cmp(output, expected)
239
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):
272 return default_route_withdrawn(router)
273
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)
351
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
401 def test_bgp_conditional_advertisement_tc_1_1():
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
410 # TC11: R3 BGP convergence, without advertise-map configuration.
411 # All routes are advertised to R3.
412 test_func = functools.partial(all_routes_advertised, router3)
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
420
421 def test_bgp_conditional_advertisement_tc_2_1():
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
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
437 neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
438 """
439 )
440
441 test_func = functools.partial(exist_map_routes_present, router3)
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
449
450 def test_bgp_conditional_advertisement_tc_2_2():
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
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
470 test_func = functools.partial(exist_map_routes_not_present, router3)
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
478
479 def test_bgp_conditional_advertisement_tc_2_3():
480 tgen = get_topogen()
481 if tgen.routers_have_failure():
482 pytest.skip(tgen.errors)
483
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
502 msg = "TC23: advertise-map with exist-map configuration is removed from peer - "
503 assert result is None, msg + failed
504
505 logger.info(msg + passed)
506
507
508 def test_bgp_conditional_advertisement_tc_3_1():
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
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
524 neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
525 """
526 )
527
528 test_func = functools.partial(non_exist_map_routes_not_present, router3)
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
536
537 def test_bgp_conditional_advertisement_tc_3_2():
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
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
557 test_func = functools.partial(non_exist_map_routes_present, router3)
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
565
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"]
574
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
589 msg = (
590 "TC33: advertise-map with non-exist-map configuration is removed from a peer - "
591 )
592 assert result is None, msg + failed
593
594 logger.info(msg + passed)
595
596
597 def test_bgp_conditional_advertisement_tc_4_1():
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
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
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
614 no route-map EXIST-MAP permit 10
615 """
616 )
617
618 test_func = functools.partial(non_exist_map_no_condition_route_map, router3)
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
626
627 def test_bgp_conditional_advertisement_tc_4_2():
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
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
643 neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
644 """
645 )
646
647 test_func = functools.partial(exist_map_no_condition_route_map, router3)
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
655
656 def test_bgp_conditional_advertisement_tc_5_1():
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
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 !
674 router bgp 2
675 address-family ipv4 unicast
676 neighbor 10.10.20.3 route-map RMAP-1 out
677 """
678 )
679
680 test_func = functools.partial(exist_map_routes_present_rmap_filter, router3)
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
688
689 def test_bgp_conditional_advertisement_tc_5_2():
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
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
705 no neighbor 10.10.20.3 route-map RMAP-1 out
706 """
707 )
708
709 test_func = functools.partial(exist_map_routes_present_no_rmap_filter, router3)
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
717
718 def test_bgp_conditional_advertisement_tc_5_3():
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
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
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
736 """
737 )
738
739 test_func = functools.partial(non_exist_map_routes_present_rmap_filter, router3)
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
747
748 def test_bgp_conditional_advertisement_tc_5_4():
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
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
764 no neighbor 10.10.20.3 route-map RMAP-1 out
765 """
766 )
767
768 test_func = functools.partial(non_exist_map_routes_present_no_rmap_filter, router3)
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
776
777 def test_bgp_conditional_advertisement_tc_6_1():
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
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
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
803 """
804 )
805
806 test_func = functools.partial(exist_map_routes_not_present_rmap_filter, router3)
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
814
815 def test_bgp_conditional_advertisement_tc_6_2():
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
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
831 no neighbor 10.10.20.3 route-map RMAP-1 out
832 """
833 )
834
835 test_func = functools.partial(exist_map_routes_not_present_no_rmap_filter, router3)
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
843
844 def test_bgp_conditional_advertisement_tc_6_3():
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
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
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
862 """
863 )
864
865 test_func = functools.partial(non_exist_map_routes_not_present_rmap_filter, router3)
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
873
874 def test_bgp_conditional_advertisement_tc_6_4():
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
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
890 no neighbor 10.10.20.3 route-map RMAP-1 out
891 """
892 )
893
894 test_func = functools.partial(
895 non_exist_map_routes_not_present_no_rmap_filter, router3
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
904
905 def test_bgp_conditional_advertisement_tc_7_1():
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
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
934 test_func = functools.partial(exist_map_routes_present_rmap2_filter, router3)
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
942
943 def test_bgp_conditional_advertisement_tc_7_2():
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
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
963 test_func = functools.partial(exist_map_routes_present_no_rmap2_filter, router3)
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
971
972 def test_bgp_conditional_advertisement_tc_7_3():
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
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
993 test_func = functools.partial(non_exist_map_routes_present_rmap2_filter, router3)
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
1001
1002 def test_bgp_conditional_advertisement_tc_7_4():
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
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
1022 test_func = functools.partial(non_exist_map_routes_present_no_rmap2_filter, router3)
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
1030
1031 def test_bgp_conditional_advertisement_tc_8_1():
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
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
1060 test_func = functools.partial(exist_map_routes_not_present_rmap2_filter, router3)
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
1068
1069 def test_bgp_conditional_advertisement_tc_8_2():
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
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
1089 test_func = functools.partial(exist_map_routes_not_present_no_rmap2_filter, router3)
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
1097
1098 def test_bgp_conditional_advertisement_tc_8_3():
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
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(
1120 non_exist_map_routes_not_present_rmap2_filter, router3
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
1129
1130 def test_bgp_conditional_advertisement_tc_8_4():
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
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(
1151 non_exist_map_routes_not_present_no_rmap2_filter, router3
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
1160
1161 def test_bgp_conditional_advertisement_tc_9_1():
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
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
1190 test_func = functools.partial(exist_map_routes_present_rmap2_network, router3)
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
1198
1199 def test_bgp_conditional_advertisement_tc_9_2():
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
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
1219 test_func = functools.partial(exist_map_routes_present_rmap2_no_network, router3)
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
1227
1228 def test_bgp_conditional_advertisement_tc_9_3():
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
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(
1258 non_exist_map_routes_not_present_rmap2_network, router3
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
1267
1268 def test_bgp_conditional_advertisement_tc_9_4():
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
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(
1289 non_exist_map_routes_not_present_rmap2_no_network, router3
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
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))