]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.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_topo2.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 Changing route-map configurations(match/set clauses) on
27 the fly it takes immediate effect.
28 2. Verify BGP best path selection algorithm works fine when
29 routes are imported from ISR to default vrf and vice versa.
30 """
31
32 import os
33 import sys
34 import json
35 import time
36 import pytest
37 import platform
38
39 # Save the Current Working Directory to find configuration files.
40 CWD = os.path.dirname(os.path.realpath(__file__))
41 sys.path.append(os.path.join(CWD, "../"))
42 sys.path.append(os.path.join(CWD, "../lib/"))
43
44 # Required to instantiate the topology builder class.
45
46 # pylint: disable=C0413
47 # Import topogen and topotest helpers
48 from lib.topogen import Topogen, get_topogen
49 from lib.topotest import version_cmp
50
51 from lib.common_config import (
52 start_topology,
53 write_test_header,
54 check_address_types,
55 write_test_footer,
56 step,
57 create_route_maps,
58 create_prefix_lists,
59 create_bgp_community_lists,
60 check_router_status,
61 get_frr_ipv6_linklocal,
62 shutdown_bringup_interface,
63 )
64
65 from lib.topolog import logger
66 from lib.bgp import (
67 verify_bgp_convergence,
68 create_router_bgp,
69 verify_bgp_community,
70 verify_bgp_attributes,
71 verify_best_path_as_per_bgp_attribute,
72 verify_bgp_rib,
73 )
74 from lib.topojson import build_topo_from_json, build_config_from_json
75
76 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
77
78 # Global variables
79 NETWORK1_1 = {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"}
80 NETWORK3_3 = {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"}
81 NETWORK3_4 = {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"}
82
83 PREFERRED_NEXT_HOP = "global"
84
85
86 def setup_module(mod):
87 """
88 Sets up the pytest environment
89
90 * `mod`: module name
91 """
92
93 global topo
94 testsuite_run_time = time.asctime(time.localtime(time.time()))
95 logger.info("Testsuite start time: {}".format(testsuite_run_time))
96 logger.info("=" * 40)
97
98 logger.info("Running setup_module to create topology")
99
100 # This function initiates the topology build with Topogen...
101 json_file = "{}/bgp_vrf_dynamic_route_leak_topo2.json".format(CWD)
102 tgen = Topogen(json_file, mod.__name__)
103 topo = tgen.json_topo
104 # ... and here it calls Mininet initialization functions.
105
106 # Starting topology, create tmp files which are loaded to routers
107 # to start daemons and then start routers
108 start_topology(tgen)
109
110 # Run these tests for kernel version 4.19 or above
111 if version_cmp(platform.release(), "4.19") < 0:
112 error_msg = (
113 "BGP vrf dynamic route leak tests will not run "
114 '(have kernel "{}", but it requires >= 4.19)'.format(platform.release())
115 )
116 pytest.skip(error_msg)
117
118 # Creating configuration from JSON
119 build_config_from_json(tgen, topo)
120
121 global BGP_CONVERGENCE
122 global ADDR_TYPES
123 ADDR_TYPES = check_address_types()
124
125 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
126 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
127 BGP_CONVERGENCE
128 )
129
130 logger.info("Running setup_module() done")
131
132
133 def teardown_module():
134 """Teardown the pytest environment"""
135
136 logger.info("Running teardown_module to delete topology")
137
138 tgen = get_topogen()
139
140 # Stop toplogy and Remove tmp files
141 tgen.stop_topology()
142
143 logger.info(
144 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
145 )
146 logger.info("=" * 40)
147
148
149 #####################################################
150 #
151 # Testcases
152 #
153 #####################################################
154
155
156 def test_bgp_best_path_with_dynamic_import_p0(request):
157 """
158 TC6_FUNC_6:
159 1.5.6. Verify BGP best path selection algorithm works fine when
160 routes are imported from ISR to default vrf and vice versa.
161 """
162
163 tgen = get_topogen()
164 tc_name = request.node.name
165 write_test_header(tc_name)
166 build_config_from_json(tgen, topo)
167
168 if tgen.routers_have_failure():
169 check_router_status(tgen)
170
171 for addr_type in ADDR_TYPES:
172
173 step(
174 "Redistribute configured static routes into BGP process" " on R1/R2 and R3"
175 )
176
177 input_dict_1 = {}
178 DUT = ["r1", "r2", "r3", "r4"]
179 VRFS = ["ISR", "ISR", "default", "default"]
180 AS_NUM = [100, 100, 300, 400]
181
182 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
183 temp = {dut: {"bgp": []}}
184 input_dict_1.update(temp)
185
186 temp[dut]["bgp"].append(
187 {
188 "local_as": as_num,
189 "vrf": vrf,
190 "address_family": {
191 addr_type: {
192 "unicast": {"redistribute": [{"redist_type": "static"}]}
193 }
194 },
195 }
196 )
197
198 result = create_router_bgp(tgen, topo, input_dict_1)
199 assert result is True, "Testcase {} :Failed \n Error: {}".format(
200 tc_name, result
201 )
202
203 for addr_type in ADDR_TYPES:
204
205 step("Import from default vrf into vrf ISR on R1 and R2 as below")
206
207 input_dict_vrf = {}
208 DUT = ["r1", "r2"]
209 VRFS = ["ISR", "ISR"]
210 AS_NUM = [100, 100]
211
212 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
213 temp = {dut: {"bgp": []}}
214 input_dict_vrf.update(temp)
215
216 temp[dut]["bgp"].append(
217 {
218 "local_as": as_num,
219 "vrf": vrf,
220 "address_family": {
221 addr_type: {"unicast": {"import": {"vrf": "default"}}}
222 },
223 }
224 )
225
226 result = create_router_bgp(tgen, topo, input_dict_vrf)
227 assert result is True, "Testcase {} : Failed \n Error: {}".format(
228 tc_name, result
229 )
230
231 input_dict_default = {}
232 DUT = ["r1", "r2"]
233 VRFS = ["default", "default"]
234 AS_NUM = [100, 100]
235
236 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
237 temp = {dut: {"bgp": []}}
238 input_dict_default.update(temp)
239
240 temp[dut]["bgp"].append(
241 {
242 "local_as": as_num,
243 "vrf": vrf,
244 "address_family": {
245 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
246 },
247 }
248 )
249
250 result = create_router_bgp(tgen, topo, input_dict_default)
251 assert result is True, "Testcase {} : Failed \n Error: {}".format(
252 tc_name, result
253 )
254
255 step(
256 "Verify ECMP/Next-hop/Imported routes Vs Locally originated "
257 "routes/eBGP routes vs iBGP routes --already covered in almost"
258 " all tests"
259 )
260
261 for addr_type in ADDR_TYPES:
262
263 step("Verify Pre-emption")
264
265 input_routes_r3 = {
266 "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]}
267 }
268
269 intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
270 intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]
271
272 if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
273 nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
274 nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
275 else:
276 nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][addr_type].split("/")[
277 0
278 ]
279 nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][addr_type].split("/")[
280 0
281 ]
282
283 result = verify_bgp_rib(
284 tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r4_r1]
285 )
286 assert result is True, "Testcase {} : Failed \n Error {}".format(
287 tc_name, result
288 )
289
290 step("Shutdown interface connected to r1 from r4:")
291 shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False)
292
293 for addr_type in ADDR_TYPES:
294
295 input_routes_r3 = {
296 "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]}
297 }
298
299 intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
300 intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]
301
302 if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
303 nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
304 nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
305 else:
306 nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][addr_type].split("/")[
307 0
308 ]
309 nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][addr_type].split("/")[
310 0
311 ]
312
313 step("Verify next-hop is changed")
314 result = verify_bgp_rib(
315 tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r3_r1]
316 )
317 assert result is True, "Testcase {} : Failed \n Error {}".format(
318 tc_name, result
319 )
320
321 step("Bringup interface connected to r1 from r4:")
322 shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True)
323
324 for addr_type in ADDR_TYPES:
325
326 input_routes_r3 = {
327 "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]}
328 }
329
330 intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
331 intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]
332
333 if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
334 nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
335 nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
336 else:
337 nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][addr_type].split("/")[
338 0
339 ]
340 nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][addr_type].split("/")[
341 0
342 ]
343
344 step("Verify next-hop is not chnaged aftr shutdown:")
345 result = verify_bgp_rib(
346 tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r3_r1]
347 )
348 assert result is True, "Testcase {} : Failed \n Error {}".format(
349 tc_name, result
350 )
351
352 step("Active-Standby scenario(as-path prepend and Local pref)")
353
354 for addr_type in ADDR_TYPES:
355
356 step("Create prefix-list")
357
358 input_dict_pf = {
359 "r1": {
360 "prefix_lists": {
361 addr_type: {
362 "pf_ls_{}".format(addr_type): [
363 {
364 "seqid": 10,
365 "network": NETWORK3_4[addr_type],
366 "action": "permit",
367 }
368 ]
369 }
370 }
371 }
372 }
373 result = create_prefix_lists(tgen, input_dict_pf)
374 assert result is True, "Testcase {} : Failed \n Error: {}".format(
375 tc_name, result
376 )
377
378 for addr_type in ADDR_TYPES:
379
380 step("Create route-map to match prefix-list and set localpref 500")
381
382 input_dict_rm = {
383 "r1": {
384 "route_maps": {
385 "rmap_PATH1_{}".format(addr_type): [
386 {
387 "action": "permit",
388 "seq_id": 10,
389 "match": {
390 addr_type: {
391 "prefix_lists": "pf_ls_{}".format(addr_type)
392 }
393 },
394 "set": {"locPrf": 500},
395 }
396 ]
397 }
398 }
399 }
400
401 result = create_route_maps(tgen, input_dict_rm)
402 assert result is True, "Testcase {} : Failed \n Error: {}".format(
403 tc_name, result
404 )
405
406 step("Create route-map to match prefix-list and set localpref 600")
407
408 input_dict_rm = {
409 "r1": {
410 "route_maps": {
411 "rmap_PATH2_{}".format(addr_type): [
412 {
413 "action": "permit",
414 "seq_id": 20,
415 "match": {
416 addr_type: {
417 "prefix_lists": "pf_ls_{}".format(addr_type)
418 }
419 },
420 "set": {"locPrf": 600},
421 }
422 ]
423 }
424 }
425 }
426
427 result = create_route_maps(tgen, input_dict_rm)
428 assert result is True, "Testcase {} : Failed \n Error: {}".format(
429 tc_name, result
430 )
431
432 input_dict_rma = {
433 "r1": {
434 "bgp": [
435 {
436 "local_as": "100",
437 "address_family": {
438 addr_type: {
439 "unicast": {
440 "neighbor": {
441 "r3": {
442 "dest_link": {
443 "r1-link1": {
444 "route_maps": [
445 {
446 "name": "rmap_PATH1_{}".format(
447 addr_type
448 ),
449 "direction": "in",
450 }
451 ]
452 }
453 }
454 },
455 "r4": {
456 "dest_link": {
457 "r1-link1": {
458 "route_maps": [
459 {
460 "name": "rmap_PATH2_{}".format(
461 addr_type
462 ),
463 "direction": "in",
464 }
465 ]
466 }
467 }
468 },
469 }
470 }
471 }
472 },
473 }
474 ]
475 }
476 }
477
478 result = create_router_bgp(tgen, topo, input_dict_rma)
479 assert result is True, "Testcase {} : Failed \n Error: {}".format(
480 tc_name, result
481 )
482
483 dut = "r1"
484 attribute = "locPrf"
485
486 for addr_type in ADDR_TYPES:
487
488 step("Verify bestpath is installed as per highest localpref")
489
490 input_routes_r3 = {
491 "r3": {
492 "static_routes": [
493 {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]}
494 ]
495 }
496 }
497
498 result = verify_best_path_as_per_bgp_attribute(
499 tgen, addr_type, dut, input_routes_r3, attribute
500 )
501 assert result is True, "Testcase {} : Failed \n Error: {}".format(
502 tc_name, result
503 )
504
505 for addr_type in ADDR_TYPES:
506
507 step("Create route-map to match prefix-list and set localpref 700")
508
509 input_dict_rm = {
510 "r1": {
511 "route_maps": {
512 "rmap_PATH1_{}".format(addr_type): [
513 {
514 "action": "permit",
515 "seq_id": 10,
516 "match": {
517 addr_type: {
518 "prefix_lists": "pf_ls_{}".format(addr_type)
519 }
520 },
521 "set": {"locPrf": 700},
522 }
523 ]
524 }
525 }
526 }
527
528 result = create_route_maps(tgen, input_dict_rm)
529 assert result is True, "Testcase {} : Failed \n Error: {}".format(
530 tc_name, result
531 )
532
533 for addr_type in ADDR_TYPES:
534
535 step("Verify bestpath is changed as per highest localpref")
536
537 input_routes_r3 = {
538 "r3": {
539 "static_routes": [
540 {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]}
541 ]
542 }
543 }
544
545 result = verify_best_path_as_per_bgp_attribute(
546 tgen, addr_type, dut, input_routes_r3, attribute
547 )
548 assert result is True, "Testcase {} : Failed \n Error: {}".format(
549 tc_name, result
550 )
551
552 for addr_type in ADDR_TYPES:
553
554 step("Create route-map to match prefix-list and set as-path prepend")
555
556 input_dict_rm = {
557 "r1": {
558 "route_maps": {
559 "rmap_PATH2_{}".format(addr_type): [
560 {
561 "action": "permit",
562 "seq_id": 20,
563 "match": {
564 addr_type: {
565 "prefix_lists": "pf_ls_{}".format(addr_type)
566 }
567 },
568 "set": {
569 "localpref": 700,
570 "path": {"as_num": "111", "as_action": "prepend"},
571 },
572 }
573 ]
574 }
575 }
576 }
577
578 result = create_route_maps(tgen, input_dict_rm)
579 assert result is True, "Testcase {} : Failed \n Error: {}".format(
580 tc_name, result
581 )
582
583 attribute = "path"
584
585 for addr_type in ADDR_TYPES:
586
587 step("Verify bestpath is changed as per shortest as-path")
588
589 input_routes_r3 = {
590 "r3": {
591 "static_routes": [
592 {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]}
593 ]
594 }
595 }
596
597 result = verify_best_path_as_per_bgp_attribute(
598 tgen, addr_type, dut, input_routes_r3, attribute
599 )
600 assert result is True, "Testcase {} : Failed \n Error: {}".format(
601 tc_name, result
602 )
603
604 write_test_footer(tc_name)
605
606
607 def test_modify_route_map_match_set_clauses_p1(request):
608 """
609 TC13_CHAOS_4:
610 1.5.13. Verify that Changing route-map configurations(match/set clauses) on
611 the fly it takes immediate effect.
612 """
613
614 tgen = get_topogen()
615 tc_name = request.node.name
616 write_test_header(tc_name)
617 build_config_from_json(tgen, topo)
618
619 if tgen.routers_have_failure():
620 check_router_status(tgen)
621
622 for addr_type in ADDR_TYPES:
623
624 step(
625 "Configure route-map to set community attribute for a specific"
626 "prefix on R1 in vrf ISR"
627 )
628
629 input_dict_pf = {
630 "r1": {
631 "prefix_lists": {
632 addr_type: {
633 "pflist_ABC_{}".format(addr_type): [
634 {
635 "seqid": 10,
636 "network": NETWORK1_1[addr_type],
637 "action": "permit",
638 }
639 ]
640 }
641 }
642 }
643 }
644 result = create_prefix_lists(tgen, input_dict_pf)
645 assert result is True, "Testcase {} : Failed \n Error: {}".format(
646 tc_name, result
647 )
648
649 input_dict_cl = {
650 "r1": {
651 "bgp_community_lists": [
652 {
653 "community_type": "expanded",
654 "action": "permit",
655 "name": "COMM",
656 "value": "100:100",
657 }
658 ]
659 }
660 }
661 result = create_bgp_community_lists(tgen, input_dict_cl)
662 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
663
664 for addr_type in ADDR_TYPES:
665 input_dict_rm = {
666 "r1": {
667 "route_maps": {
668 "rmap_XYZ_{}".format(addr_type): [
669 {
670 "action": "permit",
671 "match": {
672 addr_type: {
673 "prefix_lists": "pflist_ABC_{}".format(addr_type)
674 }
675 },
676 "set": {"community": {"num": "100:100"}},
677 }
678 ]
679 }
680 }
681 }
682 result = create_route_maps(tgen, input_dict_rm)
683 assert result is True, "Testcase {} : Failed \n Error: {}".format(
684 tc_name, result
685 )
686
687 for addr_type in ADDR_TYPES:
688
689 step(
690 "Apply this route-map on R1 to vrf ISR while redistributing the"
691 " prefixes into BGP"
692 )
693
694 input_dict_1 = {}
695 DUT = ["r1"]
696 VRFS = ["ISR"]
697 AS_NUM = [100]
698
699 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
700 temp = {dut: {"bgp": []}}
701 input_dict_1.update(temp)
702
703 temp[dut]["bgp"].append(
704 {
705 "local_as": as_num,
706 "vrf": vrf,
707 "address_family": {
708 addr_type: {
709 "unicast": {
710 "redistribute": [
711 {
712 "redist_type": "static",
713 "attribute": {
714 "route-map": "rmap_XYZ_{}".format(addr_type)
715 },
716 }
717 ]
718 }
719 }
720 },
721 }
722 )
723
724 result = create_router_bgp(tgen, topo, input_dict_1)
725 assert result is True, "Testcase {} :Failed \n Error: {}".format(
726 tc_name, result
727 )
728
729 for addr_type in ADDR_TYPES:
730
731 step(
732 "Configure another route-map for filtering the prefixes based on"
733 " community attribute while importing into default vrf"
734 )
735
736 input_dict_rm = {
737 "r1": {
738 "route_maps": {
739 "rmap_IMP_{}".format(addr_type): [
740 {
741 "action": "permit",
742 "seq_id": 10,
743 "match": {"community_list": {"id": "COMM"}},
744 "set": {"community": {"num": "none"}},
745 }
746 ]
747 }
748 }
749 }
750 result = create_route_maps(tgen, input_dict_rm)
751 assert result is True, "Testcase {} : Failed \n Error: {}".format(
752 tc_name, result
753 )
754
755 for addr_type in ADDR_TYPES:
756
757 step(
758 "Apply the route-map while Importing vrf ISR's prefixes into "
759 "default vrf on router R1:"
760 )
761
762 input_dict_isr = {}
763 DUT = ["r1"]
764 VRFS = ["default"]
765 AS_NUM = [100]
766
767 for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
768 temp = {dut: {"bgp": []}}
769 input_dict_isr.update(temp)
770
771 temp[dut]["bgp"].append(
772 {
773 "local_as": as_num,
774 "vrf": vrf,
775 "address_family": {
776 addr_type: {"unicast": {"import": {"vrf": "ISR"}}}
777 },
778 }
779 )
780
781 temp[dut]["bgp"].append(
782 {
783 "local_as": as_num,
784 "vrf": vrf,
785 "address_family": {
786 addr_type: {
787 "unicast": {
788 "import": {
789 "vrf": "route-map rmap_IMP_{}".format(addr_type)
790 }
791 }
792 }
793 },
794 }
795 )
796
797 result = create_router_bgp(tgen, topo, input_dict_isr)
798 assert result is True, "Testcase {} : Failed \n Error: {}".format(
799 tc_name, result
800 )
801
802 for addr_type in ADDR_TYPES:
803
804 step(
805 "Verify on R1 that only prefixes with community value 100:100"
806 "in vrf ISR are imported to vrf default. While importing, the"
807 " community value has been stripped off:"
808 )
809
810 input_routes_r1 = {
811 "r1": {
812 "static_routes": [
813 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
814 ]
815 }
816 }
817
818 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
819 assert result is True, "Testcase {} : Failed \n Error {}".format(
820 tc_name, result
821 )
822
823 for addr_type in ADDR_TYPES:
824
825 step("Add set clause in route-map IMP:")
826
827 input_dict_rm = {
828 "r1": {
829 "route_maps": {
830 "rmap_IMP_{}".format(addr_type): [
831 {
832 "action": "permit",
833 "seq_id": 10,
834 "match": {"community_list": {"id": "COMM"}},
835 "set": {
836 "large_community": {"num": "100:100:100"},
837 "locPrf": 500,
838 "path": {"as_num": "100 100", "as_action": "prepend"},
839 },
840 }
841 ]
842 }
843 }
844 }
845 result = create_route_maps(tgen, input_dict_rm)
846 assert result is True, "Testcase {} : Failed \n Error: {}".format(
847 tc_name, result
848 )
849
850 for addr_type in ADDR_TYPES:
851
852 step(
853 "Verify that as we continue adding different attributes "
854 "step-by-step in route-map IMP those attributes gets "
855 "attached to prefixes:"
856 )
857
858 input_routes_r1 = {
859 "r1": {
860 "static_routes": [
861 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
862 ]
863 }
864 }
865
866 input_dict_comm = {"largeCommunity": "100:100:100"}
867
868 result = verify_bgp_community(
869 tgen, addr_type, dut, [NETWORK1_1[addr_type]], input_dict_comm
870 )
871 assert result is True, "Testcase {} : Failed \n Error {}".format(
872 tc_name, result
873 )
874
875 input_rmap = {
876 "r1": {
877 "route_maps": {
878 "rmap_IMP_{}".format(addr_type): [{"set": {"locPrf": 500}}]
879 }
880 }
881 }
882
883 result = verify_bgp_attributes(
884 tgen,
885 addr_type,
886 "r1",
887 [NETWORK1_1[addr_type]],
888 rmap_name="rmap_IMP_{}".format(addr_type),
889 input_dict=input_rmap,
890 )
891 assert result is True, "Testcase {} : Failed \n Error: {}".format(
892 tc_name, result
893 )
894
895 step("Change community-list to match a different value then " "100:100.")
896
897 input_dict_cl = {
898 "r1": {
899 "bgp_community_lists": [
900 {
901 "community_type": "expanded",
902 "action": "permit",
903 "name": "COMM",
904 "value": "100:100",
905 "delete": True,
906 }
907 ]
908 }
909 }
910 result = create_bgp_community_lists(tgen, input_dict_cl)
911 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
912
913 for addr_type in ADDR_TYPES:
914
915 input_routes_r1 = {
916 "r1": {
917 "static_routes": [
918 {"network": [NETWORK1_1[addr_type]], "vrf": "default"}
919 ]
920 }
921 }
922
923 result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False)
924 assert (
925 result is not True
926 ), "Testcase {} : Failed \n Error : Routes are still " "present {}".format(
927 tc_name, result
928 )
929
930 write_test_footer(tc_name)
931
932
933 if __name__ == "__main__":
934 args = ["-s"] + sys.argv[1:]
935 sys.exit(pytest.main(args))