]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map/test_route_map_topo1.py
Merge pull request #9561 from idryzhov/bgp-no-router-vrf-default
[mirror_frr.git] / tests / topotests / bgp_route_map / test_route_map_topo1.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 import sys
24 import time
25 import pytest
26 import os
27
28 # Save the Current Working Directory to find configuration files.
29 CWD = os.path.dirname(os.path.realpath(__file__))
30 sys.path.append(os.path.join(CWD, "../"))
31
32 # pylint: disable=C0413
33 # Import topogen and topotest helpers
34 from lib.topogen import Topogen, get_topogen
35
36 # Required to instantiate the topology builder class.
37 from lib.common_config import (
38 start_topology,
39 write_test_header,
40 write_test_footer,
41 verify_rib,
42 create_route_maps,
43 create_static_routes,
44 create_prefix_lists,
45 check_address_types,
46 reset_config_on_routers,
47 )
48 from lib.topolog import logger
49 from lib.bgp import (
50 verify_bgp_convergence,
51 create_router_bgp,
52 verify_bgp_attributes,
53 )
54 from lib.topojson import build_config_from_json
55
56 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
57
58
59 #################################
60 # TOPOLOGY
61 #################################
62 """
63
64 +-------+
65 +------- | R2 |
66 | +-------+
67 | |
68 +-------+ |
69 | R1 | |
70 +-------+ |
71 | |
72 | +-------+ +-------+
73 +---------- | R3 |----------| R4 |
74 +-------+ +-------+
75
76 """
77
78 #################################
79 # TEST SUMMARY
80 #################################
81 """
82 Following tests are covered to test route-map functionality:
83 TC_34:
84 Verify if route-maps is applied in both inbound and
85 outbound direction to same neighbor/interface.
86 TC_36:
87 Test permit/deny statements operation in route-maps with a
88 permutation and combination of permit/deny in prefix-lists
89 TC_35:
90 Test multiple sequence numbers in a single route-map for different
91 match/set clauses.
92 TC_37:
93 Test add/remove route-maps with multiple set
94 clauses and without any match statement.(Set only)
95 TC_38:
96 Test add/remove route-maps with multiple match
97 clauses and without any set statement.(Match only)
98 """
99
100 # Global variables
101 bgp_convergence = False
102 BGP_CONVERGENCE = False
103 ADDR_TYPES = check_address_types()
104
105 # Global variables
106 bgp_convergence = False
107 NETWORK = {"ipv4": ["11.0.20.1/32", "20.0.20.1/32"], "ipv6": ["1::1/128", "2::1/128"]}
108 MASK = {"ipv4": "32", "ipv6": "128"}
109 NEXT_HOP = {"ipv4": "10.0.0.2", "ipv6": "fd00::2"}
110 ADDR_TYPES = check_address_types()
111
112
113 def setup_module(mod):
114 """
115 Sets up the pytest environment
116
117 * `mod`: module name
118 """
119 global ADDR_TYPES
120 testsuite_run_time = time.asctime(time.localtime(time.time()))
121 logger.info("Testsuite start time: {}".format(testsuite_run_time))
122 logger.info("=" * 40)
123
124 logger.info("Running setup_module to create topology")
125
126 # This function initiates the topology build with Topogen...
127 json_file = "{}/bgp_route_map_topo1.json".format(CWD)
128 tgen = Topogen(json_file, mod.__name__)
129 global topo
130 topo = tgen.json_topo
131 # ... and here it calls Mininet initialization functions.
132
133 # Starting topology, create tmp files which are loaded to routers
134 # to start deamons and then start routers
135 start_topology(tgen)
136
137 # Creating configuration from JSON
138 build_config_from_json(tgen, topo)
139
140 # Checking BGP convergence
141 global bgp_convergence
142
143 # Don"t run this test if we have any failure.
144 if tgen.routers_have_failure():
145 pytest.skip(tgen.errors)
146
147 # Api call verify whether BGP is converged
148 bgp_convergence = verify_bgp_convergence(tgen, topo)
149 assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format(
150 bgp_convergence
151 )
152
153 logger.info("Running setup_module() done")
154
155
156 def teardown_module():
157 """
158 Teardown the pytest environment
159
160 * `mod`: module name
161 """
162
163 logger.info("Running teardown_module to delete topology")
164
165 tgen = get_topogen()
166
167 # Stop toplogy and Remove tmp files
168 tgen.stop_topology()
169
170 logger.info(
171 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
172 )
173 logger.info("=" * 40)
174
175
176 def test_route_map_inbound_outbound_same_neighbor_p0(request):
177 """
178 TC_34:
179 Verify if route-maps is applied in both inbound and
180 outbound direction to same neighbor/interface.
181 """
182
183 tc_name = request.node.name
184 write_test_header(tc_name)
185 tgen = get_topogen()
186
187 # Don"t run this test if we have any failure.
188 if tgen.routers_have_failure():
189 pytest.skip(tgen.errors)
190
191 # Creating configuration from JSON
192 reset_config_on_routers(tgen)
193
194 for adt in ADDR_TYPES:
195
196 # Create Static routes
197 input_dict = {
198 "r1": {
199 "static_routes": [
200 {
201 "network": NETWORK[adt][0],
202 "no_of_ip": 9,
203 "next_hop": NEXT_HOP[adt],
204 }
205 ]
206 }
207 }
208
209 result = create_static_routes(tgen, input_dict)
210 assert result is True, "Testcase {} : Failed \n Error: {}".format(
211 tc_name, result
212 )
213
214 # Api call to redistribute static routes
215 input_dict_1 = {
216 "r1": {
217 "bgp": {
218 "local_as": 100,
219 "address_family": {
220 "ipv4": {
221 "unicast": {
222 "redistribute": [
223 {"redist_type": "static"},
224 {"redist_type": "connected"},
225 ]
226 }
227 },
228 "ipv6": {
229 "unicast": {
230 "redistribute": [
231 {"redist_type": "static"},
232 {"redist_type": "connected"},
233 ]
234 }
235 },
236 },
237 }
238 }
239 }
240
241 result = create_router_bgp(tgen, topo, input_dict_1)
242 assert result is True, "Testcase {} : Failed \n Error: {}".format(
243 tc_name, result
244 )
245
246 input_dict_2 = {
247 "r4": {
248 "static_routes": [
249 {
250 "network": NETWORK[adt][1],
251 "no_of_ip": 9,
252 "next_hop": NEXT_HOP[adt],
253 }
254 ]
255 }
256 }
257
258 result = create_static_routes(tgen, input_dict_2)
259 assert result is True, "Testcase {} : Failed \n Error: {}".format(
260 tc_name, result
261 )
262
263 # Api call to redistribute static routes
264 input_dict_5 = {
265 "r1": {
266 "bgp": {
267 "address_family": {
268 "ipv4": {
269 "unicast": {
270 "redistribute": [
271 {"redist_type": "static"},
272 {"redist_type": "connected"},
273 ]
274 }
275 },
276 "ipv6": {
277 "unicast": {
278 "redistribute": [
279 {"redist_type": "static"},
280 {"redist_type": "connected"},
281 ]
282 }
283 },
284 }
285 }
286 }
287 }
288 result = create_router_bgp(tgen, topo, input_dict_5)
289 assert result is True, "Testcase {} : Failed \n Error: {}".format(
290 tc_name, result
291 )
292
293 input_dict_2 = {
294 "r3": {
295 "prefix_lists": {
296 "ipv4": {
297 "pf_list_1_ipv4": [
298 {
299 "seqid": 10,
300 "action": "permit",
301 "network": NETWORK["ipv4"][0],
302 }
303 ],
304 "pf_list_2_ipv4": [
305 {
306 "seqid": 10,
307 "action": "permit",
308 "network": NETWORK["ipv4"][1],
309 }
310 ],
311 },
312 "ipv6": {
313 "pf_list_1_ipv6": [
314 {
315 "seqid": 100,
316 "action": "permit",
317 "network": NETWORK["ipv6"][0],
318 }
319 ],
320 "pf_list_2_ipv6": [
321 {
322 "seqid": 100,
323 "action": "permit",
324 "network": NETWORK["ipv6"][1],
325 }
326 ],
327 },
328 }
329 }
330 }
331 result = create_prefix_lists(tgen, input_dict_2)
332 assert result is True, "Testcase {} : Failed \n Error: {}".format(
333 tc_name, result
334 )
335
336 # Create route map
337 for addr_type in ADDR_TYPES:
338 input_dict_6 = {
339 "r3": {
340 "route_maps": {
341 "rmap_match_tag_1_{}".format(addr_type): [
342 {
343 "action": "deny",
344 "match": {
345 addr_type: {
346 "prefix_lists": "pf_list_1_{}".format(addr_type)
347 }
348 },
349 }
350 ],
351 "rmap_match_tag_2_{}".format(addr_type): [
352 {
353 "action": "permit",
354 "match": {
355 addr_type: {
356 "prefix_lists": "pf_list_2_{}".format(addr_type)
357 }
358 },
359 }
360 ],
361 }
362 }
363 }
364 result = create_route_maps(tgen, input_dict_6)
365 assert result is True, "Testcase {} : Failed \n Error: {}".format(
366 tc_name, result
367 )
368
369 # Configure neighbor for route map
370 input_dict_7 = {
371 "r3": {
372 "bgp": {
373 "address_family": {
374 "ipv4": {
375 "unicast": {
376 "neighbor": {
377 "r4": {
378 "dest_link": {
379 "r3": {
380 "route_maps": [
381 {
382 "name": "rmap_match_tag_1_ipv4",
383 "direction": "in",
384 },
385 {
386 "name": "rmap_match_tag_1_ipv4",
387 "direction": "out",
388 },
389 ]
390 }
391 }
392 }
393 }
394 }
395 },
396 "ipv6": {
397 "unicast": {
398 "neighbor": {
399 "r4": {
400 "dest_link": {
401 "r3": {
402 "route_maps": [
403 {
404 "name": "rmap_match_tag_1_ipv6",
405 "direction": "in",
406 },
407 {
408 "name": "rmap_match_tag_1_ipv6",
409 "direction": "out",
410 },
411 ]
412 }
413 }
414 }
415 }
416 }
417 },
418 }
419 }
420 }
421 }
422
423 result = create_router_bgp(tgen, topo, input_dict_7)
424 assert result is True, "Testcase {} : Failed \n Error: {}".format(
425 tc_name, result
426 )
427
428 for adt in ADDR_TYPES:
429 # Verifying RIB routes
430 dut = "r3"
431 protocol = "bgp"
432 input_dict_2 = {
433 "r4": {
434 "static_routes": [
435 {
436 "network": [NETWORK[adt][1]],
437 "no_of_ip": 9,
438 "next_hop": NEXT_HOP[adt],
439 }
440 ]
441 }
442 }
443
444 result = verify_rib(
445 tgen, adt, dut, input_dict_2, protocol=protocol, expected=False
446 )
447 assert result is not True, (
448 "Testcase {} : Failed \n"
449 "routes are not present in rib \n Error: {}".format(tc_name, result)
450 )
451 logger.info("Expected behaviour: {}".format(result))
452
453 # Verifying RIB routes
454 dut = "r4"
455 input_dict = {
456 "r1": {
457 "static_routes": [
458 {
459 "network": [NETWORK[adt][0]],
460 "no_of_ip": 9,
461 "next_hop": NEXT_HOP[adt],
462 }
463 ]
464 }
465 }
466 result = verify_rib(
467 tgen, adt, dut, input_dict, protocol=protocol, expected=False
468 )
469 assert result is not True, (
470 "Testcase {} : Failed \n "
471 "routes are not present in rib \n Error: {}".format(tc_name, result)
472 )
473 logger.info("Expected behaviour: {}".format(result))
474
475 write_test_footer(tc_name)
476
477
478 @pytest.mark.parametrize(
479 "prefix_action, rmap_action",
480 [("permit", "permit"), ("permit", "deny"), ("deny", "permit"), ("deny", "deny")],
481 )
482 def test_route_map_with_action_values_combination_of_prefix_action_p0(
483 request, prefix_action, rmap_action
484 ):
485 """
486 TC_36:
487 Test permit/deny statements operation in route-maps with a permutation and
488 combination of permit/deny in prefix-lists
489 """
490 tc_name = request.node.name
491 write_test_header(tc_name)
492 tgen = get_topogen()
493
494 # Don"t run this test if we have any failure.
495 if tgen.routers_have_failure():
496 pytest.skip(tgen.errors)
497
498 # Creating configuration from JSON
499 reset_config_on_routers(tgen)
500
501 for adt in ADDR_TYPES:
502 # Create Static routes
503 input_dict = {
504 "r1": {
505 "static_routes": [
506 {
507 "network": NETWORK[adt][0],
508 "no_of_ip": 9,
509 "next_hop": NEXT_HOP[adt],
510 }
511 ]
512 }
513 }
514
515 result = create_static_routes(tgen, input_dict)
516 assert result is True, "Testcase {} : Failed \n Error: {}".format(
517 tc_name, result
518 )
519
520 # Api call to redistribute static routes
521 input_dict_1 = {
522 "r1": {
523 "bgp": {
524 "local_as": 100,
525 "address_family": {
526 "ipv4": {
527 "unicast": {
528 "redistribute": [
529 {"redist_type": "static"},
530 {"redist_type": "connected"},
531 ]
532 }
533 },
534 "ipv6": {
535 "unicast": {
536 "redistribute": [
537 {"redist_type": "static"},
538 {"redist_type": "connected"},
539 ]
540 }
541 },
542 },
543 }
544 }
545 }
546
547 result = create_router_bgp(tgen, topo, input_dict_1)
548 assert result is True, "Testcase {} : Failed \n Error: {}".format(
549 tc_name, result
550 )
551
552 # Permit in perfix list and route-map
553 input_dict_2 = {
554 "r3": {
555 "prefix_lists": {
556 "ipv4": {
557 "pf_list_1_ipv4": [
558 {"seqid": 10, "network": "any", "action": prefix_action}
559 ]
560 },
561 "ipv6": {
562 "pf_list_1_ipv6": [
563 {"seqid": 100, "network": "any", "action": prefix_action}
564 ]
565 },
566 }
567 }
568 }
569 result = create_prefix_lists(tgen, input_dict_2)
570 assert result is True, "Testcase {} : Failed \n Error: {}".format(
571 tc_name, result
572 )
573
574 # Create route map
575 for addr_type in ADDR_TYPES:
576 input_dict_3 = {
577 "r3": {
578 "route_maps": {
579 "rmap_match_pf_1_{}".format(addr_type): [
580 {
581 "action": rmap_action,
582 "match": {
583 addr_type: {
584 "prefix_lists": "pf_list_1_{}".format(addr_type)
585 }
586 },
587 }
588 ]
589 }
590 }
591 }
592 result = create_route_maps(tgen, input_dict_3)
593 assert result is True, "Testcase {} : Failed \n Error: {}".format(
594 tc_name, result
595 )
596
597 # Configure neighbor for route map
598 input_dict_7 = {
599 "r3": {
600 "bgp": {
601 "address_family": {
602 "ipv4": {
603 "unicast": {
604 "neighbor": {
605 "r1": {
606 "dest_link": {
607 "r3": {
608 "route_maps": [
609 {
610 "name": "rmap_match_pf_1_ipv4",
611 "direction": "in",
612 }
613 ]
614 }
615 }
616 }
617 }
618 }
619 },
620 "ipv6": {
621 "unicast": {
622 "neighbor": {
623 "r1": {
624 "dest_link": {
625 "r3": {
626 "route_maps": [
627 {
628 "name": "rmap_match_pf_1_ipv6",
629 "direction": "in",
630 }
631 ]
632 }
633 }
634 }
635 }
636 }
637 },
638 }
639 }
640 }
641 }
642
643 result = create_router_bgp(tgen, topo, input_dict_7)
644 assert result is True, "Testcase {} : Failed \n Error: {}".format(
645 tc_name, result
646 )
647
648 dut = "r3"
649 protocol = "bgp"
650 input_dict_2 = {
651 "r1": {
652 "static_routes": [
653 {
654 "network": [NETWORK[adt][0]],
655 "no_of_ip": 9,
656 "next_hop": NEXT_HOP[adt],
657 }
658 ]
659 }
660 }
661
662 # tgen.mininet_cli()
663 if "deny" in [prefix_action, rmap_action]:
664 result = verify_rib(
665 tgen, adt, dut, input_dict_2, protocol=protocol, expected=False
666 )
667 assert result is not True, (
668 "Testcase {} : Failed \n "
669 "Routes are still present \n Error: {}".format(tc_name, result)
670 )
671 logger.info("Expected behaviour: {}".format(result))
672 else:
673 result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol)
674 assert result is True, "Testcase {} : Failed \n Error: {}".format(
675 tc_name, result
676 )
677
678
679 def test_route_map_multiple_seq_different_match_set_clause_p0(request):
680 """
681 TC_35:
682 Test multiple sequence numbers in a single route-map for different
683 match/set clauses.
684 """
685
686 tgen = get_topogen()
687 # test case name
688 tc_name = request.node.name
689 write_test_header(tc_name)
690
691 # Creating configuration from JSON
692 reset_config_on_routers(tgen)
693
694 for adt in ADDR_TYPES:
695 # Create Static routes
696 input_dict = {
697 "r1": {
698 "static_routes": [
699 {
700 "network": NETWORK[adt][0],
701 "no_of_ip": 1,
702 "next_hop": NEXT_HOP[adt],
703 }
704 ]
705 }
706 }
707 result = create_static_routes(tgen, input_dict)
708 assert result is True, "Testcase {} : Failed \n Error: {}".format(
709 tc_name, result
710 )
711
712 # Api call to redistribute static routes
713 input_dict_1 = {
714 "r1": {
715 "bgp": {
716 "address_family": {
717 "ipv4": {
718 "unicast": {
719 "redistribute": [
720 {"redist_type": "static"},
721 {"redist_type": "connected"},
722 ]
723 }
724 },
725 "ipv6": {
726 "unicast": {
727 "redistribute": [
728 {"redist_type": "static"},
729 {"redist_type": "connected"},
730 ]
731 }
732 },
733 }
734 }
735 }
736 }
737 result = create_router_bgp(tgen, topo, input_dict_1)
738 assert result is True, "Testcase {} : Failed \n Error: {}".format(
739 tc_name, result
740 )
741
742 # Create ip prefix list
743 input_dict_2 = {
744 "r3": {
745 "prefix_lists": {
746 "ipv4": {
747 "pf_list_1_ipv4": [
748 {"seqid": 10, "network": "any", "action": "permit"}
749 ]
750 },
751 "ipv6": {
752 "pf_list_1_ipv6": [
753 {"seqid": 100, "network": "any", "action": "permit"}
754 ]
755 },
756 }
757 }
758 }
759 result = create_prefix_lists(tgen, input_dict_2)
760 assert result is True, "Testcase {} : Failed \n Error: {}".format(
761 tc_name, result
762 )
763
764 # Create route map
765 for addr_type in ADDR_TYPES:
766 input_dict_3 = {
767 "r3": {
768 "route_maps": {
769 "rmap_match_pf_1_{}".format(addr_type): [
770 {
771 "action": "permit",
772 "match": {
773 addr_type: {
774 "prefix_lists": "pf_list_2_{}".format(addr_type)
775 }
776 },
777 "set": {"path": {"as_num": 500}},
778 },
779 {
780 "action": "permit",
781 "match": {
782 addr_type: {
783 "prefix_lists": "pf_list_2_{}".format(addr_type)
784 }
785 },
786 "set": {
787 "locPrf": 150,
788 },
789 },
790 {
791 "action": "permit",
792 "match": {
793 addr_type: {
794 "prefix_lists": "pf_list_1_{}".format(addr_type)
795 }
796 },
797 "set": {"metric": 50},
798 },
799 ]
800 }
801 }
802 }
803 result = create_route_maps(tgen, input_dict_3)
804 assert result is True, "Testcase {} : Failed \n Error: {}".format(
805 tc_name, result
806 )
807
808 # Configure neighbor for route map
809 input_dict_4 = {
810 "r3": {
811 "bgp": {
812 "address_family": {
813 "ipv4": {
814 "unicast": {
815 "neighbor": {
816 "r1": {
817 "dest_link": {
818 "r3": {
819 "route_maps": [
820 {
821 "name": "rmap_match_pf_1_ipv4",
822 "direction": "in",
823 }
824 ]
825 }
826 }
827 },
828 "r4": {
829 "dest_link": {
830 "r3": {
831 "route_maps": [
832 {
833 "name": "rmap_match_pf_1_ipv4",
834 "direction": "out",
835 }
836 ]
837 }
838 }
839 },
840 }
841 }
842 },
843 "ipv6": {
844 "unicast": {
845 "neighbor": {
846 "r1": {
847 "dest_link": {
848 "r3": {
849 "route_maps": [
850 {
851 "name": "rmap_match_pf_1_ipv6",
852 "direction": "in",
853 }
854 ]
855 }
856 }
857 },
858 "r4": {
859 "dest_link": {
860 "r3": {
861 "route_maps": [
862 {
863 "name": "rmap_match_pf_1_ipv6",
864 "direction": "out",
865 }
866 ]
867 }
868 }
869 },
870 }
871 }
872 },
873 }
874 }
875 }
876 }
877 result = create_router_bgp(tgen, topo, input_dict_4)
878 assert result is True, "Testcase {} : Failed \n Error: {}".format(
879 tc_name, result
880 )
881
882 for adt in ADDR_TYPES:
883 # Verifying RIB routes
884 dut = "r3"
885 protocol = "bgp"
886 input_dict = {
887 "r3": {
888 "route_maps": {
889 "rmap_match_pf_list1": [
890 {
891 "set": {
892 "metric": 50,
893 }
894 }
895 ],
896 }
897 }
898 }
899
900 static_routes = [NETWORK[adt][0]]
901
902 time.sleep(2)
903 result = verify_bgp_attributes(
904 tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict
905 )
906 assert result is True, "Test case {} : Failed \n Error: {}".format(
907 tc_name, result
908 )
909
910 dut = "r4"
911 result = verify_bgp_attributes(
912 tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict
913 )
914 assert result is True, "Test case {} : Failed \n Error: {}".format(
915 tc_name, result
916 )
917
918 logger.info("Testcase " + tc_name + " :Passed \n")
919
920 # Uncomment next line for debugging
921 # tgen.mininet_cli()
922
923
924 def test_route_map_set_only_no_match_p0(request):
925 """
926 TC_37:
927 Test add/remove route-maps with multiple set
928 clauses and without any match statement.(Set only)
929 """
930
931 tgen = get_topogen()
932 # test case name
933 tc_name = request.node.name
934 write_test_header(tc_name)
935
936 # Creating configuration from JSON
937 reset_config_on_routers(tgen)
938
939 for adt in ADDR_TYPES:
940 # Create Static routes
941 input_dict = {
942 "r1": {
943 "static_routes": [
944 {
945 "network": NETWORK[adt][0],
946 "no_of_ip": 1,
947 "next_hop": NEXT_HOP[adt],
948 }
949 ]
950 }
951 }
952 result = create_static_routes(tgen, input_dict)
953 assert result is True, "Testcase {} : Failed \n Error: {}".format(
954 tc_name, result
955 )
956
957 # Api call to redistribute static routes
958 input_dict_1 = {
959 "r1": {
960 "bgp": {
961 "address_family": {
962 "ipv4": {
963 "unicast": {
964 "redistribute": [
965 {"redist_type": "static"},
966 {"redist_type": "connected"},
967 ]
968 }
969 },
970 "ipv6": {
971 "unicast": {
972 "redistribute": [
973 {"redist_type": "static"},
974 {"redist_type": "connected"},
975 ]
976 }
977 },
978 }
979 }
980 }
981 }
982 result = create_router_bgp(tgen, topo, input_dict_1)
983 assert result is True, "Testcase {} : Failed \n Error: {}".format(
984 tc_name, result
985 )
986
987 # Create route map
988 input_dict_3 = {
989 "r3": {
990 "route_maps": {
991 "rmap_match_pf_1": [
992 {
993 "action": "permit",
994 "set": {"metric": 50, "locPrf": 150, "weight": 4000},
995 }
996 ]
997 }
998 }
999 }
1000 result = create_route_maps(tgen, input_dict_3)
1001 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1002 tc_name, result
1003 )
1004
1005 # Configure neighbor for route map
1006 input_dict_4 = {
1007 "r3": {
1008 "bgp": {
1009 "address_family": {
1010 "ipv4": {
1011 "unicast": {
1012 "neighbor": {
1013 "r1": {
1014 "dest_link": {
1015 "r3": {
1016 "route_maps": [
1017 {
1018 "name": "rmap_match_pf_1",
1019 "direction": "in",
1020 }
1021 ]
1022 }
1023 }
1024 },
1025 "r4": {
1026 "dest_link": {
1027 "r3": {
1028 "route_maps": [
1029 {
1030 "name": "rmap_match_pf_1",
1031 "direction": "out",
1032 }
1033 ]
1034 }
1035 }
1036 },
1037 }
1038 }
1039 },
1040 "ipv6": {
1041 "unicast": {
1042 "neighbor": {
1043 "r1": {
1044 "dest_link": {
1045 "r3": {
1046 "route_maps": [
1047 {
1048 "name": "rmap_match_pf_1",
1049 "direction": "in",
1050 }
1051 ]
1052 }
1053 }
1054 },
1055 "r4": {
1056 "dest_link": {
1057 "r3": {
1058 "route_maps": [
1059 {
1060 "name": "rmap_match_pf_1",
1061 "direction": "out",
1062 }
1063 ]
1064 }
1065 }
1066 },
1067 }
1068 }
1069 },
1070 }
1071 }
1072 }
1073 }
1074 result = create_router_bgp(tgen, topo, input_dict_4)
1075 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1076 tc_name, result
1077 )
1078
1079 time.sleep(2)
1080 for adt in ADDR_TYPES:
1081 input_dict_4 = {
1082 "r3": {
1083 "route_maps": {
1084 "rmap_match_pf_1": [
1085 {
1086 "action": "permit",
1087 "set": {
1088 "metric": 50,
1089 },
1090 }
1091 ]
1092 }
1093 }
1094 }
1095 # Verifying RIB routes
1096 static_routes = [NETWORK[adt][0]]
1097 result = verify_bgp_attributes(
1098 tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3
1099 )
1100 assert result is True, "Test case {} : Failed \n Error: {}".format(
1101 tc_name, result
1102 )
1103
1104 result = verify_bgp_attributes(
1105 tgen, adt, "r4", static_routes, "rmap_match_pf_1", input_dict_4
1106 )
1107 assert result is True, "Test case {} : Failed \n Error: {}".format(
1108 tc_name, result
1109 )
1110
1111 logger.info("Testcase " + tc_name + " :Passed \n")
1112
1113 # Uncomment next line for debugging
1114 # tgen.mininet_cli()
1115
1116
1117 def test_route_map_match_only_no_set_p0(request):
1118 """
1119 TC_38:
1120 Test add/remove route-maps with multiple match
1121 clauses and without any set statement.(Match only)
1122 """
1123
1124 tgen = get_topogen()
1125 # test case name
1126 tc_name = request.node.name
1127 write_test_header(tc_name)
1128
1129 # Creating configuration from JSON
1130 reset_config_on_routers(tgen)
1131
1132 for adt in ADDR_TYPES:
1133 # Create Static routes
1134 input_dict = {
1135 "r1": {
1136 "static_routes": [
1137 {
1138 "network": NETWORK[adt][0],
1139 "no_of_ip": 1,
1140 "next_hop": NEXT_HOP[adt],
1141 }
1142 ]
1143 }
1144 }
1145 result = create_static_routes(tgen, input_dict)
1146 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1147 tc_name, result
1148 )
1149
1150 # Api call to redistribute static routes
1151 input_dict_1 = {
1152 "r1": {
1153 "bgp": {
1154 "address_family": {
1155 "ipv4": {
1156 "unicast": {
1157 "redistribute": [
1158 {"redist_type": "static"},
1159 {"redist_type": "connected"},
1160 ]
1161 }
1162 },
1163 "ipv6": {
1164 "unicast": {
1165 "redistribute": [
1166 {"redist_type": "static"},
1167 {"redist_type": "connected"},
1168 ]
1169 }
1170 },
1171 }
1172 }
1173 }
1174 }
1175 result = create_router_bgp(tgen, topo, input_dict_1)
1176 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1177 tc_name, result
1178 )
1179
1180 # Create ip prefix list
1181 input_dict_2 = {
1182 "r1": {
1183 "prefix_lists": {
1184 "ipv4": {
1185 "pf_list_1_ipv4": [
1186 {"seqid": 10, "network": "any", "action": "permit"}
1187 ]
1188 },
1189 "ipv6": {
1190 "pf_list_1_ipv6": [
1191 {"seqid": 100, "network": "any", "action": "permit"}
1192 ]
1193 },
1194 }
1195 }
1196 }
1197 result = create_prefix_lists(tgen, input_dict_2)
1198 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1199 tc_name, result
1200 )
1201
1202 # Create route map
1203 for addr_type in ADDR_TYPES:
1204 input_dict_3 = {
1205 "r1": {
1206 "route_maps": {
1207 "rmap_match_pf_1_{}".format(addr_type): [
1208 {
1209 "action": "permit",
1210 "set": {
1211 "metric": 50,
1212 "locPrf": 150,
1213 },
1214 }
1215 ]
1216 }
1217 }
1218 }
1219 result = create_route_maps(tgen, input_dict_3)
1220 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1221 tc_name, result
1222 )
1223
1224 # Configure neighbor for route map
1225 input_dict_4 = {
1226 "r1": {
1227 "bgp": {
1228 "address_family": {
1229 "ipv4": {
1230 "unicast": {
1231 "neighbor": {
1232 "r3": {
1233 "dest_link": {
1234 "r1": {
1235 "route_maps": [
1236 {
1237 "name": "rmap_match_pf_1_ipv4",
1238 "direction": "out",
1239 }
1240 ]
1241 }
1242 }
1243 }
1244 }
1245 }
1246 },
1247 "ipv6": {
1248 "unicast": {
1249 "neighbor": {
1250 "r3": {
1251 "dest_link": {
1252 "r1": {
1253 "route_maps": [
1254 {
1255 "name": "rmap_match_pf_1_ipv6",
1256 "direction": "out",
1257 }
1258 ]
1259 }
1260 }
1261 }
1262 }
1263 }
1264 },
1265 }
1266 }
1267 }
1268 }
1269 result = create_router_bgp(tgen, topo, input_dict_4)
1270 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1271 tc_name, result
1272 )
1273
1274 # Create ip prefix list
1275 input_dict_5 = {
1276 "r3": {
1277 "prefix_lists": {
1278 "ipv4": {
1279 "pf_list_1_ipv4": [
1280 {"seqid": 10, "network": "any", "action": "permit"}
1281 ]
1282 },
1283 "ipv6": {
1284 "pf_list_1_ipv6": [
1285 {"seqid": 100, "network": "any", "action": "permit"}
1286 ]
1287 },
1288 }
1289 }
1290 }
1291 result = create_prefix_lists(tgen, input_dict_5)
1292 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1293 tc_name, result
1294 )
1295
1296 # Create route map
1297 for addr_type in ADDR_TYPES:
1298 input_dict_6 = {
1299 "r3": {
1300 "route_maps": {
1301 "rmap_match_pf_2_{}".format(addr_type): [
1302 {
1303 "action": "permit",
1304 "match": {
1305 addr_type: {
1306 "prefix_lists": "pf_list_1_{}".format(addr_type)
1307 }
1308 },
1309 }
1310 ]
1311 }
1312 }
1313 }
1314 result = create_route_maps(tgen, input_dict_6)
1315 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1316 tc_name, result
1317 )
1318
1319 # Configure neighbor for route map
1320 input_dict_7 = {
1321 "r3": {
1322 "bgp": {
1323 "address_family": {
1324 "ipv4": {
1325 "unicast": {
1326 "neighbor": {
1327 "r1": {
1328 "dest_link": {
1329 "r3": {
1330 "route_maps": [
1331 {
1332 "name": "rmap_match_pf_2_ipv4",
1333 "direction": "in",
1334 }
1335 ]
1336 }
1337 }
1338 },
1339 "r4": {
1340 "dest_link": {
1341 "r3": {
1342 "route_maps": [
1343 {
1344 "name": "rmap_match_pf_2_ipv4",
1345 "direction": "out",
1346 }
1347 ]
1348 }
1349 }
1350 },
1351 }
1352 }
1353 },
1354 "ipv6": {
1355 "unicast": {
1356 "neighbor": {
1357 "r1": {
1358 "dest_link": {
1359 "r3": {
1360 "route_maps": [
1361 {
1362 "name": "rmap_match_pf_2_ipv6",
1363 "direction": "in",
1364 }
1365 ]
1366 }
1367 }
1368 },
1369 "r4": {
1370 "dest_link": {
1371 "r3": {
1372 "route_maps": [
1373 {
1374 "name": "rmap_match_pf_2_ipv6",
1375 "direction": "out",
1376 }
1377 ]
1378 }
1379 }
1380 },
1381 }
1382 }
1383 },
1384 }
1385 }
1386 }
1387 }
1388 result = create_router_bgp(tgen, topo, input_dict_7)
1389 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1390 tc_name, result
1391 )
1392
1393 for adt in ADDR_TYPES:
1394 # Verifying RIB routes
1395 static_routes = [NETWORK[adt][0]]
1396 result = verify_bgp_attributes(
1397 tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3
1398 )
1399 assert result is True, "Test case {} : Failed \n Error: {}".format(
1400 tc_name, result
1401 )
1402
1403
1404 if __name__ == "__main__":
1405 args = ["-s"] + sys.argv[1:]
1406 sys.exit(pytest.main(args))