]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp-route-map/test_route_map_topo2.py
tests: please follow the style guide
[mirror_frr.git] / tests / topotests / bgp-route-map / test_route_map_topo2.py
1 #!/usr/bin/env python
2
3 #
4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
7 #
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
11 # in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 # OF THIS SOFTWARE.
21 #
22
23 """Following tests are covered to test route-map functionality.
24 TC_57:
25 Create route map to match prefix-list and permit inbound
26 and outbound prefixes and set criteria on match
27 TC_52:
28 Test modify set/match clauses in a route-map to see
29 if it takes immediate effect.
30 TC_61:
31 Delete the route maps.
32 TC_50_1:
33 Test modify/remove prefix-lists referenced by a
34 route-map for match statement.
35 TC_50_2:
36 Remove prefix-list referencec by route-map match cluase
37 and verifying it reflecting as intended
38 TC_51:
39 Add and remove community-list referencec by route-map match cluase
40 and verifying it reflecting as intended
41 TC_45:
42 Test multiple match statements as part of a route-map"s single
43 sequence number. (Logical OR-ed of multiple match statements)
44 TC_44:
45 Test multiple match statements as part of a route-map"s single
46 sequence number. (Logical AND of multiple match statements)
47 TC_41:
48 Test add/remove route-maps to specific neighbor and see if
49 it takes effect as intended
50 TC_56:
51 Test clear BGP sessions and interface flaps to see if
52 route-map properties are intact.
53 TC_46:
54 Verify if a blank sequence number can be create(without any
55 match/set clause) and check if it allows all the traffic/prefixes
56 TC_48:
57 Create route map setting local preference and weight to eBGP peeer
58 and metric to ibgp peer and verifying it should not get advertised
59 TC_43:
60 Test multiple set statements as part of a route-map"s
61 single sequence number.
62 TC_54:
63 Verify route-maps continue clause functionality.
64 TC_55:
65 Verify route-maps goto clause functionality.
66 TC_53:
67 Verify route-maps call clause functionality.
68 TC_58:
69 Create route map deny inbound and outbound prefixes on
70 match prefix list and set criteria on match
71 TC_59:
72 Create route map to permit inbound prefixes with filter
73 match tag and set criteria
74 TC_60
75 Create route map to deny outbound prefixes with filter match tag,
76 and set criteria
77 """
78
79 #################################
80 # TOPOLOGY
81 #################################
82 """
83
84 +-------+
85 +--------- | R2 |
86 | +-------+
87 |iBGP |
88 +-------+ |
89 | R1 | |iBGP
90 +-------+ |
91 | |
92 | iBGP +-------+ eBGP +-------+
93 +---------- | R3 |----------| R4 |
94 +-------+ +-------+
95 |
96 |eBGP
97 |
98 +-------+
99 | R5 |
100 +-------+
101
102
103 """
104
105 import sys
106 import json
107 import time
108 import pytest
109 import inspect
110 import os
111 from time import sleep
112
113 # Save the Current Working Directory to find configuration files.
114 CWD = os.path.dirname(os.path.realpath(__file__))
115 sys.path.append(os.path.join(CWD, "../"))
116
117 # pylint: disable=C0413
118 # Import topogen and topotest helpers
119 from lib import topotest
120 from lib.topogen import Topogen, get_topogen
121 from mininet.topo import Topo
122
123 # Required to instantiate the topology builder class.
124 from lib.common_config import (
125 start_topology,
126 write_test_header,
127 write_test_footer,
128 create_static_routes,
129 verify_rib,
130 delete_route_maps,
131 create_bgp_community_lists,
132 interface_status,
133 create_route_maps,
134 create_prefix_lists,
135 verify_route_maps,
136 check_address_types,
137 verify_bgp_community,
138 shutdown_bringup_interface,
139 verify_prefix_lists,
140 reset_config_on_routers,
141 verify_create_community_list,
142 )
143 from lib.topolog import logger
144 from lib.bgp import (
145 verify_bgp_convergence,
146 create_router_bgp,
147 clear_bgp_and_verify,
148 verify_bgp_attributes,
149 )
150 from lib.topojson import build_topo_from_json, build_config_from_json
151
152 # Reading the data from JSON File for topology and configuration creation
153 jsonFile = "{}/bgp_route_map_topo2.json".format(CWD)
154
155 try:
156 with open(jsonFile, "r") as topoJson:
157 topo = json.load(topoJson)
158 except IOError:
159 assert False, "Could not read file {}".format(jsonFile)
160
161 # Global variables
162 # Global variables
163 bgp_convergence = False
164 NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]}
165
166 bgp_convergence = False
167 BGP_CONVERGENCE = False
168 ADDR_TYPES = check_address_types()
169
170
171 class BGPRmapTopo(Topo):
172 """BGPRmapTopo.
173
174 BGPRmap topology 1
175 * `Topo`: Topology object
176 """
177
178 def build(self, *_args, **_opts):
179 """Build function."""
180 tgen = get_topogen(self)
181
182 # Building topology and configuration from json file
183 build_topo_from_json(tgen, topo)
184
185
186 def setup_module(mod):
187 """setup_module.
188
189 Set up the pytest environment
190 * `mod`: module name
191 """
192 testsuite_run_time = time.asctime(time.localtime(time.time()))
193 logger.info("Testsuite start time: {}".format(testsuite_run_time))
194 logger.info("=" * 40)
195
196 logger.info("Running setup_module to create topology")
197
198 # This function initiates the topology build with Topogen...
199 tgen = Topogen(BGPRmapTopo, mod.__name__)
200 # ... and here it calls Mininet initialization functions.
201
202 # Starting topology, create tmp files which are loaded to routers
203 # to start deamons and then start routers
204 start_topology(tgen)
205
206 # Creating configuration from JSON
207 build_config_from_json(tgen, topo)
208
209 # Checking BGP convergence
210 global bgp_convergence
211 global ADDR_TYPES
212
213 # Don"t run this test if we have any failure.
214 if tgen.routers_have_failure():
215 pytest.skip(tgen.errors)
216
217 # Api call verify whether BGP is converged
218 bgp_convergence = verify_bgp_convergence(tgen, topo)
219 assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format(
220 bgp_convergence
221 )
222 logger.info("Running setup_module() done")
223
224
225 def teardown_module(mod):
226 """teardown_module.
227
228 Teardown the pytest environment.
229 * `mod`: module name
230 """
231 logger.info("Running teardown_module to delete topology")
232 tgen = get_topogen()
233
234 # Stop toplogy and Remove tmp files
235 tgen.stop_topology()
236
237 logger.info(
238 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
239 )
240 logger.info("=" * 40)
241
242
243 #####################################################
244 # Tests starting
245 #####################################################
246
247
248 def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0():
249 """
250 TC: 57
251 Create route map to match prefix-list and permit inbound
252 and outbound prefixes and set criteria on match
253 """
254 tgen = get_topogen()
255 global bgp_convergence
256
257 if bgp_convergence is not True:
258 pytest.skip("skipped because of BGP Convergence failure")
259
260 # test case name
261 tc_name = inspect.stack()[0][3]
262 write_test_header(tc_name)
263 reset_config_on_routers(tgen)
264
265 # Create ip prefix list
266 input_dict_2 = {
267 "r3": {
268 "prefix_lists": {
269 "ipv4": {
270 "pf_list_1_ipv4": [
271 {
272 "seqid": 10,
273 "network": "any",
274 "action": "permit",
275 }
276 ]
277 },
278 "ipv6": {
279 "pf_list_1_ipv6": [
280 {
281 "seqid": 10,
282 "network": "any",
283 "action": "permit",
284 }
285 ]
286 },
287 }
288 }
289 }
290
291 result = create_prefix_lists(tgen, input_dict_2)
292 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
293 for addr_type in ADDR_TYPES:
294 # Create route map
295 input_dict_3 = {
296 "r3": {
297 "route_maps": {
298 "rmap_match_pf_1_{}".format(addr_type): [
299 {
300 "action": "permit",
301 "seq_id": "5",
302 "match": {
303 addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
304 },
305 "set": {"locPrf": 150, "weight": 100},
306 },
307 ],
308 "rmap_match_pf_2_{}".format(addr_type): [
309 {
310 "action": "permit",
311 "seq_id": "5",
312 "match": {
313 addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
314 },
315 "set": {"metric": 50},
316 },
317 ],
318 }
319 }
320 }
321 result = create_route_maps(tgen, input_dict_3)
322 assert result is True, "Testcase {} : Failed \n Error: {}".format(
323 tc_name, result
324 )
325
326 # Configure neighbor for route map
327 input_dict_4 = {
328 "r3": {
329 "bgp": {
330 "address_family": {
331 "ipv4": {
332 "unicast": {
333 "neighbor": {
334 "r1": {
335 "dest_link": {
336 "r3": {
337 "route_maps": [
338 {
339 "name": "rmap_match_pf_1_ipv4",
340 "direction": "in",
341 }
342 ]
343 }
344 }
345 },
346 "r4": {
347 "dest_link": {
348 "r3": {
349 "route_maps": [
350 {
351 "name": "rmap_match_pf_2_ipv4",
352 "direction": "out",
353 }
354 ]
355 }
356 }
357 },
358 }
359 }
360 },
361 "ipv6": {
362 "unicast": {
363 "neighbor": {
364 "r1": {
365 "dest_link": {
366 "r3": {
367 "route_maps": [
368 {
369 "name": "rmap_match_pf_1_ipv6",
370 "direction": "in",
371 }
372 ]
373 }
374 }
375 },
376 "r4": {
377 "dest_link": {
378 "r3": {
379 "route_maps": [
380 {
381 "name": "rmap_match_pf_2_ipv6",
382 "direction": "out",
383 }
384 ]
385 }
386 }
387 },
388 }
389 }
390 },
391 }
392 }
393 }
394 }
395
396 result = create_router_bgp(tgen, topo, input_dict_4)
397 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
398
399 # Verifying RIB routes
400 dut = "r3"
401 protocol = "bgp"
402 input_dict = topo["routers"]
403
404 # dual stack changes
405 for addr_type in ADDR_TYPES:
406 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
407 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
408 tc_name, result4
409 )
410
411 # Verifying BGP set attributes
412 dut = "r3"
413 routes = {
414 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
415 "ipv6": ["1::1/128", "1::2/128"],
416 }
417 # dual stack changes
418 for addr_type in ADDR_TYPES:
419 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
420 result4 = verify_bgp_attributes(
421 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
422 )
423 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
424 tc_name, result4
425 )
426
427 # Verifying RIB routes
428 dut = "r4"
429 protocol = "bgp"
430 # dual stack changes
431 for addr_type in ADDR_TYPES:
432 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
433 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
434 tc_name, result4
435 )
436
437 # Verifying BGP set attributes
438 dut = "r4"
439 routes = {
440 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
441 "ipv6": ["1::1/128", "1::2/128"],
442 }
443 # dual stack changes
444 for addr_type in ADDR_TYPES:
445 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
446 result = verify_bgp_attributes(
447 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
448 )
449 assert result is True, "Testcase {} : Failed \n Error: {}".format(
450 tc_name, result
451 )
452 write_test_footer(tc_name)
453
454 # Uncomment next line for debugging
455 # tgen.mininet_cli()
456
457
458 def test_modify_set_match_clauses_in_rmap_p0():
459 """
460 TC_52:
461 Test modify set/match clauses in a route-map to see
462 if it takes immediate effect.
463 """
464
465 tgen = get_topogen()
466 global bgp_convergence
467
468 if bgp_convergence is not True:
469 pytest.skip("skipped because of BGP Convergence failure")
470
471 # test case name
472 tc_name = inspect.stack()[0][3]
473 write_test_header(tc_name)
474 reset_config_on_routers(tgen)
475
476 # Create ip prefix list
477
478 input_dict_2 = {
479 "r3": {
480 "prefix_lists": {
481 "ipv4": {
482 "pf_list_1_ipv4": [
483 {
484 "seqid": 10,
485 "network": "any",
486 "action": "permit",
487 }
488 ],
489 "pf_list_2_ipv4": [
490 {"seqid": 10, "network": "any", "action": "permit"}
491 ],
492 },
493 "ipv6": {
494 "pf_list_1_ipv6": [
495 {
496 "seqid": 10,
497 "network": "any",
498 "action": "permit",
499 }
500 ],
501 "pf_list_2_ipv6": [
502 {"seqid": 10, "network": "any", "action": "permit"}
503 ],
504 },
505 }
506 }
507 }
508 result = create_prefix_lists(tgen, input_dict_2)
509 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
510
511 # Create route map
512 for addr_type in ADDR_TYPES:
513 input_dict_3 = {
514 "r3": {
515 "route_maps": {
516 "rmap_match_pf_1_{}".format(addr_type): [
517 {
518 "action": "permit",
519 "seq_id": "5",
520 "match": {
521 addr_type: {
522 "prefix_lists": "pf_list_1_{}".format(addr_type)
523 }
524 },
525 "set": {
526 "locPrf": 150,
527 },
528 }
529 ],
530 "rmap_match_pf_2_{}".format(addr_type): [
531 {
532 "action": "permit",
533 "seq_id": "5",
534 "match": {
535 addr_type: {
536 "prefix_lists": "pf_list_1_{}".format(addr_type)
537 }
538 },
539 "set": {"metric": 50},
540 }
541 ],
542 }
543 }
544 }
545 result = create_route_maps(tgen, input_dict_3)
546 assert result is True, "Testcase {} : Failed \n Error: {}".format(
547 tc_name, result
548 )
549
550 # Configure neighbor for route map
551 input_dict_4 = {
552 "r3": {
553 "bgp": {
554 "address_family": {
555 "ipv4": {
556 "unicast": {
557 "neighbor": {
558 "r1": {
559 "dest_link": {
560 "r3": {
561 "route_maps": [
562 {
563 "name": "rmap_match_pf_1_ipv4",
564 "direction": "in",
565 }
566 ]
567 }
568 }
569 },
570 "r4": {
571 "dest_link": {
572 "r3": {
573 "route_maps": [
574 {
575 "name": "rmap_match_pf_2_ipv4",
576 "direction": "out",
577 }
578 ]
579 }
580 }
581 },
582 }
583 }
584 },
585 "ipv6": {
586 "unicast": {
587 "neighbor": {
588 "r1": {
589 "dest_link": {
590 "r3": {
591 "route_maps": [
592 {
593 "name": "rmap_match_pf_1_ipv6",
594 "direction": "in",
595 }
596 ]
597 }
598 }
599 },
600 "r4": {
601 "dest_link": {
602 "r3": {
603 "route_maps": [
604 {
605 "name": "rmap_match_pf_2_ipv6",
606 "direction": "out",
607 }
608 ]
609 }
610 }
611 },
612 }
613 }
614 },
615 }
616 }
617 }
618 }
619 result = create_router_bgp(tgen, topo, input_dict_4)
620 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
621
622 # Verifying RIB routes
623 dut = "r3"
624 protocol = "bgp"
625 input_dict = topo["routers"]
626 for addr_type in ADDR_TYPES:
627 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
628 assert result is True, "Testcase {} : Failed \n Error: {}".format(
629 tc_name, result
630 )
631
632 # Verifying BGP set attributes
633 dut = "r3"
634 routes = {
635 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
636 "ipv6": ["1::1/128", "1::2/128"],
637 }
638 # dual stack changes
639 for addr_type in ADDR_TYPES:
640 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
641 result4 = verify_bgp_attributes(
642 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
643 )
644 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
645 tc_name, result4
646 )
647
648 # Verifying RIB routes
649 dut = "r4"
650 protocol = "bgp"
651 # dual stack changes
652 for addr_type in ADDR_TYPES:
653 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
654 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
655 tc_name, result4
656 )
657
658 # Verifying BGP set attributes
659 dut = "r4"
660 routes = {
661 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
662 "ipv6": ["1::1/128", "1::2/128"],
663 }
664 for addr_type in ADDR_TYPES:
665 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
666 result = verify_bgp_attributes(
667 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
668 )
669 assert result is True, "Testcase {} : Failed \n Error: {}".format(
670 tc_name, result
671 )
672
673 # Modify set/match clause of in-used route map
674 for addr_type in ADDR_TYPES:
675 input_dict_3 = {
676 "r3": {
677 "route_maps": {
678 "rmap_match_pf_1_{}".format(addr_type): [
679 {
680 "action": "permit",
681 "seq_id": "5",
682 "match": {
683 addr_type: {
684 "prefix_lists": "pf_list_1_{}".format(addr_type)
685 }
686 },
687 "set": {
688 "locPrf": 1000,
689 },
690 }
691 ],
692 "rmap_match_pf_2_{}".format(addr_type): [
693 {
694 "action": "permit",
695 "seq_id": "5",
696 "match": {
697 addr_type: {
698 "prefix_lists": "pf_list_1_{}".format(addr_type)
699 }
700 },
701 "set": {"metric": 2000},
702 }
703 ],
704 }
705 }
706 }
707 result = create_route_maps(tgen, input_dict_3)
708 assert result is True, "Testcase {} : Failed \n Error: {}".format(
709 tc_name, result
710 )
711
712 # Verifying RIB routes
713 dut = "r3"
714 protocol = "bgp"
715 for addr_type in ADDR_TYPES:
716 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
717 assert result is True, "Testcase {} : Failed \n Error: {}".format(
718 tc_name, result
719 )
720
721 # Verifying BGP set attributes
722 dut = "r3"
723 routes = {
724 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
725 "ipv6": ["1::1/128", "1::2/128"],
726 }
727 for addr_type in ADDR_TYPES:
728 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
729 result = verify_bgp_attributes(
730 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
731 )
732 assert result is True, "Testcase {} : Failed \n Error: {}".format(
733 tc_name, result
734 )
735
736 # Verifying RIB routes
737 dut = "r4"
738 protocol = "bgp"
739 for addr_type in ADDR_TYPES:
740 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
741 assert result is True, "Testcase {} : Failed \n Error: {}".format(
742 tc_name, result
743 )
744
745 # Verifying BGP set attributes
746 dut = "r4"
747 routes = {
748 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
749 "ipv6": ["1::1/128", "1::2/128"],
750 }
751 for addr_type in ADDR_TYPES:
752 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
753 result = verify_bgp_attributes(
754 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
755 )
756 assert result is True, "Testcase {} : Failed \n Error: {}".format(
757 tc_name, result
758 )
759
760 write_test_footer(tc_name)
761
762 # Uncomment next line for debugging
763 # tgen.mininet_cli()
764
765
766 def test_delete_route_maps_p1():
767 """
768 TC_61:
769 Delete the route maps.
770 """
771
772 tgen = get_topogen()
773 global bgp_convergence
774
775 if bgp_convergence is not True:
776 pytest.skip("skipped because of BGP Convergence failure")
777
778 # test case name
779 tc_name = inspect.stack()[0][3]
780 write_test_header(tc_name)
781 reset_config_on_routers(tgen)
782
783 # Create route map
784 for addr_type in ADDR_TYPES:
785 input_dict_3 = {
786 "r3": {
787 "route_maps": {
788 "rmap_match_tag_1_{}".format(addr_type): [
789 {"action": "deny", "match": {addr_type: {"tag": "4001"}}}
790 ]
791 }
792 }
793 }
794 result = create_route_maps(tgen, input_dict_3)
795 assert result is True, "Testcase {} : Failed \n Error: {}".format(
796 tc_name, result
797 )
798
799 # Delete route maps
800 for addr_type in ADDR_TYPES:
801 input_dict = {"r3": {"route_maps": ["rmap_match_tag_1_{}".format(addr_type)]}}
802 result = delete_route_maps(tgen, input_dict)
803 assert result is True, "Testcase {} : Failed \n Error: {}".format(
804 tc_name, result
805 )
806
807 result = verify_route_maps(tgen, input_dict)
808 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
809 write_test_footer(tc_name)
810
811 # Uncomment next line for debugging
812 # tgen.mininet_cli()
813
814
815 def test_modify_prefix_list_referenced_by_rmap_p0():
816 """
817 TC_50_1:
818 Test modify/remove prefix-lists referenced by a
819 route-map for match statement.
820 """
821
822 tgen = get_topogen()
823 global bgp_convergence
824
825 if bgp_convergence is not True:
826 pytest.skip("skipped because of BGP Convergence failure")
827
828 # test case name
829 tc_name = inspect.stack()[0][3]
830 write_test_header(tc_name)
831 reset_config_on_routers(tgen)
832
833 # Create ip prefix list
834 input_dict_2 = {
835 "r3": {
836 "prefix_lists": {
837 "ipv4": {
838 "pf_list_1_ipv4": [
839 {
840 "seqid": 10,
841 "network": "any",
842 "action": "permit",
843 }
844 ]
845 },
846 "ipv6": {
847 "pf_list_1_ipv6": [
848 {
849 "seqid": 100,
850 "network": "any",
851 "action": "permit",
852 }
853 ]
854 },
855 }
856 }
857 }
858 result = create_prefix_lists(tgen, input_dict_2)
859 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
860
861 # Create route map
862 for addr_type in ADDR_TYPES:
863 input_dict_3 = {
864 "r3": {
865 "route_maps": {
866 "rmap_match_pf_1_{}".format(addr_type): [
867 {
868 "action": "permit",
869 "seq_id": "5",
870 "match": {
871 addr_type: {
872 "prefix_lists": "pf_list_1_{}".format(addr_type)
873 }
874 },
875 "set": {"locPrf": 150, "weight": 100},
876 }
877 ],
878 "rmap_match_pf_2_{}".format(addr_type): [
879 {
880 "action": "permit",
881 "seq_id": "5",
882 "match": {
883 addr_type: {
884 "prefix_lists": "pf_list_1_{}".format(addr_type)
885 }
886 },
887 "set": {"metric": 50},
888 }
889 ],
890 }
891 }
892 }
893 result = create_route_maps(tgen, input_dict_3)
894 assert result is True, "Testcase {} : Failed \n Error: {}".format(
895 tc_name, result
896 )
897
898 # Configure neighbor for route map
899 input_dict_4 = {
900 "r3": {
901 "bgp": {
902 "address_family": {
903 "ipv4": {
904 "unicast": {
905 "neighbor": {
906 "r1": {
907 "dest_link": {
908 "r3": {
909 "route_maps": [
910 {
911 "name": "rmap_match_pf_1_ipv4",
912 "direction": "in",
913 }
914 ]
915 }
916 }
917 },
918 "r4": {
919 "dest_link": {
920 "r3": {
921 "route_maps": [
922 {
923 "name": "rmap_match_pf_2_ipv4",
924 "direction": "out",
925 }
926 ]
927 }
928 }
929 },
930 }
931 }
932 },
933 "ipv6": {
934 "unicast": {
935 "neighbor": {
936 "r1": {
937 "dest_link": {
938 "r3": {
939 "route_maps": [
940 {
941 "name": "rmap_match_pf_1_ipv6",
942 "direction": "in",
943 }
944 ]
945 }
946 }
947 },
948 "r4": {
949 "dest_link": {
950 "r3": {
951 "route_maps": [
952 {
953 "name": "rmap_match_pf_2_ipv6",
954 "direction": "out",
955 }
956 ]
957 }
958 }
959 },
960 }
961 }
962 },
963 }
964 }
965 }
966 }
967
968 result = create_router_bgp(tgen, topo, input_dict_4)
969 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
970
971 # Verifying RIB routes
972 dut = "r3"
973 protocol = "bgp"
974 input_dict = topo["routers"]
975 for addr_type in ADDR_TYPES:
976 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
977 assert result is True, "Testcase {} : Failed \n Error: {}".format(
978 tc_name, result
979 )
980
981 # Verifying BGP set attributes
982 dut = "r3"
983 routes = {
984 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
985 "ipv6": ["1::1/128", "1::2/128"],
986 }
987 for addr_type in ADDR_TYPES:
988 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
989 result = verify_bgp_attributes(
990 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
991 )
992 assert result is True, "Testcase {} : Failed \n Error: {}".format(
993 tc_name, result
994 )
995
996 # Verifying RIB routes
997 dut = "r4"
998 protocol = "bgp"
999 for addr_type in ADDR_TYPES:
1000 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
1001 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1002 tc_name, result
1003 )
1004
1005 # Verifying BGP set attributes
1006 dut = "r4"
1007 routes = {
1008 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1009 "ipv6": ["1::1/128", "1::2/128"],
1010 }
1011
1012 for addr_type in ADDR_TYPES:
1013 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
1014 result = verify_bgp_attributes(
1015 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1016 )
1017 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1018 tc_name, result
1019 )
1020
1021 # Modify ip prefix list
1022 input_dict_2 = {
1023 "r3": {
1024 "prefix_lists": {
1025 "ipv4": {
1026 "pf_list_1_ipv4": [
1027 {"seqid": 10, "network": "any", "action": "deny"}
1028 ]
1029 },
1030 "ipv6": {
1031 "pf_list_1_ipv6": [
1032 {"seqid": 100, "network": "any", "action": "deny"}
1033 ]
1034 },
1035 }
1036 }
1037 }
1038 result = create_prefix_lists(tgen, input_dict_2)
1039 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1040
1041 sleep(5)
1042 # Verifying RIB routes
1043 dut = "r3"
1044 protocol = "bgp"
1045 for addr_type in ADDR_TYPES:
1046 result = verify_rib(
1047 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1048 )
1049 assert result is not True, "Testcase {} : Failed \n"
1050 "routes are not present \n Error: {}".format(tc_name, result)
1051 logger.info("Expected behaviour: {}".format(result))
1052
1053 # Verifying RIB routes
1054 dut = "r4"
1055 protocol = "bgp"
1056 for addr_type in ADDR_TYPES:
1057 result = verify_rib(
1058 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1059 )
1060 assert result is not True, "Testcase {} : Failed \n"
1061 "Expected behaviour: routes are not present \n "
1062 "Error: {}".format(tc_name, result)
1063
1064 write_test_footer(tc_name)
1065
1066 # Uncomment next line for debugging
1067 # tgen.mininet_cli()
1068
1069
1070 def test_remove_prefix_list_referenced_by_rmap_p0():
1071 """
1072 TC_50_2:
1073 Remove prefix-list referencec by route-map match cluase
1074 and verifying it reflecting as intended
1075 """
1076 tgen = get_topogen()
1077 global bgp_convergence
1078
1079 if bgp_convergence is not True:
1080 pytest.skip("skipped because of BGP Convergence failure")
1081
1082 # test case name
1083 tc_name = inspect.stack()[0][3]
1084 write_test_header(tc_name)
1085 reset_config_on_routers(tgen)
1086
1087 # Create ip prefix list
1088 input_dict_2 = {
1089 "r3": {
1090 "prefix_lists": {
1091 "ipv4": {
1092 "pf_list_1_ipv4": [
1093 {"seqid": 10, "network": "any", "action": "permit"}
1094 ]
1095 },
1096 "ipv6": {
1097 "pf_list_1_ipv6": [
1098 {"seqid": 100, "network": "any", "action": "permit"}
1099 ]
1100 },
1101 }
1102 }
1103 }
1104 result = create_prefix_lists(tgen, input_dict_2)
1105 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1106
1107 # Create route map
1108 for addr_type in ADDR_TYPES:
1109 input_dict_3 = {
1110 "r3": {
1111 "route_maps": {
1112 "rmap_match_pf_1_{}".format(addr_type): [
1113 {
1114 "action": "permit",
1115 "seq_id": "5",
1116 "match": {
1117 addr_type: {
1118 "prefix_lists": "pf_list_1_{}".format(addr_type)
1119 }
1120 },
1121 "set": {
1122 "locPrf": 150,
1123 },
1124 }
1125 ],
1126 "rmap_match_pf_2_{}".format(addr_type): [
1127 {
1128 "action": "permit",
1129 "seq_id": "5",
1130 "match": {
1131 addr_type: {
1132 "prefix_lists": "pf_list_1_{}".format(addr_type)
1133 }
1134 },
1135 "set": {"metric": 50},
1136 }
1137 ],
1138 }
1139 }
1140 }
1141 result = create_route_maps(tgen, input_dict_3)
1142 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1143 tc_name, result
1144 )
1145
1146 # Configure neighbor for route map
1147 for addr_type in ADDR_TYPES:
1148 input_dict_4 = {
1149 "r3": {
1150 "bgp": {
1151 "address_family": {
1152 "ipv4": {
1153 "unicast": {
1154 "neighbor": {
1155 "r1": {
1156 "dest_link": {
1157 "r3": {
1158 "route_maps": [
1159 {
1160 "name": "rmap_match_pf_1_ipv4",
1161 "direction": "in",
1162 }
1163 ]
1164 }
1165 }
1166 },
1167 "r4": {
1168 "dest_link": {
1169 "r3": {
1170 "route_maps": [
1171 {
1172 "name": "rmap_match_pf_2_ipv4",
1173 "direction": "out",
1174 }
1175 ]
1176 }
1177 }
1178 },
1179 }
1180 }
1181 },
1182 "ipv6": {
1183 "unicast": {
1184 "neighbor": {
1185 "r1": {
1186 "dest_link": {
1187 "r3": {
1188 "route_maps": [
1189 {
1190 "name": "rmap_match_pf_1_ipv6",
1191 "direction": "in",
1192 }
1193 ]
1194 }
1195 }
1196 },
1197 "r4": {
1198 "dest_link": {
1199 "r3": {
1200 "route_maps": [
1201 {
1202 "name": "rmap_match_pf_2_ipv6",
1203 "direction": "out",
1204 }
1205 ]
1206 }
1207 }
1208 },
1209 }
1210 }
1211 },
1212 }
1213 }
1214 }
1215 }
1216 result = create_router_bgp(tgen, topo, input_dict_4)
1217 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1218 tc_name, result
1219 )
1220
1221 # Verifying RIB routes
1222 dut = "r3"
1223 protocol = "bgp"
1224 input_dict = topo["routers"]
1225 for addr_type in ADDR_TYPES:
1226 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
1227 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1228 tc_name, result
1229 )
1230
1231 # Verifying BGP set attributes
1232 dut = "r3"
1233 routes = {
1234 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1235 "ipv6": ["1::1/128", "1::2/128"],
1236 }
1237 for addr_type in ADDR_TYPES:
1238 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
1239 result = verify_bgp_attributes(
1240 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1241 )
1242 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1243 tc_name, result
1244 )
1245
1246 # Verifying RIB routes
1247 dut = "r4"
1248 protocol = "bgp"
1249 for addr_type in ADDR_TYPES:
1250 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
1251 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1252 tc_name, result
1253 )
1254
1255 # Verifying BGP set attributes
1256 dut = "r4"
1257 routes = {
1258 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1259 "ipv6": ["1::1/128", "1::2/128"],
1260 }
1261 for addr_type in ADDR_TYPES:
1262 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
1263 result = verify_bgp_attributes(
1264 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1265 )
1266 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1267 tc_name, result
1268 )
1269
1270 # Remove/Delete prefix list
1271 input_dict_3 = {
1272 "r3": {
1273 "prefix_lists": {
1274 "ipv4": {
1275 "pf_list_1_ipv4": [
1276 {
1277 "seqid": 10,
1278 "network": "any",
1279 "action": "permit",
1280 "delete": True,
1281 }
1282 ]
1283 },
1284 "ipv6": {
1285 "pf_list_1_ipv6": [
1286 {
1287 "seqid": 100,
1288 "network": "any",
1289 "action": "permit",
1290 "delete": True,
1291 }
1292 ]
1293 },
1294 }
1295 }
1296 }
1297 result = create_prefix_lists(tgen, input_dict_3)
1298 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1299
1300 result = verify_prefix_lists(tgen, input_dict_3)
1301 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1302
1303 # Api call to clear bgp, so config changes would be reflected
1304 dut = "r3"
1305 result = clear_bgp_and_verify(tgen, topo, dut)
1306 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1307
1308 # Verifying RIB routes
1309 dut = "r3"
1310 protocol = "bgp"
1311 for addr_type in ADDR_TYPES:
1312 result = verify_rib(
1313 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1314 )
1315 assert result is not True, "Testcase {} : Failed \n"
1316 "routes are not present \n Error: {}".format(tc_name, result)
1317 logger.info("Expected behaviour: {}".format(result))
1318
1319 # Verifying RIB routes
1320 dut = "r4"
1321 protocol = "bgp"
1322 for addr_type in ADDR_TYPES:
1323 result = verify_rib(
1324 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1325 )
1326 assert result is not True, "Testcase {} : Failed \n"
1327 "routes are not present \n Error: {}".format(tc_name, result)
1328 logger.info("Expected behaviour: {}".format(result))
1329
1330 write_test_footer(tc_name)
1331
1332 # Uncomment next line for debugging
1333 # tgen.mininet_cli()
1334
1335
1336 def test_add_and_remove_community_list_referenced_by_rmap_p0():
1337 """
1338 TC_51:
1339 Add and remove community-list referencec by route-map match cluase
1340 and verifying it reflecting as intended
1341 """
1342 tgen = get_topogen()
1343 global bgp_convergence
1344
1345 if bgp_convergence is not True:
1346 pytest.skip("skipped because of BGP Convergence failure")
1347
1348 # test case name
1349 tc_name = inspect.stack()[0][3]
1350 write_test_header(tc_name)
1351 reset_config_on_routers(tgen)
1352
1353 # Creating configuration from JSON
1354 # build_config_from_json(tgen, topo)
1355
1356 # Create route map
1357 for addr_type in ADDR_TYPES:
1358 input_dict_5 = {
1359 "r1": {
1360 "route_maps": {
1361 "rm_r1_out_{}".format(addr_type): [
1362 {
1363 "action": "permit",
1364 "set": {
1365 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1366 },
1367 }
1368 ]
1369 }
1370 }
1371 }
1372 result = create_route_maps(tgen, input_dict_5)
1373 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1374 tc_name, result
1375 )
1376
1377 # Configure neighbor for route map
1378 input_dict_6 = {
1379 "r1": {
1380 "bgp": {
1381 "address_family": {
1382 "ipv4": {
1383 "unicast": {
1384 "neighbor": {
1385 "r3": {
1386 "dest_link": {
1387 "r1": {
1388 "route_maps": [
1389 {
1390 "name": "rm_r1_out_ipv4",
1391 "direction": "out",
1392 }
1393 ]
1394 }
1395 }
1396 }
1397 }
1398 }
1399 },
1400 "ipv6": {
1401 "unicast": {
1402 "neighbor": {
1403 "r3": {
1404 "dest_link": {
1405 "r1": {
1406 "route_maps": [
1407 {
1408 "name": "rm_r1_out_ipv6",
1409 "direction": "out",
1410 }
1411 ]
1412 }
1413 }
1414 }
1415 }
1416 }
1417 },
1418 }
1419 }
1420 }
1421 }
1422
1423 result = create_router_bgp(tgen, topo, input_dict_6)
1424 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1425
1426 for addr_type in ADDR_TYPES:
1427 # Create standard large commumity-list
1428 input_dict_1 = {
1429 "r3": {
1430 "bgp_community_lists": [
1431 {
1432 "community_type": "standard",
1433 "action": "permit",
1434 "name": "rmap_lcomm_{}".format(addr_type),
1435 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
1436 "large": True,
1437 }
1438 ]
1439 }
1440 }
1441 result = create_bgp_community_lists(tgen, input_dict_1)
1442 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1443 tc_name, result
1444 )
1445
1446 # Verify BGP large community is created
1447 result = verify_create_community_list(tgen, input_dict_1)
1448 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1449
1450 for addr_type in ADDR_TYPES:
1451 # Create route map
1452 input_dict_2 = {
1453 "r3": {
1454 "route_maps": {
1455 "rm_r3_in_{}".format(addr_type): [
1456 {
1457 "action": "permit",
1458 "match": {
1459 addr_type: {
1460 "large-community-list": {
1461 "id": "rmap_lcomm_" + addr_type
1462 }
1463 }
1464 },
1465 }
1466 ]
1467 }
1468 }
1469 }
1470 result = create_route_maps(tgen, input_dict_2)
1471 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1472 tc_name, result
1473 )
1474
1475 # Configure neighbor for route map
1476 input_dict_3 = {
1477 "r3": {
1478 "bgp": {
1479 "address_family": {
1480 "ipv4": {
1481 "unicast": {
1482 "neighbor": {
1483 "r1": {
1484 "dest_link": {
1485 "r3": {
1486 "route_maps": [
1487 {
1488 "name": "rm_r3_in_ipv4",
1489 "direction": "in",
1490 }
1491 ]
1492 }
1493 }
1494 }
1495 }
1496 }
1497 },
1498 "ipv6": {
1499 "unicast": {
1500 "neighbor": {
1501 "r1": {
1502 "dest_link": {
1503 "r3": {
1504 "route_maps": [
1505 {
1506 "name": "rm_r3_in_ipv6",
1507 "direction": "in",
1508 }
1509 ]
1510 }
1511 }
1512 }
1513 }
1514 }
1515 },
1516 }
1517 }
1518 }
1519 }
1520 result = create_router_bgp(tgen, topo, input_dict_3)
1521
1522 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1523
1524 sleep(5)
1525 # Verifying RIB routes
1526 dut = "r3"
1527 protocol = "bgp"
1528 input_dict = topo["routers"]
1529 for addr_type in ADDR_TYPES:
1530 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
1531 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1532 tc_name, result
1533 )
1534
1535 # Verify large-community-list
1536 dut = "r3"
1537 networks = {
1538 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1539 "ipv6": ["1::1/128", "1::2/128"],
1540 }
1541 input_dict_4 = {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2"}
1542 for addr_type in ADDR_TYPES:
1543 result = verify_bgp_community(
1544 tgen, addr_type, dut, networks[addr_type], input_dict_4
1545 )
1546 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1547 tc_name, result
1548 )
1549 write_test_footer(tc_name)
1550
1551 # Uncomment next line for debugging
1552 # tgen.mininet_cli()
1553
1554
1555 def test_multiple_match_statement_in_route_map_logical_ORed_p0():
1556 """
1557 TC_45:
1558 Test multiple match statements as part of a route-map"s single
1559 sequence number. (Logical OR-ed of multiple match statements)
1560 """
1561 tgen = get_topogen()
1562 global bgp_convergence
1563
1564 if bgp_convergence is not True:
1565 pytest.skip("skipped because of BGP Convergence failure")
1566
1567 # test case name
1568 tc_name = inspect.stack()[0][3]
1569 write_test_header(tc_name)
1570 reset_config_on_routers(tgen)
1571
1572 # Api call to advertise networks
1573 input_dict_nw1 = {
1574 "r1": {
1575 "bgp": {
1576 "address_family": {
1577 "ipv4": {
1578 "unicast": {"advertise_networks": [{"network": "10.0.30.1/32"}]}
1579 },
1580 "ipv6": {
1581 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1582 },
1583 }
1584 }
1585 }
1586 }
1587
1588 result = create_router_bgp(tgen, topo, input_dict_nw1)
1589 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1590
1591 # Api call to advertise networks
1592 input_dict_nw2 = {
1593 "r1": {
1594 "bgp": {
1595 "address_family": {
1596 "ipv4": {
1597 "unicast": {"advertise_networks": [{"network": "20.0.30.1/32"}]}
1598 },
1599 "ipv6": {
1600 "unicast": {"advertise_networks": [{"network": "2::1/128"}]}
1601 },
1602 }
1603 }
1604 }
1605 }
1606
1607 result = create_router_bgp(tgen, topo, input_dict_nw2)
1608 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1609
1610 # Create ip prefix list
1611 input_dict_2 = {
1612 "r3": {
1613 "prefix_lists": {
1614 "ipv4": {
1615 "pf_list_1_ipv4": [
1616 {"seqid": 10, "network": "any", "action": "permit"}
1617 ]
1618 },
1619 "ipv6": {
1620 "pf_list_1_ipv6": [
1621 {"seqid": 100, "network": "any", "action": "permit"}
1622 ]
1623 },
1624 }
1625 }
1626 }
1627 result = create_prefix_lists(tgen, input_dict_2)
1628 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1629
1630 # Create ip prefix list
1631 input_dict_2 = {
1632 "r3": {
1633 "prefix_lists": {
1634 "ipv4": {
1635 "pf_list_2_ipv4": [
1636 {"seqid": 10, "network": "any", "action": "permit"}
1637 ]
1638 },
1639 "ipv6": {
1640 "pf_list_2_ipv6": [
1641 {"seqid": 100, "network": "any", "action": "permit"}
1642 ]
1643 },
1644 }
1645 }
1646 }
1647 result = create_prefix_lists(tgen, input_dict_2)
1648 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1649
1650 input_dict_3_addr_type = {}
1651 # Create route map
1652 for addr_type in ADDR_TYPES:
1653 input_dict_3 = {
1654 "r3": {
1655 "route_maps": {
1656 "rmap_match_pf_1_{}".format(addr_type): [
1657 {
1658 "action": "permit",
1659 "seq_id": "5",
1660 "match": {
1661 addr_type: {
1662 "prefix_lists": "pf_list_1_{}".format(addr_type)
1663 }
1664 },
1665 "set": {"locPrf": 150},
1666 }
1667 ]
1668 }
1669 }
1670 }
1671 input_dict_3_addr_type[addr_type] = input_dict_3
1672 result = create_route_maps(tgen, input_dict_3)
1673 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1674 tc_name, result
1675 )
1676
1677 # Create route map
1678 for addr_type in ADDR_TYPES:
1679 input_dict_3 = {
1680 "r3": {
1681 "route_maps": {
1682 "rmap_match_pf_1_{}".format(addr_type): [
1683 {
1684 "action": "permit",
1685 "seq_id": "5",
1686 "match": {
1687 addr_type: {
1688 "prefix_lists": "pf_list_1_{}".format(addr_type)
1689 }
1690 },
1691 "set": {"locPrf": 200},
1692 }
1693 ]
1694 }
1695 }
1696 }
1697 input_dict_3_addr_type[addr_type] = input_dict_3
1698 result = create_route_maps(tgen, input_dict_3)
1699 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1700 tc_name, result
1701 )
1702
1703 # Configure neighbor for route map
1704 input_dict_6 = {
1705 "r3": {
1706 "bgp": {
1707 "address_family": {
1708 "ipv4": {
1709 "unicast": {
1710 "neighbor": {
1711 "r1": {
1712 "dest_link": {
1713 "r3": {
1714 "route_maps": [
1715 {
1716 "name": "rmap_match_pf_1_ipv4",
1717 "direction": "in",
1718 }
1719 ]
1720 }
1721 }
1722 }
1723 }
1724 }
1725 },
1726 "ipv6": {
1727 "unicast": {
1728 "neighbor": {
1729 "r1": {
1730 "dest_link": {
1731 "r3": {
1732 "route_maps": [
1733 {
1734 "name": "rmap_match_pf_1_ipv6",
1735 "direction": "in",
1736 }
1737 ]
1738 }
1739 }
1740 }
1741 }
1742 }
1743 },
1744 }
1745 }
1746 }
1747 }
1748
1749 result = create_router_bgp(tgen, topo, input_dict_6)
1750 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1751
1752 # Verifying RIB routes
1753 dut = "r3"
1754 protocol = "bgp"
1755 input_dict = topo["routers"]
1756 for addr_type in ADDR_TYPES:
1757 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
1758 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1759 tc_name, result
1760 )
1761
1762 # Verifying BGP set attributes
1763 dut = "r3"
1764 routes = {"ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"]}
1765 for addr_type in ADDR_TYPES:
1766 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
1767 result = verify_bgp_attributes(
1768 tgen,
1769 addr_type,
1770 dut,
1771 routes[addr_type],
1772 rmap_name,
1773 input_dict_3_addr_type[addr_type],
1774 )
1775 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1776 tc_name, result
1777 )
1778
1779 # Verifying BGP set attributes
1780 routes = {"ipv4": ["20.0.30.1/32"], "ipv6": ["2::1/128"]}
1781 for addr_type in ADDR_TYPES:
1782 result = verify_bgp_attributes(
1783 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1784 )
1785 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1786 tc_name, result
1787 )
1788
1789 write_test_footer(tc_name)
1790
1791 # Uncomment next line for debugging
1792 # tgen.mininet_cli()
1793
1794
1795 def test_multiple_match_statement_in_route_map_logical_ANDed_p1():
1796 """
1797 TC_44:
1798 Test multiple match statements as part of a route-map"s single
1799 sequence number. (Logical AND of multiple match statements)
1800 """
1801 tgen = get_topogen()
1802 global bgp_convergence
1803
1804 if bgp_convergence is not True:
1805 pytest.skip("skipped because of BGP Convergence failure")
1806
1807 # test case name
1808 tc_name = inspect.stack()[0][3]
1809 write_test_header(tc_name)
1810 reset_config_on_routers(tgen)
1811
1812 # Create route map
1813 for addr_type in ADDR_TYPES:
1814 input_dict_5 = {
1815 "r1": {
1816 "route_maps": {
1817 "rm_r1_out_{}".format(addr_type): [
1818 {
1819 "action": "permit",
1820 "set": {
1821 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1822 },
1823 }
1824 ]
1825 }
1826 }
1827 }
1828 result = create_route_maps(tgen, input_dict_5)
1829 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1830 tc_name, result
1831 )
1832
1833 # Configure neighbor for route map
1834 for addr_type in ADDR_TYPES:
1835 input_dict_6 = {
1836 "r1": {
1837 "bgp": {
1838 "address_family": {
1839 addr_type: {
1840 "unicast": {
1841 "neighbor": {
1842 "r3": {
1843 "dest_link": {
1844 "r1": {
1845 "route_maps": [
1846 {
1847 "name": "rm_r1_out_{}".format(
1848 addr_type
1849 ),
1850 "direction": "out",
1851 }
1852 ]
1853 }
1854 }
1855 }
1856 }
1857 }
1858 }
1859 }
1860 }
1861 }
1862 }
1863 result = create_router_bgp(tgen, topo, input_dict_6)
1864 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1865 tc_name, result
1866 )
1867
1868 # Create ip prefix list
1869 input_dict_2 = {
1870 "r3": {
1871 "prefix_lists": {
1872 "ipv4": {
1873 "pf_list_1_ipv4": [
1874 {"seqid": 10, "network": "any", "action": "permit"}
1875 ]
1876 },
1877 "ipv6": {
1878 "pf_list_1_ipv6": [
1879 {"seqid": 100, "network": "any", "action": "permit"}
1880 ]
1881 },
1882 }
1883 }
1884 }
1885 result = create_prefix_lists(tgen, input_dict_2)
1886
1887 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1888
1889 for addr_type in ADDR_TYPES:
1890 # Create standard large commumity-list
1891 input_dict_1 = {
1892 "r3": {
1893 "bgp_community_lists": [
1894 {
1895 "community_type": "standard",
1896 "action": "permit",
1897 "name": "rmap_lcomm_{}".format(addr_type),
1898 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
1899 "large": True,
1900 }
1901 ]
1902 }
1903 }
1904 result = create_bgp_community_lists(tgen, input_dict_1)
1905 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1906 tc_name, result
1907 )
1908
1909 # Verify BGP large community is created
1910 result = verify_create_community_list(tgen, input_dict_1)
1911 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1912
1913 # Create route map
1914 for addr_type in ADDR_TYPES:
1915 input_dict_3 = {
1916 "r3": {
1917 "route_maps": {
1918 "rmap_match_pf_1_{}".format(addr_type): [
1919 {
1920 "action": "permit",
1921 "seq_id": "5",
1922 "match": {
1923 addr_type: {
1924 "prefix_lists": "pf_list_1_{}".format(addr_type)
1925 }
1926 },
1927 "set": {
1928 "locPrf": 150,
1929 },
1930 }
1931 ]
1932 }
1933 }
1934 }
1935 result = create_route_maps(tgen, input_dict_3)
1936 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1937 tc_name, result
1938 )
1939
1940 for addr_type in ADDR_TYPES:
1941 # Create route map
1942 input_dict_3 = {
1943 "r3": {
1944 "route_maps": {
1945 "rmap_match_pf_1_{}".format(addr_type): [
1946 {
1947 "action": "permit",
1948 "seq_id": "5",
1949 "match": {
1950 addr_type: {
1951 "large_community_list": {
1952 "id": "rmap_lcomm_" + addr_type
1953 }
1954 }
1955 },
1956 "set": {
1957 "locPrf": 150,
1958 },
1959 }
1960 ]
1961 }
1962 }
1963 }
1964 result = create_route_maps(tgen, input_dict_3)
1965 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1966 tc_name, result
1967 )
1968 # Configure neighbor for route map
1969 for addr_type in ADDR_TYPES:
1970 input_dict_4 = {
1971 "r3": {
1972 "bgp": {
1973 "address_family": {
1974 addr_type: {
1975 "unicast": {
1976 "neighbor": {
1977 "r1": {
1978 "dest_link": {
1979 "r3": {
1980 "route_maps": [
1981 {
1982 "name": "rmap_match_pf_1_{}".format(
1983 addr_type
1984 ),
1985 "direction": "in",
1986 }
1987 ]
1988 }
1989 }
1990 }
1991 }
1992 }
1993 }
1994 }
1995 }
1996 }
1997 }
1998 result = create_router_bgp(tgen, topo, input_dict_4)
1999 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2000 tc_name, result
2001 )
2002 # sleep(10)
2003 # Verifying RIB routes
2004 dut = "r3"
2005 protocol = "bgp"
2006 input_dict = topo["routers"]
2007 for addr_type in ADDR_TYPES:
2008 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2009 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2010 tc_name, result
2011 )
2012
2013 # Verifying BGP set attributes
2014 dut = "r3"
2015 routes = {
2016 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2017 "ipv6": ["1::1/128", "1::2/128"],
2018 }
2019 for addr_type in ADDR_TYPES:
2020 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2021 result = verify_bgp_attributes(
2022 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2023 )
2024 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2025 tc_name, result
2026 )
2027
2028 write_test_footer(tc_name)
2029
2030 # Uncomment next line for debugging
2031 # tgen.mininet_cli()
2032
2033
2034 def test_add_remove_rmap_to_specific_neighbor_p0():
2035 """
2036 TC_41:
2037 Test add/remove route-maps to specific neighbor and see if
2038 it takes effect as intended
2039 """
2040 tgen = get_topogen()
2041 global bgp_convergence
2042
2043 if bgp_convergence is not True:
2044 pytest.skip("skipped because of BGP Convergence failure")
2045
2046 # test case name
2047 tc_name = inspect.stack()[0][3]
2048 write_test_header(tc_name)
2049 reset_config_on_routers(tgen)
2050
2051 # Create ip prefix list
2052 input_dict_2 = {
2053 "r3": {
2054 "prefix_lists": {
2055 "ipv4": {
2056 "pf_list_1_ipv4": [
2057 {"seqid": 10, "network": "any", "action": "deny"}
2058 ]
2059 },
2060 "ipv6": {
2061 "pf_list_1_ipv6": [
2062 {"seqid": 100, "network": "any", "action": "deny"}
2063 ]
2064 },
2065 }
2066 }
2067 }
2068 result = create_prefix_lists(tgen, input_dict_2)
2069 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2070
2071 # Create route map
2072 for addr_type in ADDR_TYPES:
2073 input_dict_3 = {
2074 "r3": {
2075 "route_maps": {
2076 "rmap_match_pf_1_{}".format(addr_type): [
2077 {
2078 "action": "permit",
2079 "seq_id": "5",
2080 "match": {
2081 addr_type: {
2082 "prefix_lists": "pf_list_1_{}".format(addr_type)
2083 }
2084 },
2085 "set": {
2086 "locPrf": 150,
2087 },
2088 }
2089 ]
2090 }
2091 }
2092 }
2093 result = create_route_maps(tgen, input_dict_3)
2094 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2095 tc_name, result
2096 )
2097
2098 # Configure neighbor for route map
2099 input_dict_4 = {
2100 "r3": {
2101 "bgp": {
2102 "address_family": {
2103 "ipv4": {
2104 "unicast": {
2105 "neighbor": {
2106 "r1": {
2107 "dest_link": {
2108 "r3": {
2109 "route_maps": [
2110 {
2111 "name": "rmap_match_pf_1_ipv4",
2112 "direction": "in",
2113 }
2114 ]
2115 }
2116 }
2117 }
2118 }
2119 }
2120 },
2121 "ipv6": {
2122 "unicast": {
2123 "neighbor": {
2124 "r1": {
2125 "dest_link": {
2126 "r3": {
2127 "route_maps": [
2128 {
2129 "name": "rmap_match_pf_1_ipv6",
2130 "direction": "in",
2131 }
2132 ]
2133 }
2134 }
2135 }
2136 }
2137 }
2138 },
2139 }
2140 }
2141 }
2142 }
2143
2144 result = create_router_bgp(tgen, topo, input_dict_4)
2145 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2146
2147 # Verifying RIB routes
2148 dut = "r3"
2149 protocol = "bgp"
2150 input_dict = topo["routers"]
2151 for addr_type in ADDR_TYPES:
2152 result = verify_rib(
2153 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
2154 )
2155 assert result is not True, "Testcase {} : Failed \n Error"
2156 "Routes are still present: {}".format(tc_name, result)
2157 logger.info("Expected behaviour: {}".format(result))
2158
2159 # Remove applied rmap from neighbor
2160 input_dict_4 = {
2161 "r3": {
2162 "bgp": {
2163 "address_family": {
2164 "ipv4": {
2165 "unicast": {
2166 "neighbor": {
2167 "r1": {
2168 "dest_link": {
2169 "r3": {
2170 "route_maps": [
2171 {
2172 "name": "rmap_match_pf_1_ipv4",
2173 "direction": "in",
2174 "delete": True,
2175 }
2176 ]
2177 }
2178 }
2179 }
2180 }
2181 }
2182 },
2183 "ipv6": {
2184 "unicast": {
2185 "neighbor": {
2186 "r1": {
2187 "dest_link": {
2188 "r3": {
2189 "route_maps": [
2190 {
2191 "name": "rmap_match_pf_1_ipv6",
2192 "direction": "in",
2193 "delete": True,
2194 }
2195 ]
2196 }
2197 }
2198 }
2199 }
2200 }
2201 },
2202 }
2203 }
2204 }
2205 }
2206
2207 result = create_router_bgp(tgen, topo, input_dict_4)
2208 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2209
2210 # Verifying RIB routes
2211 dut = "r3"
2212 protocol = "bgp"
2213 input_dict = topo["routers"]
2214 for addr_type in ADDR_TYPES:
2215 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2216 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2217 tc_name, result
2218 )
2219
2220 write_test_footer(tc_name)
2221
2222 # Uncomment next line for debugging
2223 # tgen.mininet_cli()
2224
2225
2226 def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0():
2227 """
2228 TC_56:
2229 Test clear BGP sessions and interface flaps to see if
2230 route-map properties are intact.
2231 """
2232 tgen = get_topogen()
2233 global bgp_convergence
2234
2235 if bgp_convergence is not True:
2236 pytest.skip("skipped because of BGP Convergence failure")
2237
2238 # test case name
2239 tc_name = inspect.stack()[0][3]
2240 write_test_header(tc_name)
2241 reset_config_on_routers(tgen)
2242
2243 # Create ip prefix list
2244 input_dict_2 = {
2245 "r3": {
2246 "prefix_lists": {
2247 "ipv4": {
2248 "pf_list_1_ipv4": [
2249 {"seqid": 10, "network": "any", "action": "permit"}
2250 ]
2251 },
2252 "ipv6": {
2253 "pf_list_1_ipv6": [
2254 {"seqid": 100, "network": "any", "action": "permit"}
2255 ]
2256 },
2257 }
2258 }
2259 }
2260 result = create_prefix_lists(tgen, input_dict_2)
2261 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2262
2263 # Create route map
2264 for addr_type in ADDR_TYPES:
2265 input_dict_3 = {
2266 "r3": {
2267 "route_maps": {
2268 "rmap_match_pf_1_{}".format(addr_type): [
2269 {
2270 "action": "permit",
2271 "seq_id": "5",
2272 "match": {
2273 addr_type: {
2274 "prefix_lists": "pf_list_1_{}".format(addr_type)
2275 }
2276 },
2277 "set": {"locPrf": 150, "weight": 100},
2278 }
2279 ]
2280 }
2281 }
2282 }
2283 result = create_route_maps(tgen, input_dict_3)
2284 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2285 tc_name, result
2286 )
2287
2288 # Configure neighbor for route map
2289 input_dict_4 = {
2290 "r3": {
2291 "bgp": {
2292 "address_family": {
2293 "ipv4": {
2294 "unicast": {
2295 "neighbor": {
2296 "r1": {
2297 "dest_link": {
2298 "r3": {
2299 "route_maps": [
2300 {
2301 "name": "rmap_match_pf_1_ipv4",
2302 "direction": "in",
2303 }
2304 ]
2305 }
2306 }
2307 }
2308 }
2309 }
2310 },
2311 "ipv6": {
2312 "unicast": {
2313 "neighbor": {
2314 "r1": {
2315 "dest_link": {
2316 "r3": {
2317 "route_maps": [
2318 {
2319 "name": "rmap_match_pf_1_ipv6",
2320 "direction": "in",
2321 }
2322 ]
2323 }
2324 }
2325 }
2326 }
2327 }
2328 },
2329 }
2330 }
2331 }
2332 }
2333
2334 result = create_router_bgp(tgen, topo, input_dict_4)
2335 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2336
2337 # Verifying RIB routes
2338 dut = "r3"
2339 protocol = "bgp"
2340 input_dict = topo["routers"]
2341 for addr_type in ADDR_TYPES:
2342 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2343 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2344 tc_name, result
2345 )
2346
2347 # Verifying BGP set attributes
2348 dut = "r3"
2349 routes = {
2350 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2351 "ipv6": ["1::1/128", "1::2/128"],
2352 }
2353 for addr_type in ADDR_TYPES:
2354 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2355 result = verify_bgp_attributes(
2356 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2357 )
2358 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2359 tc_name, result
2360 )
2361
2362 # clear bgp, so config changes would be reflected
2363 dut = "r3"
2364 result = clear_bgp_and_verify(tgen, topo, dut)
2365 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2366
2367 # Verifying RIB routes
2368 dut = "r3"
2369 protocol = "bgp"
2370 input_dict = topo["routers"]
2371 for addr_type in ADDR_TYPES:
2372 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2373 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2374 tc_name, result
2375 )
2376
2377 # Verifying BGP set attributes
2378 dut = "r3"
2379 routes = {
2380 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2381 "ipv6": ["1::1/128", "1::2/128"],
2382 }
2383 for addr_type in ADDR_TYPES:
2384 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2385 result = verify_bgp_attributes(
2386 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2387 )
2388 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2389 tc_name, result
2390 )
2391
2392 # Flap interface to see if route-map properties are intact
2393 # Shutdown interface
2394 dut = "r3"
2395 intf = "r3-r1-eth0"
2396 shutdown_bringup_interface(tgen, dut, intf, False)
2397
2398 sleep(5)
2399
2400 # Bringup interface
2401 dut = "r3"
2402 intf = "r3-r1-eth0"
2403 shutdown_bringup_interface(tgen, dut, intf, True)
2404
2405 # Verify BGP convergence once interface is up
2406 result = verify_bgp_convergence(tgen, topo)
2407 assert result is True, "setup_module :Failed \n Error:" " {}".format(result)
2408
2409 # Verifying RIB routes
2410 dut = "r3"
2411 protocol = "bgp"
2412 input_dict = topo["routers"]
2413 for addr_type in ADDR_TYPES:
2414 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2415 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2416 tc_name, result
2417 )
2418
2419 # Verifying BGP set attributes
2420 dut = "r3"
2421 routes = {
2422 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2423 "ipv6": ["1::1/128", "1::2/128"],
2424 }
2425 for addr_type in ADDR_TYPES:
2426 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2427 result = verify_bgp_attributes(
2428 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2429 )
2430 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2431 tc_name, result
2432 )
2433
2434 write_test_footer(tc_name)
2435
2436 # Uncomment next line for debugging
2437 # tgen.mininet_cli()
2438
2439
2440 def test_rmap_without_match_and_set_clause_p0():
2441 """
2442 TC_46:
2443 Verify if a blank sequence number can be create(without any
2444 match/set clause) and check if it allows all the traffic/prefixes
2445 """
2446 tgen = get_topogen()
2447 global bgp_convergence
2448
2449 if bgp_convergence is not True:
2450 pytest.skip("skipped because of BGP Convergence failure")
2451
2452 # test case name
2453 tc_name = inspect.stack()[0][3]
2454 write_test_header(tc_name)
2455 reset_config_on_routers(tgen)
2456
2457 # Create route map
2458 for addr_type in ADDR_TYPES:
2459 input_dict_3 = {
2460 "r3": {
2461 "route_maps": {
2462 "rmap_no_match_set_1_{}".format(addr_type): [
2463 {"action": "permit", "seq_id": "5"}
2464 ],
2465 "rmap_no_match_set_2_{}".format(addr_type): [
2466 {"action": "deny", "seq_id": "5"}
2467 ],
2468 }
2469 }
2470 }
2471 result = create_route_maps(tgen, input_dict_3)
2472 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2473 tc_name, result
2474 )
2475
2476 # Configure neighbor for route map
2477 input_dict_4 = {
2478 "r3": {
2479 "bgp": {
2480 "address_family": {
2481 "ipv4": {
2482 "unicast": {
2483 "neighbor": {
2484 "r1": {
2485 "dest_link": {
2486 "r3": {
2487 "route_maps": [
2488 {
2489 "name": "rmap_no_match_set_1_ipv4",
2490 "direction": "in",
2491 }
2492 ]
2493 }
2494 }
2495 },
2496 "r4": {
2497 "dest_link": {
2498 "r3": {
2499 "route_maps": [
2500 {
2501 "name": "rmap_no_match_set_2_ipv4",
2502 "direction": "out",
2503 }
2504 ]
2505 }
2506 }
2507 },
2508 }
2509 }
2510 },
2511 "ipv6": {
2512 "unicast": {
2513 "neighbor": {
2514 "r1": {
2515 "dest_link": {
2516 "r3": {
2517 "route_maps": [
2518 {
2519 "name": "rmap_no_match_set_1_ipv6",
2520 "direction": "in",
2521 }
2522 ]
2523 }
2524 }
2525 },
2526 "r4": {
2527 "dest_link": {
2528 "r3": {
2529 "route_maps": [
2530 {
2531 "name": "rmap_no_match_set_2_ipv6",
2532 "direction": "out",
2533 }
2534 ]
2535 }
2536 }
2537 },
2538 }
2539 }
2540 },
2541 }
2542 }
2543 }
2544 }
2545
2546 result = create_router_bgp(tgen, topo, input_dict_4)
2547 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2548
2549 # Verifying RIB routes
2550 dut = "r3"
2551 protocol = "bgp"
2552 input_dict = topo["routers"]
2553 for addr_type in ADDR_TYPES:
2554 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2555 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2556 tc_name, result
2557 )
2558
2559 # Verifying RIB routes
2560 dut = "r4"
2561 protocol = "bgp"
2562 for addr_type in ADDR_TYPES:
2563 result = verify_rib(
2564 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
2565 )
2566 assert result is not True, "Testcase {} : Failed \n"
2567 "routes are not present \n Error: {}".format(tc_name, result)
2568 logger.info("Expected behaviour: {}".format(result))
2569
2570 write_test_footer(tc_name)
2571 # Uncomment next line for debugging
2572 # tgen.mininet_cli()
2573
2574
2575 def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0():
2576 """
2577 TC_48:
2578 Create route map setting local preference and weight to eBGP peeer
2579 and metric to ibgp peer and verifying it should not get advertised
2580 """
2581 tgen = get_topogen()
2582 global bgp_convergence
2583
2584 if bgp_convergence is not True:
2585 pytest.skip("skipped because of BGP Convergence failure")
2586
2587 # test case name
2588 tc_name = inspect.stack()[0][3]
2589 write_test_header(tc_name)
2590 reset_config_on_routers(tgen)
2591
2592 # Create ip prefix list
2593 input_dict_2 = {
2594 "r3": {
2595 "prefix_lists": {
2596 "ipv4": {
2597 "pf_list_1_ipv4": [
2598 {"seqid": 10, "network": "any", "action": "permit"}
2599 ]
2600 },
2601 "ipv6": {
2602 "pf_list_1_ipv6": [
2603 {"seqid": 100, "network": "any", "action": "permit"}
2604 ]
2605 },
2606 }
2607 }
2608 }
2609 result = create_prefix_lists(tgen, input_dict_2)
2610 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2611
2612 # Create route map
2613 input_dict_3_addr_type = {}
2614 for addr_type in ADDR_TYPES:
2615 input_dict_3 = {
2616 "r3": {
2617 "route_maps": {
2618 "rmap_match_pf_1_{}".format(addr_type): [
2619 {
2620 "action": "permit",
2621 "match": {
2622 addr_type: {
2623 "prefix_lists": "pf_list_1_{}".format(addr_type)
2624 }
2625 },
2626 "set": {"metric": 50},
2627 }
2628 ],
2629 "rmap_match_pf_2_{}".format(addr_type): [
2630 {
2631 "action": "permit",
2632 "match": {
2633 addr_type: {
2634 "prefix_lists": "pf_list_1_{}".format(addr_type)
2635 }
2636 },
2637 "set": {"locPrf": 150},
2638 }
2639 ],
2640 "rmap_match_pf_3_{}".format(addr_type): [
2641 {
2642 "action": "permit",
2643 "match": {
2644 addr_type: {
2645 "prefix_lists": "pf_list_1_{}".format(addr_type)
2646 }
2647 },
2648 "set": {"weight": 1000},
2649 }
2650 ],
2651 }
2652 }
2653 }
2654 input_dict_3_addr_type[addr_type] = input_dict_3
2655 result = create_route_maps(tgen, input_dict_3)
2656 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2657 tc_name, result
2658 )
2659
2660 # Configure neighbor for route map
2661 input_dict_4 = {
2662 "r3": {
2663 "bgp": {
2664 "address_family": {
2665 "ipv4": {
2666 "unicast": {
2667 "neighbor": {
2668 "r1": {
2669 "dest_link": {
2670 "r3": {
2671 "route_maps": [
2672 {
2673 "name": "rmap_match_pf_1_ipv4",
2674 "direction": "in",
2675 }
2676 ]
2677 }
2678 }
2679 },
2680 "r4": {
2681 "dest_link": {
2682 "r3": {
2683 "route_maps": [
2684 {
2685 "name": "rmap_match_pf_2_ipv4",
2686 "direction": "out",
2687 }
2688 ]
2689 }
2690 }
2691 },
2692 "r5": {
2693 "dest_link": {
2694 "r3": {
2695 "route_maps": [
2696 {
2697 "name": "rmap_match_pf_3_ipv4",
2698 "direction": "out",
2699 }
2700 ]
2701 }
2702 }
2703 },
2704 }
2705 }
2706 },
2707 "ipv6": {
2708 "unicast": {
2709 "neighbor": {
2710 "r1": {
2711 "dest_link": {
2712 "r3": {
2713 "route_maps": [
2714 {
2715 "name": "rmap_match_pf_1_ipv6",
2716 "direction": "in",
2717 }
2718 ]
2719 }
2720 }
2721 },
2722 "r4": {
2723 "dest_link": {
2724 "r3": {
2725 "route_maps": [
2726 {
2727 "name": "rmap_match_pf_2_ipv6",
2728 "direction": "out",
2729 }
2730 ]
2731 }
2732 }
2733 },
2734 "r5": {
2735 "dest_link": {
2736 "r3": {
2737 "route_maps": [
2738 {
2739 "name": "rmap_match_pf_3_ipv6",
2740 "direction": "out",
2741 }
2742 ]
2743 }
2744 }
2745 },
2746 }
2747 }
2748 },
2749 }
2750 }
2751 }
2752 }
2753
2754 result = create_router_bgp(tgen, topo, input_dict_4)
2755 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2756
2757 # Verifying RIB routes
2758 dut = "r3"
2759 protocol = "bgp"
2760 input_dict = topo["routers"]
2761 for addr_type in ADDR_TYPES:
2762 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2763 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2764 tc_name, result
2765 )
2766
2767 # Verifying BGP set attributes
2768 dut = "r3"
2769 routes = {
2770 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2771 "ipv6": ["1::1/128", "1::2/128"],
2772 }
2773 rmap_name = "rmap_match_pf_1"
2774 for addr_type in ADDR_TYPES:
2775 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2776 result = verify_bgp_attributes(
2777 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2778 )
2779 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2780 tc_name, result
2781 )
2782
2783 # Verifying RIB routes
2784 dut = "r4"
2785 protocol = "bgp"
2786 for addr_type in ADDR_TYPES:
2787 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2788 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2789 tc_name, result
2790 )
2791
2792 # Verifying BGP set attributes
2793 dut = "r4"
2794 routes = {
2795 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2796 "ipv6": ["1::1/128", "1::2/128"],
2797 }
2798 rmap_name = "rmap_match_pf_2"
2799 for addr_type in ADDR_TYPES:
2800 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
2801
2802 result = verify_bgp_attributes(
2803 tgen,
2804 addr_type,
2805 dut,
2806 routes[addr_type],
2807 rmap_name,
2808 input_dict_3_addr_type[addr_type],
2809 expected=False,
2810 )
2811 assert result is not True, "Testcase {} : Failed \n"
2812 "Attributes are not set \n Error: {}".format(tc_name, result)
2813 logger.info("Expected behaviour: {}".format(result))
2814
2815 # Verifying RIB routes
2816 dut = "r5"
2817 protocol = "bgp"
2818 for addr_type in ADDR_TYPES:
2819 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2820 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2821 tc_name, result
2822 )
2823 # Verifying BGP set attributes
2824 dut = "r5"
2825 routes = {
2826 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2827 "ipv6": ["1::1/128", "1::2/128"],
2828 }
2829
2830 rmap_name = "rmap_match_pf_3"
2831 for addr_type in ADDR_TYPES:
2832 rmap_name = "rmap_match_pf_3_{}".format(addr_type)
2833 result = verify_bgp_attributes(
2834 tgen,
2835 addr_type,
2836 dut,
2837 routes[addr_type],
2838 rmap_name,
2839 input_dict_3_addr_type[addr_type],
2840 expected=False,
2841 )
2842 assert result is not True, "Testcase {} : Failed \n"
2843 "Attributes are not set \n Error: {}".format(tc_name, result)
2844 logger.info("Expected behaviour: {}".format(result))
2845
2846 write_test_footer(tc_name)
2847
2848 # Uncomment next line for debugging
2849 # tgen.mininet_cli()
2850
2851
2852 def test_multiple_set_on_single_sequence_in_rmap_p0():
2853 """
2854 TC_43:
2855 Test multiple set statements as part of a route-map"s
2856 single sequence number.
2857 """
2858 tgen = get_topogen()
2859 global bgp_convergence
2860
2861 if bgp_convergence is not True:
2862 pytest.skip("skipped because of BGP Convergence failure")
2863
2864 # test case name
2865 tc_name = inspect.stack()[0][3]
2866 write_test_header(tc_name)
2867 reset_config_on_routers(tgen)
2868
2869 # Create ip prefix list
2870 input_dict_2 = {
2871 "r3": {
2872 "prefix_lists": {
2873 "ipv4": {
2874 "pf_list_1_ipv4": [
2875 {"seqid": 10, "network": "any", "action": "permit"}
2876 ]
2877 },
2878 "ipv6": {
2879 "pf_list_1_ipv6": [
2880 {"seqid": 100, "network": "any", "action": "permit"}
2881 ]
2882 },
2883 }
2884 }
2885 }
2886 result = create_prefix_lists(tgen, input_dict_2)
2887 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2888
2889 # Create route map
2890 for addr_type in ADDR_TYPES:
2891 input_dict_3 = {
2892 "r3": {
2893 "route_maps": {
2894 "rmap_match_pf_1_{}".format(addr_type): [
2895 {
2896 "action": "permit",
2897 "match": {
2898 addr_type: {
2899 "prefix_lists": "pf_list_1_{}".format(addr_type)
2900 }
2901 },
2902 "set": {"locPrf": 150, "weight": 100, "metric": 50},
2903 }
2904 ]
2905 }
2906 }
2907 }
2908 result = create_route_maps(tgen, input_dict_3)
2909 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2910 tc_name, result
2911 )
2912
2913 # Configure neighbor for route map
2914 input_dict_4 = {
2915 "r3": {
2916 "bgp": {
2917 "address_family": {
2918 "ipv4": {
2919 "unicast": {
2920 "neighbor": {
2921 "r1": {
2922 "dest_link": {
2923 "r3": {
2924 "route_maps": [
2925 {
2926 "name": "rmap_match_pf_1_ipv4",
2927 "direction": "in",
2928 }
2929 ]
2930 }
2931 }
2932 }
2933 }
2934 }
2935 },
2936 "ipv6": {
2937 "unicast": {
2938 "neighbor": {
2939 "r1": {
2940 "dest_link": {
2941 "r3": {
2942 "route_maps": [
2943 {
2944 "name": "rmap_match_pf_1_ipv6",
2945 "direction": "in",
2946 }
2947 ]
2948 }
2949 }
2950 }
2951 }
2952 }
2953 },
2954 }
2955 }
2956 }
2957 }
2958 result = create_router_bgp(tgen, topo, input_dict_4)
2959 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2960
2961 # Verifying RIB routes
2962 dut = "r3"
2963 protocol = "bgp"
2964 input_dict = topo["routers"]
2965 for addr_type in ADDR_TYPES:
2966 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
2967 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2968 tc_name, result
2969 )
2970
2971 # Verifying BGP set attributes
2972 dut = "r3"
2973 routes = {
2974 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2975 "ipv6": ["1::1/128", "1::2/128"],
2976 }
2977
2978 rmap_name = "rmap_match_pf_1"
2979 for addr_type in ADDR_TYPES:
2980 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
2981 result = verify_bgp_attributes(
2982 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2983 )
2984 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2985 tc_name, result
2986 )
2987
2988 write_test_footer(tc_name)
2989
2990 # Uncomment next line for debugging
2991 # tgen.mininet_cli()
2992
2993
2994 def test_route_maps_with_continue_clause_p0():
2995 """
2996 TC_54:
2997 Verify route-maps continue clause functionality.
2998 """
2999 tgen = get_topogen()
3000 global bgp_convergence
3001
3002 if bgp_convergence is not True:
3003 pytest.skip("skipped because of BGP Convergence failure")
3004
3005 # test case name
3006 tc_name = inspect.stack()[0][3]
3007 write_test_header(tc_name)
3008 reset_config_on_routers(tgen)
3009
3010 # Create ip prefix list
3011 input_dict_2 = {
3012 "r3": {
3013 "prefix_lists": {
3014 "ipv4": {
3015 "pf_list_1_ipv4": [
3016 {"seqid": 10, "network": "any", "action": "permit"}
3017 ]
3018 },
3019 "ipv6": {
3020 "pf_list_1_ipv6": [
3021 {"seqid": 100, "network": "any", "action": "permit"}
3022 ]
3023 },
3024 }
3025 }
3026 }
3027 result = create_prefix_lists(tgen, input_dict_2)
3028 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3029
3030 # Create route map
3031 for addr_type in ADDR_TYPES:
3032 input_dict_3 = {
3033 "r3": {
3034 "route_maps": {
3035 "rmap_match_pf_1_{}".format(addr_type): [
3036 {
3037 "action": "permit",
3038 "seq_id": "10",
3039 "match": {
3040 addr_type: {
3041 "prefix_lists": "pf_list_1_{}".format(addr_type)
3042 }
3043 },
3044 "set": {"locPrf": 150},
3045 "continue": "30",
3046 },
3047 {
3048 "action": "permit",
3049 "seq_id": "20",
3050 "match": {
3051 addr_type: {
3052 "prefix_lists": "pf_list_1_{}".format(addr_type)
3053 }
3054 },
3055 "set": {"metric": 200},
3056 },
3057 {
3058 "action": "permit",
3059 "seq_id": "30",
3060 "match": {
3061 addr_type: {
3062 "prefix_lists": "pf_list_1_{}".format(addr_type)
3063 }
3064 },
3065 "set": {"metric": 100},
3066 },
3067 ]
3068 }
3069 }
3070 }
3071 result = create_route_maps(tgen, input_dict_3)
3072 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3073 tc_name, result
3074 )
3075
3076 # Configure neighbor for route map
3077 input_dict_4 = {
3078 "r3": {
3079 "bgp": {
3080 "address_family": {
3081 "ipv4": {
3082 "unicast": {
3083 "neighbor": {
3084 "r1": {
3085 "dest_link": {
3086 "r3": {
3087 "route_maps": [
3088 {
3089 "name": "rmap_match_pf_1_ipv4",
3090 "direction": "in",
3091 }
3092 ]
3093 }
3094 }
3095 }
3096 }
3097 }
3098 },
3099 "ipv6": {
3100 "unicast": {
3101 "neighbor": {
3102 "r1": {
3103 "dest_link": {
3104 "r3": {
3105 "route_maps": [
3106 {
3107 "name": "rmap_match_pf_1_ipv6",
3108 "direction": "in",
3109 }
3110 ]
3111 }
3112 }
3113 }
3114 }
3115 }
3116 },
3117 }
3118 }
3119 }
3120 }
3121 result = create_router_bgp(tgen, topo, input_dict_4)
3122 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3123
3124 # Verifying RIB routes
3125 dut = "r3"
3126 protocol = "bgp"
3127 input_dict = topo["routers"]
3128 for addr_type in ADDR_TYPES:
3129 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
3130 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3131 tc_name, result
3132 )
3133
3134 # Verifying BGP set attributes
3135 dut = "r3"
3136 rmap_name = "rmap_match_pf_1"
3137 routes = {
3138 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3139 "ipv6": ["1::1/128", "1::2/128"],
3140 }
3141 seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
3142 for addr_type in ADDR_TYPES:
3143 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
3144 result = verify_bgp_attributes(
3145 tgen,
3146 addr_type,
3147 dut,
3148 routes[addr_type],
3149 rmap_name,
3150 input_dict_3,
3151 seq_id[addr_type],
3152 )
3153 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3154 tc_name, result
3155 )
3156
3157 write_test_footer(tc_name)
3158
3159 # Uncomment next line for debugging
3160 # tgen.mininet_cli()
3161
3162
3163 def test_route_maps_with_goto_clause_p0():
3164 """
3165 TC_55:
3166 Verify route-maps goto clause functionality.
3167 """
3168 tgen = get_topogen()
3169 global bgp_convergence
3170
3171 if bgp_convergence is not True:
3172 pytest.skip("skipped because of BGP Convergence failure")
3173
3174 # test case name
3175 tc_name = inspect.stack()[0][3]
3176 write_test_header(tc_name)
3177 reset_config_on_routers(tgen)
3178
3179 # Create ip prefix list
3180 input_dict_2 = {
3181 "r3": {
3182 "prefix_lists": {
3183 "ipv4": {
3184 "pf_list_1_ipv4": [
3185 {"seqid": 10, "network": "any", "action": "permit"}
3186 ]
3187 },
3188 "ipv6": {
3189 "pf_list_1_ipv6": [
3190 {"seqid": 100, "network": "any", "action": "permit"}
3191 ]
3192 },
3193 }
3194 }
3195 }
3196 result = create_prefix_lists(tgen, input_dict_2)
3197 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3198
3199 # Create route map
3200 for addr_type in ADDR_TYPES:
3201 input_dict_3 = {
3202 "r3": {
3203 "route_maps": {
3204 "rmap_match_pf_1_{}".format(addr_type): [
3205 {
3206 "action": "permit",
3207 "seq_id": "10",
3208 "match": {
3209 addr_type: {
3210 "prefix_lists": "pf_list_1_{}".format(addr_type)
3211 }
3212 },
3213 "goto": "30",
3214 },
3215 {
3216 "action": "permit",
3217 "seq_id": "20",
3218 "match": {
3219 addr_type: {
3220 "prefix_lists": "pf_list_1_{}".format(addr_type)
3221 }
3222 },
3223 "set": {"metric": 100},
3224 },
3225 {
3226 "action": "permit",
3227 "seq_id": "30",
3228 "match": {
3229 addr_type: {
3230 "prefix_lists": "pf_list_1_{}".format(addr_type)
3231 }
3232 },
3233 "set": {"metric": 200},
3234 },
3235 ]
3236 }
3237 }
3238 }
3239 result = create_route_maps(tgen, input_dict_3)
3240 # tgen.mininet_cli()
3241 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3242 tc_name, result
3243 )
3244
3245 # Configure neighbor for route map
3246 input_dict_4 = {
3247 "r3": {
3248 "bgp": {
3249 "address_family": {
3250 "ipv4": {
3251 "unicast": {
3252 "neighbor": {
3253 "r1": {
3254 "dest_link": {
3255 "r3": {
3256 "route_maps": [
3257 {
3258 "name": "rmap_match_pf_1_ipv4",
3259 "direction": "in",
3260 }
3261 ]
3262 }
3263 }
3264 }
3265 }
3266 }
3267 },
3268 "ipv6": {
3269 "unicast": {
3270 "neighbor": {
3271 "r1": {
3272 "dest_link": {
3273 "r3": {
3274 "route_maps": [
3275 {
3276 "name": "rmap_match_pf_1_ipv6",
3277 "direction": "in",
3278 }
3279 ]
3280 }
3281 }
3282 }
3283 }
3284 }
3285 },
3286 }
3287 }
3288 }
3289 }
3290 result = create_router_bgp(tgen, topo, input_dict_4)
3291 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3292
3293 # Verifying RIB routes
3294 dut = "r3"
3295 protocol = "bgp"
3296 input_dict = topo["routers"]
3297 for addr_type in ADDR_TYPES:
3298 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
3299 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3300 tc_name, result
3301 )
3302
3303 # Verifying BGP set attributes
3304 dut = "r3"
3305 rmap_name = "rmap_match_pf_1"
3306 routes = {
3307 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3308 "ipv6": ["1::1/128", "1::2/128"],
3309 }
3310 seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
3311 for addr_type in ADDR_TYPES:
3312 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
3313 result = verify_bgp_attributes(
3314 tgen,
3315 addr_type,
3316 dut,
3317 routes[addr_type],
3318 rmap_name,
3319 input_dict_3,
3320 seq_id[addr_type],
3321 )
3322 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3323 tc_name, result
3324 )
3325
3326 write_test_footer(tc_name)
3327
3328 # Uncomment next line for debugging
3329 # tgen.mininet_cli()
3330
3331
3332 def test_route_maps_with_call_clause_p0():
3333 """
3334 TC_53:
3335 Verify route-maps call clause functionality.
3336 """
3337 tgen = get_topogen()
3338 global bgp_convergence
3339
3340 if bgp_convergence is not True:
3341 pytest.skip("skipped because of BGP Convergence failure")
3342
3343 # test case name
3344 tc_name = inspect.stack()[0][3]
3345 write_test_header(tc_name)
3346 reset_config_on_routers(tgen)
3347
3348 # Create ip prefix list
3349 input_dict_2 = {
3350 "r3": {
3351 "prefix_lists": {
3352 "ipv4": {
3353 "pf_list_1_ipv4": [
3354 {"seqid": 10, "network": "any", "action": "permit"}
3355 ]
3356 },
3357 "ipv6": {
3358 "pf_list_1_ipv6": [
3359 {"seqid": 100, "network": "any", "action": "permit"}
3360 ]
3361 },
3362 }
3363 }
3364 }
3365 result = create_prefix_lists(tgen, input_dict_2)
3366 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3367
3368 # Create route map
3369 for addr_type in ADDR_TYPES:
3370 input_dict_3 = {
3371 "r3": {
3372 "route_maps": {
3373 "rmap_match_pf_1_{}".format(addr_type): [
3374 {
3375 "action": "permit",
3376 "match": {
3377 addr_type: {
3378 "prefix_lists": "pf_list_1_{}".format(addr_type)
3379 }
3380 },
3381 "set": {"locPrf": 150},
3382 "call": "rmap_match_pf_2_{}".format(addr_type),
3383 }
3384 ],
3385 "rmap_match_pf_2_{}".format(addr_type): [
3386 {
3387 "action": "permit",
3388 "match": {
3389 addr_type: {
3390 "prefix_lists": "pf_list_1_{}".format(addr_type)
3391 }
3392 },
3393 "set": {"metric": 200},
3394 }
3395 ],
3396 }
3397 }
3398 }
3399 result = create_route_maps(tgen, input_dict_3)
3400 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3401 tc_name, result
3402 )
3403
3404 # Configure neighbor for route map
3405 input_dict_4 = {
3406 "r3": {
3407 "bgp": {
3408 "address_family": {
3409 "ipv4": {
3410 "unicast": {
3411 "neighbor": {
3412 "r1": {
3413 "dest_link": {
3414 "r3": {
3415 "route_maps": [
3416 {
3417 "name": "rmap_match_pf_1_ipv4",
3418 "direction": "in",
3419 }
3420 ]
3421 }
3422 }
3423 }
3424 }
3425 }
3426 },
3427 "ipv6": {
3428 "unicast": {
3429 "neighbor": {
3430 "r1": {
3431 "dest_link": {
3432 "r3": {
3433 "route_maps": [
3434 {
3435 "name": "rmap_match_pf_1_ipv6",
3436 "direction": "in",
3437 }
3438 ]
3439 }
3440 }
3441 }
3442 }
3443 }
3444 },
3445 }
3446 }
3447 }
3448 }
3449 result = create_router_bgp(tgen, topo, input_dict_4)
3450 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3451
3452 # Verifying RIB routes
3453 dut = "r3"
3454 protocol = "bgp"
3455 input_dict = topo["routers"]
3456 for addr_type in ADDR_TYPES:
3457 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
3458 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3459 tc_name, result
3460 )
3461
3462 # Verifying BGP set attributes
3463 dut = "r3"
3464 routes = {
3465 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3466 "ipv6": ["1::1/128", "1::2/128"],
3467 }
3468 rmap_name = "rmap_match_pf_1"
3469 for addr_type in ADDR_TYPES:
3470 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
3471 result = verify_bgp_attributes(
3472 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
3473 )
3474 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3475 tc_name, result
3476 )
3477
3478 rmap_name = "rmap_match_pf_2"
3479 for addr_type in ADDR_TYPES:
3480 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
3481 result = verify_bgp_attributes(
3482 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
3483 )
3484 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3485 tc_name, result
3486 )
3487
3488 write_test_footer(tc_name)
3489
3490 # Uncomment next line for debugging
3491 # tgen.mininet_cli()
3492
3493
3494 def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0():
3495 """
3496 TC_58:
3497 Create route map deny inbound and outbound prefixes on
3498 match prefix list and set criteria on match
3499 """
3500 tgen = get_topogen()
3501 global bgp_convergence
3502
3503 if bgp_convergence is not True:
3504 pytest.skip("skipped because of BGP Convergence failure")
3505
3506 # test case name
3507 tc_name = inspect.stack()[0][3]
3508 write_test_header(tc_name)
3509 reset_config_on_routers(tgen)
3510
3511 # Create ip prefix list
3512 input_dict_2 = {
3513 "r3": {
3514 "prefix_lists": {
3515 "ipv4": {
3516 "pf_list_1_ipv4": [
3517 {"seqid": 10, "network": "any", "action": "permit"}
3518 ]
3519 },
3520 "ipv6": {
3521 "pf_list_1_ipv6": [
3522 {"seqid": 100, "network": "any", "action": "permit"}
3523 ]
3524 },
3525 }
3526 }
3527 }
3528 result = create_prefix_lists(tgen, input_dict_2)
3529 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3530
3531 # Create route map
3532 for addr_type in ADDR_TYPES:
3533 input_dict_3 = {
3534 "r3": {
3535 "route_maps": {
3536 "rmap_match_pf_1_{}".format(addr_type): [
3537 {
3538 "action": "deny",
3539 "match": {
3540 addr_type: {
3541 "prefix_lists": "pf_list_1_{}".format(addr_type)
3542 }
3543 },
3544 "set": {
3545 "locPrf": 150,
3546 },
3547 }
3548 ],
3549 "rmap_match_pf_2_{}".format(addr_type): [
3550 {
3551 "action": "deny",
3552 "match": {
3553 addr_type: {
3554 "prefix_lists": "pf_list_1_{}".format(addr_type)
3555 }
3556 },
3557 "set": {"metric": 50},
3558 }
3559 ],
3560 }
3561 }
3562 }
3563 result = create_route_maps(tgen, input_dict_3)
3564 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3565 tc_name, result
3566 )
3567
3568 # Configure neighbor for route map
3569 input_dict_4 = {
3570 "r3": {
3571 "bgp": {
3572 "address_family": {
3573 "ipv4": {
3574 "unicast": {
3575 "neighbor": {
3576 "r1": {
3577 "dest_link": {
3578 "r3": {
3579 "route_maps": [
3580 {
3581 "name": "rmap_match_pf_1_ipv4",
3582 "direction": "in",
3583 }
3584 ]
3585 }
3586 }
3587 },
3588 "r4": {
3589 "dest_link": {
3590 "r3": {
3591 "route_maps": [
3592 {
3593 "name": "rmap_match_pf_2_ipv6",
3594 "direction": "out",
3595 }
3596 ]
3597 }
3598 }
3599 },
3600 }
3601 }
3602 },
3603 "ipv6": {
3604 "unicast": {
3605 "neighbor": {
3606 "r1": {
3607 "dest_link": {
3608 "r3": {
3609 "route_maps": [
3610 {
3611 "name": "rmap_match_pf_1_ipv4",
3612 "direction": "in",
3613 }
3614 ]
3615 }
3616 }
3617 },
3618 "r4": {
3619 "dest_link": {
3620 "r3": {
3621 "route_maps": [
3622 {
3623 "name": "rmap_match_pf_2_ipv6",
3624 "direction": "out",
3625 }
3626 ]
3627 }
3628 }
3629 },
3630 }
3631 }
3632 },
3633 }
3634 }
3635 }
3636 }
3637 result = create_router_bgp(tgen, topo, input_dict_4)
3638 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3639
3640 # Verifying RIB routes
3641 dut = "r3"
3642 protocol = "bgp"
3643 input_dict = topo["routers"]
3644 for addr_type in ADDR_TYPES:
3645 result = verify_rib(
3646 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3647 )
3648 assert result is not True, "Testcase {} : Failed \n"
3649 "routes are not present \n Error: {}".format(tc_name, result)
3650 logger.info("Expected behaviour: {}".format(result))
3651
3652 # Verifying RIB routes
3653 dut = "r4"
3654 protocol = "bgp"
3655 for addr_type in ADDR_TYPES:
3656 result = verify_rib(
3657 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3658 )
3659 assert result is not True, "Testcase {} : Failed \n"
3660 "routes are not present \n Error: {}".format(tc_name, result)
3661 logger.info("Expected behaviour: {}".format(result))
3662
3663 write_test_footer(tc_name)
3664
3665 # Uncomment next line for debugging
3666 # tgen.mininet_cli()
3667
3668
3669 def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0():
3670 """
3671 TC_59:
3672 Create route map to permit inbound prefixes with filter
3673 match tag and set criteria
3674 """
3675 tgen = get_topogen()
3676 global bgp_convergence
3677
3678 if bgp_convergence is not True:
3679 pytest.skip("skipped because of BGP Convergence failure")
3680
3681 # test case name
3682 tc_name = inspect.stack()[0][3]
3683 write_test_header(tc_name)
3684 reset_config_on_routers(tgen)
3685
3686 for addr_type in ADDR_TYPES:
3687 # Create Static routes
3688 input_dict = {
3689 "r1": {
3690 "static_routes": [
3691 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
3692 ]
3693 }
3694 }
3695
3696 result = create_static_routes(tgen, input_dict)
3697 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3698 tc_name, result
3699 )
3700
3701 # Api call to redistribute static routes
3702 input_dict_1 = {
3703 "r1": {
3704 "bgp": {
3705 "local_as": 100,
3706 "address_family": {
3707 "ipv4": {
3708 "unicast": {
3709 "redistribute": [
3710 {"redist_type": "static"},
3711 {"redist_type": "connected"},
3712 ]
3713 }
3714 },
3715 "ipv6": {
3716 "unicast": {
3717 "redistribute": [
3718 {"redist_type": "static"},
3719 {"redist_type": "connected"},
3720 ]
3721 }
3722 },
3723 },
3724 }
3725 }
3726 }
3727
3728 result = create_router_bgp(tgen, topo, input_dict_1)
3729 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3730 tc_name, result
3731 )
3732
3733 # Create route map
3734 input_dict_3 = {
3735 "r1": {
3736 "route_maps": {
3737 "rmap_match_tag_1_{}".format(addr_type): [
3738 {"action": "permit", "match": {addr_type: {"tag": "4001"}}}
3739 ]
3740 }
3741 }
3742 }
3743 result = create_route_maps(tgen, input_dict_3)
3744 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3745 tc_name, result
3746 )
3747
3748 # Configure neighbor for route map
3749 input_dict_4 = {
3750 "r1": {
3751 "bgp": {
3752 "address_family": {
3753 "ipv4": {
3754 "unicast": {
3755 "neighbor": {
3756 "r3": {
3757 "dest_link": {
3758 "r1": {
3759 "route_maps": [
3760 {
3761 "name": "rmap_match_tag_1_ipv4",
3762 "direction": "out",
3763 }
3764 ]
3765 }
3766 }
3767 }
3768 }
3769 }
3770 },
3771 "ipv6": {
3772 "unicast": {
3773 "neighbor": {
3774 "r3": {
3775 "dest_link": {
3776 "r1": {
3777 "route_maps": [
3778 {
3779 "name": "rmap_match_tag_1_ipv6",
3780 "direction": "out",
3781 }
3782 ]
3783 }
3784 }
3785 }
3786 }
3787 }
3788 },
3789 }
3790 }
3791 }
3792 }
3793 result = create_router_bgp(tgen, topo, input_dict_4)
3794 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3795
3796 # Verifying RIB routes
3797 dut = "r3"
3798 protocol = "bgp"
3799
3800 for addr_type in ADDR_TYPES:
3801 input_dict = {
3802 "r1": {
3803 "static_routes": [
3804 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
3805 ]
3806 }
3807 }
3808 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
3809 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3810 tc_name, result
3811 )
3812
3813 write_test_footer(tc_name)
3814
3815 # Uncomment next line for debugging
3816 # tgen.mininet_cli()
3817
3818
3819 def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0():
3820 """
3821 TC_60
3822 Create route map to deny outbound prefixes with filter match tag,
3823 and set criteria
3824 """
3825 tgen = get_topogen()
3826 global bgp_convergence
3827
3828 if bgp_convergence is not True:
3829 pytest.skip("skipped because of BGP Convergence failure")
3830
3831 # test case name
3832 tc_name = inspect.stack()[0][3]
3833 write_test_header(tc_name)
3834 reset_config_on_routers(tgen)
3835
3836 for addr_type in ADDR_TYPES:
3837 # Create Static routes
3838 input_dict = {
3839 "r1": {
3840 "static_routes": [
3841 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
3842 ]
3843 }
3844 }
3845
3846 result = create_static_routes(tgen, input_dict)
3847 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3848 tc_name, result
3849 )
3850
3851 # Api call to redistribute static routes
3852 input_dict_1 = {
3853 "r1": {
3854 "bgp": {
3855 "local_as": 100,
3856 "address_family": {
3857 "ipv4": {
3858 "unicast": {
3859 "redistribute": [
3860 {"redist_type": "static"},
3861 {"redist_type": "connected"},
3862 ]
3863 }
3864 },
3865 "ipv6": {
3866 "unicast": {
3867 "redistribute": [
3868 {"redist_type": "static"},
3869 {"redist_type": "connected"},
3870 ]
3871 }
3872 },
3873 },
3874 }
3875 }
3876 }
3877
3878 result = create_router_bgp(tgen, topo, input_dict_1)
3879 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3880 tc_name, result
3881 )
3882
3883 # Create route map
3884 input_dict_3 = {
3885 "r1": {
3886 "route_maps": {
3887 "rmap_match_tag_1_{}".format(addr_type): [
3888 {"action": "deny", "match": {addr_type: {"tag": "4001"}}}
3889 ]
3890 }
3891 }
3892 }
3893 result = create_route_maps(tgen, input_dict_3)
3894 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3895 tc_name, result
3896 )
3897
3898 # Configure neighbor for route map
3899 input_dict_4 = {
3900 "r1": {
3901 "bgp": {
3902 "address_family": {
3903 "ipv4": {
3904 "unicast": {
3905 "neighbor": {
3906 "r3": {
3907 "dest_link": {
3908 "r1": {
3909 "route_maps": [
3910 {
3911 "name": "rmap_match_tag_1_ipv4",
3912 "direction": "out",
3913 }
3914 ]
3915 }
3916 }
3917 }
3918 }
3919 }
3920 },
3921 "ipv6": {
3922 "unicast": {
3923 "neighbor": {
3924 "r3": {
3925 "dest_link": {
3926 "r1": {
3927 "route_maps": [
3928 {
3929 "name": "rmap_match_tag_1_ipv6",
3930 "direction": "out",
3931 }
3932 ]
3933 }
3934 }
3935 }
3936 }
3937 }
3938 },
3939 }
3940 }
3941 }
3942 }
3943 result = create_router_bgp(tgen, topo, input_dict_4)
3944 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3945
3946 # Verifying RIB routes
3947 dut = "r3"
3948 protocol = "bgp"
3949
3950 for addr_type in ADDR_TYPES:
3951 input_dict = {
3952 "r1": {
3953 "static_routes": [
3954 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
3955 ]
3956 }
3957 }
3958 result = verify_rib(
3959 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3960 )
3961 assert result is not True, "Testcase {} : Failed \n"
3962 "routes are denied \n Error: {}".format(tc_name, result)
3963 logger.info("Expected behaviour: {}".format(result))
3964
3965 write_test_footer(tc_name)
3966
3967 # Uncomment next line for debugging
3968 # tgen.mininet_cli()
3969
3970
3971 if __name__ == "__main__":
3972 args = ["-s"] + sys.argv[1:]
3973 sys.exit(pytest.main(args))