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