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