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