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