]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py
Merge pull request #8441 from mjstapp/fix_topo_pylint1
[mirror_frr.git] / tests / topotests / bgp_multi_vrf_topo1 / test_bgp_multi_vrf_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:
25
26 FUNC_1:
27 Within each VRF, each address must be unambiguous on DUT.
28 FUNC_2:
29 Different VRFs can have ambiguous/overlapping
30 addresses on DUT.
31 FUNC_3:
32 Create static routes(IPv4+IPv6) associated to specific VRFs
33 and verify on DUT that same prefixes are present in corresponding
34 routing table.
35 FUNC_4_&_5:
36 Each VRF should be mapped with a unique VLAN on DUT
37 for traffic segregation, when using a single physical interface.
38 FUNC_6:
39 Advertise same set of prefixes from different VRFs
40 and verify on remote router that these prefixes are not
41 leaking to each other
42 FUNC_7:
43 Redistribute Static routes and verify on remote routers
44 that routes are advertised within specific VRF instance, which
45 those static routes belong to.
46 FUNC_8:
47 Test end to end traffic isolation based on VRF tables.
48 FUNC_9:
49 Use static routes for inter-vrf communication
50 (route-leaking) on DUT.
51 FUNC_10:
52 Verify intra-vrf and inter-vrf communication between
53 iBGP peers.
54 FUNC_11:
55 Verify intra-vrf and inter-vrf communication
56 between eBGP peers.
57 FUNC_12_a:
58 Configure route-maps within a VRF, to alter BGP attributes.
59 Verify that route-map doesn't affect any other VRF instances'
60 routing on DUT.
61 FUNC_12_b:
62 Configure route-maps within a VRF, to alter BGP attributes.
63 Verify that route-map doesn't affect any other VRF instances'
64 routing on DUT.
65 FUNC_12_c:
66 Configure route-maps within a VRF, to alter BGP attributes.
67 Verify that route-map doesn't affect any other VRF instances'
68 routing on DUT.
69 FUNC_12_d:
70 Configure route-maps within a VRF, to alter BGP attributes.
71 Verify that route-map doesn't affect any other VRF instances'
72 routing on DUT.
73 FUNC_12_e:
74 Configure route-maps within a VRF, to alter BGP attributes.
75 Verify that route-map doesn't affect any other VRF instances'
76 routing on DUT.
77 FUNC_12_f:
78 Configure route-maps within a VRF, to alter BGP attributes.
79 Verify that route-map doesn't affect any other VRF instances'
80 routing on DUT.
81 FUNC_13:
82 Configure a route-map on DUT to match traffic based
83 on a VRF interfaces.
84 FUNC_14:
85 Test VRF-lite with Static+BGP originated routes.
86 FUNC_15:
87 Configure prefix-lists on DUT and apply to BGP peers to
88 permit/deny prefixes.
89 FUNC_16_1:
90 Configure a route-map on DUT to match traffic based various
91 match/set causes.
92 FUNC_16_2:
93 Configure a route-map on DUT to match traffic based various
94 match/set causes.
95 FUNC_16_3:
96 Configure a route-map on DUT to match traffic based various
97 match/set causes.
98 """
99
100 import os
101 import sys
102 import json
103 import time
104 import pytest
105 from copy import deepcopy
106
107 # Save the Current Working Directory to find configuration files.
108 CWD = os.path.dirname(os.path.realpath(__file__))
109 sys.path.append(os.path.join(CWD, "../"))
110 sys.path.append(os.path.join(CWD, "../lib/"))
111
112 # Required to instantiate the topology builder class.
113
114 # pylint: disable=C0413
115 # Import topogen and topotest helpers
116 from lib.topogen import Topogen, get_topogen
117 from mininet.topo import Topo
118 from lib.topotest import iproute2_is_vrf_capable
119 from lib.common_config import (
120 step,
121 verify_rib,
122 start_topology,
123 write_test_header,
124 check_address_types,
125 write_test_footer,
126 reset_config_on_routers,
127 create_route_maps,
128 create_static_routes,
129 create_prefix_lists,
130 create_interface_in_kernel,
131 create_bgp_community_lists,
132 check_router_status,
133 apply_raw_config,
134 required_linux_kernel_version,
135 )
136
137 from lib.topolog import logger
138 from lib.bgp import (
139 clear_bgp,
140 verify_bgp_rib,
141 create_router_bgp,
142 verify_bgp_community,
143 verify_bgp_convergence,
144 verify_best_path_as_per_bgp_attribute,
145 )
146 from lib.topojson import build_topo_from_json, build_config_from_json
147
148 # Reading the data from JSON File for topology creation
149 jsonFile = "{}/bgp_multi_vrf_topo1.json".format(CWD)
150
151 try:
152 with open(jsonFile, "r") as topoJson:
153 topo = json.load(topoJson)
154 except IOError:
155 assert False, "Could not read file {}".format(jsonFile)
156
157 # Global variables
158 NETWORK1_1 = {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"}
159 NETWORK1_2 = {"ipv4": "1.1.1.2/32", "ipv6": "1::2/128"}
160 NETWORK2_1 = {"ipv4": "2.1.1.1/32", "ipv6": "2::1/128"}
161 NETWORK2_2 = {"ipv4": "2.1.1.2/32", "ipv6": "2::2/128"}
162 NETWORK3_1 = {"ipv4": "3.1.1.1/32", "ipv6": "3::1/128"}
163 NETWORK3_2 = {"ipv4": "3.1.1.2/32", "ipv6": "3::2/128"}
164 NETWORK4_1 = {"ipv4": "4.1.1.1/32", "ipv6": "4::1/128"}
165 NETWORK4_2 = {"ipv4": "4.1.1.2/32", "ipv6": "4::2/128"}
166 NETWORK5_1 = {"ipv4": "5.1.1.1/32", "ipv6": "5::1/128"}
167 NETWORK5_2 = {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"}
168 NETWORK6_1 = {"ipv4": "6.1.1.1/32", "ipv6": "6::1/128"}
169 NETWORK6_2 = {"ipv4": "6.1.1.2/32", "ipv6": "6::2/128"}
170 NETWORK7_1 = {"ipv4": "7.1.1.1/32", "ipv6": "7::1/128"}
171 NETWORK7_2 = {"ipv4": "7.1.1.2/32", "ipv6": "7::2/128"}
172 NETWORK8_1 = {"ipv4": "8.1.1.1/32", "ipv6": "8::1/128"}
173 NETWORK8_2 = {"ipv4": "8.1.1.2/32", "ipv6": "8::2/128"}
174
175 NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
176
177 LOOPBACK_1 = {
178 "ipv4": "10.10.10.10/32",
179 "ipv6": "10::10:10/128",
180 "ipv4_mask": "255.255.255.255",
181 "ipv6_mask": None,
182 }
183 LOOPBACK_2 = {
184 "ipv4": "20.20.20.20/32",
185 "ipv6": "20::20:20/128",
186 "ipv4_mask": "255.255.255.255",
187 "ipv6_mask": None,
188 }
189
190
191 class CreateTopo(Topo):
192 """
193 Test BasicTopo - topology 1
194
195 * `Topo`: Topology object
196 """
197
198 def build(self, *_args, **_opts):
199 """Build function"""
200 tgen = get_topogen(self)
201
202 # Building topology from json file
203 build_topo_from_json(tgen, topo)
204
205
206 def setup_module(mod):
207 """
208 Sets up the pytest environment
209
210 * `mod`: module name
211 """
212 # Required linux kernel version for this suite to run.
213 result = required_linux_kernel_version("4.15")
214 if result is not True:
215 pytest.skip("Kernel requirements are not met")
216
217 # iproute2 needs to support VRFs for this suite to run.
218 if not iproute2_is_vrf_capable():
219 pytest.skip("Installed iproute2 version does not support VRFs")
220
221 testsuite_run_time = time.asctime(time.localtime(time.time()))
222 logger.info("Testsuite start time: {}".format(testsuite_run_time))
223 logger.info("=" * 40)
224
225 logger.info("Running setup_module to create topology")
226
227 # This function initiates the topology build with Topogen...
228 tgen = Topogen(CreateTopo, mod.__name__)
229 # ... and here it calls Mininet initialization functions.
230
231 # Starting topology, create tmp files which are loaded to routers
232 # to start deamons and then start routers
233 start_topology(tgen)
234
235 # Creating configuration from JSON
236 build_config_from_json(tgen, topo)
237
238 global BGP_CONVERGENCE
239 global ADDR_TYPES
240 ADDR_TYPES = check_address_types()
241
242 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
243 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
244 BGP_CONVERGENCE
245 )
246
247 logger.info("Running setup_module() done")
248
249
250 def teardown_module():
251 """Teardown the pytest environment"""
252
253 logger.info("Running teardown_module to delete topology")
254
255 tgen = get_topogen()
256
257 # Stop toplogy and Remove tmp files
258 tgen.stop_topology()
259
260 logger.info(
261 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
262 )
263 logger.info("=" * 40)
264
265
266 #####################################################
267 #
268 # Testcases
269 #
270 #####################################################
271
272
273 def test_address_unambiguous_within_each_vrf_p0(request):
274 """
275 FUNC_1:
276 Within each VRF, each address must be unambiguous on DUT.
277 """
278
279 tgen = get_topogen()
280 tc_name = request.node.name
281 write_test_header(tc_name)
282
283 if tgen.routers_have_failure():
284 check_router_status(tgen)
285
286 step("Configure a set of static routes(IPv4+IPv6) in " "RED_A on router RED-1")
287
288 for addr_type in ADDR_TYPES:
289 input_dict_1 = {
290 "red1": {
291 "static_routes": [
292 {
293 "network": NETWORK1_1[addr_type],
294 "next_hop": NEXT_HOP_IP[addr_type],
295 "vrf": "RED_A",
296 }
297 ]
298 }
299 }
300 result = create_static_routes(tgen, input_dict_1)
301 assert result is True, "Testcase {} : Failed \n Error: {}".format(
302 tc_name, result
303 )
304
305 step(
306 "Configure the same static routes(IPv4+IPv6) with a TAG value"
307 "of 500 in RED_A on router RED-1"
308 )
309
310 for addr_type in ADDR_TYPES:
311 input_dict_2 = {
312 "red1": {
313 "static_routes": [
314 {
315 "network": NETWORK1_1[addr_type],
316 "next_hop": NEXT_HOP_IP[addr_type],
317 "tag": 500,
318 "vrf": "RED_A",
319 }
320 ]
321 }
322 }
323 result = create_static_routes(tgen, input_dict_2)
324 assert result is True, "Testcase {} : Failed \n Error: {}".format(
325 tc_name, result
326 )
327
328 step("Redistribute static..")
329
330 input_dict_3 = {
331 "red1": {
332 "bgp": {
333 "local_as": "500",
334 "vrf": "RED_A",
335 "address_family": {
336 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
337 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
338 },
339 }
340 }
341 }
342
343 result = create_router_bgp(tgen, topo, input_dict_3)
344 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
345
346 step(
347 "Verify that static routes(IPv4+IPv6) is overridden and doesn't"
348 " have duplicate entries within VRF RED_A on router RED-1"
349 )
350
351 for addr_type in ADDR_TYPES:
352 dut = "red1"
353 input_dict_2 = {
354 "red1": {
355 "static_routes": [
356 {
357 "network": NETWORK1_1[addr_type],
358 "next_hop": NEXT_HOP_IP[addr_type],
359 "tag": 500,
360 "vrf": "RED_A",
361 }
362 ]
363 }
364 }
365
366 result = verify_rib(tgen, addr_type, dut, input_dict_2, tag=500)
367 assert result is True, "Testcase {} : Failed \n Error {}".format(
368 tc_name, result
369 )
370
371 step("Make sure routes are not present in global routing table")
372
373 for addr_type in ADDR_TYPES:
374 dut = "red1"
375 input_dict_2 = {
376 "red1": {
377 "static_routes": [
378 {
379 "network": NETWORK1_1[addr_type],
380 "next_hop": NEXT_HOP_IP[addr_type],
381 }
382 ]
383 }
384 }
385
386 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
387 assert result is not True, (
388 "Testcase {} : Failed \n Expected Behaviour: Routes are not "
389 "present on Global Routing table \n Error {}".format(tc_name, result)
390 )
391
392 write_test_footer(tc_name)
393
394
395 def test_ambiguous_overlapping_addresses_in_different_vrfs_p0(request):
396 """
397 FUNC_2:
398 Different VRFs can have ambiguous/overlapping
399 addresses on DUT.
400 """
401
402 tgen = get_topogen()
403 tc_name = request.node.name
404 write_test_header(tc_name)
405 reset_config_on_routers(tgen)
406
407 if tgen.routers_have_failure():
408 check_router_status(tgen)
409
410 step("Configure a set of static routes(IPv4+IPv6) in vrf RED_A" "on router RED-1")
411
412 for addr_type in ADDR_TYPES:
413 input_dict_1 = {
414 "red1": {
415 "static_routes": [
416 {
417 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
418 "next_hop": NEXT_HOP_IP[addr_type],
419 "vrf": "RED_A",
420 }
421 ]
422 }
423 }
424 result = create_static_routes(tgen, input_dict_1)
425 assert result is True, "Testcase {} : Failed \n Error: {}".format(
426 tc_name, result
427 )
428
429 step(
430 "Configure the same static routes(IPv4+IPv6) with a"
431 " TAG value of 500 in vrf RED_B on router RED-1"
432 )
433
434 for addr_type in ADDR_TYPES:
435 input_dict_2 = {
436 "red1": {
437 "static_routes": [
438 {
439 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
440 "next_hop": NEXT_HOP_IP[addr_type],
441 "tag": 500,
442 "vrf": "RED_B",
443 }
444 ]
445 }
446 }
447 result = create_static_routes(tgen, input_dict_2)
448 assert result is True, "Testcase {} : Failed \n Error: {}".format(
449 tc_name, result
450 )
451
452 step("Redistribute static..")
453
454 input_dict_3 = {}
455 for dut in ["red1"]:
456 temp = {dut: {"bgp": []}}
457 input_dict_3.update(temp)
458
459 if "red" in dut:
460 VRFS = ["RED_A", "RED_B"]
461 AS_NUM = [500, 500]
462 elif "blue" in dut:
463 VRFS = ["BLUE_A", "BLUE_B"]
464 AS_NUM = [800, 800]
465
466 for vrf, as_num in zip(VRFS, AS_NUM):
467 temp[dut]["bgp"].append(
468 {
469 "local_as": as_num,
470 "vrf": vrf,
471 "address_family": {
472 "ipv4": {
473 "unicast": {"redistribute": [{"redist_type": "static"}]}
474 },
475 "ipv6": {
476 "unicast": {"redistribute": [{"redist_type": "static"}]}
477 },
478 },
479 }
480 )
481
482 result = create_router_bgp(tgen, topo, input_dict_3)
483 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
484
485 step("Verify that RED_A has the static routes without any" " TAG value")
486
487 for addr_type in ADDR_TYPES:
488 dut = "red1"
489 input_dict_1 = {
490 "red1": {
491 "static_routes": [
492 {
493 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
494 "next_hop": NEXT_HOP_IP[addr_type],
495 "vrf": "RED_A",
496 }
497 ]
498 }
499 }
500
501 result = verify_rib(tgen, addr_type, dut, input_dict_1)
502 assert result is True, "Testcase {} : Failed \n Error {}".format(
503 tc_name, result
504 )
505
506 result = verify_rib(tgen, addr_type, dut, input_dict_1, tag=500, expected=False)
507 assert result is not True, (
508 "Testcase {} : Failed \n "
509 "Routes are present with tag value 500 \n Error: {}".format(tc_name, result)
510 )
511 logger.info("Expected Behavior: {}".format(result))
512
513 step(
514 "Verify that RED_B has the same routes with TAG value "
515 "500 on same device RED-1"
516 )
517
518 for addr_type in ADDR_TYPES:
519 dut = "red1"
520 input_dict_2 = {
521 "red1": {
522 "static_routes": [
523 {
524 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
525 "next_hop": NEXT_HOP_IP[addr_type],
526 "tag": 500,
527 "vrf": "RED_B",
528 }
529 ]
530 }
531 }
532
533 result = verify_rib(tgen, addr_type, dut, input_dict_2, tag=500)
534 assert result is True, "Testcase {} : Failed \n Error {}".format(
535 tc_name, result
536 )
537
538 step("Make sure routes are not present in global routing table")
539
540 for addr_type in ADDR_TYPES:
541 dut = "red1"
542 input_dict_2 = {
543 "red1": {
544 "static_routes": [
545 {
546 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
547 "next_hop": NEXT_HOP_IP[addr_type],
548 }
549 ]
550 }
551 }
552
553 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
554 assert result is not True, (
555 "Testcase {} : Failed \n Expected Behaviour: Routes are not "
556 "present on Global Routing table \n Error {}".format(tc_name, result)
557 )
558
559 write_test_footer(tc_name)
560
561
562 def test_static_routes_associated_to_specific_vrfs_p0(request):
563 """
564 FUNC_3:
565 Create static routes(IPv4+IPv6) associated to specific VRFs
566 and verify on DUT that same prefixes are present in corresponding
567 routing table.
568 """
569
570 tgen = get_topogen()
571 tc_name = request.node.name
572 write_test_header(tc_name)
573 reset_config_on_routers(tgen)
574
575 if tgen.routers_have_failure():
576 check_router_status(tgen)
577
578 step(
579 "Configure a set of unique static(IPv4+IPv6) routes in vrf"
580 " RED_A on router RED-1"
581 )
582
583 for addr_type in ADDR_TYPES:
584 input_dict_1 = {
585 "red1": {
586 "static_routes": [
587 {
588 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
589 "next_hop": NEXT_HOP_IP[addr_type],
590 "vrf": "RED_A",
591 },
592 {
593 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
594 "next_hop": NEXT_HOP_IP[addr_type],
595 "vrf": "RED_B",
596 },
597 ]
598 }
599 }
600 result = create_static_routes(tgen, input_dict_1)
601 assert result is True, "Testcase {} : Failed \n Error: {}".format(
602 tc_name, result
603 )
604
605 step(
606 "Configure set of unique static routes(IPv4+IPv6) in vrf "
607 "RED_B on router RED-1"
608 )
609
610 for addr_type in ADDR_TYPES:
611 input_dict_2 = {
612 "blue1": {
613 "static_routes": [
614 {
615 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
616 "next_hop": NEXT_HOP_IP[addr_type],
617 "vrf": "BLUE_A",
618 },
619 {
620 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
621 "next_hop": NEXT_HOP_IP[addr_type],
622 "vrf": "BLUE_B",
623 },
624 ]
625 }
626 }
627 result = create_static_routes(tgen, input_dict_2)
628 assert result is True, "Testcase {} : Failed \n Error: {}".format(
629 tc_name, result
630 )
631
632 step("Redistribute static..")
633
634 input_dict_3 = {}
635 for dut in ["red1", "blue1"]:
636 temp = {dut: {"bgp": []}}
637 input_dict_3.update(temp)
638
639 if "red" in dut:
640 VRFS = ["RED_A", "RED_B"]
641 AS_NUM = [500, 500]
642 elif "blue" in dut:
643 VRFS = ["BLUE_A", "BLUE_B"]
644 AS_NUM = [800, 800]
645
646 for vrf, as_num in zip(VRFS, AS_NUM):
647 temp[dut]["bgp"].append(
648 {
649 "local_as": as_num,
650 "vrf": vrf,
651 "address_family": {
652 "ipv4": {
653 "unicast": {"redistribute": [{"redist_type": "static"}]}
654 },
655 "ipv6": {
656 "unicast": {"redistribute": [{"redist_type": "static"}]}
657 },
658 },
659 }
660 )
661
662 result = create_router_bgp(tgen, topo, input_dict_3)
663 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
664
665 step(
666 "Verify that static routes 1.x.x.x/32 and 1::x/128 appear " "in VRF RED_A table"
667 )
668 step(
669 "Verify that static routes 2.x.x.x/32 and 2::x/128 appear " "in VRF RED_B table"
670 )
671
672 for addr_type in ADDR_TYPES:
673 dut = "red1"
674 input_dict_1 = {
675 "red1": {
676 "static_routes": [
677 {
678 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
679 "next_hop": NEXT_HOP_IP[addr_type],
680 "vrf": "RED_A",
681 },
682 {
683 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
684 "next_hop": NEXT_HOP_IP[addr_type],
685 "vrf": "RED_B",
686 },
687 ]
688 }
689 }
690
691 result = verify_rib(tgen, addr_type, dut, input_dict_1)
692 assert result is True, "Testcase {} : Failed \n Error {}".format(
693 tc_name, result
694 )
695
696 step(
697 "Verify that static routes 1.x.x.x/32 and 1::x/128 appear "
698 "in VRF BLUE_A table"
699 )
700 step(
701 "Verify that static routes 2.x.x.x/32 and 2::x/128 appear "
702 "in VRF BLUE_B table"
703 )
704
705 for addr_type in ADDR_TYPES:
706 dut = "blue1"
707 input_dict_2 = {
708 "blue1": {
709 "static_routes": [
710 {
711 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
712 "next_hop": NEXT_HOP_IP[addr_type],
713 "vrf": "BLUE_A",
714 },
715 {
716 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
717 "next_hop": NEXT_HOP_IP[addr_type],
718 "vrf": "BLUE_B",
719 },
720 ]
721 }
722 }
723
724 result = verify_rib(tgen, addr_type, dut, input_dict_2)
725 assert result is True, "Testcase {} : Failed \n Error {}".format(
726 tc_name, result
727 )
728
729 step("Make sure routes are not present in global routing table")
730
731 for addr_type in ADDR_TYPES:
732 dut = "blue1"
733 input_dict_2 = {
734 "blue1": {
735 "static_routes": [
736 {
737 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
738 "next_hop": NEXT_HOP_IP[addr_type],
739 },
740 {
741 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
742 "next_hop": NEXT_HOP_IP[addr_type],
743 },
744 ]
745 }
746 }
747
748 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
749 assert result is not True, (
750 "Testcase {} : Failed \n Expected Behaviour: Routes are not "
751 "present on Global Routing table \n Error {}".format(tc_name, result)
752 )
753
754 write_test_footer(tc_name)
755
756
757 def test_vrf_with_unique_physical_interface_p0(request):
758 """
759 FUNC_4_&_5:
760 Each VRF should be mapped with a unique VLAN on DUT
761 for traffic segregation, when using a single physical interface.
762
763 Each VRF should be mapped to a unique physical
764 interface(without VLAN tagging) on DUT for traffic segregation.
765 """
766
767 tgen = get_topogen()
768 tc_name = request.node.name
769 write_test_header(tc_name)
770 reset_config_on_routers(tgen)
771
772 if tgen.routers_have_failure():
773 check_router_status(tgen)
774
775 step(
776 "R1 is receiving routes in 4 VRFs instances "
777 "(RED_A, RED_B, BLUE_A, BLUE_B) from RED_1 and BLUE_1."
778 )
779
780 for addr_type in ADDR_TYPES:
781 input_dict_1 = {
782 "red1": {
783 "static_routes": [
784 {
785 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
786 "next_hop": NEXT_HOP_IP[addr_type],
787 "vrf": "RED_A",
788 },
789 {
790 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
791 "next_hop": NEXT_HOP_IP[addr_type],
792 "vrf": "RED_B",
793 },
794 ]
795 }
796 }
797 result = create_static_routes(tgen, input_dict_1)
798 assert result is True, "Testcase {} : Failed \n Error: {}".format(
799 tc_name, result
800 )
801
802 step(
803 "Advertise a set of unique BGP prefixes(IPv4+IPv6) from "
804 "routers RED_1 & BLUE_1 in each VRF using static redistribution"
805 )
806
807 for addr_type in ADDR_TYPES:
808 input_dict_2 = {
809 "blue1": {
810 "static_routes": [
811 {
812 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
813 "next_hop": NEXT_HOP_IP[addr_type],
814 "vrf": "BLUE_A",
815 },
816 {
817 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
818 "next_hop": NEXT_HOP_IP[addr_type],
819 "vrf": "BLUE_B",
820 },
821 ]
822 }
823 }
824 result = create_static_routes(tgen, input_dict_2)
825 assert result is True, "Testcase {} : Failed \n Error: {}".format(
826 tc_name, result
827 )
828
829 step("Redistribute static..")
830
831 input_dict_3 = {}
832 for dut in ["red1", "blue1"]:
833 temp = {dut: {"bgp": []}}
834 input_dict_3.update(temp)
835
836 if "red" in dut:
837 VRFS = ["RED_A", "RED_B"]
838 AS_NUM = [500, 500]
839 elif "blue" in dut:
840 VRFS = ["BLUE_A", "BLUE_B"]
841 AS_NUM = [800, 800]
842
843 for vrf, as_num in zip(VRFS, AS_NUM):
844 temp[dut]["bgp"].append(
845 {
846 "local_as": as_num,
847 "vrf": vrf,
848 "address_family": {
849 "ipv4": {
850 "unicast": {"redistribute": [{"redist_type": "static"}]}
851 },
852 "ipv6": {
853 "unicast": {"redistribute": [{"redist_type": "static"}]}
854 },
855 },
856 }
857 )
858
859 result = create_router_bgp(tgen, topo, input_dict_3)
860 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
861
862 step(
863 "Each VRF table on R2 should maintain it's associated "
864 "routes and and accordingly install in zebra"
865 )
866
867 for addr_type in ADDR_TYPES:
868 dut = "r2"
869 input_dict_1 = {
870 "red1": {
871 "static_routes": [
872 {
873 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
874 "next_hop": NEXT_HOP_IP[addr_type],
875 "vrf": "RED_A",
876 },
877 {
878 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
879 "next_hop": NEXT_HOP_IP[addr_type],
880 "vrf": "RED_B",
881 },
882 ]
883 }
884 }
885
886 input_dict_2 = {
887 "blue1": {
888 "static_routes": [
889 {
890 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
891 "next_hop": NEXT_HOP_IP[addr_type],
892 "vrf": "BLUE_A",
893 },
894 {
895 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
896 "next_hop": NEXT_HOP_IP[addr_type],
897 "vrf": "BLUE_B",
898 },
899 ]
900 }
901 }
902
903 result = verify_rib(tgen, addr_type, dut, input_dict_1)
904 assert result is True, "Testcase {} : Failed \n Error {}".format(
905 tc_name, result
906 )
907
908 result = verify_rib(tgen, addr_type, dut, input_dict_2)
909 assert result is True, "Testcase {} : Failed \n Error {}".format(
910 tc_name, result
911 )
912
913 write_test_footer(tc_name)
914
915
916 def test_prefixes_leaking_p0(request):
917 """
918 FUNC_6:
919 Advertise same set of prefixes from different VRFs
920 and verify on remote router that these prefixes are not
921 leaking to each other
922 """
923
924 tgen = get_topogen()
925 tc_name = request.node.name
926 write_test_header(tc_name)
927 reset_config_on_routers(tgen)
928
929 if tgen.routers_have_failure():
930 check_router_status(tgen)
931
932 step("Configure a set of static routes(IPv4+IPv6) in vrf " "RED_A on router RED-1")
933
934 for addr_type in ADDR_TYPES:
935 input_dict_1 = {
936 "red1": {
937 "static_routes": [
938 {
939 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
940 "next_hop": NEXT_HOP_IP[addr_type],
941 "vrf": "RED_A",
942 }
943 ]
944 },
945 "blue1": {
946 "static_routes": [
947 {
948 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
949 "next_hop": NEXT_HOP_IP[addr_type],
950 "vrf": "BLUE_A",
951 }
952 ]
953 },
954 }
955 result = create_static_routes(tgen, input_dict_1)
956 assert result is True, "Testcase {} : Failed \n Error: {}".format(
957 tc_name, result
958 )
959
960 step(
961 "Configure a set of static routes(IPv4+IPv6) in vrf " "BLUE_A on router BLUE-1"
962 )
963
964 for addr_type in ADDR_TYPES:
965 input_dict_2 = {
966 "red1": {
967 "static_routes": [
968 {
969 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
970 "next_hop": NEXT_HOP_IP[addr_type],
971 "vrf": "RED_B",
972 }
973 ]
974 },
975 "blue1": {
976 "static_routes": [
977 {
978 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
979 "next_hop": NEXT_HOP_IP[addr_type],
980 "vrf": "BLUE_B",
981 }
982 ]
983 },
984 }
985 result = create_static_routes(tgen, input_dict_2)
986 assert result is True, "Testcase {} : Failed \n Error: {}".format(
987 tc_name, result
988 )
989
990 step(
991 "Configure the same set of static routes with a "
992 "metric value of 123 in vrf RED_B on router RED-1"
993 )
994 step(
995 "Configure the same set of static routes with a "
996 "metric value of 123 in vrf BLUE_B on router BLUE-1"
997 )
998
999 input_dict_3 = {
1000 "red1": {
1001 "bgp": [
1002 {
1003 "local_as": "500",
1004 "vrf": "RED_A",
1005 "address_family": {
1006 "ipv4": {
1007 "unicast": {"redistribute": [{"redist_type": "static"}]}
1008 },
1009 "ipv6": {
1010 "unicast": {"redistribute": [{"redist_type": "static"}]}
1011 },
1012 },
1013 },
1014 {
1015 "local_as": "500",
1016 "vrf": "RED_B",
1017 "address_family": {
1018 "ipv4": {
1019 "unicast": {
1020 "redistribute": [
1021 {
1022 "redist_type": "static",
1023 "attribute": {"metric": 123},
1024 }
1025 ]
1026 }
1027 },
1028 "ipv6": {
1029 "unicast": {
1030 "redistribute": [
1031 {
1032 "redist_type": "static",
1033 "attribute": {"metric": 123},
1034 }
1035 ]
1036 }
1037 },
1038 },
1039 },
1040 ]
1041 },
1042 "blue1": {
1043 "bgp": [
1044 {
1045 "local_as": "800",
1046 "vrf": "BLUE_A",
1047 "address_family": {
1048 "ipv4": {
1049 "unicast": {"redistribute": [{"redist_type": "static"}]}
1050 },
1051 "ipv6": {
1052 "unicast": {"redistribute": [{"redist_type": "static"}]}
1053 },
1054 },
1055 },
1056 {
1057 "local_as": "800",
1058 "vrf": "BLUE_B",
1059 "address_family": {
1060 "ipv4": {
1061 "unicast": {
1062 "redistribute": [
1063 {
1064 "redist_type": "static",
1065 "attribute": {"metric": 123},
1066 }
1067 ]
1068 }
1069 },
1070 "ipv6": {
1071 "unicast": {
1072 "redistribute": [
1073 {
1074 "redist_type": "static",
1075 "attribute": {"metric": 123},
1076 }
1077 ]
1078 }
1079 },
1080 },
1081 },
1082 ]
1083 },
1084 }
1085
1086 result = create_router_bgp(tgen, topo, input_dict_3)
1087 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1088
1089 step(
1090 "Verify on R1 that RED_A doesn't receive any static "
1091 "route with metric value 123"
1092 )
1093
1094 for addr_type in ADDR_TYPES:
1095 dut = "r1"
1096 input_dict_1 = {
1097 "red1": {
1098 "static_routes": [
1099 {
1100 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1101 "next_hop": NEXT_HOP_IP[addr_type],
1102 "vrf": "RED_A",
1103 }
1104 ]
1105 },
1106 "blue1": {
1107 "static_routes": [
1108 {
1109 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1110 "next_hop": NEXT_HOP_IP[addr_type],
1111 "vrf": "BLUE_A",
1112 }
1113 ]
1114 },
1115 }
1116
1117 input_dict_2 = {
1118 "red1": {
1119 "static_routes": [
1120 {
1121 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1122 "next_hop": NEXT_HOP_IP[addr_type],
1123 "vrf": "RED_B",
1124 }
1125 ]
1126 },
1127 "blue1": {
1128 "static_routes": [
1129 {
1130 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1131 "next_hop": NEXT_HOP_IP[addr_type],
1132 "vrf": "BLUE_B",
1133 }
1134 ]
1135 },
1136 }
1137
1138 result = verify_rib(tgen, addr_type, dut, input_dict_1)
1139 assert result is True, "Testcase {} : Failed \n Error {}".format(
1140 tc_name, result
1141 )
1142
1143 result = verify_rib(
1144 tgen, addr_type, dut, input_dict_1, metric=123, expected=False
1145 )
1146 assert result is not True, (
1147 "Testcase {} : Failed \n "
1148 "Routes are present with metric value 123 \n Error: {}".format(
1149 tc_name, result
1150 )
1151 )
1152 logger.info("Expected Behavior: {}".format(result))
1153
1154 result = verify_rib(tgen, addr_type, dut, input_dict_2, metric=123)
1155 assert result is True, "Testcase {} : Failed \n Error {}".format(
1156 tc_name, result
1157 )
1158
1159 result = verify_rib(
1160 tgen, addr_type, dut, input_dict_2, metric=0, expected=False
1161 )
1162 assert result is not True, (
1163 "Testcase {} : Failed \n "
1164 "Routes are present with metric value 0 \n Error: {}".format(
1165 tc_name, result
1166 )
1167 )
1168 logger.info("Expected Behavior: {}".format(result))
1169
1170 write_test_footer(tc_name)
1171
1172
1173 def test_static_routes_advertised_within_specific_vrf_p0(request):
1174 """
1175 FUNC_7:
1176 Redistribute Static routes and verify on remote routers
1177 that routes are advertised within specific VRF instance, which
1178 those static routes belong to.
1179 """
1180
1181 tgen = get_topogen()
1182 tc_name = request.node.name
1183 write_test_header(tc_name)
1184 reset_config_on_routers(tgen)
1185
1186 if tgen.routers_have_failure():
1187 check_router_status(tgen)
1188
1189 step(
1190 "Advertise a set of unique BGP prefixes(IPv4+IPv6) "
1191 "through static redistribution into VRF RED_A and RED_B"
1192 " from router RED-1."
1193 )
1194
1195 for addr_type in ADDR_TYPES:
1196 input_dict_1 = {
1197 "red1": {
1198 "static_routes": [
1199 {
1200 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1201 "next_hop": NEXT_HOP_IP[addr_type],
1202 "vrf": "RED_A",
1203 },
1204 {
1205 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1206 "next_hop": NEXT_HOP_IP[addr_type],
1207 "vrf": "RED_B",
1208 },
1209 ]
1210 }
1211 }
1212 result = create_static_routes(tgen, input_dict_1)
1213 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1214 tc_name, result
1215 )
1216
1217 step(
1218 "Advertise same as above set of BGP prefixes(IPv4+IPv6) "
1219 "through static redistribution into VRF BLUE_A and BLUE_B"
1220 " from router BLUE-1."
1221 )
1222
1223 for addr_type in ADDR_TYPES:
1224 input_dict_2 = {
1225 "blue1": {
1226 "static_routes": [
1227 {
1228 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1229 "next_hop": NEXT_HOP_IP[addr_type],
1230 "vrf": "BLUE_A",
1231 },
1232 {
1233 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1234 "next_hop": NEXT_HOP_IP[addr_type],
1235 "vrf": "BLUE_B",
1236 },
1237 ]
1238 }
1239 }
1240 result = create_static_routes(tgen, input_dict_2)
1241 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1242 tc_name, result
1243 )
1244
1245 step("Redistribute static..")
1246
1247 input_dict_3 = {}
1248 for dut in ["red1", "blue1"]:
1249 temp = {dut: {"bgp": []}}
1250 input_dict_3.update(temp)
1251
1252 if "red" in dut:
1253 VRFS = ["RED_A", "RED_B"]
1254 AS_NUM = [500, 500]
1255 elif "blue" in dut:
1256 VRFS = ["BLUE_A", "BLUE_B"]
1257 AS_NUM = [800, 800]
1258
1259 for vrf, as_num in zip(VRFS, AS_NUM):
1260 temp[dut]["bgp"].append(
1261 {
1262 "local_as": as_num,
1263 "vrf": vrf,
1264 "address_family": {
1265 "ipv4": {
1266 "unicast": {"redistribute": [{"redist_type": "static"}]}
1267 },
1268 "ipv6": {
1269 "unicast": {"redistribute": [{"redist_type": "static"}]}
1270 },
1271 },
1272 }
1273 )
1274
1275 result = create_router_bgp(tgen, topo, input_dict_3)
1276 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1277
1278 step(
1279 "Verify that static routes are installed into vrfs RED_A"
1280 "and RED_B tables only, not in global routing table of RED_1"
1281 )
1282
1283 for addr_type in ADDR_TYPES:
1284 dut = "red1"
1285 input_dict_1 = {
1286 "red1": {
1287 "static_routes": [
1288 {
1289 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1290 "next_hop": NEXT_HOP_IP[addr_type],
1291 "vrf": "RED_A",
1292 },
1293 {
1294 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1295 "next_hop": NEXT_HOP_IP[addr_type],
1296 "vrf": "RED_B",
1297 },
1298 ]
1299 }
1300 }
1301
1302 result = verify_rib(tgen, addr_type, dut, input_dict_1, protocol="static")
1303 assert result is True, "Testcase {} : Failed \n Error {}".format(
1304 tc_name, result
1305 )
1306
1307 step(
1308 "Verify that static routes are installed into vrfs BLUE_A and"
1309 "BLUE_B tables only, not in global routing table of BLUE_1."
1310 )
1311
1312 for addr_type in ADDR_TYPES:
1313 dut = "blue1"
1314 input_dict_2 = {
1315 "blue1": {
1316 "static_routes": [
1317 {
1318 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1319 "next_hop": NEXT_HOP_IP[addr_type],
1320 "vrf": "BLUE_A",
1321 },
1322 {
1323 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1324 "next_hop": NEXT_HOP_IP[addr_type],
1325 "vrf": "BLUE_B",
1326 },
1327 ]
1328 }
1329 }
1330
1331 result = verify_rib(tgen, addr_type, dut, input_dict_2, protocol="static")
1332 assert result is True, "Testcase {} : Failed \n Error {}".format(
1333 tc_name, result
1334 )
1335
1336 step(
1337 "Verify on router R1, that each set of prefixes is received"
1338 " into associated vrf tables only."
1339 )
1340
1341 result = verify_bgp_convergence(tgen, topo)
1342 assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result)
1343
1344 for addr_type in ADDR_TYPES:
1345 dut = "r1"
1346 input_dict_1 = {
1347 "red1": {
1348 "static_routes": [
1349 {
1350 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1351 "next_hop": NEXT_HOP_IP[addr_type],
1352 "vrf": "RED_A",
1353 },
1354 {
1355 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1356 "next_hop": NEXT_HOP_IP[addr_type],
1357 "vrf": "RED_B",
1358 },
1359 ]
1360 }
1361 }
1362
1363 input_dict_2 = {
1364 "blue1": {
1365 "static_routes": [
1366 {
1367 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1368 "next_hop": NEXT_HOP_IP[addr_type],
1369 "vrf": "BLUE_A",
1370 },
1371 {
1372 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1373 "next_hop": NEXT_HOP_IP[addr_type],
1374 "vrf": "BLUE_B",
1375 },
1376 ]
1377 }
1378 }
1379
1380 result = verify_rib(tgen, addr_type, dut, input_dict_1)
1381 assert result is True, "Testcase {} : Failed \n Error {}".format(
1382 tc_name, result
1383 )
1384
1385 result = verify_rib(tgen, addr_type, dut, input_dict_2)
1386 assert result is True, "Testcase {} : Failed \n Error {}".format(
1387 tc_name, result
1388 )
1389
1390 write_test_footer(tc_name)
1391
1392
1393 def test_end_to_end_traffic_isolation_p0(request):
1394 """
1395 FUNC_8:
1396 Test end to end traffic isolation based on VRF tables.
1397 """
1398
1399 tgen = get_topogen()
1400 tc_name = request.node.name
1401 write_test_header(tc_name)
1402 reset_config_on_routers(tgen)
1403
1404 if tgen.routers_have_failure():
1405 check_router_status(tgen)
1406
1407 step(
1408 "Advertise unique BGP prefixes(IPv4+IPv6) from RED_1 "
1409 "in vrf instances(RED_A and RED_B)."
1410 )
1411
1412 for addr_type in ADDR_TYPES:
1413 input_dict_1 = {
1414 "red1": {
1415 "static_routes": [
1416 {
1417 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1418 "next_hop": NEXT_HOP_IP[addr_type],
1419 "vrf": "RED_A",
1420 },
1421 {
1422 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1423 "next_hop": NEXT_HOP_IP[addr_type],
1424 "vrf": "RED_B",
1425 },
1426 ]
1427 }
1428 }
1429 result = create_static_routes(tgen, input_dict_1)
1430 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1431 tc_name, result
1432 )
1433
1434 step(
1435 "Advertise unique BGP prefixes(IPv4+IPv6) from from BLUE_1 in"
1436 " vrf instances(BLUE_A and BLUE_B)."
1437 )
1438
1439 for addr_type in ADDR_TYPES:
1440 input_dict_2 = {
1441 "blue1": {
1442 "static_routes": [
1443 {
1444 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
1445 "next_hop": NEXT_HOP_IP[addr_type],
1446 "vrf": "BLUE_A",
1447 },
1448 {
1449 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
1450 "next_hop": NEXT_HOP_IP[addr_type],
1451 "vrf": "BLUE_B",
1452 },
1453 ]
1454 }
1455 }
1456 result = create_static_routes(tgen, input_dict_2)
1457 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1458 tc_name, result
1459 )
1460
1461 step("Redistribute static..")
1462
1463 input_dict_3 = {}
1464 for dut in ["red1", "blue1"]:
1465 temp = {dut: {"bgp": []}}
1466 input_dict_3.update(temp)
1467
1468 if "red" in dut:
1469 VRFS = ["RED_A", "RED_B"]
1470 AS_NUM = [500, 500]
1471 elif "blue" in dut:
1472 VRFS = ["BLUE_A", "BLUE_B"]
1473 AS_NUM = [800, 800]
1474
1475 for vrf, as_num in zip(VRFS, AS_NUM):
1476 temp[dut]["bgp"].append(
1477 {
1478 "local_as": as_num,
1479 "vrf": vrf,
1480 "address_family": {
1481 "ipv4": {
1482 "unicast": {"redistribute": [{"redist_type": "static"}]}
1483 },
1484 "ipv6": {
1485 "unicast": {"redistribute": [{"redist_type": "static"}]}
1486 },
1487 },
1488 }
1489 )
1490
1491 result = create_router_bgp(tgen, topo, input_dict_3)
1492 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1493
1494 step(
1495 "Use below commands to send prefixes with as-path prepend"
1496 "VRF BLUE_A and BLUE_B from router BLUE-1."
1497 )
1498
1499 for addr_type in ADDR_TYPES:
1500 input_dict_4 = {
1501 "blue1": {
1502 "route_maps": {
1503 "ASP_{}".format(addr_type): [
1504 {
1505 "action": "permit",
1506 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1507 }
1508 ]
1509 }
1510 }
1511 }
1512 result = create_route_maps(tgen, input_dict_4)
1513 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1514 tc_name, result
1515 )
1516
1517 step("Apply route-map to neighbours")
1518
1519 input_dict_5 = {
1520 "blue1": {
1521 "bgp": [
1522 {
1523 "local_as": "800",
1524 "vrf": "BLUE_A",
1525 "address_family": {
1526 "ipv4": {
1527 "unicast": {
1528 "neighbor": {
1529 "r1": {
1530 "dest_link": {
1531 "blue1-link1": {
1532 "route_maps": [
1533 {
1534 "name": "ASP_ipv4",
1535 "direction": "out",
1536 }
1537 ]
1538 }
1539 }
1540 }
1541 }
1542 }
1543 },
1544 "ipv6": {
1545 "unicast": {
1546 "neighbor": {
1547 "r1": {
1548 "dest_link": {
1549 "blue1-link1": {
1550 "route_maps": [
1551 {
1552 "name": "ASP_ipv6",
1553 "direction": "out",
1554 }
1555 ]
1556 }
1557 }
1558 }
1559 }
1560 }
1561 },
1562 },
1563 },
1564 {
1565 "local_as": "800",
1566 "vrf": "BLUE_B",
1567 "address_family": {
1568 "ipv4": {
1569 "unicast": {
1570 "neighbor": {
1571 "r1": {
1572 "dest_link": {
1573 "blue1-link2": {
1574 "route_maps": [
1575 {
1576 "name": "ASP_ipv4",
1577 "direction": "out",
1578 }
1579 ]
1580 }
1581 }
1582 }
1583 }
1584 }
1585 },
1586 "ipv6": {
1587 "unicast": {
1588 "neighbor": {
1589 "r1": {
1590 "dest_link": {
1591 "blue1-link2": {
1592 "route_maps": [
1593 {
1594 "name": "ASP_ipv6",
1595 "direction": "out",
1596 }
1597 ]
1598 }
1599 }
1600 }
1601 }
1602 }
1603 },
1604 },
1605 },
1606 ]
1607 }
1608 }
1609
1610 result = create_router_bgp(tgen, topo, input_dict_5)
1611 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1612
1613 step(
1614 "Verify on R1 that BLUE_A and BLUE_B VRFs are receiving the"
1615 " prefixes with as-path 123 prepended."
1616 )
1617
1618 for addr_type in ADDR_TYPES:
1619 dut = "r1"
1620 input_dict_6 = {
1621 "red1": {
1622 "static_routes": [
1623 {
1624 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1625 "next_hop": NEXT_HOP_IP[addr_type],
1626 "vrf": "RED_A",
1627 },
1628 {
1629 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
1630 "next_hop": NEXT_HOP_IP[addr_type],
1631 "vrf": "BLUE_A",
1632 },
1633 ]
1634 }
1635 }
1636
1637 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_6)
1638 assert result is True, "Testcase {} : Failed \n Error {}".format(
1639 tc_name, result
1640 )
1641
1642 result = verify_rib(tgen, addr_type, dut, input_dict_6)
1643 assert result is True, "Testcase {} : Failed \n Error {}".format(
1644 tc_name, result
1645 )
1646
1647 for addr_type in ADDR_TYPES:
1648 dut = "r1"
1649 input_dict_7 = {
1650 "red1": {
1651 "static_routes": [
1652 {
1653 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1654 "next_hop": NEXT_HOP_IP[addr_type],
1655 "vrf": "RED_B",
1656 },
1657 {
1658 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
1659 "next_hop": NEXT_HOP_IP[addr_type],
1660 "vrf": "BLUE_B",
1661 },
1662 ]
1663 }
1664 }
1665
1666 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_7)
1667 assert result is True, "Testcase {} : Failed \n Error {}".format(
1668 tc_name, result
1669 )
1670
1671 result = verify_rib(tgen, addr_type, dut, input_dict_7)
1672 assert result is True, "Testcase {} : Failed \n Error {}".format(
1673 tc_name, result
1674 )
1675
1676 step(
1677 "Use below commands to send prefixes with as-path prepend VRF"
1678 " BLUE_A and BLUE_B from router BLUE-1."
1679 )
1680
1681 input_dict_6 = {
1682 "red2": {
1683 "bgp": [
1684 {
1685 "local_as": "500",
1686 "vrf": "RED_A",
1687 "address_family": {
1688 "ipv4": {
1689 "unicast": {
1690 "neighbor": {
1691 "r3": {
1692 "dest_link": {
1693 "red2-link1": {
1694 "allowas-in": {"number_occurences": 2}
1695 }
1696 }
1697 }
1698 }
1699 }
1700 },
1701 "ipv6": {
1702 "unicast": {
1703 "neighbor": {
1704 "r3": {
1705 "dest_link": {
1706 "red2-link1": {
1707 "allowas-in": {"number_occurences": 2}
1708 }
1709 }
1710 }
1711 }
1712 }
1713 },
1714 },
1715 },
1716 {
1717 "local_as": "500",
1718 "vrf": "RED_B",
1719 "address_family": {
1720 "ipv4": {
1721 "unicast": {
1722 "neighbor": {
1723 "r3": {
1724 "dest_link": {
1725 "red2-link2": {
1726 "allowas-in": {"number_occurences": 2}
1727 }
1728 }
1729 }
1730 }
1731 }
1732 },
1733 "ipv6": {
1734 "unicast": {
1735 "neighbor": {
1736 "r3": {
1737 "dest_link": {
1738 "red2-link2": {
1739 "allowas-in": {"number_occurences": 2}
1740 }
1741 }
1742 }
1743 }
1744 }
1745 },
1746 },
1747 },
1748 ]
1749 },
1750 "blue2": {
1751 "bgp": [
1752 {
1753 "local_as": "800",
1754 "vrf": "BLUE_A",
1755 "address_family": {
1756 "ipv4": {
1757 "unicast": {
1758 "neighbor": {
1759 "r3": {
1760 "dest_link": {
1761 "blue2-link1": {
1762 "allowas-in": {"number_occurences": 2}
1763 }
1764 }
1765 }
1766 }
1767 }
1768 },
1769 "ipv6": {
1770 "unicast": {
1771 "neighbor": {
1772 "r3": {
1773 "dest_link": {
1774 "blue2-link1": {
1775 "allowas-in": {"number_occurences": 2}
1776 }
1777 }
1778 }
1779 }
1780 }
1781 },
1782 },
1783 },
1784 {
1785 "local_as": "800",
1786 "vrf": "BLUE_B",
1787 "address_family": {
1788 "ipv4": {
1789 "unicast": {
1790 "neighbor": {
1791 "r3": {
1792 "dest_link": {
1793 "blue2-link2": {
1794 "allowas-in": {"number_occurences": 2}
1795 }
1796 }
1797 }
1798 }
1799 }
1800 },
1801 "ipv6": {
1802 "unicast": {
1803 "neighbor": {
1804 "r3": {
1805 "dest_link": {
1806 "blue2-link2": {
1807 "allowas-in": {"number_occurences": 2}
1808 }
1809 }
1810 }
1811 }
1812 }
1813 },
1814 },
1815 },
1816 ]
1817 },
1818 }
1819
1820 result = create_router_bgp(tgen, topo, input_dict_6)
1821 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1822
1823 step("Verify that router RED-2 receives the prefixes in respective" " VRF tables.")
1824
1825 for addr_type in ADDR_TYPES:
1826 dut = "red2"
1827 input_dict_6 = {
1828 "red1": {
1829 "static_routes": [
1830 {
1831 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
1832 "next_hop": NEXT_HOP_IP[addr_type],
1833 "vrf": "RED_A",
1834 },
1835 {
1836 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
1837 "next_hop": NEXT_HOP_IP[addr_type],
1838 "vrf": "RED_B",
1839 },
1840 ]
1841 }
1842 }
1843
1844 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_6)
1845 assert result is True, "Testcase {} : Failed \n Error {}".format(
1846 tc_name, result
1847 )
1848
1849 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_6)
1850 assert result is True, "Testcase {} : Failed \n Error {}".format(
1851 tc_name, result
1852 )
1853
1854 for addr_type in ADDR_TYPES:
1855 dut = "blue2"
1856 input_dict_7 = {
1857 "red1": {
1858 "static_routes": [
1859 {
1860 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
1861 "next_hop": NEXT_HOP_IP[addr_type],
1862 "vrf": "BLUE_A",
1863 },
1864 {
1865 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
1866 "next_hop": NEXT_HOP_IP[addr_type],
1867 "vrf": "BLUE_B",
1868 },
1869 ]
1870 }
1871 }
1872
1873 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_7)
1874 assert result is True, "Testcase {} : Failed \n Error {}".format(
1875 tc_name, result
1876 )
1877
1878 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_7)
1879 assert result is True, "Testcase {} : Failed \n Error {}".format(
1880 tc_name, result
1881 )
1882
1883 write_test_footer(tc_name)
1884
1885
1886 def test_static_routes_for_inter_vrf_route_leaking_p0(request):
1887 """
1888 FUNC_9:
1889 Use static routes for inter-vrf communication
1890 (route-leaking) on DUT.
1891 """
1892
1893 tgen = get_topogen()
1894 tc_name = request.node.name
1895 write_test_header(tc_name)
1896 reset_config_on_routers(tgen)
1897
1898 if tgen.routers_have_failure():
1899 check_router_status(tgen)
1900
1901 step(
1902 "Configure unique loopback interfaces in VRFs RED_A "
1903 "and RED_B on router RED_1."
1904 )
1905
1906 for addr_type in ADDR_TYPES:
1907 create_interface_in_kernel(
1908 tgen,
1909 "red1",
1910 "loopback1",
1911 LOOPBACK_1[addr_type],
1912 "RED_A",
1913 LOOPBACK_1["{}_mask".format(addr_type)],
1914 )
1915 create_interface_in_kernel(
1916 tgen,
1917 "red1",
1918 "loopback2",
1919 LOOPBACK_2[addr_type],
1920 "RED_B",
1921 LOOPBACK_2["{}_mask".format(addr_type)],
1922 )
1923
1924 step(
1925 "Create a static routes in vrf RED_B on router RED_1 pointing"
1926 " next-hop as interface's IP in vrf RED_A"
1927 )
1928
1929 intf_red1_r11 = topo["routers"]["red1"]["links"]["r1-link1"]["interface"]
1930 intf_red1_r10 = topo["routers"]["red1"]["links"]["r1-link2"]["interface"]
1931 for addr_type in ADDR_TYPES:
1932 input_dict_1 = {
1933 "red1": {
1934 "static_routes": [
1935 {
1936 "network": LOOPBACK_1[addr_type],
1937 "interface": intf_red1_r10,
1938 "nexthop_vrf": "RED_B",
1939 "vrf": "RED_A",
1940 },
1941 {
1942 "network": LOOPBACK_2[addr_type],
1943 "interface": intf_red1_r11,
1944 "nexthop_vrf": "RED_A",
1945 "vrf": "RED_B",
1946 },
1947 ]
1948 }
1949 }
1950 result = create_static_routes(tgen, input_dict_1)
1951 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1952 tc_name, result
1953 )
1954
1955 step("Redistribute static..")
1956
1957 input_dict_3 = {}
1958 for dut in ["red1"]:
1959 temp = {dut: {"bgp": []}}
1960 input_dict_3.update(temp)
1961
1962 if "red" in dut:
1963 VRFS = ["RED_A", "RED_B"]
1964 AS_NUM = [500, 500]
1965 elif "blue" in dut:
1966 VRFS = ["BLUE_A", "BLUE_B"]
1967 AS_NUM = [800, 800]
1968
1969 for vrf, as_num in zip(VRFS, AS_NUM):
1970 temp[dut]["bgp"].append(
1971 {
1972 "local_as": as_num,
1973 "vrf": vrf,
1974 "address_family": {
1975 "ipv4": {
1976 "unicast": {"redistribute": [{"redist_type": "static"}]}
1977 },
1978 "ipv6": {
1979 "unicast": {"redistribute": [{"redist_type": "static"}]}
1980 },
1981 },
1982 }
1983 )
1984
1985 result = create_router_bgp(tgen, topo, input_dict_3)
1986 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1987
1988 step(
1989 "Verify that static routes are installed into vrfs RED_A"
1990 "and RED_B tables only, not in global routing table of RED_1"
1991 )
1992 for addr_type in ADDR_TYPES:
1993 dut = "red1"
1994 input_dict_1 = {
1995 "red1": {
1996 "static_routes": [
1997 {
1998 "network": LOOPBACK_1[addr_type],
1999 "interface": intf_red1_r10,
2000 "nexthop_vrf": "RED_B",
2001 "vrf": "RED_A",
2002 },
2003 {
2004 "network": LOOPBACK_2[addr_type],
2005 "interface": intf_red1_r11,
2006 "nexthop_vrf": "RED_A",
2007 "vrf": "RED_B",
2008 },
2009 ]
2010 }
2011 }
2012
2013 result = verify_rib(tgen, addr_type, dut, input_dict_1, protocol="static")
2014 assert result is True, "Testcase {} : Failed \n Error {}".format(
2015 tc_name, result
2016 )
2017
2018 write_test_footer(tc_name)
2019
2020
2021 def test_inter_vrf_and_intra_vrf_communication_iBGP_p0(request):
2022 """
2023 FUNC_10:
2024 Verify intra-vrf and inter-vrf communication between
2025 iBGP peers.
2026 """
2027
2028 tgen = get_topogen()
2029 tc_name = request.node.name
2030 write_test_header(tc_name)
2031 reset_config_on_routers(tgen)
2032
2033 if tgen.routers_have_failure():
2034 check_router_status(tgen)
2035
2036 step(
2037 "Configure unique loopback IP(IPv4+IPv6) in vrf RED_A on router"
2038 " R1 and advertise it in BGP process using redistribute "
2039 "connected command."
2040 )
2041
2042 for addr_type in ADDR_TYPES:
2043 create_interface_in_kernel(
2044 tgen,
2045 "r1",
2046 "loopback1",
2047 LOOPBACK_1[addr_type],
2048 "RED_A",
2049 LOOPBACK_1["{}_mask".format(addr_type)],
2050 )
2051
2052 create_interface_in_kernel(
2053 tgen,
2054 "r1",
2055 "loopback2",
2056 LOOPBACK_2[addr_type],
2057 "BLUE_A",
2058 LOOPBACK_2["{}_mask".format(addr_type)],
2059 )
2060
2061 step(
2062 "Create a static routes in vrf RED_B on router RED_1 pointing"
2063 " next-hop as interface's IP in vrf RED_A"
2064 )
2065
2066 intf_r2_r12 = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
2067 intf_r2_r10 = topo["routers"]["r2"]["links"]["r1-link3"]["interface"]
2068 for addr_type in ADDR_TYPES:
2069 input_dict_1 = {
2070 "r2": {
2071 "static_routes": [
2072 {
2073 "network": LOOPBACK_2[addr_type],
2074 "interface": intf_r2_r10,
2075 "nexthop_vrf": "BLUE_A",
2076 "vrf": "RED_A",
2077 },
2078 {
2079 "network": LOOPBACK_1[addr_type],
2080 "interface": intf_r2_r12,
2081 "nexthop_vrf": "RED_A",
2082 "vrf": "BLUE_A",
2083 },
2084 ]
2085 }
2086 }
2087 result = create_static_routes(tgen, input_dict_1)
2088 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2089 tc_name, result
2090 )
2091
2092 step("Redistribute connected..")
2093
2094 input_dict_3 = {}
2095 for dut in ["r1"]:
2096 temp = {dut: {"bgp": []}}
2097 input_dict_3.update(temp)
2098
2099 VRFS = ["RED_A", "BLUE_A"]
2100 AS_NUM = [100, 100]
2101
2102 for vrf, as_num in zip(VRFS, AS_NUM):
2103 temp[dut]["bgp"].append(
2104 {
2105 "local_as": as_num,
2106 "vrf": vrf,
2107 "address_family": {
2108 "ipv4": {
2109 "unicast": {"redistribute": [{"redist_type": "connected"}]}
2110 },
2111 "ipv6": {
2112 "unicast": {"redistribute": [{"redist_type": "connected"}]}
2113 },
2114 },
2115 }
2116 )
2117
2118 result = create_router_bgp(tgen, topo, input_dict_3)
2119 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2120
2121 step("Redistribute static..")
2122
2123 input_dict_3 = {}
2124 for dut in ["r2"]:
2125 temp = {dut: {"bgp": []}}
2126 input_dict_3.update(temp)
2127
2128 VRFS = ["RED_A", "BLUE_A"]
2129 AS_NUM = [100, 100]
2130
2131 for vrf, as_num in zip(VRFS, AS_NUM):
2132 temp[dut]["bgp"].append(
2133 {
2134 "local_as": as_num,
2135 "vrf": vrf,
2136 "address_family": {
2137 "ipv4": {
2138 "unicast": {"redistribute": [{"redist_type": "static"}]}
2139 },
2140 "ipv6": {
2141 "unicast": {"redistribute": [{"redist_type": "static"}]}
2142 },
2143 },
2144 }
2145 )
2146
2147 result = create_router_bgp(tgen, topo, input_dict_3)
2148 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2149
2150 step(
2151 "Verify that static routes are installed into vrfs RED_A"
2152 "and RED_B tables only, not in global routing table of RED_1"
2153 )
2154
2155 for addr_type in ADDR_TYPES:
2156 dut = "r2"
2157 input_dict = {
2158 "r2": {
2159 "static_routes": [
2160 {
2161 "network": LOOPBACK_2[addr_type],
2162 "interface": intf_r2_r10,
2163 "nexthop_vrf": "BLUE_A",
2164 "vrf": "RED_A",
2165 },
2166 {
2167 "network": LOOPBACK_1[addr_type],
2168 "interface": intf_r2_r12,
2169 "nexthop_vrf": "RED_A",
2170 "vrf": "BLUE_A",
2171 },
2172 ]
2173 }
2174 }
2175
2176 result = verify_rib(tgen, addr_type, dut, input_dict)
2177 assert result is True, "Testcase {} : Failed \n Error {}".format(
2178 tc_name, result
2179 )
2180
2181 write_test_footer(tc_name)
2182
2183
2184 def test_inter_vrf_and_intra_vrf_communication_eBGP_p0(request):
2185 """
2186 FUNC_11:
2187 Verify intra-vrf and inter-vrf communication
2188 between eBGP peers.
2189 """
2190
2191 tgen = get_topogen()
2192 tc_name = request.node.name
2193 write_test_header(tc_name)
2194 reset_config_on_routers(tgen)
2195
2196 if tgen.routers_have_failure():
2197 check_router_status(tgen)
2198
2199 step(
2200 "Configure unique loopback IP(IPv4+IPv6) in vrf RED_A on router"
2201 " R2 and advertise it in BGP process using redistribute "
2202 "connected command."
2203 )
2204
2205 step(
2206 "Configure unique loopback IP(IPv4+IPv6) in vrf BLUE_A on router"
2207 " R2 and advertise it in BGP process using redistribute "
2208 "connected command."
2209 )
2210
2211 for addr_type in ADDR_TYPES:
2212 create_interface_in_kernel(
2213 tgen,
2214 "r2",
2215 "loopback1",
2216 LOOPBACK_1[addr_type],
2217 "RED_A",
2218 LOOPBACK_1["{}_mask".format(addr_type)],
2219 )
2220 create_interface_in_kernel(
2221 tgen,
2222 "r2",
2223 "loopback2",
2224 LOOPBACK_2[addr_type],
2225 "BLUE_A",
2226 LOOPBACK_2["{}_mask".format(addr_type)],
2227 )
2228
2229 step(
2230 "Create a static routes in vrf RED_B on router RED_1 pointing"
2231 " next-hop as interface's IP in vrf RED_A"
2232 )
2233
2234 intf_r3_r21 = topo["routers"]["r3"]["links"]["r2-link1"]["interface"]
2235 intf_r3_r23 = topo["routers"]["r3"]["links"]["r2-link3"]["interface"]
2236 for addr_type in ADDR_TYPES:
2237 input_dict_1 = {
2238 "r3": {
2239 "static_routes": [
2240 {
2241 "network": LOOPBACK_2[addr_type],
2242 "interface": intf_r3_r23,
2243 "nexthop_vrf": "BLUE_A",
2244 "vrf": "RED_A",
2245 },
2246 {
2247 "network": LOOPBACK_1[addr_type],
2248 "interface": intf_r3_r21,
2249 "nexthop_vrf": "RED_A",
2250 "vrf": "BLUE_A",
2251 },
2252 ]
2253 }
2254 }
2255 result = create_static_routes(tgen, input_dict_1)
2256 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2257 tc_name, result
2258 )
2259
2260 step("Redistribute static..")
2261
2262 input_dict_3 = {}
2263 for dut in ["r3"]:
2264 temp = {dut: {"bgp": []}}
2265 input_dict_3.update(temp)
2266
2267 VRFS = ["RED_A", "BLUE_A"]
2268 AS_NUM = [200, 200]
2269
2270 for vrf, as_num in zip(VRFS, AS_NUM):
2271 temp[dut]["bgp"].append(
2272 {
2273 "local_as": as_num,
2274 "vrf": vrf,
2275 "address_family": {
2276 "ipv4": {
2277 "unicast": {"redistribute": [{"redist_type": "static"}]}
2278 },
2279 "ipv6": {
2280 "unicast": {"redistribute": [{"redist_type": "static"}]}
2281 },
2282 },
2283 }
2284 )
2285
2286 result = create_router_bgp(tgen, topo, input_dict_3)
2287 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2288
2289 step("Redistribute connected..")
2290
2291 input_dict_3 = {}
2292 for dut in ["r2"]:
2293 temp = {dut: {"bgp": []}}
2294 input_dict_3.update(temp)
2295
2296 VRFS = ["RED_A", "BLUE_A"]
2297 AS_NUM = [100, 100]
2298
2299 for vrf, as_num in zip(VRFS, AS_NUM):
2300 temp[dut]["bgp"].append(
2301 {
2302 "local_as": as_num,
2303 "vrf": vrf,
2304 "address_family": {
2305 "ipv4": {
2306 "unicast": {"redistribute": [{"redist_type": "connected"}]}
2307 },
2308 "ipv6": {
2309 "unicast": {"redistribute": [{"redist_type": "connected"}]}
2310 },
2311 },
2312 }
2313 )
2314
2315 result = create_router_bgp(tgen, topo, input_dict_3)
2316 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2317
2318 step(
2319 "Verify that static routes are installed into vrfs RED_A"
2320 "and RED_B tables only, not in global routing table of RED_1"
2321 )
2322
2323 for addr_type in ADDR_TYPES:
2324 dut = "r3"
2325 input_dict = {
2326 "r3": {
2327 "static_routes": [
2328 {
2329 "network": LOOPBACK_2[addr_type],
2330 "interface": intf_r3_r23,
2331 "nexthop_vrf": "BLUE_A",
2332 "vrf": "RED_A",
2333 },
2334 {
2335 "network": LOOPBACK_1[addr_type],
2336 "interface": intf_r3_r21,
2337 "nexthop_vrf": "RED_A",
2338 "vrf": "BLUE_A",
2339 },
2340 ]
2341 }
2342 }
2343
2344 result = verify_rib(tgen, addr_type, dut, input_dict)
2345 assert result is True, "Testcase {} : Failed \n Error {}".format(
2346 tc_name, result
2347 )
2348
2349 write_test_footer(tc_name)
2350
2351
2352 def test_route_map_within_vrf_to_alter_bgp_attribute_nexthop_p0(request):
2353 """
2354 FUNC_12_a:
2355 Configure route-maps within a VRF, to alter BGP attributes.
2356 Verify that route-map doesn't affect any other VRF instances'
2357 routing on DUT.
2358 """
2359
2360 tgen = get_topogen()
2361 tc_name = request.node.name
2362 write_test_header(tc_name)
2363 reset_config_on_routers(tgen)
2364
2365 if tgen.routers_have_failure():
2366 check_router_status(tgen)
2367
2368 step(
2369 "Advertise a set of BGP prefixes(IPv4+IPv6) from RED_1 and"
2370 " RED_2 in vrf instances(RED_A and RED_B)."
2371 )
2372
2373 for addr_type in ADDR_TYPES:
2374 input_dict_1 = {
2375 "red1": {
2376 "static_routes": [
2377 {
2378 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2379 "next_hop": NEXT_HOP_IP[addr_type],
2380 "vrf": "RED_A",
2381 },
2382 {
2383 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2384 "next_hop": NEXT_HOP_IP[addr_type],
2385 "vrf": "RED_B",
2386 },
2387 ]
2388 }
2389 }
2390 result = create_static_routes(tgen, input_dict_1)
2391 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2392 tc_name, result
2393 )
2394
2395 step(
2396 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
2397 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
2398 )
2399
2400 for addr_type in ADDR_TYPES:
2401 input_dict_2 = {
2402 "blue1": {
2403 "static_routes": [
2404 {
2405 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2406 "next_hop": NEXT_HOP_IP[addr_type],
2407 "vrf": "BLUE_A",
2408 },
2409 {
2410 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2411 "next_hop": NEXT_HOP_IP[addr_type],
2412 "vrf": "BLUE_B",
2413 },
2414 ]
2415 }
2416 }
2417 result = create_static_routes(tgen, input_dict_2)
2418 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2419 tc_name, result
2420 )
2421
2422 step("Redistribute static..")
2423
2424 input_dict_3 = {}
2425 for dut in ["red1", "blue1"]:
2426 temp = {dut: {"bgp": []}}
2427 input_dict_3.update(temp)
2428
2429 if "red" in dut:
2430 VRFS = ["RED_A", "RED_B"]
2431 AS_NUM = [500, 500]
2432 elif "blue" in dut:
2433 VRFS = ["BLUE_A", "BLUE_B"]
2434 AS_NUM = [800, 800]
2435
2436 for vrf, as_num in zip(VRFS, AS_NUM):
2437 temp[dut]["bgp"].append(
2438 {
2439 "local_as": as_num,
2440 "vrf": vrf,
2441 "address_family": {
2442 "ipv4": {
2443 "unicast": {"redistribute": [{"redist_type": "static"}]}
2444 },
2445 "ipv6": {
2446 "unicast": {"redistribute": [{"redist_type": "static"}]}
2447 },
2448 },
2449 }
2450 )
2451
2452 result = create_router_bgp(tgen, topo, input_dict_3)
2453 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2454
2455 step(
2456 "Verify that within vrf instances, BGP best path selection"
2457 " algorithm remains intact and doesn't affect any other VRFs"
2458 " routing decision."
2459 )
2460
2461 for addr_type in ADDR_TYPES:
2462 dut = "r2"
2463 input_dict_1 = {
2464 "red1": {
2465 "static_routes": [
2466 {
2467 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2468 "next_hop": NEXT_HOP_IP[addr_type],
2469 "vrf": "RED_A",
2470 },
2471 {
2472 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2473 "next_hop": NEXT_HOP_IP[addr_type],
2474 "vrf": "RED_B",
2475 },
2476 ]
2477 }
2478 }
2479
2480 input_dict_2 = {
2481 "blue1": {
2482 "static_routes": [
2483 {
2484 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2485 "next_hop": NEXT_HOP_IP[addr_type],
2486 "vrf": "BLUE_A",
2487 },
2488 {
2489 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2490 "next_hop": NEXT_HOP_IP[addr_type],
2491 "vrf": "BLUE_B",
2492 },
2493 ]
2494 }
2495 }
2496
2497 result = verify_rib(tgen, addr_type, dut, input_dict_1)
2498 assert result is True, "Testcase {} : Failed \n Error {}".format(
2499 tc_name, result
2500 )
2501
2502 result = verify_rib(tgen, addr_type, dut, input_dict_2)
2503 assert result is True, "Testcase {} : Failed \n Error {}".format(
2504 tc_name, result
2505 )
2506
2507 step("Delete nexthop-self configure from r1")
2508
2509 input_dict_4 = {
2510 "r1": {
2511 "bgp": [
2512 {
2513 "local_as": "100",
2514 "vrf": "RED_A",
2515 "address_family": {
2516 "ipv4": {
2517 "unicast": {
2518 "neighbor": {
2519 "r2": {
2520 "dest_link": {
2521 "r1-link1": {"next_hop_self": False}
2522 }
2523 }
2524 }
2525 }
2526 },
2527 "ipv6": {
2528 "unicast": {
2529 "neighbor": {
2530 "r2": {
2531 "dest_link": {
2532 "r1-link1": {"next_hop_self": False}
2533 }
2534 }
2535 }
2536 }
2537 },
2538 },
2539 },
2540 {
2541 "local_as": "100",
2542 "vrf": "RED_B",
2543 "address_family": {
2544 "ipv4": {
2545 "unicast": {
2546 "neighbor": {
2547 "r2": {
2548 "dest_link": {
2549 "r1-link2": {"next_hop_self": False}
2550 }
2551 }
2552 }
2553 }
2554 },
2555 "ipv6": {
2556 "unicast": {
2557 "neighbor": {
2558 "r2": {
2559 "dest_link": {
2560 "r1-link2": {"next_hop_self": False}
2561 }
2562 }
2563 }
2564 }
2565 },
2566 },
2567 },
2568 {
2569 "local_as": "100",
2570 "vrf": "BLUE_A",
2571 "address_family": {
2572 "ipv4": {
2573 "unicast": {
2574 "neighbor": {
2575 "r2": {
2576 "dest_link": {
2577 "r1-link3": {"next_hop_self": False}
2578 }
2579 },
2580 }
2581 }
2582 },
2583 "ipv6": {
2584 "unicast": {
2585 "neighbor": {
2586 "r2": {
2587 "dest_link": {
2588 "r1-link3": {"next_hop_self": False}
2589 }
2590 }
2591 }
2592 }
2593 },
2594 },
2595 },
2596 {
2597 "local_as": "100",
2598 "vrf": "BLUE_B",
2599 "address_family": {
2600 "ipv4": {
2601 "unicast": {
2602 "neighbor": {
2603 "r2": {
2604 "dest_link": {
2605 "r1-link4": {"next_hop_self": False}
2606 }
2607 }
2608 }
2609 }
2610 },
2611 "ipv6": {
2612 "unicast": {
2613 "neighbor": {
2614 "r2": {
2615 "dest_link": {
2616 "r1-link4": {"next_hop_self": False}
2617 }
2618 }
2619 }
2620 }
2621 },
2622 },
2623 },
2624 ]
2625 }
2626 }
2627
2628 result = create_router_bgp(tgen, topo, input_dict_4)
2629 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2630
2631 step(
2632 "Verify that within vrf instances, BGP best path selection"
2633 " algorithm remains intact and doesn't affect any other VRFs"
2634 " routing decision."
2635 )
2636
2637 for addr_type in ADDR_TYPES:
2638 dut = "r2"
2639 input_dict_1 = {
2640 "red1": {
2641 "static_routes": [
2642 {
2643 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2644 "next_hop": NEXT_HOP_IP[addr_type],
2645 "vrf": "RED_A",
2646 },
2647 {
2648 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2649 "next_hop": NEXT_HOP_IP[addr_type],
2650 "vrf": "RED_B",
2651 },
2652 ]
2653 }
2654 }
2655
2656 input_dict_2 = {
2657 "blue1": {
2658 "static_routes": [
2659 {
2660 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2661 "next_hop": NEXT_HOP_IP[addr_type],
2662 "vrf": "BLUE_A",
2663 },
2664 {
2665 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2666 "next_hop": NEXT_HOP_IP[addr_type],
2667 "vrf": "BLUE_B",
2668 },
2669 ]
2670 }
2671 }
2672
2673 result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
2674 assert (
2675 result is not True
2676 ), "Testcase {} : Failed \n Expected Behaviour: Routes are rejected because nexthop-self config is deleted \n Error {}".format(tc_name, result)
2677
2678 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
2679 assert (
2680 result is not True
2681 ), "Testcase {} : Failed \n Expected Behaviour: Routes are rejected because nexthop-self config is deleted \n Error {}".format(tc_name, result)
2682
2683 write_test_footer(tc_name)
2684
2685
2686 @pytest.mark.parametrize("attribute", ["locPrf", "weight", "metric"])
2687 def test_route_map_within_vrf_to_alter_bgp_attribute_p0(request, attribute):
2688 """
2689 FUNC_12_b/c/d:
2690 Configure route-maps within a VRF, to alter BGP attributes.
2691 Verify that route-map doesn't affect any other VRF instances'
2692 routing on DUT.
2693 """
2694
2695 tgen = get_topogen()
2696 tc_name = request.node.name
2697 write_test_header(tc_name)
2698 reset_config_on_routers(tgen)
2699
2700 if tgen.routers_have_failure():
2701 check_router_status(tgen)
2702
2703 step(
2704 "Advertise a set of BGP prefixes(IPv4+IPv6) from RED_1 and"
2705 " RED_2 in vrf instances(RED_A and RED_B)."
2706 )
2707
2708 for addr_type in ADDR_TYPES:
2709 input_dict_1 = {
2710 "red1": {
2711 "static_routes": [
2712 {
2713 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2714 "next_hop": NEXT_HOP_IP[addr_type],
2715 "vrf": "RED_A",
2716 },
2717 {
2718 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2719 "next_hop": NEXT_HOP_IP[addr_type],
2720 "vrf": "RED_B",
2721 },
2722 ]
2723 },
2724 "red2": {
2725 "static_routes": [
2726 {
2727 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2728 "next_hop": NEXT_HOP_IP[addr_type],
2729 "vrf": "RED_A",
2730 },
2731 {
2732 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2733 "next_hop": NEXT_HOP_IP[addr_type],
2734 "vrf": "RED_B",
2735 },
2736 ]
2737 },
2738 }
2739 result = create_static_routes(tgen, input_dict_1)
2740 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2741 tc_name, result
2742 )
2743
2744 step(
2745 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
2746 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
2747 )
2748
2749 for addr_type in ADDR_TYPES:
2750 input_dict_2 = {
2751 "blue1": {
2752 "static_routes": [
2753 {
2754 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2755 "next_hop": NEXT_HOP_IP[addr_type],
2756 "vrf": "BLUE_A",
2757 },
2758 {
2759 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2760 "next_hop": NEXT_HOP_IP[addr_type],
2761 "vrf": "BLUE_B",
2762 },
2763 ]
2764 },
2765 "blue2": {
2766 "static_routes": [
2767 {
2768 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
2769 "next_hop": NEXT_HOP_IP[addr_type],
2770 "vrf": "BLUE_A",
2771 },
2772 {
2773 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
2774 "next_hop": NEXT_HOP_IP[addr_type],
2775 "vrf": "BLUE_B",
2776 },
2777 ]
2778 },
2779 }
2780 result = create_static_routes(tgen, input_dict_2)
2781 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2782 tc_name, result
2783 )
2784
2785 step("Redistribute static..")
2786
2787 input_dict_3 = {}
2788 for dut in ["red1", "red2", "blue1", "blue2"]:
2789 temp = {dut: {"bgp": []}}
2790 input_dict_3.update(temp)
2791
2792 if "red" in dut:
2793 VRFS = ["RED_A", "RED_B"]
2794 AS_NUM = [500, 500]
2795 elif "blue" in dut:
2796 VRFS = ["BLUE_A", "BLUE_B"]
2797 AS_NUM = [800, 800]
2798
2799 for vrf, as_num in zip(VRFS, AS_NUM):
2800 temp[dut]["bgp"].append(
2801 {
2802 "local_as": as_num,
2803 "vrf": vrf,
2804 "address_family": {
2805 "ipv4": {
2806 "unicast": {"redistribute": [{"redist_type": "static"}]}
2807 },
2808 "ipv6": {
2809 "unicast": {"redistribute": [{"redist_type": "static"}]}
2810 },
2811 },
2812 }
2813 )
2814
2815 result = create_router_bgp(tgen, topo, input_dict_3)
2816 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2817
2818 step("Configure a route-maps to influence BGP parameters - " " Local Preference")
2819
2820 for addr_type in ADDR_TYPES:
2821 input_dict_4 = {
2822 "r2": {
2823 "route_maps": {
2824 "rmap_r1_{}".format(addr_type): [
2825 {"action": "permit", "set": {attribute: 120}}
2826 ],
2827 "rmap_r3_{}".format(addr_type): [
2828 {"action": "permit", "set": {attribute: 150}}
2829 ],
2830 }
2831 }
2832 }
2833
2834 result = create_route_maps(tgen, input_dict_4)
2835 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2836 tc_name, result
2837 )
2838
2839 step("Configure neighbor for route map")
2840 input_dict_4 = {
2841 "r2": {
2842 "bgp": [
2843 {
2844 "local_as": "100",
2845 "vrf": "RED_A",
2846 "address_family": {
2847 "ipv4": {
2848 "unicast": {
2849 "neighbor": {
2850 "r1": {
2851 "dest_link": {
2852 "r2-link1": {
2853 "route_maps": [
2854 {
2855 "name": "rmap_r1_ipv4",
2856 "direction": "in",
2857 }
2858 ]
2859 }
2860 }
2861 },
2862 "r3": {
2863 "dest_link": {
2864 "r2-link1": {
2865 "route_maps": [
2866 {
2867 "name": "rmap_r3_ipv4",
2868 "direction": "in",
2869 }
2870 ]
2871 }
2872 }
2873 },
2874 }
2875 }
2876 },
2877 "ipv6": {
2878 "unicast": {
2879 "neighbor": {
2880 "r1": {
2881 "dest_link": {
2882 "r2-link1": {
2883 "route_maps": [
2884 {
2885 "name": "rmap_r1_ipv6",
2886 "direction": "in",
2887 }
2888 ]
2889 }
2890 }
2891 },
2892 "r3": {
2893 "dest_link": {
2894 "r2-link1": {
2895 "route_maps": [
2896 {
2897 "name": "rmap_r3_ipv6",
2898 "direction": "in",
2899 }
2900 ]
2901 }
2902 }
2903 },
2904 }
2905 }
2906 },
2907 },
2908 },
2909 {
2910 "local_as": "100",
2911 "vrf": "RED_B",
2912 "address_family": {
2913 "ipv4": {
2914 "unicast": {
2915 "neighbor": {
2916 "r1": {
2917 "dest_link": {
2918 "r2-link2": {
2919 "route_maps": [
2920 {
2921 "name": "rmap_r1_ipv4",
2922 "direction": "in",
2923 }
2924 ]
2925 }
2926 }
2927 },
2928 "r3": {
2929 "dest_link": {
2930 "r2-link2": {
2931 "route_maps": [
2932 {
2933 "name": "rmap_r3_ipv4",
2934 "direction": "in",
2935 }
2936 ]
2937 }
2938 }
2939 },
2940 }
2941 }
2942 },
2943 "ipv6": {
2944 "unicast": {
2945 "neighbor": {
2946 "r1": {
2947 "dest_link": {
2948 "r2-link2": {
2949 "route_maps": [
2950 {
2951 "name": "rmap_r1_ipv6",
2952 "direction": "in",
2953 }
2954 ]
2955 }
2956 }
2957 },
2958 "r3": {
2959 "dest_link": {
2960 "r2-link2": {
2961 "route_maps": [
2962 {
2963 "name": "rmap_r3_ipv6",
2964 "direction": "in",
2965 }
2966 ]
2967 }
2968 }
2969 },
2970 }
2971 }
2972 },
2973 },
2974 },
2975 {
2976 "local_as": "100",
2977 "vrf": "BLUE_A",
2978 "address_family": {
2979 "ipv4": {
2980 "unicast": {
2981 "neighbor": {
2982 "r1": {
2983 "dest_link": {
2984 "r2-link3": {
2985 "route_maps": [
2986 {
2987 "name": "rmap_r1_ipv4",
2988 "direction": "in",
2989 }
2990 ]
2991 }
2992 }
2993 },
2994 "r3": {
2995 "dest_link": {
2996 "r2-link3": {
2997 "route_maps": [
2998 {
2999 "name": "rmap_r3_ipv4",
3000 "direction": "in",
3001 }
3002 ]
3003 }
3004 }
3005 },
3006 }
3007 }
3008 },
3009 "ipv6": {
3010 "unicast": {
3011 "neighbor": {
3012 "r1": {
3013 "dest_link": {
3014 "r2-link3": {
3015 "route_maps": [
3016 {
3017 "name": "rmap_r1_ipv6",
3018 "direction": "in",
3019 }
3020 ]
3021 }
3022 }
3023 },
3024 "r3": {
3025 "dest_link": {
3026 "r2-link3": {
3027 "route_maps": [
3028 {
3029 "name": "rmap_r3_ipv6",
3030 "direction": "in",
3031 }
3032 ]
3033 }
3034 }
3035 },
3036 }
3037 }
3038 },
3039 },
3040 },
3041 {
3042 "local_as": "100",
3043 "vrf": "BLUE_B",
3044 "address_family": {
3045 "ipv4": {
3046 "unicast": {
3047 "neighbor": {
3048 "r1": {
3049 "dest_link": {
3050 "r2-link4": {
3051 "route_maps": [
3052 {
3053 "name": "rmap_r1_ipv4",
3054 "direction": "in",
3055 }
3056 ]
3057 }
3058 }
3059 },
3060 "r3": {
3061 "dest_link": {
3062 "r2-link4": {
3063 "route_maps": [
3064 {
3065 "name": "rmap_r3_ipv4",
3066 "direction": "in",
3067 }
3068 ]
3069 }
3070 }
3071 },
3072 }
3073 }
3074 },
3075 "ipv6": {
3076 "unicast": {
3077 "neighbor": {
3078 "r1": {
3079 "dest_link": {
3080 "r2-link4": {
3081 "route_maps": [
3082 {
3083 "name": "rmap_r1_ipv6",
3084 "direction": "in",
3085 }
3086 ]
3087 }
3088 }
3089 },
3090 "r3": {
3091 "dest_link": {
3092 "r2-link4": {
3093 "route_maps": [
3094 {
3095 "name": "rmap_r3_ipv6",
3096 "direction": "in",
3097 }
3098 ]
3099 }
3100 }
3101 },
3102 }
3103 }
3104 },
3105 },
3106 },
3107 ]
3108 }
3109 }
3110
3111 result = create_router_bgp(tgen, topo, input_dict_4)
3112 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3113
3114 step(
3115 "Verify that within vrf instances, BGP best path selection"
3116 " algorithm remains intact and doesn't affect any other VRFs"
3117 " routing decision."
3118 )
3119
3120 dut = "r2"
3121 for addr_type in ADDR_TYPES:
3122 input_dict_1 = {
3123 "red1": {
3124 "static_routes": [
3125 {
3126 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3127 "next_hop": NEXT_HOP_IP[addr_type],
3128 "vrf": "RED_A",
3129 },
3130 {
3131 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3132 "next_hop": NEXT_HOP_IP[addr_type],
3133 "vrf": "RED_B",
3134 },
3135 ]
3136 }
3137 }
3138
3139 input_dict_2 = {
3140 "blue1": {
3141 "static_routes": [
3142 {
3143 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3144 "next_hop": NEXT_HOP_IP[addr_type],
3145 "vrf": "BLUE_A",
3146 },
3147 {
3148 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3149 "next_hop": NEXT_HOP_IP[addr_type],
3150 "vrf": "BLUE_B",
3151 },
3152 ]
3153 }
3154 }
3155
3156 result = verify_best_path_as_per_bgp_attribute(
3157 tgen, addr_type, dut, input_dict_1, attribute
3158 )
3159 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3160 tc_name, result
3161 )
3162
3163 result = verify_best_path_as_per_bgp_attribute(
3164 tgen, addr_type, dut, input_dict_2, attribute
3165 )
3166 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3167 tc_name, result
3168 )
3169
3170 write_test_footer(tc_name)
3171
3172
3173 def test_route_map_within_vrf_to_alter_bgp_attribute_aspath_p0(request):
3174 """
3175 FUNC_12_e:
3176 Configure route-maps within a VRF, to alter BGP attributes.
3177 Verify that route-map doesn't affect any other VRF instances'
3178 routing on DUT.
3179 """
3180
3181 tgen = get_topogen()
3182 tc_name = request.node.name
3183 write_test_header(tc_name)
3184 reset_config_on_routers(tgen)
3185
3186 if tgen.routers_have_failure():
3187 check_router_status(tgen)
3188
3189 step(
3190 "Advertise a set of BGP prefixes(IPv4+IPv6) from RED_1 and"
3191 " RED_2 in vrf instances(RED_A and RED_B)."
3192 )
3193
3194 for addr_type in ADDR_TYPES:
3195 input_dict_1 = {
3196 "red1": {
3197 "static_routes": [
3198 {
3199 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3200 "next_hop": NEXT_HOP_IP[addr_type],
3201 "vrf": "RED_A",
3202 },
3203 {
3204 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3205 "next_hop": NEXT_HOP_IP[addr_type],
3206 "vrf": "RED_B",
3207 },
3208 ]
3209 },
3210 "red2": {
3211 "static_routes": [
3212 {
3213 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3214 "next_hop": NEXT_HOP_IP[addr_type],
3215 "vrf": "RED_A",
3216 },
3217 {
3218 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3219 "next_hop": NEXT_HOP_IP[addr_type],
3220 "vrf": "RED_B",
3221 },
3222 ]
3223 },
3224 }
3225 result = create_static_routes(tgen, input_dict_1)
3226 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3227 tc_name, result
3228 )
3229
3230 step(
3231 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
3232 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
3233 )
3234
3235 for addr_type in ADDR_TYPES:
3236 input_dict_2 = {
3237 "blue1": {
3238 "static_routes": [
3239 {
3240 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3241 "next_hop": NEXT_HOP_IP[addr_type],
3242 "vrf": "BLUE_A",
3243 },
3244 {
3245 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3246 "next_hop": NEXT_HOP_IP[addr_type],
3247 "vrf": "BLUE_B",
3248 },
3249 ]
3250 },
3251 "blue2": {
3252 "static_routes": [
3253 {
3254 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3255 "next_hop": NEXT_HOP_IP[addr_type],
3256 "vrf": "BLUE_A",
3257 },
3258 {
3259 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3260 "next_hop": NEXT_HOP_IP[addr_type],
3261 "vrf": "BLUE_B",
3262 },
3263 ]
3264 },
3265 }
3266 result = create_static_routes(tgen, input_dict_2)
3267 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3268 tc_name, result
3269 )
3270
3271 step("Redistribute static..")
3272
3273 input_dict_3 = {}
3274 for dut in ["red1", "red2", "blue1", "blue2"]:
3275 temp = {dut: {"bgp": []}}
3276 input_dict_3.update(temp)
3277
3278 if "red" in dut:
3279 VRFS = ["RED_A", "RED_B"]
3280 AS_NUM = [500, 500]
3281 elif "blue" in dut:
3282 VRFS = ["BLUE_A", "BLUE_B"]
3283 AS_NUM = [800, 800]
3284
3285 for vrf, as_num in zip(VRFS, AS_NUM):
3286 temp[dut]["bgp"].append(
3287 {
3288 "local_as": as_num,
3289 "vrf": vrf,
3290 "address_family": {
3291 "ipv4": {
3292 "unicast": {"redistribute": [{"redist_type": "static"}]}
3293 },
3294 "ipv6": {
3295 "unicast": {"redistribute": [{"redist_type": "static"}]}
3296 },
3297 },
3298 }
3299 )
3300
3301 result = create_router_bgp(tgen, topo, input_dict_3)
3302 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3303
3304 step("Configure a route-maps to influence BGP parameters - " " Local Preference")
3305
3306 for addr_type in ADDR_TYPES:
3307 input_dict_4 = {
3308 "r2": {
3309 "route_maps": {
3310 "rmap_r1_{}".format(addr_type): [
3311 {
3312 "action": "permit",
3313 "set": {
3314 "path": {"as_num": "111 222", "as_action": "prepend"}
3315 },
3316 }
3317 ]
3318 }
3319 }
3320 }
3321 result = create_route_maps(tgen, input_dict_4)
3322 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3323 tc_name, result
3324 )
3325
3326 step("Configure neighbor for route map")
3327 input_dict_4 = {
3328 "r2": {
3329 "bgp": [
3330 {
3331 "local_as": "100",
3332 "vrf": "RED_A",
3333 "address_family": {
3334 "ipv4": {
3335 "unicast": {
3336 "neighbor": {
3337 "r1": {
3338 "dest_link": {
3339 "r2-link1": {
3340 "route_maps": [
3341 {
3342 "name": "rmap_r1_ipv4",
3343 "direction": "in",
3344 }
3345 ]
3346 }
3347 }
3348 },
3349 "r3": {"dest_link": {"r2-link1": {}}},
3350 }
3351 }
3352 },
3353 "ipv6": {
3354 "unicast": {
3355 "neighbor": {
3356 "r1": {
3357 "dest_link": {
3358 "r2-link1": {
3359 "route_maps": [
3360 {
3361 "name": "rmap_r1_ipv6",
3362 "direction": "in",
3363 }
3364 ]
3365 }
3366 }
3367 },
3368 "r3": {"dest_link": {"r2-link1": {}}},
3369 }
3370 }
3371 },
3372 },
3373 },
3374 {
3375 "local_as": "100",
3376 "vrf": "RED_B",
3377 "address_family": {
3378 "ipv4": {
3379 "unicast": {
3380 "neighbor": {
3381 "r1": {
3382 "dest_link": {
3383 "r2-link2": {
3384 "route_maps": [
3385 {
3386 "name": "rmap_r1_ipv4",
3387 "direction": "in",
3388 }
3389 ]
3390 }
3391 }
3392 },
3393 "r3": {"dest_link": {"r2-link2": {}}},
3394 }
3395 }
3396 },
3397 "ipv6": {
3398 "unicast": {
3399 "neighbor": {
3400 "r1": {
3401 "dest_link": {
3402 "r2-link2": {
3403 "route_maps": [
3404 {
3405 "name": "rmap_r1_ipv6",
3406 "direction": "in",
3407 }
3408 ]
3409 }
3410 }
3411 },
3412 "r3": {"dest_link": {"r2-link2": {}}},
3413 }
3414 }
3415 },
3416 },
3417 },
3418 {
3419 "local_as": "100",
3420 "vrf": "BLUE_A",
3421 "address_family": {
3422 "ipv4": {
3423 "unicast": {
3424 "neighbor": {
3425 "r1": {
3426 "dest_link": {
3427 "r2-link3": {
3428 "route_maps": [
3429 {
3430 "name": "rmap_r1_ipv4",
3431 "direction": "in",
3432 }
3433 ]
3434 }
3435 }
3436 },
3437 "r3": {"dest_link": {"r2-link3": {}}},
3438 }
3439 }
3440 },
3441 "ipv6": {
3442 "unicast": {
3443 "neighbor": {
3444 "r1": {
3445 "dest_link": {
3446 "r2-link3": {
3447 "route_maps": [
3448 {
3449 "name": "rmap_r1_ipv6",
3450 "direction": "in",
3451 }
3452 ]
3453 }
3454 }
3455 },
3456 "r3": {"dest_link": {"r2-link3": {}}},
3457 }
3458 }
3459 },
3460 },
3461 },
3462 {
3463 "local_as": "100",
3464 "vrf": "BLUE_B",
3465 "address_family": {
3466 "ipv4": {
3467 "unicast": {
3468 "neighbor": {
3469 "r1": {
3470 "dest_link": {
3471 "r2-link4": {
3472 "route_maps": [
3473 {
3474 "name": "rmap_r1_ipv4",
3475 "direction": "in",
3476 }
3477 ]
3478 }
3479 }
3480 },
3481 "r3": {"dest_link": {"r2-link4": {}}},
3482 }
3483 }
3484 },
3485 "ipv6": {
3486 "unicast": {
3487 "neighbor": {
3488 "r1": {
3489 "dest_link": {
3490 "r2-link4": {
3491 "route_maps": [
3492 {
3493 "name": "rmap_r1_ipv6",
3494 "direction": "in",
3495 }
3496 ]
3497 }
3498 }
3499 },
3500 "r3": {"dest_link": {"r2-link4": {}}},
3501 }
3502 }
3503 },
3504 },
3505 },
3506 ]
3507 }
3508 }
3509
3510 result = create_router_bgp(tgen, topo, input_dict_4)
3511 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3512
3513 step(
3514 "Verify that within vrf instances, BGP best path selection"
3515 " algorithm remains intact and doesn't affect any other VRFs"
3516 " routing decision."
3517 )
3518
3519 dut = "r2"
3520 attribute = "path"
3521 for addr_type in ADDR_TYPES:
3522 input_dict_1 = {
3523 "red1": {
3524 "static_routes": [
3525 {
3526 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3527 "next_hop": NEXT_HOP_IP[addr_type],
3528 "vrf": "RED_A",
3529 },
3530 {
3531 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3532 "next_hop": NEXT_HOP_IP[addr_type],
3533 "vrf": "RED_B",
3534 },
3535 ]
3536 }
3537 }
3538
3539 input_dict_2 = {
3540 "blue1": {
3541 "static_routes": [
3542 {
3543 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3544 "next_hop": NEXT_HOP_IP[addr_type],
3545 "vrf": "BLUE_A",
3546 },
3547 {
3548 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3549 "next_hop": NEXT_HOP_IP[addr_type],
3550 "vrf": "BLUE_B",
3551 },
3552 ]
3553 }
3554 }
3555
3556 result = verify_best_path_as_per_bgp_attribute(
3557 tgen, addr_type, dut, input_dict_1, attribute
3558 )
3559 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3560 tc_name, result
3561 )
3562
3563 result = verify_best_path_as_per_bgp_attribute(
3564 tgen, addr_type, dut, input_dict_2, attribute
3565 )
3566 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3567 tc_name, result
3568 )
3569
3570 write_test_footer(tc_name)
3571
3572
3573 def test_route_map_within_vrf_to_alter_bgp_attribute_lcomm_p0(request):
3574 """
3575 FUNC_12_f:
3576 Configure route-maps within a VRF, to alter BGP attributes.
3577 Verify that route-map doesn't affect any other VRF instances'
3578 routing on DUT.
3579 """
3580
3581 tgen = get_topogen()
3582 tc_name = request.node.name
3583 write_test_header(tc_name)
3584 reset_config_on_routers(tgen)
3585
3586 if tgen.routers_have_failure():
3587 check_router_status(tgen)
3588
3589 step(
3590 "Advertise a set of BGP prefixes(IPv4+IPv6) from RED_1 and"
3591 " RED_2 in vrf instances(RED_A and RED_B)."
3592 )
3593
3594 for addr_type in ADDR_TYPES:
3595 input_dict_1 = {
3596 "red1": {
3597 "static_routes": [
3598 {
3599 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3600 "next_hop": NEXT_HOP_IP[addr_type],
3601 "vrf": "RED_A",
3602 },
3603 {
3604 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3605 "next_hop": NEXT_HOP_IP[addr_type],
3606 "vrf": "RED_B",
3607 },
3608 ]
3609 },
3610 "red2": {
3611 "static_routes": [
3612 {
3613 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3614 "next_hop": NEXT_HOP_IP[addr_type],
3615 "vrf": "RED_A",
3616 },
3617 {
3618 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3619 "next_hop": NEXT_HOP_IP[addr_type],
3620 "vrf": "RED_B",
3621 },
3622 ]
3623 },
3624 }
3625 result = create_static_routes(tgen, input_dict_1)
3626 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3627 tc_name, result
3628 )
3629
3630 step(
3631 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
3632 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
3633 )
3634
3635 for addr_type in ADDR_TYPES:
3636 input_dict_2 = {
3637 "blue1": {
3638 "static_routes": [
3639 {
3640 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3641 "next_hop": NEXT_HOP_IP[addr_type],
3642 "vrf": "BLUE_A",
3643 },
3644 {
3645 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3646 "next_hop": NEXT_HOP_IP[addr_type],
3647 "vrf": "BLUE_B",
3648 },
3649 ]
3650 },
3651 "blue2": {
3652 "static_routes": [
3653 {
3654 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
3655 "next_hop": NEXT_HOP_IP[addr_type],
3656 "vrf": "BLUE_A",
3657 },
3658 {
3659 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
3660 "next_hop": NEXT_HOP_IP[addr_type],
3661 "vrf": "BLUE_B",
3662 },
3663 ]
3664 },
3665 }
3666 result = create_static_routes(tgen, input_dict_2)
3667 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3668 tc_name, result
3669 )
3670
3671 step("Redistribute static..")
3672
3673 input_dict_3 = {}
3674 for dut in ["red1", "red2", "blue1", "blue2"]:
3675 temp = {dut: {"bgp": []}}
3676 input_dict_3.update(temp)
3677
3678 if "red" in dut:
3679 VRFS = ["RED_A", "RED_B"]
3680 AS_NUM = [500, 500]
3681 elif "blue" in dut:
3682 VRFS = ["BLUE_A", "BLUE_B"]
3683 AS_NUM = [800, 800]
3684
3685 for vrf, as_num in zip(VRFS, AS_NUM):
3686 temp[dut]["bgp"].append(
3687 {
3688 "local_as": as_num,
3689 "vrf": vrf,
3690 "address_family": {
3691 "ipv4": {
3692 "unicast": {"redistribute": [{"redist_type": "static"}]}
3693 },
3694 "ipv6": {
3695 "unicast": {"redistribute": [{"redist_type": "static"}]}
3696 },
3697 },
3698 }
3699 )
3700
3701 result = create_router_bgp(tgen, topo, input_dict_3)
3702 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3703
3704 step("Configure a route-maps to influence BGP parameters - " " Large-community")
3705
3706 step("Create standard large commumity-list in r2")
3707
3708 for addr_type in ADDR_TYPES:
3709 input_dict_1 = {
3710 "r2": {
3711 "bgp_community_lists": [
3712 {
3713 "community_type": "standard",
3714 "action": "permit",
3715 "name": "rmap_lcomm_{}".format(addr_type),
3716 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
3717 "large": True,
3718 }
3719 ]
3720 }
3721 }
3722 result = create_bgp_community_lists(tgen, input_dict_1)
3723 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3724 tc_name, result
3725 )
3726
3727 step("Create route-maps in red1 and r1")
3728
3729 for addr_type in ADDR_TYPES:
3730 input_dict_4 = {
3731 "red1": {
3732 "route_maps": {
3733 "rmap_red1_{}".format(addr_type): [
3734 {
3735 "action": "permit",
3736 "set": {
3737 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
3738 },
3739 }
3740 ]
3741 }
3742 },
3743 "r2": {
3744 "route_maps": {
3745 "rmap_r1_{}".format(addr_type): [
3746 {
3747 "action": "permit",
3748 "match": {
3749 "large_community_list": {
3750 "id": "rmap_lcomm_" + addr_type
3751 }
3752 },
3753 }
3754 ]
3755 }
3756 },
3757 }
3758 result = create_route_maps(tgen, input_dict_4)
3759 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3760 tc_name, result
3761 )
3762
3763 step("Configure neighbor for route map in red1")
3764
3765 input_dict_4 = {
3766 "red1": {
3767 "bgp": [
3768 {
3769 "local_as": "500",
3770 "vrf": "RED_A",
3771 "address_family": {
3772 "ipv4": {
3773 "unicast": {
3774 "neighbor": {
3775 "r1": {
3776 "dest_link": {
3777 "red1-link1": {
3778 "route_maps": [
3779 {
3780 "name": "rmap_red1_ipv4",
3781 "direction": "out",
3782 }
3783 ]
3784 }
3785 }
3786 }
3787 }
3788 }
3789 },
3790 "ipv6": {
3791 "unicast": {
3792 "neighbor": {
3793 "r1": {
3794 "dest_link": {
3795 "red1-link1": {
3796 "route_maps": [
3797 {
3798 "name": "rmap_red1_ipv6",
3799 "direction": "out",
3800 }
3801 ]
3802 }
3803 }
3804 }
3805 }
3806 }
3807 },
3808 },
3809 },
3810 {
3811 "local_as": "500",
3812 "vrf": "RED_B",
3813 "address_family": {
3814 "ipv4": {
3815 "unicast": {
3816 "neighbor": {
3817 "r1": {
3818 "dest_link": {
3819 "red1-link2": {
3820 "route_maps": [
3821 {
3822 "name": "rmap_red1_ipv4",
3823 "direction": "out",
3824 }
3825 ]
3826 }
3827 }
3828 }
3829 }
3830 }
3831 },
3832 "ipv6": {
3833 "unicast": {
3834 "neighbor": {
3835 "r1": {
3836 "dest_link": {
3837 "red1-link2": {
3838 "route_maps": [
3839 {
3840 "name": "rmap_red1_ipv6",
3841 "direction": "out",
3842 }
3843 ]
3844 }
3845 }
3846 }
3847 }
3848 }
3849 },
3850 },
3851 },
3852 ]
3853 }
3854 }
3855
3856 result = create_router_bgp(tgen, topo, input_dict_4)
3857 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3858
3859 step("Configure neighbor for route map in r2")
3860
3861 input_dict_4 = {
3862 "r2": {
3863 "bgp": [
3864 {
3865 "local_as": "100",
3866 "vrf": "RED_A",
3867 "address_family": {
3868 "ipv4": {
3869 "unicast": {
3870 "neighbor": {
3871 "r1": {
3872 "dest_link": {
3873 "r2-link1": {
3874 "route_maps": [
3875 {
3876 "name": "rmap_r1_ipv4",
3877 "direction": "in",
3878 }
3879 ]
3880 }
3881 }
3882 }
3883 }
3884 }
3885 },
3886 "ipv6": {
3887 "unicast": {
3888 "neighbor": {
3889 "r1": {
3890 "dest_link": {
3891 "r2-link1": {
3892 "route_maps": [
3893 {
3894 "name": "rmap_r1_ipv6",
3895 "direction": "in",
3896 }
3897 ]
3898 }
3899 }
3900 }
3901 }
3902 }
3903 },
3904 },
3905 },
3906 {
3907 "local_as": "100",
3908 "vrf": "RED_B",
3909 "address_family": {
3910 "ipv4": {
3911 "unicast": {
3912 "neighbor": {
3913 "r1": {
3914 "dest_link": {
3915 "r2-link2": {
3916 "route_maps": [
3917 {
3918 "name": "rmap_r1_ipv4",
3919 "direction": "in",
3920 }
3921 ]
3922 }
3923 }
3924 }
3925 }
3926 }
3927 },
3928 "ipv6": {
3929 "unicast": {
3930 "neighbor": {
3931 "r1": {
3932 "dest_link": {
3933 "r2-link2": {
3934 "route_maps": [
3935 {
3936 "name": "rmap_r1_ipv6",
3937 "direction": "in",
3938 }
3939 ]
3940 }
3941 }
3942 }
3943 }
3944 }
3945 },
3946 },
3947 },
3948 {
3949 "local_as": "100",
3950 "vrf": "BLUE_A",
3951 "address_family": {
3952 "ipv4": {
3953 "unicast": {
3954 "neighbor": {
3955 "r1": {
3956 "dest_link": {
3957 "r2-link3": {
3958 "route_maps": [
3959 {
3960 "name": "rmap_r1_ipv4",
3961 "direction": "in",
3962 }
3963 ]
3964 }
3965 }
3966 }
3967 }
3968 }
3969 },
3970 "ipv6": {
3971 "unicast": {
3972 "neighbor": {
3973 "r1": {
3974 "dest_link": {
3975 "r2-link3": {
3976 "route_maps": [
3977 {
3978 "name": "rmap_r1_ipv6",
3979 "direction": "in",
3980 }
3981 ]
3982 }
3983 }
3984 }
3985 }
3986 }
3987 },
3988 },
3989 },
3990 {
3991 "local_as": "100",
3992 "vrf": "BLUE_B",
3993 "address_family": {
3994 "ipv4": {
3995 "unicast": {
3996 "neighbor": {
3997 "r1": {
3998 "dest_link": {
3999 "r2-link4": {
4000 "route_maps": [
4001 {
4002 "name": "rmap_r1_ipv4",
4003 "direction": "in",
4004 }
4005 ]
4006 }
4007 }
4008 }
4009 }
4010 }
4011 },
4012 "ipv6": {
4013 "unicast": {
4014 "neighbor": {
4015 "r1": {
4016 "dest_link": {
4017 "r2-link4": {
4018 "route_maps": [
4019 {
4020 "name": "rmap_r1_ipv6",
4021 "direction": "in",
4022 }
4023 ]
4024 }
4025 }
4026 }
4027 }
4028 }
4029 },
4030 },
4031 },
4032 ]
4033 }
4034 }
4035
4036 result = create_router_bgp(tgen, topo, input_dict_4)
4037 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4038
4039 step(
4040 "All the prefixes advertised from RED_1 and BLUE_1 should carry"
4041 " attributes set by outbound route-maps within specific vrfs. "
4042 "Router R1 should be able to match and permit/deny those "
4043 "prefixes based on received attributes. Please use below "
4044 "commands to verify."
4045 )
4046
4047 input_dict = {
4048 "largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2",
4049 }
4050
4051 for addr_type in ADDR_TYPES:
4052 vrf = "RED_A"
4053 routes = [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]]
4054 result = verify_bgp_community(tgen, addr_type, "r2", routes, input_dict, vrf)
4055 assert result is True, "Test case {} : Failed \n Error: {}".format(
4056 tc_name, result
4057 )
4058
4059 for addr_type in ADDR_TYPES:
4060 vrf = "RED_B"
4061 routes = [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]]
4062 result = verify_bgp_community(tgen, addr_type, "r2", routes, input_dict, vrf)
4063 assert result is True, "Test case {} : Failed \n Error: {}".format(
4064 tc_name, result
4065 )
4066
4067 write_test_footer(tc_name)
4068
4069
4070 def test_route_map_match_traffic_based_on_vrf_p0(request):
4071 """
4072 FUNC_13:
4073 Configure a route-map on DUT to match traffic based
4074 on a VRF interfaces.
4075 """
4076
4077 tgen = get_topogen()
4078 tc_name = request.node.name
4079 write_test_header(tc_name)
4080 reset_config_on_routers(tgen)
4081
4082 if tgen.routers_have_failure():
4083 check_router_status(tgen)
4084
4085 step(
4086 "Advertise unique BGP prefixes(IPv4+IPv6) from RED_1 "
4087 "in vrf instances(RED_A and RED_B)."
4088 )
4089
4090 for addr_type in ADDR_TYPES:
4091 input_dict_1 = {
4092 "red1": {
4093 "static_routes": [
4094 {
4095 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4096 "next_hop": NEXT_HOP_IP[addr_type],
4097 "vrf": "RED_A",
4098 },
4099 {
4100 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4101 "next_hop": NEXT_HOP_IP[addr_type],
4102 "vrf": "RED_B",
4103 },
4104 ]
4105 }
4106 }
4107 result = create_static_routes(tgen, input_dict_1)
4108 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4109 tc_name, result
4110 )
4111
4112 step(
4113 "Advertise unique BGP prefixes(IPv4+IPv6) from from BLUE_1 in"
4114 " vrf instances(BLUE_A and BLUE_B)."
4115 )
4116
4117 for addr_type in ADDR_TYPES:
4118 input_dict_2 = {
4119 "blue1": {
4120 "static_routes": [
4121 {
4122 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
4123 "next_hop": NEXT_HOP_IP[addr_type],
4124 "vrf": "BLUE_A",
4125 },
4126 {
4127 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
4128 "next_hop": NEXT_HOP_IP[addr_type],
4129 "vrf": "BLUE_B",
4130 },
4131 ]
4132 }
4133 }
4134 result = create_static_routes(tgen, input_dict_2)
4135 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4136 tc_name, result
4137 )
4138
4139 step("Redistribute static..")
4140
4141 input_dict_3 = {}
4142 for dut in ["red1", "blue1"]:
4143 temp = {dut: {"bgp": []}}
4144 input_dict_3.update(temp)
4145
4146 if "red" in dut:
4147 VRFS = ["RED_A", "RED_B"]
4148 AS_NUM = [500, 500]
4149 elif "blue" in dut:
4150 VRFS = ["BLUE_A", "BLUE_B"]
4151 AS_NUM = [800, 800]
4152
4153 for vrf, as_num in zip(VRFS, AS_NUM):
4154 temp[dut]["bgp"].append(
4155 {
4156 "local_as": as_num,
4157 "vrf": vrf,
4158 "address_family": {
4159 "ipv4": {
4160 "unicast": {"redistribute": [{"redist_type": "static"}]}
4161 },
4162 "ipv6": {
4163 "unicast": {"redistribute": [{"redist_type": "static"}]}
4164 },
4165 },
4166 }
4167 )
4168
4169 result = create_router_bgp(tgen, topo, input_dict_3)
4170 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4171
4172 step(
4173 "Configure a route-map on R1 to match the prefixes "
4174 "coming from vrf RED_A and set as-prepend to these routes."
4175 )
4176
4177 input_dict_4 = {
4178 "r1": {
4179 "route_maps": {
4180 "ABC": [
4181 {
4182 "action": "permit",
4183 "match": {"source-vrf": "RED_A"},
4184 "set": {"path": {"as_num": 1, "as_action": "prepend"}},
4185 }
4186 ]
4187 }
4188 }
4189 }
4190 result = create_route_maps(tgen, input_dict_4)
4191 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4192
4193 step(
4194 "On R1, import the routes form vrf RED_A and RED_B to BLUE_A and"
4195 " apply the route-map under vrf BLUE_A while importing"
4196 )
4197
4198 raw_config = {
4199 "r1": {
4200 "raw_config": [
4201 "router bgp 100 vrf BLUE_A",
4202 "address-family ipv4 unicast",
4203 "import vrf RED_A",
4204 "import vrf RED_B",
4205 "import vrf route-map ABC",
4206 "address-family ipv6 unicast",
4207 "import vrf RED_A",
4208 "import vrf RED_B",
4209 "import vrf route-map ABC",
4210 ]
4211 }
4212 }
4213 result = apply_raw_config(tgen, raw_config)
4214 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
4215
4216 step(
4217 "All the prefixes advertised from RED_1 and BLUE_1 in vrfs "
4218 "RED_B and BLUE_B must prepend the AS number in as-path on R2."
4219 )
4220
4221 for addr_type in ADDR_TYPES:
4222 input_dict_7 = {
4223 "red1": {
4224 "static_routes": [
4225 {
4226 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4227 "next_hop": NEXT_HOP_IP[addr_type],
4228 "vrf": "BLUE_A",
4229 },
4230 {
4231 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
4232 "next_hop": NEXT_HOP_IP[addr_type],
4233 "vrf": "BLUE_A",
4234 },
4235 ]
4236 }
4237 }
4238
4239 result = verify_bgp_rib(tgen, addr_type, "r1", input_dict_7)
4240 assert result is True, "Testcase {} : Failed \n Error {}".format(
4241 tc_name, result
4242 )
4243
4244 write_test_footer(tc_name)
4245
4246
4247 def test_vrf_lite_with_static_bgp_originated_routes_p0(request):
4248 """
4249 FUNC_14:
4250 Test VRF-lite with Static+BGP originated routes.
4251 """
4252
4253 tgen = get_topogen()
4254 tc_name = request.node.name
4255 write_test_header(tc_name)
4256 reset_config_on_routers(tgen)
4257
4258 if tgen.routers_have_failure():
4259 check_router_status(tgen)
4260
4261 step(
4262 "Advertise unique BGP prefixes(IPv4+IPv6) from from RED_1"
4263 " in vrf instances(RED_A and RED_B)."
4264 )
4265
4266 for addr_type in ADDR_TYPES:
4267 input_dict_1 = {
4268 "red1": {
4269 "static_routes": [
4270 {
4271 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4272 "next_hop": NEXT_HOP_IP[addr_type],
4273 "vrf": "RED_A",
4274 },
4275 {
4276 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4277 "next_hop": NEXT_HOP_IP[addr_type],
4278 "vrf": "RED_B",
4279 },
4280 ]
4281 }
4282 }
4283 result = create_static_routes(tgen, input_dict_1)
4284 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4285 tc_name, result
4286 )
4287
4288 step(
4289 "Advertise unique BGP prefixes(IPv4+IPv6) from from BLUE_1 in"
4290 " vrf instances(BLUE_A and BLUE_B)."
4291 )
4292
4293 for addr_type in ADDR_TYPES:
4294 input_dict_2 = {
4295 "blue1": {
4296 "static_routes": [
4297 {
4298 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4299 "next_hop": NEXT_HOP_IP[addr_type],
4300 "vrf": "BLUE_A",
4301 },
4302 {
4303 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4304 "next_hop": NEXT_HOP_IP[addr_type],
4305 "vrf": "BLUE_B",
4306 },
4307 ]
4308 }
4309 }
4310 result = create_static_routes(tgen, input_dict_2)
4311 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4312 tc_name, result
4313 )
4314
4315 input_dict_3 = {
4316 "red1": {
4317 "bgp": [
4318 {
4319 "local_as": "500",
4320 "vrf": "RED_A",
4321 "address_family": {
4322 "ipv4": {
4323 "unicast": {
4324 "advertise_networks": [
4325 {
4326 "network": [NETWORK5_1["ipv4"]]
4327 + [NETWORK5_2["ipv4"]]
4328 }
4329 ],
4330 "redistribute": [{"redist_type": "static"}],
4331 }
4332 },
4333 "ipv6": {
4334 "unicast": {
4335 "advertise_networks": [
4336 {
4337 "network": [NETWORK5_1["ipv6"]]
4338 + [NETWORK5_2["ipv6"]]
4339 }
4340 ],
4341 "redistribute": [{"redist_type": "static"}],
4342 }
4343 },
4344 },
4345 },
4346 {
4347 "local_as": "500",
4348 "vrf": "RED_B",
4349 "address_family": {
4350 "ipv4": {
4351 "unicast": {
4352 "advertise_networks": [
4353 {
4354 "network": [NETWORK6_1["ipv4"]]
4355 + [NETWORK6_2["ipv4"]]
4356 }
4357 ],
4358 "redistribute": [{"redist_type": "static"}],
4359 }
4360 },
4361 "ipv6": {
4362 "unicast": {
4363 "advertise_networks": [
4364 {
4365 "network": [NETWORK6_1["ipv6"]]
4366 + [NETWORK6_2["ipv6"]]
4367 }
4368 ],
4369 "redistribute": [{"redist_type": "static"}],
4370 }
4371 },
4372 },
4373 },
4374 ]
4375 },
4376 "blue1": {
4377 "bgp": [
4378 {
4379 "local_as": "800",
4380 "vrf": "BLUE_A",
4381 "address_family": {
4382 "ipv4": {
4383 "unicast": {
4384 "advertise_networks": [
4385 {
4386 "network": [NETWORK7_1["ipv4"]]
4387 + [NETWORK7_2["ipv4"]]
4388 }
4389 ],
4390 "redistribute": [{"redist_type": "static"}],
4391 }
4392 },
4393 "ipv6": {
4394 "unicast": {
4395 "advertise_networks": [
4396 {
4397 "network": [NETWORK7_1["ipv6"]]
4398 + [NETWORK7_2["ipv6"]]
4399 }
4400 ],
4401 "redistribute": [{"redist_type": "static"}],
4402 }
4403 },
4404 },
4405 },
4406 {
4407 "local_as": "800",
4408 "vrf": "BLUE_B",
4409 "address_family": {
4410 "ipv4": {
4411 "unicast": {
4412 "advertise_networks": [
4413 {
4414 "network": [NETWORK8_1["ipv4"]]
4415 + [NETWORK8_2["ipv4"]]
4416 }
4417 ],
4418 "redistribute": [{"redist_type": "static"}],
4419 }
4420 },
4421 "ipv6": {
4422 "unicast": {
4423 "advertise_networks": [
4424 {
4425 "network": [NETWORK8_1["ipv6"]]
4426 + [NETWORK8_2["ipv6"]]
4427 }
4428 ],
4429 "redistribute": [{"redist_type": "static"}],
4430 }
4431 },
4432 },
4433 },
4434 ]
4435 },
4436 }
4437
4438 result = create_router_bgp(tgen, topo, input_dict_3)
4439 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4440
4441 step("Static routes must be installed in associated VRF" " table only.")
4442
4443 for addr_type in ADDR_TYPES:
4444 dut = "r1"
4445 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_3)
4446 assert result is True, "Testcase {} : Failed \n Error {}".format(
4447 tc_name, result
4448 )
4449
4450 step(
4451 "All the routers must receive advertised as well as "
4452 "redistributed(static) prefixes in associated VRF tables."
4453 )
4454
4455 for addr_type in ADDR_TYPES:
4456 dut = "r1"
4457 input_dict_1 = {
4458 "red1": {
4459 "static_routes": [
4460 {
4461 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4462 "next_hop": NEXT_HOP_IP[addr_type],
4463 "vrf": "RED_A",
4464 },
4465 {
4466 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4467 "next_hop": NEXT_HOP_IP[addr_type],
4468 "vrf": "RED_B",
4469 },
4470 ]
4471 }
4472 }
4473
4474 input_dict_2 = {
4475 "blue1": {
4476 "static_routes": [
4477 {
4478 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4479 "next_hop": NEXT_HOP_IP[addr_type],
4480 "vrf": "BLUE_A",
4481 },
4482 {
4483 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4484 "next_hop": NEXT_HOP_IP[addr_type],
4485 "vrf": "BLUE_B",
4486 },
4487 ]
4488 }
4489 }
4490
4491 result = verify_rib(tgen, addr_type, dut, input_dict_1)
4492 assert result is True, "Testcase {} : Failed \n Error {}".format(
4493 tc_name, result
4494 )
4495
4496 result = verify_rib(tgen, addr_type, dut, input_dict_2)
4497 assert result is True, "Testcase {} : Failed \n Error {}".format(
4498 tc_name, result
4499 )
4500
4501 write_test_footer(tc_name)
4502
4503
4504 def test_prefix_list_to_permit_deny_prefixes_p0(request):
4505 """
4506 FUNC_15:
4507 Configure prefix-lists on DUT and apply to BGP peers to
4508 permit/deny prefixes.
4509 """
4510
4511 tgen = get_topogen()
4512 tc_name = request.node.name
4513 write_test_header(tc_name)
4514 reset_config_on_routers(tgen)
4515
4516 if tgen.routers_have_failure():
4517 check_router_status(tgen)
4518
4519 step(
4520 "Advertise unique BGP prefixes(IPv4+IPv6) from from RED_1"
4521 " in vrf instances(RED_A and RED_B)."
4522 )
4523
4524 for addr_type in ADDR_TYPES:
4525 input_dict_1 = {
4526 "red1": {
4527 "static_routes": [
4528 {
4529 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4530 "next_hop": NEXT_HOP_IP[addr_type],
4531 "vrf": "RED_A",
4532 },
4533 {
4534 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4535 "next_hop": NEXT_HOP_IP[addr_type],
4536 "vrf": "RED_B",
4537 },
4538 ]
4539 }
4540 }
4541 result = create_static_routes(tgen, input_dict_1)
4542 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4543 tc_name, result
4544 )
4545
4546 step(
4547 "Advertise unique BGP prefixes(IPv4+IPv6) from from BLUE_1 in"
4548 " vrf instances(BLUE_A and BLUE_B)."
4549 )
4550
4551 for addr_type in ADDR_TYPES:
4552 input_dict_2 = {
4553 "blue1": {
4554 "static_routes": [
4555 {
4556 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4557 "next_hop": NEXT_HOP_IP[addr_type],
4558 "vrf": "BLUE_A",
4559 },
4560 {
4561 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4562 "next_hop": NEXT_HOP_IP[addr_type],
4563 "vrf": "BLUE_B",
4564 },
4565 ]
4566 }
4567 }
4568 result = create_static_routes(tgen, input_dict_2)
4569 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4570 tc_name, result
4571 )
4572
4573 step("Redistribute static..")
4574
4575 input_dict_3 = {}
4576 for dut in ["red1", "blue1"]:
4577 temp = {dut: {"bgp": []}}
4578 input_dict_3.update(temp)
4579
4580 if "red" in dut:
4581 VRFS = ["RED_A", "RED_B"]
4582 AS_NUM = [500, 500]
4583 elif "blue" in dut:
4584 VRFS = ["BLUE_A", "BLUE_B"]
4585 AS_NUM = [800, 800]
4586
4587 for vrf, as_num in zip(VRFS, AS_NUM):
4588 temp[dut]["bgp"].append(
4589 {
4590 "local_as": as_num,
4591 "vrf": vrf,
4592 "address_family": {
4593 "ipv4": {
4594 "unicast": {"redistribute": [{"redist_type": "static"}]}
4595 },
4596 "ipv6": {
4597 "unicast": {"redistribute": [{"redist_type": "static"}]}
4598 },
4599 },
4600 }
4601 )
4602
4603 result = create_router_bgp(tgen, topo, input_dict_3)
4604 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4605
4606 step("Verify routes are present before applying prefix-list")
4607 for addr_type in ADDR_TYPES:
4608 dut = "r1"
4609 input_dict_1 = {
4610 "red1": {
4611 "static_routes": [
4612 {
4613 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4614 "next_hop": NEXT_HOP_IP[addr_type],
4615 "vrf": "RED_A",
4616 },
4617 {
4618 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4619 "next_hop": NEXT_HOP_IP[addr_type],
4620 "vrf": "RED_B",
4621 },
4622 ]
4623 }
4624 }
4625
4626 input_dict_2 = {
4627 "blue1": {
4628 "static_routes": [
4629 {
4630 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
4631 "next_hop": NEXT_HOP_IP[addr_type],
4632 "vrf": "BLUE_A",
4633 },
4634 {
4635 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
4636 "next_hop": NEXT_HOP_IP[addr_type],
4637 "vrf": "BLUE_B",
4638 },
4639 ]
4640 }
4641 }
4642
4643 result = verify_rib(tgen, addr_type, dut, input_dict_1)
4644 assert result is True, "Testcase {} : Failed \n Error {}".format(
4645 tc_name, result
4646 )
4647
4648 result = verify_rib(tgen, addr_type, dut, input_dict_2)
4649 assert result is True, "Testcase {} : Failed \n Error {}".format(
4650 tc_name, result
4651 )
4652
4653 step(
4654 "On routers RED_1 and BLUE_1, configure prefix-lists to permit"
4655 " 4 prefixes and deny 1 prefix x.x.x.5. Apply these in outbound"
4656 "direction for each neighbour."
4657 )
4658
4659 for addr_type in ADDR_TYPES:
4660 input_dict_4 = {
4661 "red1": {
4662 "prefix_lists": {
4663 addr_type: {
4664 "pflist_red1_{}".format(addr_type): [
4665 {
4666 "seqid": 10,
4667 "network": NETWORK1_1[addr_type],
4668 "action": "permit",
4669 },
4670 {
4671 "seqid": 11,
4672 "network": NETWORK2_1[addr_type],
4673 "action": "permit",
4674 },
4675 {
4676 "seqid": 12,
4677 "network": NETWORK1_2[addr_type],
4678 "action": "deny",
4679 },
4680 {
4681 "seqid": 13,
4682 "network": NETWORK2_2[addr_type],
4683 "action": "deny",
4684 },
4685 ]
4686 }
4687 }
4688 },
4689 "blue1": {
4690 "prefix_lists": {
4691 addr_type: {
4692 "pflist_blue1_{}".format(addr_type): [
4693 {
4694 "seqid": 10,
4695 "network": NETWORK1_1[addr_type],
4696 "action": "permit",
4697 },
4698 {
4699 "seqid": 11,
4700 "network": NETWORK2_1[addr_type],
4701 "action": "permit",
4702 },
4703 {
4704 "seqid": 12,
4705 "network": NETWORK1_2[addr_type],
4706 "action": "deny",
4707 },
4708 {
4709 "seqid": 13,
4710 "network": NETWORK2_2[addr_type],
4711 "action": "deny",
4712 },
4713 ]
4714 }
4715 }
4716 },
4717 "r1": {
4718 "prefix_lists": {
4719 addr_type: {
4720 "pflist_r1_{}".format(addr_type): [
4721 {
4722 "seqid": 10,
4723 "network": NETWORK1_1[addr_type],
4724 "action": "permit",
4725 },
4726 {
4727 "seqid": 11,
4728 "network": NETWORK2_1[addr_type],
4729 "action": "deny",
4730 },
4731 ]
4732 }
4733 }
4734 },
4735 }
4736 result = create_prefix_lists(tgen, input_dict_4)
4737 assert result is True, "Testcase {} : Failed \n Error: {}".format(
4738 tc_name, result
4739 )
4740
4741 input_dict_5 = {
4742 "red1": {
4743 "bgp": [
4744 {
4745 "local_as": "500",
4746 "vrf": "RED_A",
4747 "address_family": {
4748 "ipv4": {
4749 "unicast": {
4750 "neighbor": {
4751 "r1": {
4752 "dest_link": {
4753 "red1-link1": {
4754 "prefix_lists": [
4755 {
4756 "name": "pflist_red1_ipv4",
4757 "direction": "out",
4758 }
4759 ]
4760 }
4761 }
4762 }
4763 }
4764 }
4765 },
4766 "ipv6": {
4767 "unicast": {
4768 "neighbor": {
4769 "r1": {
4770 "dest_link": {
4771 "red1-link1": {
4772 "prefix_lists": [
4773 {
4774 "name": "pflist_red1_ipv6",
4775 "direction": "out",
4776 }
4777 ]
4778 }
4779 }
4780 }
4781 }
4782 }
4783 },
4784 },
4785 },
4786 {
4787 "local_as": "500",
4788 "vrf": "RED_B",
4789 "address_family": {
4790 "ipv4": {
4791 "unicast": {
4792 "neighbor": {
4793 "r1": {
4794 "dest_link": {
4795 "red1-link2": {
4796 "prefix_lists": [
4797 {
4798 "name": "pflist_red1_ipv4",
4799 "direction": "out",
4800 }
4801 ]
4802 }
4803 }
4804 }
4805 }
4806 }
4807 },
4808 "ipv6": {
4809 "unicast": {
4810 "neighbor": {
4811 "r1": {
4812 "dest_link": {
4813 "red1-link2": {
4814 "prefix_lists": [
4815 {
4816 "name": "pflist_red1_ipv6",
4817 "direction": "out",
4818 }
4819 ]
4820 }
4821 }
4822 }
4823 }
4824 }
4825 },
4826 },
4827 },
4828 ]
4829 },
4830 "blue1": {
4831 "bgp": [
4832 {
4833 "local_as": "800",
4834 "vrf": "BLUE_A",
4835 "address_family": {
4836 "ipv4": {
4837 "unicast": {
4838 "neighbor": {
4839 "r1": {
4840 "dest_link": {
4841 "blue1-link1": {
4842 "prefix_lists": [
4843 {
4844 "name": "pflist_blue1_ipv4",
4845 "direction": "out",
4846 }
4847 ]
4848 }
4849 }
4850 }
4851 }
4852 }
4853 },
4854 "ipv6": {
4855 "unicast": {
4856 "neighbor": {
4857 "r1": {
4858 "dest_link": {
4859 "blue1-link1": {
4860 "prefix_lists": [
4861 {
4862 "name": "pflist_blue1_ipv6",
4863 "direction": "out",
4864 }
4865 ]
4866 }
4867 }
4868 }
4869 }
4870 }
4871 },
4872 },
4873 },
4874 {
4875 "local_as": "800",
4876 "vrf": "BLUE_B",
4877 "address_family": {
4878 "ipv4": {
4879 "unicast": {
4880 "neighbor": {
4881 "r1": {
4882 "dest_link": {
4883 "blue1-link2": {
4884 "prefix_lists": [
4885 {
4886 "name": "pflist_blue1_ipv4",
4887 "direction": "out",
4888 }
4889 ]
4890 }
4891 }
4892 }
4893 }
4894 }
4895 },
4896 "ipv6": {
4897 "unicast": {
4898 "neighbor": {
4899 "r1": {
4900 "dest_link": {
4901 "blue1-link2": {
4902 "prefix_lists": [
4903 {
4904 "name": "pflist_blue1_ipv6",
4905 "direction": "out",
4906 }
4907 ]
4908 }
4909 }
4910 }
4911 }
4912 }
4913 },
4914 },
4915 },
4916 ]
4917 },
4918 }
4919
4920 result = create_router_bgp(tgen, topo, input_dict_5)
4921 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
4922
4923 step(
4924 "Verify that within vrf instances, each BGP neighbor receives 1"
4925 " prefixes in routing table and drops (x.x.x.2)."
4926 )
4927
4928 for addr_type in ADDR_TYPES:
4929 dut = "r1"
4930 permitted_routes = {
4931 "red1": {
4932 "static_routes": [
4933 {"network": [NETWORK1_1[addr_type]], "vrf": "RED_A"},
4934 {"network": [NETWORK2_1[addr_type]], "vrf": "RED_B"},
4935 ]
4936 }
4937 }
4938
4939 denied_routes = {
4940 "red1": {
4941 "static_routes": [
4942 {"network": [NETWORK1_2[addr_type]], "vrf": "RED_A"},
4943 {"network": [NETWORK2_2[addr_type]], "vrf": "RED_B"},
4944 ]
4945 }
4946 }
4947
4948 result = verify_rib(tgen, addr_type, dut, permitted_routes)
4949 assert result is True, "Testcase {} : Failed \n Error {}".format(
4950 tc_name, result
4951 )
4952
4953 result = verify_rib(tgen, addr_type, dut, denied_routes, expected=False)
4954 assert result is not True, "Testcase {} : Failed \n"
4955 "{}:Expected behaviour: Routes are denied by prefix-list \nError {}".format(tc_name, result)
4956
4957 step(
4958 "On router R1, configure prefix-lists to permit 2 "
4959 "prefixes(x.x.x.1-2) and deny 2 prefix(x.x.x.3-4). Apply"
4960 " these in inbound direction for each neighbour."
4961 )
4962
4963 input_dict_6 = {
4964 "r1": {
4965 "bgp": [
4966 {
4967 "local_as": "100",
4968 "vrf": "RED_A",
4969 "address_family": {
4970 "ipv4": {
4971 "unicast": {
4972 "neighbor": {
4973 "red1": {
4974 "dest_link": {
4975 "r1-link1": {
4976 "prefix_lists": [
4977 {
4978 "name": "pflist_r1_ipv4",
4979 "direction": "in",
4980 }
4981 ]
4982 }
4983 }
4984 }
4985 }
4986 }
4987 },
4988 "ipv6": {
4989 "unicast": {
4990 "neighbor": {
4991 "red1": {
4992 "dest_link": {
4993 "r1-link1": {
4994 "prefix_lists": [
4995 {
4996 "name": "pflist_r1_ipv6",
4997 "direction": "in",
4998 }
4999 ]
5000 }
5001 }
5002 }
5003 }
5004 }
5005 },
5006 },
5007 },
5008 {
5009 "local_as": "100",
5010 "vrf": "RED_B",
5011 "address_family": {
5012 "ipv4": {
5013 "unicast": {
5014 "neighbor": {
5015 "red1": {
5016 "dest_link": {
5017 "r1-link2": {
5018 "prefix_lists": [
5019 {
5020 "name": "pflist_r1_ipv4",
5021 "direction": "in",
5022 }
5023 ]
5024 }
5025 }
5026 }
5027 }
5028 }
5029 },
5030 "ipv6": {
5031 "unicast": {
5032 "neighbor": {
5033 "red1": {
5034 "dest_link": {
5035 "r1-link2": {
5036 "prefix_lists": [
5037 {
5038 "name": "pflist_r1_ipv6",
5039 "direction": "in",
5040 }
5041 ]
5042 }
5043 }
5044 }
5045 }
5046 }
5047 },
5048 },
5049 },
5050 {
5051 "local_as": "100",
5052 "vrf": "BLUE_A",
5053 "address_family": {
5054 "ipv4": {
5055 "unicast": {
5056 "neighbor": {
5057 "blue1": {
5058 "dest_link": {
5059 "r1-link1": {
5060 "prefix_lists": [
5061 {
5062 "name": "pflist_r1_ipv4",
5063 "direction": "in",
5064 }
5065 ]
5066 }
5067 }
5068 }
5069 }
5070 }
5071 },
5072 "ipv6": {
5073 "unicast": {
5074 "neighbor": {
5075 "blue1": {
5076 "dest_link": {
5077 "r1-link1": {
5078 "prefix_lists": [
5079 {
5080 "name": "pflist_r1_ipv6",
5081 "direction": "in",
5082 }
5083 ]
5084 }
5085 }
5086 }
5087 }
5088 }
5089 },
5090 },
5091 },
5092 {
5093 "local_as": "100",
5094 "vrf": "BLUE_B",
5095 "address_family": {
5096 "ipv4": {
5097 "unicast": {
5098 "neighbor": {
5099 "blue1": {
5100 "dest_link": {
5101 "r1-link2": {
5102 "prefix_lists": [
5103 {
5104 "name": "pflist_r1_ipv4",
5105 "direction": "in",
5106 }
5107 ]
5108 }
5109 }
5110 }
5111 }
5112 }
5113 },
5114 "ipv6": {
5115 "unicast": {
5116 "neighbor": {
5117 "blue1": {
5118 "dest_link": {
5119 "r1-link2": {
5120 "prefix_lists": [
5121 {
5122 "name": "pflist_r1_ipv6",
5123 "direction": "in",
5124 }
5125 ]
5126 }
5127 }
5128 }
5129 }
5130 }
5131 },
5132 },
5133 },
5134 ]
5135 }
5136 }
5137
5138 result = create_router_bgp(tgen, topo, input_dict_6)
5139 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5140
5141 step(
5142 "Verify that within vrf instances, each BGP neighbor installs"
5143 " only 1 prefix (x.x.x.1)."
5144 )
5145 for addr_type in ADDR_TYPES:
5146 dut = "r2"
5147 permitted_routes = {
5148 "red1": {
5149 "static_routes": [{"network": [NETWORK1_1[addr_type]], "vrf": "RED_A"}]
5150 }
5151 }
5152
5153 denied_routes = {
5154 "red1": {
5155 "static_routes": [{"network": [NETWORK2_1[addr_type]], "vrf": "RED_A"}]
5156 }
5157 }
5158
5159 result = verify_rib(tgen, addr_type, dut, permitted_routes)
5160 assert result is True, "Testcase {} : Failed \n Error {}".format(
5161 tc_name, result
5162 )
5163
5164 result = verify_rib(tgen, addr_type, dut, denied_routes, expected=False)
5165 assert result is not True, "Testcase {} : Failed \nExpected behaviour: Routes are denied by prefix-list \nError {}".format(tc_name, result)
5166
5167 write_test_footer(tc_name)
5168
5169
5170 def test_route_map_set_and_match_tag_p0(request):
5171 """
5172 FUNC_16_1:
5173 Configure a route-map on DUT to match traffic based various
5174 match/set causes.
5175 """
5176
5177 tgen = get_topogen()
5178 tc_name = request.node.name
5179 write_test_header(tc_name)
5180 reset_config_on_routers(tgen)
5181
5182 if tgen.routers_have_failure():
5183 check_router_status(tgen)
5184
5185 step(
5186 "Advertise unique BGP prefixes(IPv4+IPv6) from RED_1"
5187 " in vrf instances(RED_A and RED_B)."
5188 )
5189
5190 for addr_type in ADDR_TYPES:
5191 input_dict_1 = {
5192 "red1": {
5193 "static_routes": [
5194 {
5195 "network": [NETWORK1_1[addr_type]],
5196 "next_hop": NEXT_HOP_IP[addr_type],
5197 "tag": 4001,
5198 "vrf": "RED_A",
5199 },
5200 {
5201 "network": [NETWORK1_2[addr_type]],
5202 "next_hop": NEXT_HOP_IP[addr_type],
5203 "vrf": "RED_A",
5204 },
5205 {
5206 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
5207 "next_hop": NEXT_HOP_IP[addr_type],
5208 "vrf": "RED_B",
5209 },
5210 ]
5211 }
5212 }
5213 result = create_static_routes(tgen, input_dict_1)
5214 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5215 tc_name, result
5216 )
5217
5218 step(
5219 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
5220 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
5221 )
5222
5223 for addr_type in ADDR_TYPES:
5224 input_dict_2 = {
5225 "blue1": {
5226 "static_routes": [
5227 {
5228 "network": [NETWORK3_1[addr_type]],
5229 "next_hop": NEXT_HOP_IP[addr_type],
5230 "tag": 4001,
5231 "vrf": "BLUE_A",
5232 },
5233 {
5234 "network": [NETWORK3_2[addr_type]],
5235 "next_hop": NEXT_HOP_IP[addr_type],
5236 "vrf": "BLUE_A",
5237 },
5238 {
5239 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
5240 "next_hop": NEXT_HOP_IP[addr_type],
5241 "vrf": "BLUE_B",
5242 },
5243 ]
5244 }
5245 }
5246 result = create_static_routes(tgen, input_dict_2)
5247 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5248 tc_name, result
5249 )
5250
5251 step("Redistribute static..")
5252
5253 input_dict_3 = {}
5254 for dut in ["red1", "blue1"]:
5255 temp = {dut: {"bgp": []}}
5256 input_dict_3.update(temp)
5257
5258 if "red" in dut:
5259 VRFS = ["RED_A", "RED_B"]
5260 AS_NUM = [500, 500]
5261 elif "blue" in dut:
5262 VRFS = ["BLUE_A", "BLUE_B"]
5263 AS_NUM = [800, 800]
5264
5265 for vrf, as_num in zip(VRFS, AS_NUM):
5266 temp[dut]["bgp"].append(
5267 {
5268 "local_as": as_num,
5269 "vrf": vrf,
5270 "address_family": {
5271 "ipv4": {
5272 "unicast": {"redistribute": [{"redist_type": "static"}]}
5273 },
5274 "ipv6": {
5275 "unicast": {"redistribute": [{"redist_type": "static"}]}
5276 },
5277 },
5278 }
5279 )
5280
5281 result = create_router_bgp(tgen, topo, input_dict_3)
5282 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5283
5284 step("Configure a route-maps to match tag")
5285
5286 for addr_type in ADDR_TYPES:
5287 input_dict_4 = {
5288 "red1": {
5289 "route_maps": {
5290 "rmap1_{}".format(addr_type): [
5291 {"action": "permit", "match": {addr_type: {"tag": "4001"}}}
5292 ]
5293 }
5294 }
5295 }
5296 result = create_route_maps(tgen, input_dict_4)
5297 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5298 tc_name, result
5299 )
5300
5301 step("Configure neighbor for route map")
5302 input_dict_4 = {
5303 "red1": {
5304 "bgp": [
5305 {
5306 "local_as": "500",
5307 "vrf": "RED_A",
5308 "address_family": {
5309 "ipv4": {
5310 "unicast": {
5311 "neighbor": {
5312 "r1": {
5313 "dest_link": {
5314 "red1-link1": {
5315 "route_maps": [
5316 {
5317 "name": "rmap1_ipv4",
5318 "direction": "out",
5319 }
5320 ]
5321 }
5322 }
5323 }
5324 }
5325 }
5326 },
5327 "ipv6": {
5328 "unicast": {
5329 "neighbor": {
5330 "r1": {
5331 "dest_link": {
5332 "red1-link1": {
5333 "route_maps": [
5334 {
5335 "name": "rmap1_ipv6",
5336 "direction": "out",
5337 }
5338 ]
5339 }
5340 }
5341 }
5342 }
5343 }
5344 },
5345 },
5346 },
5347 {
5348 "local_as": "500",
5349 "vrf": "RED_B",
5350 "address_family": {
5351 "ipv4": {
5352 "unicast": {
5353 "neighbor": {
5354 "r1": {
5355 "dest_link": {
5356 "red1-link2": {
5357 "route_maps": [
5358 {
5359 "name": "rmap1_ipv4",
5360 "direction": "out",
5361 }
5362 ]
5363 }
5364 }
5365 }
5366 }
5367 }
5368 },
5369 "ipv6": {
5370 "unicast": {
5371 "neighbor": {
5372 "r1": {
5373 "dest_link": {
5374 "red1-link2": {
5375 "route_maps": [
5376 {
5377 "name": "rmap1_ipv6",
5378 "direction": "out",
5379 }
5380 ]
5381 }
5382 }
5383 }
5384 }
5385 }
5386 },
5387 },
5388 },
5389 ]
5390 }
5391 }
5392
5393 result = create_router_bgp(tgen, topo, input_dict_4)
5394 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5395
5396 step(
5397 "Verify that within vrf instances, BGP best path selection"
5398 " algorithm remains intact and doesn't affect any other VRFs"
5399 " routing decision."
5400 )
5401
5402 dut = "r1"
5403 for addr_type in ADDR_TYPES:
5404 input_dict_1 = {
5405 "red1": {
5406 "static_routes": [
5407 {
5408 "network": [NETWORK1_1[addr_type]],
5409 "next_hop": NEXT_HOP_IP[addr_type],
5410 "tag": 4001,
5411 "vrf": "RED_A",
5412 }
5413 ]
5414 }
5415 }
5416
5417 result = verify_rib(tgen, addr_type, dut, input_dict_1)
5418 assert result is True, "Testcase {} : Failed \n Error {}".format(
5419 tc_name, result
5420 )
5421
5422 for addr_type in ADDR_TYPES:
5423 input_dict_2 = {
5424 "red1": {
5425 "static_routes": [
5426 {
5427 "network": [NETWORK1_2[addr_type]],
5428 "next_hop": NEXT_HOP_IP[addr_type],
5429 "vrf": "RED_A",
5430 },
5431 {
5432 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
5433 "next_hop": NEXT_HOP_IP[addr_type],
5434 "vrf": "RED_B",
5435 },
5436 ]
5437 }
5438 }
5439
5440 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
5441 assert (
5442 result is not True
5443 ), "Testcase {} : Failed \n Expected Behavior: Routes are denied \nError {}".format(tc_name, result)
5444
5445 write_test_footer(tc_name)
5446
5447
5448 def test_route_map_set_and_match_metric_p0(request):
5449 """
5450 FUNC_16_2:
5451 Configure a route-map on DUT to match traffic based various
5452 match/set causes.
5453 """
5454
5455 tgen = get_topogen()
5456 tc_name = request.node.name
5457 write_test_header(tc_name)
5458 reset_config_on_routers(tgen)
5459
5460 if tgen.routers_have_failure():
5461 check_router_status(tgen)
5462
5463 step(
5464 "Advertise unique BGP prefixes(IPv4+IPv6) from RED_1"
5465 " in vrf instances(RED_A and RED_B)."
5466 )
5467
5468 for addr_type in ADDR_TYPES:
5469 input_dict_1 = {
5470 "red1": {
5471 "static_routes": [
5472 {
5473 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
5474 "next_hop": NEXT_HOP_IP[addr_type],
5475 "vrf": "RED_A",
5476 },
5477 {
5478 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
5479 "next_hop": NEXT_HOP_IP[addr_type],
5480 "vrf": "RED_B",
5481 },
5482 ]
5483 }
5484 }
5485 result = create_static_routes(tgen, input_dict_1)
5486 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5487 tc_name, result
5488 )
5489
5490 step(
5491 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
5492 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
5493 )
5494
5495 for addr_type in ADDR_TYPES:
5496 input_dict_2 = {
5497 "blue1": {
5498 "static_routes": [
5499 {
5500 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
5501 "next_hop": NEXT_HOP_IP[addr_type],
5502 "vrf": "BLUE_A",
5503 },
5504 {
5505 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
5506 "next_hop": NEXT_HOP_IP[addr_type],
5507 "vrf": "BLUE_B",
5508 },
5509 ]
5510 }
5511 }
5512 result = create_static_routes(tgen, input_dict_2)
5513 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5514 tc_name, result
5515 )
5516
5517 step("Redistribute static..")
5518
5519 input_dict_3 = {
5520 "red1": {
5521 "bgp": [
5522 {
5523 "local_as": "500",
5524 "vrf": "RED_A",
5525 "address_family": {
5526 "ipv4": {
5527 "unicast": {
5528 "redistribute": [
5529 {
5530 "redist_type": "static",
5531 "attribute": {"metric": 123},
5532 }
5533 ]
5534 }
5535 },
5536 "ipv6": {
5537 "unicast": {
5538 "redistribute": [
5539 {
5540 "redist_type": "static",
5541 "attribute": {"metric": 123},
5542 }
5543 ]
5544 }
5545 },
5546 },
5547 },
5548 {
5549 "local_as": "500",
5550 "vrf": "RED_B",
5551 "address_family": {
5552 "ipv4": {
5553 "unicast": {"redistribute": [{"redist_type": "static"}]}
5554 },
5555 "ipv6": {
5556 "unicast": {"redistribute": [{"redist_type": "static"}]}
5557 },
5558 },
5559 },
5560 ]
5561 },
5562 "blue1": {
5563 "bgp": [
5564 {
5565 "local_as": "800",
5566 "vrf": "BLUE_A",
5567 "address_family": {
5568 "ipv4": {
5569 "unicast": {
5570 "redistribute": [
5571 {
5572 "redist_type": "static",
5573 "attribute": {"metric": 123},
5574 }
5575 ]
5576 }
5577 },
5578 "ipv6": {
5579 "unicast": {
5580 "redistribute": [
5581 {
5582 "redist_type": "static",
5583 "attribute": {"metric": 123},
5584 }
5585 ]
5586 }
5587 },
5588 },
5589 },
5590 {
5591 "local_as": "800",
5592 "vrf": "BLUE_B",
5593 "address_family": {
5594 "ipv4": {
5595 "unicast": {"redistribute": [{"redist_type": "static"}]}
5596 },
5597 "ipv6": {
5598 "unicast": {"redistribute": [{"redist_type": "static"}]}
5599 },
5600 },
5601 },
5602 ]
5603 },
5604 }
5605
5606 result = create_router_bgp(tgen, topo, input_dict_3)
5607 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5608
5609 step("Configure a route-maps to match tag")
5610
5611 for addr_type in ADDR_TYPES:
5612 input_dict_4 = {
5613 "r1": {
5614 "route_maps": {
5615 "rmap1_{}".format(addr_type): [
5616 {"action": "permit", "match": {"metric": 123}}
5617 ]
5618 }
5619 }
5620 }
5621 result = create_route_maps(tgen, input_dict_4)
5622 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5623 tc_name, result
5624 )
5625
5626 step("Configure neighbor for route map")
5627 input_dict_4 = {
5628 "r1": {
5629 "bgp": [
5630 {
5631 "local_as": "100",
5632 "vrf": "RED_A",
5633 "address_family": {
5634 "ipv4": {
5635 "unicast": {
5636 "neighbor": {
5637 "red1": {
5638 "dest_link": {
5639 "r1-link1": {
5640 "route_maps": [
5641 {
5642 "name": "rmap1_ipv4",
5643 "direction": "in",
5644 }
5645 ]
5646 }
5647 }
5648 }
5649 }
5650 }
5651 },
5652 "ipv6": {
5653 "unicast": {
5654 "neighbor": {
5655 "red1": {
5656 "dest_link": {
5657 "r1-link1": {
5658 "route_maps": [
5659 {
5660 "name": "rmap1_ipv6",
5661 "direction": "in",
5662 }
5663 ]
5664 }
5665 }
5666 }
5667 }
5668 }
5669 },
5670 },
5671 },
5672 {
5673 "local_as": "100",
5674 "vrf": "RED_B",
5675 "address_family": {
5676 "ipv4": {
5677 "unicast": {
5678 "neighbor": {
5679 "red1": {
5680 "dest_link": {
5681 "r1-link2": {
5682 "route_maps": [
5683 {
5684 "name": "rmap1_ipv4",
5685 "direction": "in",
5686 }
5687 ]
5688 }
5689 }
5690 }
5691 }
5692 }
5693 },
5694 "ipv6": {
5695 "unicast": {
5696 "neighbor": {
5697 "red1": {
5698 "dest_link": {
5699 "r1-link2": {
5700 "route_maps": [
5701 {
5702 "name": "rmap1_ipv6",
5703 "direction": "in",
5704 }
5705 ]
5706 }
5707 }
5708 }
5709 }
5710 }
5711 },
5712 },
5713 },
5714 {
5715 "local_as": "100",
5716 "vrf": "BLUE_A",
5717 "address_family": {
5718 "ipv4": {
5719 "unicast": {
5720 "neighbor": {
5721 "blue1": {
5722 "dest_link": {
5723 "r1-link1": {
5724 "route_maps": [
5725 {
5726 "name": "rmap1_ipv4",
5727 "direction": "in",
5728 }
5729 ]
5730 }
5731 }
5732 }
5733 }
5734 }
5735 },
5736 "ipv6": {
5737 "unicast": {
5738 "neighbor": {
5739 "blue1": {
5740 "dest_link": {
5741 "r1-link1": {
5742 "route_maps": [
5743 {
5744 "name": "rmap1_ipv6",
5745 "direction": "in",
5746 }
5747 ]
5748 }
5749 }
5750 }
5751 }
5752 }
5753 },
5754 },
5755 },
5756 {
5757 "local_as": "100",
5758 "vrf": "BLUE_B",
5759 "address_family": {
5760 "ipv4": {
5761 "unicast": {
5762 "neighbor": {
5763 "blue1": {
5764 "dest_link": {
5765 "r1-link2": {
5766 "route_maps": [
5767 {
5768 "name": "rmap1_ipv4",
5769 "direction": "in",
5770 }
5771 ]
5772 }
5773 }
5774 }
5775 }
5776 }
5777 },
5778 "ipv6": {
5779 "unicast": {
5780 "neighbor": {
5781 "blue1": {
5782 "dest_link": {
5783 "r1-link2": {
5784 "route_maps": [
5785 {
5786 "name": "rmap1_ipv6",
5787 "direction": "in",
5788 }
5789 ]
5790 }
5791 }
5792 }
5793 }
5794 }
5795 },
5796 },
5797 },
5798 ]
5799 }
5800 }
5801
5802 result = create_router_bgp(tgen, topo, input_dict_4)
5803 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5804
5805 step(
5806 "Verify that within vrf instances, BGP best path selection"
5807 " algorithm remains intact and doesn't affect any other VRFs"
5808 " routing decision."
5809 )
5810
5811 dut = "r1"
5812 for addr_type in ADDR_TYPES:
5813 input_dict_1 = {
5814 "red1": {
5815 "static_routes": [
5816 {
5817 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
5818 "next_hop": NEXT_HOP_IP[addr_type],
5819 "vrf": "RED_A",
5820 }
5821 ]
5822 }
5823 }
5824
5825 result = verify_rib(tgen, addr_type, dut, input_dict_1)
5826 assert result is True, "Testcase {} : Failed \n Error {}".format(
5827 tc_name, result
5828 )
5829
5830 for addr_type in ADDR_TYPES:
5831 input_dict_2 = {
5832 "red1": {
5833 "static_routes": [
5834 {
5835 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
5836 "next_hop": NEXT_HOP_IP[addr_type],
5837 "vrf": "RED_B",
5838 }
5839 ]
5840 }
5841 }
5842
5843 result = verify_rib(tgen, addr_type, dut, input_dict_2, expected=False)
5844 assert (
5845 result is not True
5846 ), "Testcase {} : Failed \n Expected Behavior: Routes are denied \nError {}".format(tc_name, result)
5847
5848 write_test_footer(tc_name)
5849
5850
5851 def test_route_map_set_and_match_community_p0(request):
5852 """
5853 FUNC_16_3:
5854 Configure a route-map on DUT to match traffic based various
5855 match/set causes.
5856 """
5857
5858 tgen = get_topogen()
5859 tc_name = request.node.name
5860 write_test_header(tc_name)
5861 reset_config_on_routers(tgen)
5862
5863 if tgen.routers_have_failure():
5864 pytest.skip(tgen.errors)
5865
5866 step(
5867 "Advertise unique BGP prefixes(IPv4+IPv6) from RED_1"
5868 " in vrf instances(RED_A and RED_B)."
5869 )
5870
5871 for addr_type in ADDR_TYPES:
5872 input_dict_1 = {
5873 "red1": {
5874 "static_routes": [
5875 {
5876 "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
5877 "next_hop": NEXT_HOP_IP[addr_type],
5878 "vrf": "RED_A",
5879 },
5880 {
5881 "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
5882 "next_hop": NEXT_HOP_IP[addr_type],
5883 "vrf": "RED_B",
5884 },
5885 ]
5886 }
5887 }
5888 result = create_static_routes(tgen, input_dict_1)
5889 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5890 tc_name, result
5891 )
5892
5893 step(
5894 "Advertise same set of BGP prefixes(IPv4+IPv6) from BLUE_1 and"
5895 "BLUE_2 in vrf instances(BLUE_A and BLUE_B)"
5896 )
5897
5898 for addr_type in ADDR_TYPES:
5899 input_dict_2 = {
5900 "blue1": {
5901 "static_routes": [
5902 {
5903 "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
5904 "next_hop": NEXT_HOP_IP[addr_type],
5905 "vrf": "BLUE_A",
5906 },
5907 {
5908 "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
5909 "next_hop": NEXT_HOP_IP[addr_type],
5910 "vrf": "BLUE_B",
5911 },
5912 ]
5913 }
5914 }
5915 result = create_static_routes(tgen, input_dict_2)
5916 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5917 tc_name, result
5918 )
5919
5920 step("Redistribute static..")
5921
5922 input_dict_3 = {}
5923 for dut in ["red1", "blue1"]:
5924 temp = {dut: {"bgp": []}}
5925 input_dict_3.update(temp)
5926
5927 if "red" in dut:
5928 VRFS = ["RED_A", "RED_B"]
5929 AS_NUM = [500, 500]
5930 elif "blue" in dut:
5931 VRFS = ["BLUE_A", "BLUE_B"]
5932 AS_NUM = [800, 800]
5933
5934 for vrf, as_num in zip(VRFS, AS_NUM):
5935 temp[dut]["bgp"].append(
5936 {
5937 "local_as": as_num,
5938 "vrf": vrf,
5939 "address_family": {
5940 "ipv4": {
5941 "unicast": {"redistribute": [{"redist_type": "static"}]}
5942 },
5943 "ipv6": {
5944 "unicast": {"redistribute": [{"redist_type": "static"}]}
5945 },
5946 },
5947 }
5948 )
5949
5950 result = create_router_bgp(tgen, topo, input_dict_3)
5951 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
5952
5953 step("Create community-list")
5954
5955 for addr_type in ADDR_TYPES:
5956 input_dict_4 = {
5957 "r1": {
5958 "bgp_community_lists": [
5959 {
5960 "community_type": "standard",
5961 "action": "permit",
5962 "name": "rmap_lcomm_{}".format(addr_type),
5963 "value": "1:1 1:2 1:3 1:4 1:5",
5964 }
5965 ]
5966 }
5967 }
5968 result = create_bgp_community_lists(tgen, input_dict_4)
5969 assert result is True, "Testcase {} : Failed \n Error: {}".format(
5970 tc_name, result
5971 )
5972
5973 step("Configure a route-maps to match tag")
5974
5975 step("Create route-maps in red1 and r1")
5976
5977 for addr_type in ADDR_TYPES:
5978 input_dict_4 = {
5979 "red1": {
5980 "route_maps": {
5981 "rmap_red1_{}".format(addr_type): [
5982 {
5983 "action": "permit",
5984 "set": {"community": {"num": "1:1 1:2 1:3 1:4 1:5"}},
5985 }
5986 ]
5987 }
5988 },
5989 "r1": {
5990 "route_maps": {
5991 "rmap1_{}".format(addr_type): [
5992 {
5993 "action": "permit",
5994 "match": {
5995 "community_list": {"id": "rmap_lcomm_" + addr_type}
5996 },
5997 }
5998 ]
5999 }
6000 },
6001 }
6002 result = create_route_maps(tgen, input_dict_4)
6003 assert result is True, "Testcase {} : Failed \n Error: {}".format(
6004 tc_name, result
6005 )
6006
6007 step("Configure neighbor for route map")
6008 input_dict_4 = {
6009 "red1": {
6010 "bgp": [
6011 {
6012 "local_as": "500",
6013 "vrf": "RED_A",
6014 "address_family": {
6015 "ipv4": {
6016 "unicast": {
6017 "neighbor": {
6018 "r1": {
6019 "dest_link": {
6020 "red1-link1": {
6021 "route_maps": [
6022 {
6023 "name": "rmap_red1_ipv4",
6024 "direction": "out",
6025 }
6026 ]
6027 }
6028 }
6029 }
6030 }
6031 }
6032 },
6033 "ipv6": {
6034 "unicast": {
6035 "neighbor": {
6036 "r1": {
6037 "dest_link": {
6038 "red1-link1": {
6039 "route_maps": [
6040 {
6041 "name": "rmap_red1_ipv6",
6042 "direction": "out",
6043 }
6044 ]
6045 }
6046 }
6047 }
6048 }
6049 }
6050 },
6051 },
6052 },
6053 {
6054 "local_as": "500",
6055 "vrf": "RED_B",
6056 "address_family": {
6057 "ipv4": {
6058 "unicast": {
6059 "neighbor": {
6060 "r1": {
6061 "dest_link": {
6062 "red1-link2": {
6063 "route_maps": [
6064 {
6065 "name": "rmap_red1_ipv4",
6066 "direction": "out",
6067 }
6068 ]
6069 }
6070 }
6071 }
6072 }
6073 }
6074 },
6075 "ipv6": {
6076 "unicast": {
6077 "neighbor": {
6078 "r1": {
6079 "dest_link": {
6080 "red1-link2": {
6081 "route_maps": [
6082 {
6083 "name": "rmap_red1_ipv6",
6084 "direction": "out",
6085 }
6086 ]
6087 }
6088 }
6089 }
6090 }
6091 }
6092 },
6093 },
6094 },
6095 ]
6096 },
6097 "r1": {
6098 "bgp": [
6099 {
6100 "local_as": "100",
6101 "vrf": "RED_A",
6102 "address_family": {
6103 "ipv4": {
6104 "unicast": {
6105 "neighbor": {
6106 "red1": {
6107 "dest_link": {
6108 "r1-link1": {
6109 "route_maps": [
6110 {
6111 "name": "rmap1_ipv4",
6112 "direction": "in",
6113 }
6114 ]
6115 }
6116 }
6117 }
6118 }
6119 }
6120 },
6121 "ipv6": {
6122 "unicast": {
6123 "neighbor": {
6124 "red1": {
6125 "dest_link": {
6126 "r1-link1": {
6127 "route_maps": [
6128 {
6129 "name": "rmap1_ipv6",
6130 "direction": "in",
6131 }
6132 ]
6133 }
6134 }
6135 }
6136 }
6137 }
6138 },
6139 },
6140 },
6141 {
6142 "local_as": "100",
6143 "vrf": "RED_B",
6144 "address_family": {
6145 "ipv4": {
6146 "unicast": {
6147 "neighbor": {
6148 "red1": {
6149 "dest_link": {
6150 "r1-link2": {
6151 "route_maps": [
6152 {
6153 "name": "rmap1_ipv4",
6154 "direction": "in",
6155 }
6156 ]
6157 }
6158 }
6159 }
6160 }
6161 }
6162 },
6163 "ipv6": {
6164 "unicast": {
6165 "neighbor": {
6166 "red1": {
6167 "dest_link": {
6168 "r1-link2": {
6169 "route_maps": [
6170 {
6171 "name": "rmap1_ipv6",
6172 "direction": "in",
6173 }
6174 ]
6175 }
6176 }
6177 }
6178 }
6179 }
6180 },
6181 },
6182 },
6183 {
6184 "local_as": "100",
6185 "vrf": "BLUE_A",
6186 "address_family": {
6187 "ipv4": {
6188 "unicast": {
6189 "neighbor": {
6190 "blue1": {
6191 "dest_link": {
6192 "r1-link1": {
6193 "route_maps": [
6194 {
6195 "name": "rmap1_ipv4",
6196 "direction": "in",
6197 }
6198 ]
6199 }
6200 }
6201 }
6202 }
6203 }
6204 },
6205 "ipv6": {
6206 "unicast": {
6207 "neighbor": {
6208 "blue1": {
6209 "dest_link": {
6210 "r1-link1": {
6211 "route_maps": [
6212 {
6213 "name": "rmap1_ipv6",
6214 "direction": "in",
6215 }
6216 ]
6217 }
6218 }
6219 }
6220 }
6221 }
6222 },
6223 },
6224 },
6225 {
6226 "local_as": "100",
6227 "vrf": "BLUE_B",
6228 "address_family": {
6229 "ipv4": {
6230 "unicast": {
6231 "neighbor": {
6232 "blue1": {
6233 "dest_link": {
6234 "r1-link2": {
6235 "route_maps": [
6236 {
6237 "name": "rmap1_ipv4",
6238 "direction": "in",
6239 }
6240 ]
6241 }
6242 }
6243 }
6244 }
6245 }
6246 },
6247 "ipv6": {
6248 "unicast": {
6249 "neighbor": {
6250 "blue1": {
6251 "dest_link": {
6252 "r1-link2": {
6253 "route_maps": [
6254 {
6255 "name": "rmap1_ipv6",
6256 "direction": "in",
6257 }
6258 ]
6259 }
6260 }
6261 }
6262 }
6263 }
6264 },
6265 },
6266 },
6267 ]
6268 },
6269 }
6270
6271 result = create_router_bgp(tgen, topo, input_dict_4)
6272 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
6273
6274 step(
6275 "All the prefixes advertised from RED_1 and BLUE_1 should carry"
6276 " attributes set by outbound route-maps within specific vrfs. "
6277 "Router R1 should be able to match and permit/deny those "
6278 "prefixes based on received attributes. Please use below "
6279 "commands to verify."
6280 )
6281
6282 input_dict = {
6283 "community": "1:1 1:2 1:3 1:4 1:5",
6284 }
6285
6286 for addr_type in ADDR_TYPES:
6287 vrf = "RED_A"
6288 routes = [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]]
6289 result = verify_bgp_community(tgen, addr_type, "r1", routes, input_dict, vrf)
6290 assert result is True, "Test case {} : Failed \n Error: {}".format(
6291 tc_name, result
6292 )
6293
6294 for addr_type in ADDR_TYPES:
6295 vrf = "RED_B"
6296 routes = [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]]
6297 result = verify_bgp_community(tgen, addr_type, "r1", routes, input_dict, vrf)
6298 assert result is True, "Test case {} : Failed \n Error: {}".format(
6299 tc_name, result
6300 )
6301
6302 write_test_footer(tc_name)
6303
6304
6305 if __name__ == "__main__":
6306 args = ["-s"] + sys.argv[1:]
6307 sys.exit(pytest.main(args))