4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
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
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
24 Following tests are covered to test BGP Multi-VRF Dynamic Route Leaking:
26 1. Verify that dynamically imported routes are further advertised
27 to iBGP peers(peer in cluster).
28 2. Verify matching a prefix based on community attribute and
29 importing it by stripping off this value
30 3. Verify the route-map operation along with dynamic import command.
31 4. Verifying the JSON outputs for all supported commands
40 # Save the Current Working Directory to find configuration files.
41 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
42 sys
.path
.append(os
.path
.join(CWD
, "../"))
43 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
45 # Required to instantiate the topology builder class.
47 # pylint: disable=C0413
48 # Import topogen and topotest helpers
49 from lib
.topogen
import Topogen
, get_topogen
50 from lib
.topotest
import version_cmp
52 from lib
.common_config
import (
61 create_bgp_community_lists
,
62 create_interface_in_kernel
,
68 from lib
.topolog
import logger
70 verify_bgp_convergence
,
75 from lib
.topojson
import build_config_from_json
78 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
81 NETWORK1_1
= {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"}
82 NETWORK1_2
= {"ipv4": "11.11.11.11/32", "ipv6": "11:11::11/128"}
83 NETWORK1_3
= {"ipv4": "10.10.10.10/32", "ipv6": "10:10::10/128"}
84 NETWORK1_4
= {"ipv4": "10.10.10.100/32", "ipv6": "10:10::100/128"}
86 NETWORK2_1
= {"ipv4": "22.22.22.2/32", "ipv6": "22:22::2/128"}
87 NETWORK2_2
= {"ipv4": "22.22.22.22/32", "ipv6": "22:22::22/128"}
88 NETWORK2_3
= {"ipv4": "20.20.20.20/32", "ipv6": "20:20::20/128"}
89 NETWORK2_4
= {"ipv4": "20.20.20.200/32", "ipv6": "20:20::200/128"}
91 NETWORK3_1
= {"ipv4": "30.30.30.3/32", "ipv6": "30:30::3/128"}
92 NETWORK3_2
= {"ipv4": "30.30.30.30/32", "ipv6": "30:30::30/128"}
93 NETWORK3_3
= {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"}
94 NETWORK3_4
= {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"}
96 NETWORK4_1
= {"ipv4": "40.40.40.4/32", "ipv6": "40:40::4/128"}
97 NETWORK4_2
= {"ipv4": "40.40.40.40/32", "ipv6": "40:40::40/128"}
98 NETWORK4_3
= {"ipv4": "50.50.50.5/32", "ipv6": "50:50::5/128"}
99 NETWORK4_4
= {"ipv4": "50.50.50.50/32", "ipv6": "50:50::50/128"}
101 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
103 "ipv4": "10.0.0.7/24",
104 "ipv6": "fd00:0:0:1::7/64",
107 "ipv4": "10.0.0.16/24",
108 "ipv6": "fd00:0:0:3::5/64",
110 PREFERRED_NEXT_HOP
= "global"
113 def setup_module(mod
):
115 Sets up the pytest environment
120 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
121 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
122 logger
.info("=" * 40)
124 logger
.info("Running setup_module to create topology")
126 # This function initiates the topology build with Topogen...
127 json_file
= "{}/bgp_vrf_dynamic_route_leak_topo1.json".format(CWD
)
128 tgen
= Topogen(json_file
, mod
.__name
__)
130 topo
= tgen
.json_topo
131 # ... and here it calls Mininet initialization functions.
133 # Starting topology, create tmp files which are loaded to routers
134 # to start daemons and then start routers
137 # Run these tests for kernel version 4.19 or above
138 if version_cmp(platform
.release(), "4.19") < 0:
140 "BGP vrf dynamic route leak tests will not run "
141 '(have kernel "{}", but it requires >= 4.19)'.format(platform
.release())
143 pytest
.skip(error_msg
)
145 # Creating configuration from JSON
146 build_config_from_json(tgen
, topo
)
148 global BGP_CONVERGENCE
150 ADDR_TYPES
= check_address_types()
152 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
153 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
157 logger
.info("Running setup_module() done")
160 def teardown_module():
161 """Teardown the pytest environment"""
163 logger
.info("Running teardown_module to delete topology")
167 # Stop toplogy and Remove tmp files
171 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
173 logger
.info("=" * 40)
176 #####################################################
180 #####################################################
183 def disable_route_map_to_prefer_global_next_hop(tgen
, topo
):
185 This API is to remove prefer global route-map applied on neighbors
189 * `tgen` : Topogen object
190 * `topo` : Input JSON data
198 logger
.info("Remove prefer-global rmap applied on neighbors")
214 "name": "rmap_global",
238 "name": "rmap_global",
262 "name": "rmap_global",
291 "name": "rmap_global",
315 "name": "rmap_global",
339 "name": "rmap_global",
367 "name": "rmap_global",
391 "name": "rmap_global",
419 "name": "rmap_global",
443 "name": "rmap_global",
460 result
= create_router_bgp(tgen
, topo
, input_dict
)
461 assert result
is True, "Testcase :Failed \n Error: {}".format(result
)
466 #####################################################
470 #####################################################
473 def test_dynamic_imported_routes_advertised_to_iBGP_peer_p0(request
):
476 1.5.5. Verify that dynamically imported routes are further advertised
477 to iBGP peers(peer in cluster).
481 tc_name
= request
.node
.name
482 write_test_header(tc_name
)
483 build_config_from_json(tgen
, topo
)
485 if tgen
.routers_have_failure():
486 check_router_status(tgen
)
488 for addr_type
in ADDR_TYPES
:
491 "Redistribute configured static routes into BGP process" " on R1 and R3/R4"
495 DUT
= ["r1", "r3", "r4"]
496 VRFS
= ["default", "default", "default"]
497 AS_NUM
= [100, 300, 400]
499 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
500 temp
= {dut
: {"bgp": []}}
501 input_dict_1
.update(temp
)
503 temp
[dut
]["bgp"].append(
509 "unicast": {"redistribute": [{"redist_type": "static"}]}
515 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
516 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
520 for addr_type
in ADDR_TYPES
:
522 step("Verify that R1 receives BGP routes from R3 and R4 in " "vrf default.")
529 NETWORK3_1
[addr_type
],
530 NETWORK3_2
[addr_type
],
531 NETWORK3_3
[addr_type
],
532 NETWORK3_4
[addr_type
],
544 NETWORK4_1
[addr_type
],
545 NETWORK4_2
[addr_type
],
546 NETWORK4_3
[addr_type
],
547 NETWORK4_4
[addr_type
],
555 INPUT_DICT
= [input_routes_r3
, input_routes_r4
]
557 for dut
, routes
in zip(DUT
, INPUT_DICT
):
558 result
= verify_bgp_rib(tgen
, addr_type
, dut
, routes
)
559 assert result
is True, "Testcase {} : Failed \n Error {}".format(
563 result
= verify_fib_routes(tgen
, addr_type
, dut
, routes
)
564 assert result
is True, "Testcase {} : Failed \n Error {}".format(
568 for addr_type
in ADDR_TYPES
:
570 step("Import from default vrf into vrf ISR on R1")
574 VRFS
= ["ISR", "ISR"]
577 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
578 temp
= {dut
: {"bgp": []}}
579 input_dict_isr
.update(temp
)
581 temp
[dut
]["bgp"].append(
586 addr_type
: {"unicast": {"import": {"vrf": "default"}}}
591 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
592 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
596 for addr_type
in ADDR_TYPES
:
599 "Verify that default vrf's imported routes are installed "
600 "in RIB/FIB of vrf ISR on R1:"
608 NETWORK3_1
[addr_type
],
609 NETWORK3_2
[addr_type
],
610 NETWORK3_3
[addr_type
],
611 NETWORK3_4
[addr_type
],
624 NETWORK4_1
[addr_type
],
625 NETWORK4_2
[addr_type
],
626 NETWORK4_3
[addr_type
],
627 NETWORK4_4
[addr_type
],
635 INPUT_DICT_VRF
= [input_routes_r3
, input_routes_r4
]
637 for routes
in INPUT_DICT_VRF
:
638 result
= verify_bgp_rib(tgen
, addr_type
, "r1", routes
)
639 assert result
is True, "Testcase {} : Failed \n Error {}".format(
643 result
= verify_fib_routes(tgen
, addr_type
, "r1", routes
)
644 assert result
is True, "Testcase {} : Failed \n Error {}".format(
648 intf_r2_r1
= topo
["routers"]["r2"]["links"]["r1-link1"]
649 for addr_type
in ADDR_TYPES
:
652 "Create a loopback10 interface on R1 with below IP address and "
653 "associate with vrf ISR:"
656 create_interface_in_kernel(
660 LOOPBACK_2
[addr_type
],
664 for addr_type
in ADDR_TYPES
:
667 "On router R1 Change the next-hop of static routes in vrf "
675 "network": [NETWORK1_3
[addr_type
], NETWORK1_4
[addr_type
]],
683 result
= create_static_routes(tgen
, input_routes_r1
)
684 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
692 "network": [NETWORK1_3
[addr_type
], NETWORK1_4
[addr_type
]],
693 "next_hop": (intf_r2_r1
[addr_type
]).split("/")[0],
699 result
= create_static_routes(tgen
, input_routes_r1
)
700 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
704 for addr_type
in ADDR_TYPES
:
707 "Verify that, though R1 originating BGP routes with next-hop"
708 " 24.1.1.2/24::1:2, which is local to R2(but in default vrf)"
709 ", R2 must receives and install all routes from R1 in vrf ISR."
712 "Verify on R2, that it now rejects 10.10.10.x routes originated "
713 "from R1. As next-hop IP is local to R2's vrf ISR."
720 "network": [NETWORK1_3
[addr_type
], NETWORK1_4
[addr_type
]],
727 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
730 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
734 for addr_type
in ADDR_TYPES
:
736 step("On router R1 delete static routes in vrf ISR to LOOPBACK_1")
742 "network": [NETWORK1_3
[addr_type
], NETWORK1_4
[addr_type
]],
743 "next_hop": (intf_r2_r1
[addr_type
]).split("/")[0],
750 result
= create_static_routes(tgen
, input_routes_r1
)
751 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
755 write_test_footer(tc_name
)
758 def test_dynamic_imported_matching_prefix_based_on_community_list_p0(request
):
761 1.5.7. Verify matching a prefix based on community attribute and
762 importing it by stripping off this value
766 tc_name
= request
.node
.name
767 write_test_header(tc_name
)
768 build_config_from_json(tgen
, topo
)
770 if tgen
.routers_have_failure():
771 check_router_status(tgen
)
773 for addr_type
in ADDR_TYPES
:
776 "Configure route-map to set community attribute for a specific"
777 "prefix on R1 in vrf ISR"
784 "pflist_ABC_{}".format(addr_type
): [
787 "network": NETWORK1_1
[addr_type
],
795 result
= create_prefix_lists(tgen
, input_dict_pf
)
796 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
802 "bgp_community_lists": [
804 "community_type": "expanded",
812 result
= create_bgp_community_lists(tgen
, input_dict_cl
)
813 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
815 for addr_type
in ADDR_TYPES
:
819 "rmap_XYZ_{}".format(addr_type
): [
824 "prefix_lists": "pflist_ABC_{}".format(addr_type
)
827 "set": {"community": {"num": "100:100"}},
833 result
= create_route_maps(tgen
, input_dict_rm
)
834 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
838 for addr_type
in ADDR_TYPES
:
841 "Apply this route-map on R1 to vrf ISR while redistributing the"
850 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
851 temp
= {dut
: {"bgp": []}}
852 input_dict_1
.update(temp
)
854 temp
[dut
]["bgp"].append(
863 "redist_type": "static",
865 "route-map": "rmap_XYZ_{}".format(addr_type
)
875 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
876 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
880 for addr_type
in ADDR_TYPES
:
883 "Configure another route-map for filtering the prefixes based on"
884 " community attribute while importing into default vrf"
890 "rmap_IMP_{}".format(addr_type
): [
893 "match": {"community_list": {"id": "COMM"}},
894 "set": {"community": {"num": "none"}},
900 result
= create_route_maps(tgen
, input_dict_rm
)
901 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
905 for addr_type
in ADDR_TYPES
:
908 "Apply the route-map while Importing vrf ISR's prefixes into "
909 "default vrf on router R1:"
917 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
918 temp
= {dut
: {"bgp": []}}
919 input_dict_isr
.update(temp
)
921 temp
[dut
]["bgp"].append(
926 addr_type
: {"unicast": {"import": {"vrf": "ISR"}}}
931 temp
[dut
]["bgp"].append(
939 "vrf": "route-map rmap_IMP_{}".format(addr_type
)
947 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
948 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
952 for addr_type
in ADDR_TYPES
:
955 "Verify on R1 that only prefixes with community value 100:100"
956 "in vrf ISR are imported to vrf default. While importing, the"
957 " community value has been stripped off:"
963 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
968 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
969 assert result
is True, "Testcase {} : Failed \n Error {}".format(
973 input_dict_comm
= {"community": "100:100"}
975 result
= verify_bgp_community(
979 [NETWORK1_1
[addr_type
]],
985 ), "Testcase {} : Failed \n Error: Commnunity is not stipped off, {}".format(
989 for addr_type
in ADDR_TYPES
:
991 step("Remove/re-add route-map XYZ from redistribution.")
998 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
999 temp
= {dut
: {"bgp": []}}
1000 input_dict_1
.update(temp
)
1002 temp
[dut
]["bgp"].append(
1011 "redist_type": "static",
1013 "route-map": "rmap_XYZ_{}".format(addr_type
)
1024 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1025 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
1029 for addr_type
in ADDR_TYPES
:
1032 "Verify that all the routes disappear from vrf default when "
1033 "route-map is removed from redistribution, and appear again "
1034 "when route-map is re-added to redistribution in vrf ISR."
1040 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1045 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1048 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1052 for addr_type
in ADDR_TYPES
:
1059 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1060 temp
= {dut
: {"bgp": []}}
1061 input_dict_1
.update(temp
)
1063 temp
[dut
]["bgp"].append(
1072 "redist_type": "static",
1074 "route-map": "rmap_XYZ_{}".format(addr_type
)
1084 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1085 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
1089 for addr_type
in ADDR_TYPES
:
1094 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1099 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1100 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1104 for addr_type
in ADDR_TYPES
:
1106 step("Remove/re-add route-map IMP form import statement.")
1113 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1114 temp
= {dut
: {"bgp": []}}
1115 input_dict_isr
.update(temp
)
1117 temp
[dut
]["bgp"].append(
1122 addr_type
: {"unicast": {"import": {"vrf": "ISR"}}}
1127 temp
[dut
]["bgp"].append(
1135 "vrf": "route-map rmap_IMP_{}".format(addr_type
),
1144 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1145 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1149 for addr_type
in ADDR_TYPES
:
1152 "Verify that when route-map IMP is removed all the prefixes of"
1153 " vrf ISR are imported to vrf default. However when route-map "
1154 "IMP is re-added only 11.11.11.1 and 11:11::1 (with community "
1155 "value) are imported."
1161 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1166 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1167 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1171 for addr_type
in ADDR_TYPES
:
1178 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1179 temp
= {dut
: {"bgp": []}}
1180 input_dict_isr
.update(temp
)
1182 temp
[dut
]["bgp"].append(
1187 addr_type
: {"unicast": {"import": {"vrf": "ISR"}}}
1192 temp
[dut
]["bgp"].append(
1200 "vrf": "route-map rmap_IMP_{}".format(addr_type
)
1208 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1209 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1213 for addr_type
in ADDR_TYPES
:
1218 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1223 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1224 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1228 for addr_type
in ADDR_TYPES
:
1230 step("Delete/Re-add prefix-list ABC.")
1236 "pflist_ABC_{}".format(addr_type
): [
1239 "network": NETWORK1_1
[addr_type
],
1248 result
= create_prefix_lists(tgen
, input_dict_pf
)
1249 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1256 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1261 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1264 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1268 input_dict_pf
["r1"]["prefix_lists"][addr_type
][
1269 "pflist_ABC_{}".format(addr_type
)
1270 ][0]["delete"] = False
1272 result
= create_prefix_lists(tgen
, input_dict_pf
)
1273 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1277 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1278 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1282 step("Delete/Re-add community-list COMM.")
1286 "bgp_community_lists": [
1288 "community_type": "expanded",
1297 result
= create_bgp_community_lists(tgen
, input_dict_cl
)
1298 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1302 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1305 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1309 input_dict_cl
["r1"]["bgp_community_lists"][0]["delete"] = False
1311 result
= create_bgp_community_lists(tgen
, input_dict_cl
)
1312 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1316 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1317 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1321 step("Delete/Re-add route-map XYZ.")
1326 "rmap_XYZ_{}".format(addr_type
): [
1331 "prefix_lists": "pflist_ABC_{}".format(addr_type
)
1334 "set": {"community": {"num": "100:100"}},
1341 result
= create_route_maps(tgen
, input_dict_rm
)
1342 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1346 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1349 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1353 input_dict_rm
["r1"]["route_maps"]["rmap_XYZ_{}".format(addr_type
)][0][
1357 result
= create_route_maps(tgen
, input_dict_rm
)
1358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1362 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1363 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1367 step("Delete/Re-add route-map IMP.")
1372 "rmap_IMP_{}".format(addr_type
): [
1375 "match": {"community_list": {"id": "COMM"}},
1376 "set": {"community": {"num": "none"}},
1383 result
= create_route_maps(tgen
, input_dict_rm2
)
1384 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1388 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1391 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1395 input_dict_rm2
["r1"]["route_maps"]["rmap_IMP_{}".format(addr_type
)][0][
1399 result
= create_route_maps(tgen
, input_dict_rm2
)
1400 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1404 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1405 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1409 write_test_footer(tc_name
)
1412 def test_routemap_operatons_with_dynamic_import_p0(request
):
1415 1.5.8. Verify the route-map operation along with dynamic import command.
1418 tgen
= get_topogen()
1419 tc_name
= request
.node
.name
1420 write_test_header(tc_name
)
1421 build_config_from_json(tgen
, topo
)
1423 if tgen
.routers_have_failure():
1424 check_router_status(tgen
)
1426 for addr_type
in ADDR_TYPES
:
1429 "Configure route-map to set community attribute for a specific"
1430 "prefix on R1 in vrf ISR"
1437 "pflist_ABC_{}".format(addr_type
): [
1440 "network": NETWORK1_1
[addr_type
],
1448 result
= create_prefix_lists(tgen
, input_dict_pf
)
1449 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1455 "bgp_community_lists": [
1457 "community_type": "expanded",
1465 result
= create_bgp_community_lists(tgen
, input_dict_cl
)
1466 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1468 for addr_type
in ADDR_TYPES
:
1472 "rmap_XYZ_{}".format(addr_type
): [
1477 "prefix_lists": "pflist_ABC_{}".format(addr_type
)
1480 "set": {"community": {"num": "100:100"}},
1486 result
= create_route_maps(tgen
, input_dict_rm
)
1487 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1491 for addr_type
in ADDR_TYPES
:
1494 "Apply this route-map on R1 to vrf ISR while redistributing the"
1495 " prefixes into BGP"
1503 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1504 temp
= {dut
: {"bgp": []}}
1505 input_dict_1
.update(temp
)
1507 temp
[dut
]["bgp"].append(
1516 "redist_type": "static",
1518 "route-map": "rmap_XYZ_{}".format(addr_type
)
1528 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1529 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
1533 for addr_type
in ADDR_TYPES
:
1536 "Configure another route-map for filtering the prefixes based on"
1537 " community attribute while importing into default vrf"
1543 "rmap_IMP_{}".format(addr_type
): [
1546 "match": {"community_list": {"id": "COMM"}},
1547 "set": {"community": {"num": "500:500"}},
1553 result
= create_route_maps(tgen
, input_dict_rm
)
1554 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1558 for addr_type
in ADDR_TYPES
:
1561 "Apply the route-map while Importing vrf ISR's prefixes into "
1562 "default vrf on router R1:"
1570 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1571 temp
= {dut
: {"bgp": []}}
1572 input_dict_isr
.update(temp
)
1574 temp
[dut
]["bgp"].append(
1579 addr_type
: {"unicast": {"import": {"vrf": "ISR"}}}
1584 temp
[dut
]["bgp"].append(
1592 "vrf": "route-map rmap_IMP_{}".format(addr_type
)
1600 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1601 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1605 for addr_type
in ADDR_TYPES
:
1608 "Verify on R1 that only prefixes with community value 100:100"
1609 "in vrf ISR are imported to vrf default. While importing, the"
1610 " community value has been stripped off:"
1616 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1621 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1622 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1626 for addr_type
in ADDR_TYPES
:
1628 step("Applying route-map first followed by import VRF command.")
1630 "Apply the route-map while Importing vrf ISR's prefixes into "
1631 "default vrf on router R1:"
1639 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1640 temp
= {dut
: {"bgp": []}}
1641 input_dict_isr
.update(temp
)
1643 temp
[dut
]["bgp"].append(
1649 "unicast": {"import": {"vrf": "ISR", "delete": True}}
1655 temp
[dut
]["bgp"].append(
1663 "vrf": "route-map rmap_IMP_{}".format(addr_type
)
1671 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1672 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1676 for addr_type
in ADDR_TYPES
:
1679 "Verify that until 'import VRF command' is not configured, "
1680 "routes are not imported. After configuring 'import VRF command'"
1681 " repeat step-4 for verification"
1687 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1692 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1695 ), "Testcase {} : Failed \n Error : Routes are still present \n {}".format(
1699 for addr_type
in ADDR_TYPES
:
1706 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1707 temp
= {dut
: {"bgp": []}}
1708 input_dict_isr
.update(temp
)
1710 temp
[dut
]["bgp"].append(
1715 addr_type
: {"unicast": {"import": {"vrf": "ISR"}}}
1720 temp
[dut
]["bgp"].append(
1728 "vrf": "route-map rmap_IMP_{}".format(addr_type
)
1736 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1737 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1741 for addr_type
in ADDR_TYPES
:
1746 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1751 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1752 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1756 for addr_type
in ADDR_TYPES
:
1758 step("Delete/re-add import vrf ISR command multiple times in default" "vrf.")
1765 for dut
, vrf
, as_num
in zip(DUT
, VRFS
, AS_NUM
):
1766 temp
= {dut
: {"bgp": []}}
1767 input_dict_isr
.update(temp
)
1769 temp
[dut
]["bgp"].append(
1775 "unicast": {"import": {"vrf": "ISR", "delete": True}}
1781 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1782 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1787 "Verify that when import vrf ISR command is deleted, "
1788 "all routes of vrf ISR disappear from default vrf and "
1789 "when it's re-configured, repeat step-4 for verification."
1795 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1800 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1803 ), "Testcase {} : Failed \n Routes are still present, Error {}".format(
1807 input_dict_isr
["r1"]["bgp"][0]["address_family"][addr_type
]["unicast"][
1811 result
= create_router_bgp(tgen
, topo
, input_dict_isr
)
1812 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1816 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
)
1817 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1821 for addr_type
in ADDR_TYPES
:
1824 "Delete and re-configure route-map IMP from global config when "
1825 "import and route-maps are applied in a ISR vrf."
1831 "rmap_IMP_{}".format(addr_type
): [
1834 "match": {"community_list": {"id": "COMM"}},
1835 "set": {"community": {"num": "500:500"}},
1843 result
= create_route_maps(tgen
, input_dict_rm
)
1844 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1851 {"network": [NETWORK1_1
[addr_type
]], "vrf": "default"}
1856 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_routes_r1
, expected
=False)
1859 ), "Testcase {} : Failed \n Routes are still present, Error {}".format(
1863 input_dict_rm
["r1"]["route_maps"]["rmap_IMP_{}".format(addr_type
)][0][
1867 result
= create_route_maps(tgen
, input_dict_rm
)
1868 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1872 input_dict_comm
= {"community": "500:500"}
1874 result
= verify_bgp_community(
1875 tgen
, addr_type
, dut
, [NETWORK1_1
[addr_type
]], input_dict_comm
1877 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1881 write_test_footer(tc_name
)
1884 def test_verify_cli_json_p1(request
):
1887 1.5.9. Verifying the JSON outputs for all supported commands:
1890 tgen
= get_topogen()
1891 tc_name
= request
.node
.name
1892 write_test_header(tc_name
)
1893 build_config_from_json(tgen
, topo
)
1895 if tgen
.routers_have_failure():
1896 check_router_status(tgen
)
1901 "show bgp vrf default ipv4 summary",
1902 "show bgp vrf all ipv6 summary",
1903 "show bgp neighbors",
1908 result
= verify_cli_json(tgen
, input_dict
)
1909 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1911 write_test_footer(tc_name
)
1914 if __name__
== "__main__":
1915 args
= ["-s"] + sys
.argv
[1:]
1916 sys
.exit(pytest
.main(args
))