]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_vrf_dynamic_route_leak / test_bgp_vrf_dynamic_route_leak_topo1.py
1 #!/usr/bin/env python
2
3 #
4 # Copyright (c) 2020 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 """
24 Following tests are covered to test BGP Multi-VRF Dynamic Route Leaking:
25
26 1. Verify that dynamically imported routes are further advertised
27 to iBGP peers(peer in cluster).
28 2. Verify matching a prefix based on community attribute and
29 importing it by stripping off this value
30 3. Verify the route-map operation along with dynamic import command.
31 4. Verifying the JSON outputs for all supported commands
32 """
33
34 import os
35 import sys
36 import time
37 import pytest
38 import platform
39
40 # Save the Current Working Directory to find configuration files.
41 CWD = os.path.dirname(os.path.realpath(__file__))
42 sys.path.append(os.path.join(CWD, "../"))
43 sys.path.append(os.path.join(CWD, "../lib/"))
44
45 # Required to instantiate the topology builder class.
46
47 # pylint: disable=C0413
48 # Import topogen and topotest helpers
49 from lib.topogen import Topogen, get_topogen
50 from lib.topotest import version_cmp
51
52 from lib.common_config import (
53 start_topology,
54 write_test_header,
55 check_address_types,
56 write_test_footer,
57 step,
58 create_route_maps,
59 create_static_routes,
60 create_prefix_lists,
61 create_bgp_community_lists,
62 create_interface_in_kernel,
63 check_router_status,
64 verify_cli_json,
65 verify_fib_routes,
66 )
67
68 from lib.topolog import logger
69 from lib.bgp import (
70 verify_bgp_convergence,
71 create_router_bgp,
72 verify_bgp_community,
73 verify_bgp_rib,
74 )
75 from lib.topojson import build_config_from_json
76
77
78 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
79
80 # Global variables
81 NETWORK1_1 = {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"}
82 NETWORK1_2 = {"ipv4": "11.11.11.11/32", "ipv6": "11:11::11/128"}
83 NETWORK1_3 = {"ipv4": "10.10.10.10/32", "ipv6": "10:10::10/128"}
84 NETWORK1_4 = {"ipv4": "10.10.10.100/32", "ipv6": "10:10::100/128"}
85
86 NETWORK2_1 = {"ipv4": "22.22.22.2/32", "ipv6": "22:22::2/128"}
87 NETWORK2_2 = {"ipv4": "22.22.22.22/32", "ipv6": "22:22::22/128"}
88 NETWORK2_3 = {"ipv4": "20.20.20.20/32", "ipv6": "20:20::20/128"}
89 NETWORK2_4 = {"ipv4": "20.20.20.200/32", "ipv6": "20:20::200/128"}
90
91 NETWORK3_1 = {"ipv4": "30.30.30.3/32", "ipv6": "30:30::3/128"}
92 NETWORK3_2 = {"ipv4": "30.30.30.30/32", "ipv6": "30:30::30/128"}
93 NETWORK3_3 = {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"}
94 NETWORK3_4 = {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"}
95
96 NETWORK4_1 = {"ipv4": "40.40.40.4/32", "ipv6": "40:40::4/128"}
97 NETWORK4_2 = {"ipv4": "40.40.40.40/32", "ipv6": "40:40::40/128"}
98 NETWORK4_3 = {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"}
99 NETWORK4_4 = {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"}
100
101 NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
102 LOOPBACK_1 = {
103 "ipv4": "10.0.0.7/24",
104 "ipv6": "fd00:0:0:1::7/64",
105 }
106 LOOPBACK_2 = {
107 "ipv4": "10.0.0.16/24",
108 "ipv6": "fd00:0:0:3::5/64",
109 }
110 PREFERRED_NEXT_HOP = "global"
111
112
113 def setup_module(mod):
114 """
115 Sets up the pytest environment
116
117 * `mod`: module name
118 """
119
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_vrf_dynamic_route_leak_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 daemons and then start routers
135 start_topology(tgen)
136
137 # Run these tests for kernel version 4.19 or above
138 if version_cmp(platform.release(), "4.19") < 0:
139 error_msg = (
140 "BGP vrf dynamic route leak tests will not run "
141 '(have kernel "{}", but it requires >= 4.19)'.format(platform.release())
142 )
143 pytest.skip(error_msg)
144
145 # Creating configuration from JSON
146 build_config_from_json(tgen, topo)
147
148 global BGP_CONVERGENCE
149 global ADDR_TYPES
150 ADDR_TYPES = check_address_types()
151
152 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
153 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
154 BGP_CONVERGENCE
155 )
156
157 logger.info("Running setup_module() done")
158
159
160 def teardown_module():
161 """Teardown the pytest environment"""
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 #####################################################
177 #
178 # Local APIs
179 #
180 #####################################################
181
182
183 def disable_route_map_to_prefer_global_next_hop(tgen, topo):
184 """
185 This API is to remove prefer global route-map applied on neighbors
186
187 Parameter:
188 ----------
189 * `tgen` : Topogen object
190 * `topo` : Input JSON data
191
192 Returns:
193 --------
194 True/errormsg
195
196 """
197
198 logger.info("Remove prefer-global rmap applied on neighbors")
199 input_dict = {
200 "r1": {
201 "bgp": [
202 {
203 "local_as": "100",
204 "vrf": "ISR",
205 "address_family": {
206 "ipv6": {
207 "unicast": {
208 "neighbor": {
209 "r2": {
210 "dest_link": {
211 "r1-link1": {
212 "route_maps": [
213 {
214 "name": "rmap_global",
215 "direction": "in",
216 "delete": True,
217 }
218 ]
219 }
220 }
221 }
222 }
223 }
224 }
225 },
226 },
227 {
228 "local_as": "100",
229 "address_family": {
230 "ipv6": {
231 "unicast": {
232 "neighbor": {
233 "r3": {
234 "dest_link": {
235 "r1-link1": {
236 "route_maps": [
237 {
238 "name": "rmap_global",
239 "direction": "in",
240 "delete": True,
241 }
242 ]
243 }
244 }
245 }
246 }
247 }
248 }
249 },
250 },
251 {
252 "local_as": "100",
253 "address_family": {
254 "ipv6": {
255 "unicast": {
256 "neighbor": {
257 "r4": {
258 "dest_link": {
259 "r1-link1": {
260 "route_maps": [
261 {
262 "name": "rmap_global",
263 "direction": "in",
264 "delete": True,
265 }
266 ]
267 }
268 }
269 }
270 }
271 }
272 }
273 },
274 },
275 ]
276 },
277 "r2": {
278 "bgp": [
279 {
280 "local_as": "100",
281 "vrf": "ISR",
282 "address_family": {
283 "ipv6": {
284 "unicast": {
285 "neighbor": {
286 "r1": {
287 "dest_link": {
288 "r2-link1": {
289 "route_maps": [
290 {
291 "name": "rmap_global",
292 "direction": "in",
293 "delete": True,
294 }
295 ]
296 }
297 }
298 }
299 }
300 }
301 }
302 },
303 },
304 {
305 "local_as": "100",
306 "address_family": {
307 "ipv6": {
308 "unicast": {
309 "neighbor": {
310 "r3": {
311 "dest_link": {
312 "r2-link1": {
313 "route_maps": [
314 {
315 "name": "rmap_global",
316 "direction": "in",
317 "delete": True,
318 }
319 ]
320 }
321 }
322 }
323 }
324 }
325 }
326 },
327 },
328 {
329 "local_as": "100",
330 "address_family": {
331 "ipv6": {
332 "unicast": {
333 "neighbor": {
334 "r4": {
335 "dest_link": {
336 "r2-link1": {
337 "route_maps": [
338 {
339 "name": "rmap_global",
340 "direction": "in",
341 "delete": True,
342 }
343 ]
344 }
345 }
346 }
347 }
348 }
349 }
350 },
351 },
352 ]
353 },
354 "r3": {
355 "bgp": [
356 {
357 "local_as": "300",
358 "address_family": {
359 "ipv6": {
360 "unicast": {
361 "neighbor": {
362 "r1": {
363 "dest_link": {
364 "r3-link1": {
365 "route_maps": [
366 {
367 "name": "rmap_global",
368 "direction": "in",
369 "delete": True,
370 }
371 ]
372 }
373 }
374 }
375 }
376 }
377 }
378 },
379 },
380 {
381 "local_as": "300",
382 "address_family": {
383 "ipv6": {
384 "unicast": {
385 "neighbor": {
386 "r2": {
387 "dest_link": {
388 "r3-link1": {
389 "route_maps": [
390 {
391 "name": "rmap_global",
392 "direction": "in",
393 "delete": True,
394 }
395 ]
396 }
397 }
398 }
399 }
400 }
401 }
402 },
403 },
404 ]
405 },
406 "r4": {
407 "bgp": [
408 {
409 "local_as": "400",
410 "address_family": {
411 "ipv6": {
412 "unicast": {
413 "neighbor": {
414 "r1": {
415 "dest_link": {
416 "r4-link1": {
417 "route_maps": [
418 {
419 "name": "rmap_global",
420 "direction": "in",
421 "delete": True,
422 }
423 ]
424 }
425 }
426 }
427 }
428 }
429 }
430 },
431 },
432 {
433 "local_as": "400",
434 "address_family": {
435 "ipv6": {
436 "unicast": {
437 "neighbor": {
438 "r2": {
439 "dest_link": {
440 "r4-link1": {
441 "route_maps": [
442 {
443 "name": "rmap_global",
444 "direction": "in",
445 "delete": True,
446 }
447 ]
448 }
449 }
450 }
451 }
452 }
453 }
454 },
455 },
456 ]
457 },
458 }
459
460 result = create_router_bgp(tgen, topo, input_dict)
461 assert result is True, "Testcase :Failed \n Error: {}".format(result)
462
463 return True
464
465
466 #####################################################
467 #
468 # Testcases
469 #
470 #####################################################
471
472
473 def test_dynamic_imported_routes_advertised_to_iBGP_peer_p0(request):
474 """
475 TC5_FUNC_5:
476 1.5.5. Verify that dynamically imported routes are further advertised
477 to iBGP peers(peer in cluster).
478 """
479
480 tgen = get_topogen()
481 tc_name = request.node.name
482 write_test_header(tc_name)
483 build_config_from_json(tgen, topo)
484
485 if tgen.routers_have_failure():
486 check_router_status(tgen)
487
488 for addr_type in ADDR_TYPES:
489
490 step(
491 "Redistribute configured static routes into BGP process" " on R1 and R3/R4"
492 )
493
494 input_dict_1 = {}
495 DUT = ["r1", "r3", "r4"]
496 VRFS = ["default", "default", "default"]
497 AS_NUM = [100, 300, 400]
498
499 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
500 temp = {dut: {"bgp": []}}
501 input_dict_1.update(temp)
502
503 temp[dut]["bgp"].append(
504 {
505 "local_as": as_num,
506 "vrf": vrf,
507 "address_family": {
508 addr_type: {
509 "unicast": {"redistribute": [{"redist_type": "static"}]}
510 }
511 },
512 }
513 )
514
515 result = create_router_bgp(tgen, topo, input_dict_1)
516 assert result is True, "Testcase {} :Failed \n Error: {}".format(
517 tc_name, result
518 )
519
520 for addr_type in ADDR_TYPES:
521
522 step("Verify that R1 receives BGP routes from R3 and R4 in " "vrf default.")
523
524 input_routes_r3 = {
525 "r3": {
526 "static_routes": [
527 {
528 "network": [
529 NETWORK3_1[addr_type],
530 NETWORK3_2[addr_type],
531 NETWORK3_3[addr_type],
532 NETWORK3_4[addr_type],
533 ]
534 }
535 ]
536 }
537 }
538
539 input_routes_r4 = {
540 "r4": {
541 "static_routes": [
542 {
543 "network": [
544 NETWORK4_1[addr_type],
545 NETWORK4_2[addr_type],
546 NETWORK4_3[addr_type],
547 NETWORK4_4[addr_type],
548 ]
549 }
550 ]
551 }
552 }
553
554 DUT = ["r1", "r2"]
555 INPUT_DICT = [input_routes_r3, input_routes_r4]
556
557 for dut, routes in zip(DUT, INPUT_DICT):
558 result = verify_bgp_rib(tgen, addr_type, dut, routes)
559 assert result is True, "Testcase {} : Failed \n Error {}".format(
560 tc_name, result
561 )
562
563 result = verify_fib_routes(tgen, addr_type, dut, routes)
564 assert result is True, "Testcase {} : Failed \n Error {}".format(
565 tc_name, result
566 )
567
568 for addr_type in ADDR_TYPES:
569
570 step("Import from default vrf into vrf ISR on R1")
571
572 input_dict_isr = {}
573 DUT = ["r1", "r2"]
574 VRFS = ["ISR", "ISR"]
575 AS_NUM = [100, 100]
576
577 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
578 temp = {dut: {"bgp": []}}
579 input_dict_isr.update(temp)
580
581 temp[dut]["bgp"].append(
582 {
583 "local_as": as_num,
584 "vrf": vrf,
585 "address_family": {
586 addr_type: {"unicast": {"import": {"vrf": "default"}}}
587 },
588 }
589 )
590
591 result = create_router_bgp(tgen, topo, input_dict_isr)
592 assert result is True, "Testcase {} : Failed \n Error: {}".format(
593 tc_name, result
594 )
595
596 for addr_type in ADDR_TYPES:
597
598 step(
599 "Verify that default vrf's imported routes are installed "
600 "in RIB/FIB of vrf ISR on R1:"
601 )
602
603 input_routes_r3 = {
604 "r3": {
605 "static_routes": [
606 {
607 "network": [
608 NETWORK3_1[addr_type],
609 NETWORK3_2[addr_type],
610 NETWORK3_3[addr_type],
611 NETWORK3_4[addr_type],
612 ],
613 "vrf": "ISR",
614 }
615 ]
616 }
617 }
618
619 input_routes_r4 = {
620 "r4": {
621 "static_routes": [
622 {
623 "network": [
624 NETWORK4_1[addr_type],
625 NETWORK4_2[addr_type],
626 NETWORK4_3[addr_type],
627 NETWORK4_4[addr_type],
628 ],
629 "vrf": "ISR",
630 }
631 ]
632 }
633 }
634
635 INPUT_DICT_VRF = [input_routes_r3, input_routes_r4]
636
637 for routes in INPUT_DICT_VRF:
638 result = verify_bgp_rib(tgen, addr_type, "r1", routes)
639 assert result is True, "Testcase {} : Failed \n Error {}".format(
640 tc_name, result
641 )
642
643 result = verify_fib_routes(tgen, addr_type, "r1", routes)
644 assert result is True, "Testcase {} : Failed \n Error {}".format(
645 tc_name, result
646 )
647
648 intf_r2_r1 = topo["routers"]["r2"]["links"]["r1-link1"]
649 for addr_type in ADDR_TYPES:
650
651 step(
652 "Create a loopback10 interface on R1 with below IP address and "
653 "associate with vrf ISR:"
654 )
655
656 create_interface_in_kernel(
657 tgen,
658 "r1",
659 "loopback2",
660 LOOPBACK_2[addr_type],
661 "ISR",
662 )
663
664 for addr_type in ADDR_TYPES:
665
666 step(
667 "On router R1 Change the next-hop of static routes in vrf "
668 "ISR to LOOPBACK_2"
669 )
670
671 input_routes_r1 = {
672 "r1": {
673 "static_routes": [
674 {
675 "network": [NETWORK1_3[addr_type], NETWORK1_4[addr_type]],
676 "next_hop": "Null0",
677 "delete": True,
678 }
679 ]
680 }
681 }
682
683 result = create_static_routes(tgen, input_routes_r1)
684 assert result is True, "Testcase {} :Failed \n Error: {}".format(
685 tc_name, result
686 )
687
688 input_routes_r1 = {
689 "r1": {
690 "static_routes": [
691 {
692 "network": [NETWORK1_3[addr_type], NETWORK1_4[addr_type]],
693 "next_hop": (intf_r2_r1[addr_type]).split("/")[0],
694 }
695 ]
696 }
697 }
698
699 result = create_static_routes(tgen, input_routes_r1)
700 assert result is True, "Testcase {} :Failed \n Error: {}".format(
701 tc_name, result
702 )
703
704 for addr_type in ADDR_TYPES:
705
706 step(
707 "Verify that, though R1 originating BGP routes with next-hop"
708 " 24.1.1.2/24::1:2, which is local to R2(but in default vrf)"
709 ", R2 must receives and install all routes from R1 in vrf ISR."
710 )
711 step(
712 "Verify on R2, that it now rejects 10.10.10.x routes originated "
713 "from R1. As next-hop IP is local to R2's vrf ISR."
714 )
715
716 input_routes_r1 = {
717 "r1": {
718 "static_routes": [
719 {
720 "network": [NETWORK1_3[addr_type], NETWORK1_4[addr_type]],
721 "vrf": "ISR",
722 }
723 ]
724 }
725 }
726
727 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
728 assert (
729 result is not True
730 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
731 tc_name, result
732 )
733
734 for addr_type in ADDR_TYPES:
735
736 step("On router R1 delete static routes in vrf ISR to LOOPBACK_1")
737
738 input_routes_r1 = {
739 "r1": {
740 "static_routes": [
741 {
742 "network": [NETWORK1_3[addr_type], NETWORK1_4[addr_type]],
743 "next_hop": (intf_r2_r1[addr_type]).split("/")[0],
744 "delete": True,
745 }
746 ]
747 }
748 }
749
750 result = create_static_routes(tgen, input_routes_r1)
751 assert result is True, "Testcase {} :Failed \n Error: {}".format(
752 tc_name, result
753 )
754
755 write_test_footer(tc_name)
756
757
758 def test_dynamic_imported_matching_prefix_based_on_community_list_p0(request):
759 """
760 TC7_FUNC_7:
761 1.5.7. Verify matching a prefix based on community attribute and
762 importing it by stripping off this value
763 """
764
765 tgen = get_topogen()
766 tc_name = request.node.name
767 write_test_header(tc_name)
768 build_config_from_json(tgen, topo)
769
770 if tgen.routers_have_failure():
771 check_router_status(tgen)
772
773 for addr_type in ADDR_TYPES:
774
775 step(
776 "Configure route-map to set community attribute for a specific"
777 "prefix on R1 in vrf ISR"
778 )
779
780 input_dict_pf = {
781 "r1": {
782 "prefix_lists": {
783 addr_type: {
784 "pflist_ABC_{}".format(addr_type): [
785 {
786 "seqid": 10,
787 "network": NETWORK1_1[addr_type],
788 "action": "permit",
789 }
790 ]
791 }
792 }
793 }
794 }
795 result = create_prefix_lists(tgen, input_dict_pf)
796 assert result is True, "Testcase {} : Failed \n Error: {}".format(
797 tc_name, result
798 )
799
800 input_dict_cl = {
801 "r1": {
802 "bgp_community_lists": [
803 {
804 "community_type": "expanded",
805 "action": "permit",
806 "name": "COMM",
807 "value": "100:100",
808 }
809 ]
810 }
811 }
812 result = create_bgp_community_lists(tgen, input_dict_cl)
813 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
814
815 for addr_type in ADDR_TYPES:
816 input_dict_rm = {
817 "r1": {
818 "route_maps": {
819 "rmap_XYZ_{}".format(addr_type): [
820 {
821 "action": "permit",
822 "match": {
823 addr_type: {
824 "prefix_lists": "pflist_ABC_{}".format(addr_type)
825 }
826 },
827 "set": {"community": {"num": "100:100"}},
828 }
829 ]
830 }
831 }
832 }
833 result = create_route_maps(tgen, input_dict_rm)
834 assert result is True, "Testcase {} : Failed \n Error: {}".format(
835 tc_name, result
836 )
837
838 for addr_type in ADDR_TYPES:
839
840 step(
841 "Apply this route-map on R1 to vrf ISR while redistributing the"
842 " prefixes into BGP"
843 )
844
845 input_dict_1 = {}
846 DUT = ["r1"]
847 VRFS = ["ISR"]
848 AS_NUM = [100]
849
850 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
851 temp = {dut: {"bgp": []}}
852 input_dict_1.update(temp)
853
854 temp[dut]["bgp"].append(
855 {
856 "local_as": as_num,
857 "vrf": vrf,
858 "address_family": {
859 addr_type: {
860 "unicast": {
861 "redistribute": [
862 {
863 "redist_type": "static",
864 "attribute": {
865 "route-map": "rmap_XYZ_{}".format(addr_type)
866 },
867 }
868 ]
869 }
870 }
871 },
872 }
873 )
874
875 result = create_router_bgp(tgen, topo, input_dict_1)
876 assert result is True, "Testcase {} :Failed \n Error: {}".format(
877 tc_name, result
878 )
879
880 for addr_type in ADDR_TYPES:
881
882 step(
883 "Configure another route-map for filtering the prefixes based on"
884 " community attribute while importing into default vrf"
885 )
886
887 input_dict_rm = {
888 "r1": {
889 "route_maps": {
890 "rmap_IMP_{}".format(addr_type): [
891 {
892 "action": "permit",
893 "match": {"community_list": {"id": "COMM"}},
894 "set": {"community": {"num": "none"}},
895 }
896 ]
897 }
898 }
899 }
900 result = create_route_maps(tgen, input_dict_rm)
901 assert result is True, "Testcase {} : Failed \n Error: {}".format(
902 tc_name, result
903 )
904
905 for addr_type in ADDR_TYPES:
906
907 step(
908 "Apply the route-map while Importing vrf ISR's prefixes into "
909 "default vrf on router R1:"
910 )
911
912 input_dict_isr = {}
913 DUT = ["r1"]
914 VRFS = ["default"]
915 AS_NUM = [100]
916
917 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
918 temp = {dut: {"bgp": []}}
919 input_dict_isr.update(temp)
920
921 temp[dut]["bgp"].append(
922 {
923 "local_as": as_num,
924 "vrf": vrf,
925 "address_family": {
926 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
927 },
928 }
929 )
930
931 temp[dut]["bgp"].append(
932 {
933 "local_as": as_num,
934 "vrf": vrf,
935 "address_family": {
936 addr_type: {
937 "unicast": {
938 "import": {
939 "vrf": "route-map rmap_IMP_{}".format(addr_type)
940 }
941 }
942 }
943 },
944 }
945 )
946
947 result = create_router_bgp(tgen, topo, input_dict_isr)
948 assert result is True, "Testcase {} : Failed \n Error: {}".format(
949 tc_name, result
950 )
951
952 for addr_type in ADDR_TYPES:
953
954 step(
955 "Verify on R1 that only prefixes with community value 100:100"
956 "in vrf ISR are imported to vrf default. While importing, the"
957 " community value has been stripped off:"
958 )
959
960 input_routes_r1 = {
961 "r1": {
962 "static_routes": [
963 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
964 ]
965 }
966 }
967
968 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
969 assert result is True, "Testcase {} : Failed \n Error {}".format(
970 tc_name, result
971 )
972
973 input_dict_comm = {"community": "100:100"}
974
975 result = verify_bgp_community(
976 tgen,
977 addr_type,
978 dut,
979 [NETWORK1_1[addr_type]],
980 input_dict_comm,
981 expected=False,
982 )
983 assert (
984 result is not True
985 ), "Testcase {} : Failed \n Error: Commnunity is not stipped off, {}".format(
986 tc_name, result
987 )
988
989 for addr_type in ADDR_TYPES:
990
991 step("Remove/re-add route-map XYZ from redistribution.")
992
993 input_dict_1 = {}
994 DUT = ["r1"]
995 VRFS = ["ISR"]
996 AS_NUM = [100]
997
998 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
999 temp = {dut: {"bgp": []}}
1000 input_dict_1.update(temp)
1001
1002 temp[dut]["bgp"].append(
1003 {
1004 "local_as": as_num,
1005 "vrf": vrf,
1006 "address_family": {
1007 addr_type: {
1008 "unicast": {
1009 "redistribute": [
1010 {
1011 "redist_type": "static",
1012 "attribute": {
1013 "route-map": "rmap_XYZ_{}".format(addr_type)
1014 },
1015 "delete": True,
1016 }
1017 ]
1018 }
1019 }
1020 },
1021 }
1022 )
1023
1024 result = create_router_bgp(tgen, topo, input_dict_1)
1025 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1026 tc_name, result
1027 )
1028
1029 for addr_type in ADDR_TYPES:
1030
1031 step(
1032 "Verify that all the routes disappear from vrf default when "
1033 "route-map is removed from redistribution, and appear again "
1034 "when route-map is re-added to redistribution in vrf ISR."
1035 )
1036
1037 input_routes_r1 = {
1038 "r1": {
1039 "static_routes": [
1040 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1041 ]
1042 }
1043 }
1044
1045 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1046 assert (
1047 result is not True
1048 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1049 tc_name, result
1050 )
1051
1052 for addr_type in ADDR_TYPES:
1053
1054 input_dict_1 = {}
1055 DUT = ["r1"]
1056 VRFS = ["ISR"]
1057 AS_NUM = [100]
1058
1059 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1060 temp = {dut: {"bgp": []}}
1061 input_dict_1.update(temp)
1062
1063 temp[dut]["bgp"].append(
1064 {
1065 "local_as": as_num,
1066 "vrf": vrf,
1067 "address_family": {
1068 addr_type: {
1069 "unicast": {
1070 "redistribute": [
1071 {
1072 "redist_type": "static",
1073 "attribute": {
1074 "route-map": "rmap_XYZ_{}".format(addr_type)
1075 },
1076 }
1077 ]
1078 }
1079 }
1080 },
1081 }
1082 )
1083
1084 result = create_router_bgp(tgen, topo, input_dict_1)
1085 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1086 tc_name, result
1087 )
1088
1089 for addr_type in ADDR_TYPES:
1090
1091 input_routes_r1 = {
1092 "r1": {
1093 "static_routes": [
1094 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1095 ]
1096 }
1097 }
1098
1099 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1100 assert result is True, "Testcase {} : Failed \n Error {}".format(
1101 tc_name, result
1102 )
1103
1104 for addr_type in ADDR_TYPES:
1105
1106 step("Remove/re-add route-map IMP form import statement.")
1107
1108 input_dict_isr = {}
1109 DUT = ["r1"]
1110 VRFS = ["default"]
1111 AS_NUM = [100]
1112
1113 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1114 temp = {dut: {"bgp": []}}
1115 input_dict_isr.update(temp)
1116
1117 temp[dut]["bgp"].append(
1118 {
1119 "local_as": as_num,
1120 "vrf": vrf,
1121 "address_family": {
1122 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
1123 },
1124 }
1125 )
1126
1127 temp[dut]["bgp"].append(
1128 {
1129 "local_as": as_num,
1130 "vrf": vrf,
1131 "address_family": {
1132 addr_type: {
1133 "unicast": {
1134 "import": {
1135 "vrf": "route-map rmap_IMP_{}".format(addr_type),
1136 "delete": True,
1137 }
1138 }
1139 }
1140 },
1141 }
1142 )
1143
1144 result = create_router_bgp(tgen, topo, input_dict_isr)
1145 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1146 tc_name, result
1147 )
1148
1149 for addr_type in ADDR_TYPES:
1150
1151 step(
1152 "Verify that when route-map IMP is removed all the prefixes of"
1153 " vrf ISR are imported to vrf default. However when route-map "
1154 "IMP is re-added only 11.11.11.1 and 11:11::1 (with community "
1155 "value) are imported."
1156 )
1157
1158 input_routes_r1 = {
1159 "r1": {
1160 "static_routes": [
1161 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1162 ]
1163 }
1164 }
1165
1166 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1167 assert result is True, "Testcase {} : Failed \n Error {}".format(
1168 tc_name, result
1169 )
1170
1171 for addr_type in ADDR_TYPES:
1172
1173 input_dict_isr = {}
1174 DUT = ["r1"]
1175 VRFS = ["default"]
1176 AS_NUM = [100]
1177
1178 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1179 temp = {dut: {"bgp": []}}
1180 input_dict_isr.update(temp)
1181
1182 temp[dut]["bgp"].append(
1183 {
1184 "local_as": as_num,
1185 "vrf": vrf,
1186 "address_family": {
1187 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
1188 },
1189 }
1190 )
1191
1192 temp[dut]["bgp"].append(
1193 {
1194 "local_as": as_num,
1195 "vrf": vrf,
1196 "address_family": {
1197 addr_type: {
1198 "unicast": {
1199 "import": {
1200 "vrf": "route-map rmap_IMP_{}".format(addr_type)
1201 }
1202 }
1203 }
1204 },
1205 }
1206 )
1207
1208 result = create_router_bgp(tgen, topo, input_dict_isr)
1209 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1210 tc_name, result
1211 )
1212
1213 for addr_type in ADDR_TYPES:
1214
1215 input_routes_r1 = {
1216 "r1": {
1217 "static_routes": [
1218 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1219 ]
1220 }
1221 }
1222
1223 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1224 assert result is True, "Testcase {} : Failed \n Error {}".format(
1225 tc_name, result
1226 )
1227
1228 for addr_type in ADDR_TYPES:
1229
1230 step("Delete/Re-add prefix-list ABC.")
1231
1232 input_dict_pf = {
1233 "r1": {
1234 "prefix_lists": {
1235 addr_type: {
1236 "pflist_ABC_{}".format(addr_type): [
1237 {
1238 "seqid": 10,
1239 "network": NETWORK1_1[addr_type],
1240 "action": "permit",
1241 "delete": True,
1242 }
1243 ]
1244 }
1245 }
1246 }
1247 }
1248 result = create_prefix_lists(tgen, input_dict_pf)
1249 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1250 tc_name, result
1251 )
1252
1253 input_routes_r1 = {
1254 "r1": {
1255 "static_routes": [
1256 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1257 ]
1258 }
1259 }
1260
1261 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1262 assert (
1263 result is not True
1264 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1265 tc_name, result
1266 )
1267
1268 input_dict_pf["r1"]["prefix_lists"][addr_type][
1269 "pflist_ABC_{}".format(addr_type)
1270 ][0]["delete"] = False
1271
1272 result = create_prefix_lists(tgen, input_dict_pf)
1273 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1274 tc_name, result
1275 )
1276
1277 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1278 assert result is True, "Testcase {} : Failed \n Error {}".format(
1279 tc_name, result
1280 )
1281
1282 step("Delete/Re-add community-list COMM.")
1283
1284 input_dict_cl = {
1285 "r1": {
1286 "bgp_community_lists": [
1287 {
1288 "community_type": "expanded",
1289 "action": "permit",
1290 "name": "COMM",
1291 "value": "100:100",
1292 "delete": True,
1293 }
1294 ]
1295 }
1296 }
1297 result = create_bgp_community_lists(tgen, input_dict_cl)
1298 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1299 tc_name, result
1300 )
1301
1302 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1303 assert (
1304 result is not True
1305 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1306 tc_name, result
1307 )
1308
1309 input_dict_cl["r1"]["bgp_community_lists"][0]["delete"] = False
1310
1311 result = create_bgp_community_lists(tgen, input_dict_cl)
1312 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1313 tc_name, result
1314 )
1315
1316 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1317 assert result is True, "Testcase {} : Failed \n Error {}".format(
1318 tc_name, result
1319 )
1320
1321 step("Delete/Re-add route-map XYZ.")
1322
1323 input_dict_rm = {
1324 "r1": {
1325 "route_maps": {
1326 "rmap_XYZ_{}".format(addr_type): [
1327 {
1328 "action": "permit",
1329 "match": {
1330 addr_type: {
1331 "prefix_lists": "pflist_ABC_{}".format(addr_type)
1332 }
1333 },
1334 "set": {"community": {"num": "100:100"}},
1335 "delete": True,
1336 }
1337 ]
1338 }
1339 }
1340 }
1341 result = create_route_maps(tgen, input_dict_rm)
1342 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1343 tc_name, result
1344 )
1345
1346 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1347 assert (
1348 result is not True
1349 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1350 tc_name, result
1351 )
1352
1353 input_dict_rm["r1"]["route_maps"]["rmap_XYZ_{}".format(addr_type)][0][
1354 "delete"
1355 ] = False
1356
1357 result = create_route_maps(tgen, input_dict_rm)
1358 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1359 tc_name, result
1360 )
1361
1362 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1363 assert result is True, "Testcase {} : Failed \n Error {}".format(
1364 tc_name, result
1365 )
1366
1367 step("Delete/Re-add route-map IMP.")
1368
1369 input_dict_rm2 = {
1370 "r1": {
1371 "route_maps": {
1372 "rmap_IMP_{}".format(addr_type): [
1373 {
1374 "action": "permit",
1375 "match": {"community_list": {"id": "COMM"}},
1376 "set": {"community": {"num": "none"}},
1377 "delete": True,
1378 }
1379 ]
1380 }
1381 }
1382 }
1383 result = create_route_maps(tgen, input_dict_rm2)
1384 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1385 tc_name, result
1386 )
1387
1388 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1389 assert (
1390 result is not True
1391 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1392 tc_name, result
1393 )
1394
1395 input_dict_rm2["r1"]["route_maps"]["rmap_IMP_{}".format(addr_type)][0][
1396 "delete"
1397 ] = False
1398
1399 result = create_route_maps(tgen, input_dict_rm2)
1400 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1401 tc_name, result
1402 )
1403
1404 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1405 assert result is True, "Testcase {} : Failed \n Error {}".format(
1406 tc_name, result
1407 )
1408
1409 write_test_footer(tc_name)
1410
1411
1412 def test_routemap_operatons_with_dynamic_import_p0(request):
1413 """
1414 TC8_FUNC_8:
1415 1.5.8. Verify the route-map operation along with dynamic import command.
1416 """
1417
1418 tgen = get_topogen()
1419 tc_name = request.node.name
1420 write_test_header(tc_name)
1421 build_config_from_json(tgen, topo)
1422
1423 if tgen.routers_have_failure():
1424 check_router_status(tgen)
1425
1426 for addr_type in ADDR_TYPES:
1427
1428 step(
1429 "Configure route-map to set community attribute for a specific"
1430 "prefix on R1 in vrf ISR"
1431 )
1432
1433 input_dict_pf = {
1434 "r1": {
1435 "prefix_lists": {
1436 addr_type: {
1437 "pflist_ABC_{}".format(addr_type): [
1438 {
1439 "seqid": 10,
1440 "network": NETWORK1_1[addr_type],
1441 "action": "permit",
1442 }
1443 ]
1444 }
1445 }
1446 }
1447 }
1448 result = create_prefix_lists(tgen, input_dict_pf)
1449 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1450 tc_name, result
1451 )
1452
1453 input_dict_cl = {
1454 "r1": {
1455 "bgp_community_lists": [
1456 {
1457 "community_type": "expanded",
1458 "action": "permit",
1459 "name": "COMM",
1460 "value": "100:100",
1461 }
1462 ]
1463 }
1464 }
1465 result = create_bgp_community_lists(tgen, input_dict_cl)
1466 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1467
1468 for addr_type in ADDR_TYPES:
1469 input_dict_rm = {
1470 "r1": {
1471 "route_maps": {
1472 "rmap_XYZ_{}".format(addr_type): [
1473 {
1474 "action": "permit",
1475 "match": {
1476 addr_type: {
1477 "prefix_lists": "pflist_ABC_{}".format(addr_type)
1478 }
1479 },
1480 "set": {"community": {"num": "100:100"}},
1481 }
1482 ]
1483 }
1484 }
1485 }
1486 result = create_route_maps(tgen, input_dict_rm)
1487 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1488 tc_name, result
1489 )
1490
1491 for addr_type in ADDR_TYPES:
1492
1493 step(
1494 "Apply this route-map on R1 to vrf ISR while redistributing the"
1495 " prefixes into BGP"
1496 )
1497
1498 input_dict_1 = {}
1499 DUT = ["r1"]
1500 VRFS = ["ISR"]
1501 AS_NUM = [100]
1502
1503 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1504 temp = {dut: {"bgp": []}}
1505 input_dict_1.update(temp)
1506
1507 temp[dut]["bgp"].append(
1508 {
1509 "local_as": as_num,
1510 "vrf": vrf,
1511 "address_family": {
1512 addr_type: {
1513 "unicast": {
1514 "redistribute": [
1515 {
1516 "redist_type": "static",
1517 "attribute": {
1518 "route-map": "rmap_XYZ_{}".format(addr_type)
1519 },
1520 }
1521 ]
1522 }
1523 }
1524 },
1525 }
1526 )
1527
1528 result = create_router_bgp(tgen, topo, input_dict_1)
1529 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1530 tc_name, result
1531 )
1532
1533 for addr_type in ADDR_TYPES:
1534
1535 step(
1536 "Configure another route-map for filtering the prefixes based on"
1537 " community attribute while importing into default vrf"
1538 )
1539
1540 input_dict_rm = {
1541 "r1": {
1542 "route_maps": {
1543 "rmap_IMP_{}".format(addr_type): [
1544 {
1545 "action": "permit",
1546 "match": {"community_list": {"id": "COMM"}},
1547 "set": {"community": {"num": "500:500"}},
1548 }
1549 ]
1550 }
1551 }
1552 }
1553 result = create_route_maps(tgen, input_dict_rm)
1554 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1555 tc_name, result
1556 )
1557
1558 for addr_type in ADDR_TYPES:
1559
1560 step(
1561 "Apply the route-map while Importing vrf ISR's prefixes into "
1562 "default vrf on router R1:"
1563 )
1564
1565 input_dict_isr = {}
1566 DUT = ["r1"]
1567 VRFS = ["default"]
1568 AS_NUM = [100]
1569
1570 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1571 temp = {dut: {"bgp": []}}
1572 input_dict_isr.update(temp)
1573
1574 temp[dut]["bgp"].append(
1575 {
1576 "local_as": as_num,
1577 "vrf": vrf,
1578 "address_family": {
1579 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
1580 },
1581 }
1582 )
1583
1584 temp[dut]["bgp"].append(
1585 {
1586 "local_as": as_num,
1587 "vrf": vrf,
1588 "address_family": {
1589 addr_type: {
1590 "unicast": {
1591 "import": {
1592 "vrf": "route-map rmap_IMP_{}".format(addr_type)
1593 }
1594 }
1595 }
1596 },
1597 }
1598 )
1599
1600 result = create_router_bgp(tgen, topo, input_dict_isr)
1601 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1602 tc_name, result
1603 )
1604
1605 for addr_type in ADDR_TYPES:
1606
1607 step(
1608 "Verify on R1 that only prefixes with community value 100:100"
1609 "in vrf ISR are imported to vrf default. While importing, the"
1610 " community value has been stripped off:"
1611 )
1612
1613 input_routes_r1 = {
1614 "r1": {
1615 "static_routes": [
1616 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1617 ]
1618 }
1619 }
1620
1621 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1622 assert result is True, "Testcase {} : Failed \n Error {}".format(
1623 tc_name, result
1624 )
1625
1626 for addr_type in ADDR_TYPES:
1627
1628 step("Applying route-map first followed by import VRF command.")
1629 step(
1630 "Apply the route-map while Importing vrf ISR's prefixes into "
1631 "default vrf on router R1:"
1632 )
1633
1634 input_dict_isr = {}
1635 DUT = ["r1"]
1636 VRFS = ["default"]
1637 AS_NUM = [100]
1638
1639 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1640 temp = {dut: {"bgp": []}}
1641 input_dict_isr.update(temp)
1642
1643 temp[dut]["bgp"].append(
1644 {
1645 "local_as": as_num,
1646 "vrf": vrf,
1647 "address_family": {
1648 addr_type: {
1649 "unicast": {"import": {"vrf": "ISR", "delete": True}}
1650 }
1651 },
1652 }
1653 )
1654
1655 temp[dut]["bgp"].append(
1656 {
1657 "local_as": as_num,
1658 "vrf": vrf,
1659 "address_family": {
1660 addr_type: {
1661 "unicast": {
1662 "import": {
1663 "vrf": "route-map rmap_IMP_{}".format(addr_type)
1664 }
1665 }
1666 }
1667 },
1668 }
1669 )
1670
1671 result = create_router_bgp(tgen, topo, input_dict_isr)
1672 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1673 tc_name, result
1674 )
1675
1676 for addr_type in ADDR_TYPES:
1677
1678 step(
1679 "Verify that until 'import VRF command' is not configured, "
1680 "routes are not imported. After configuring 'import VRF command'"
1681 " repeat step-4 for verification"
1682 )
1683
1684 input_routes_r1 = {
1685 "r1": {
1686 "static_routes": [
1687 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1688 ]
1689 }
1690 }
1691
1692 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1693 assert (
1694 result is not True
1695 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1696 tc_name, result
1697 )
1698
1699 for addr_type in ADDR_TYPES:
1700
1701 input_dict_isr = {}
1702 DUT = ["r1"]
1703 VRFS = ["default"]
1704 AS_NUM = [100]
1705
1706 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1707 temp = {dut: {"bgp": []}}
1708 input_dict_isr.update(temp)
1709
1710 temp[dut]["bgp"].append(
1711 {
1712 "local_as": as_num,
1713 "vrf": vrf,
1714 "address_family": {
1715 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
1716 },
1717 }
1718 )
1719
1720 temp[dut]["bgp"].append(
1721 {
1722 "local_as": as_num,
1723 "vrf": vrf,
1724 "address_family": {
1725 addr_type: {
1726 "unicast": {
1727 "import": {
1728 "vrf": "route-map rmap_IMP_{}".format(addr_type)
1729 }
1730 }
1731 }
1732 },
1733 }
1734 )
1735
1736 result = create_router_bgp(tgen, topo, input_dict_isr)
1737 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1738 tc_name, result
1739 )
1740
1741 for addr_type in ADDR_TYPES:
1742
1743 input_routes_r1 = {
1744 "r1": {
1745 "static_routes": [
1746 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1747 ]
1748 }
1749 }
1750
1751 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1752 assert result is True, "Testcase {} : Failed \n Error {}".format(
1753 tc_name, result
1754 )
1755
1756 for addr_type in ADDR_TYPES:
1757
1758 step("Delete/re-add import vrf ISR command multiple times in default" "vrf.")
1759
1760 input_dict_isr = {}
1761 DUT = ["r1"]
1762 VRFS = ["default"]
1763 AS_NUM = [100]
1764
1765 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
1766 temp = {dut: {"bgp": []}}
1767 input_dict_isr.update(temp)
1768
1769 temp[dut]["bgp"].append(
1770 {
1771 "local_as": as_num,
1772 "vrf": vrf,
1773 "address_family": {
1774 addr_type: {
1775 "unicast": {"import": {"vrf": "ISR", "delete": True}}
1776 }
1777 },
1778 }
1779 )
1780
1781 result = create_router_bgp(tgen, topo, input_dict_isr)
1782 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1783 tc_name, result
1784 )
1785
1786 step(
1787 "Verify that when import vrf ISR command is deleted, "
1788 "all routes of vrf ISR disappear from default vrf and "
1789 "when it's re-configured, repeat step-4 for verification."
1790 )
1791
1792 input_routes_r1 = {
1793 "r1": {
1794 "static_routes": [
1795 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1796 ]
1797 }
1798 }
1799
1800 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1801 assert (
1802 result is not True
1803 ), "Testcase {} : Failed \n Routes are still present, Error {}".format(
1804 tc_name, result
1805 )
1806
1807 input_dict_isr["r1"]["bgp"][0]["address_family"][addr_type]["unicast"][
1808 "import"
1809 ]["delete"] = False
1810
1811 result = create_router_bgp(tgen, topo, input_dict_isr)
1812 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1813 tc_name, result
1814 )
1815
1816 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
1817 assert result is True, "Testcase {} : Failed \n Error {}".format(
1818 tc_name, result
1819 )
1820
1821 for addr_type in ADDR_TYPES:
1822
1823 step(
1824 "Delete and re-configure route-map IMP from global config when "
1825 "import and route-maps are applied in a ISR vrf."
1826 )
1827
1828 input_dict_rm = {
1829 "r1": {
1830 "route_maps": {
1831 "rmap_IMP_{}".format(addr_type): [
1832 {
1833 "action": "permit",
1834 "match": {"community_list": {"id": "COMM"}},
1835 "set": {"community": {"num": "500:500"}},
1836 "delete": True,
1837 }
1838 ]
1839 }
1840 }
1841 }
1842
1843 result = create_route_maps(tgen, input_dict_rm)
1844 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1845 tc_name, result
1846 )
1847
1848 input_routes_r1 = {
1849 "r1": {
1850 "static_routes": [
1851 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
1852 ]
1853 }
1854 }
1855
1856 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
1857 assert (
1858 result is not True
1859 ), "Testcase {} : Failed \n Routes are still present, Error {}".format(
1860 tc_name, result
1861 )
1862
1863 input_dict_rm["r1"]["route_maps"]["rmap_IMP_{}".format(addr_type)][0][
1864 "delete"
1865 ] = False
1866
1867 result = create_route_maps(tgen, input_dict_rm)
1868 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1869 tc_name, result
1870 )
1871
1872 input_dict_comm = {"community": "500:500"}
1873
1874 result = verify_bgp_community(
1875 tgen, addr_type, dut, [NETWORK1_1[addr_type]], input_dict_comm
1876 )
1877 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1878 tc_name, result
1879 )
1880
1881 write_test_footer(tc_name)
1882
1883
1884 def test_verify_cli_json_p1(request):
1885 """
1886 TC8_FUNC_9:
1887 1.5.9. Verifying the JSON outputs for all supported commands:
1888 """
1889
1890 tgen = get_topogen()
1891 tc_name = request.node.name
1892 write_test_header(tc_name)
1893 build_config_from_json(tgen, topo)
1894
1895 if tgen.routers_have_failure():
1896 check_router_status(tgen)
1897
1898 input_dict = {
1899 "r1": {
1900 "cli": [
1901 "show bgp vrf default ipv4 summary",
1902 "show bgp vrf all ipv6 summary",
1903 "show bgp neighbors",
1904 ]
1905 }
1906 }
1907
1908 result = verify_cli_json(tgen, input_dict)
1909 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1910
1911 write_test_footer(tc_name)
1912
1913
1914 if __name__ == "__main__":
1915 args = ["-s"] + sys.argv[1:]
1916 sys.exit(pytest.main(args))