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