]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo2.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2021 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
11 Following tests are covered to test BGP VRF Lite:
12 1. Verify that locally imported routes are selected as best path over eBGP imported routes
14 2. Verify ECMP for imported routes from different VRFs.
22 from time
import sleep
24 # Save the Current Working Directory to find configuration files.
25 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
26 sys
.path
.append(os
.path
.join(CWD
, "../"))
27 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
29 # Required to instantiate the topology builder class.
31 # pylint: disable=C0413
32 # Import topogen and topotest helpers
33 from lib
.topogen
import Topogen
, get_topogen
34 from lib
.topotest
import version_cmp
36 from lib
.common_config
import (
41 reset_config_on_routers
,
49 from lib
.topolog
import logger
51 verify_bgp_convergence
,
56 from lib
.topojson
import build_config_from_json
58 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
61 NETWORK1_1
= {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"}
62 NETWORK1_2
= {"ipv4": "11.11.11.11/32", "ipv6": "11:11::11/128"}
63 NETWORK1_3
= {"ipv4": "10.10.10.1/32", "ipv6": "10:10::1/128"}
64 NETWORK1_4
= {"ipv4": "10.10.10.100/32", "ipv6": "10:10::100/128"}
65 NETWORK1_5
= {"ipv4": "110.110.110.1/32", "ipv6": "110:110::1/128"}
66 NETWORK1_6
= {"ipv4": "110.110.110.100/32", "ipv6": "110:110::100/128"}
68 NETWORK2_1
= {"ipv4": "22.22.22.2/32", "ipv6": "22:22::2/128"}
69 NETWORK2_2
= {"ipv4": "22.22.22.22/32", "ipv6": "22:22::22/128"}
70 NETWORK2_3
= {"ipv4": "20.20.20.20/32", "ipv6": "20:20::20/128"}
71 NETWORK2_4
= {"ipv4": "20.20.20.200/32", "ipv6": "20:20::200/128"}
72 NETWORK2_5
= {"ipv4": "220.220.220.20/32", "ipv6": "220:220::20/128"}
73 NETWORK2_6
= {"ipv4": "220.220.220.200/32", "ipv6": "220:220::200/128"}
75 NETWORK3_1
= {"ipv4": "30.30.30.3/32", "ipv6": "30:30::3/128"}
76 NETWORK3_2
= {"ipv4": "30.30.30.30/32", "ipv6": "30:30::30/128"}
79 "ipv4": ["11.11.11.1", "22.22.22.2", "22.22.22.22"],
80 "ipv6": ["11:11::1", "22:22::2", "22:22::22"],
82 PREFERRED_NEXT_HOP
= "global"
83 VRF_LIST
= ["RED", "BLUE", "GREEN"]
84 COMM_VAL_1
= "100:100"
85 COMM_VAL_2
= "500:500"
86 COMM_VAL_3
= "600:600"
92 def setup_module(mod
):
94 Sets up the pytest environment
99 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
100 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
101 logger
.info("=" * 40)
103 logger
.info("Running setup_module to create topology")
105 # This function initiates the topology build with Topogen...
106 json_file
= "{}/bgp_vrf_lite_best_path_topo2.json".format(CWD
)
107 tgen
= Topogen(json_file
, mod
.__name
__)
109 topo
= tgen
.json_topo
110 # ... and here it calls Mininet initialization functions.
112 # Starting topology, create tmp files which are loaded to routers
113 # to start daemons and then start routers
116 # Run these tests for kernel version 4.19 or above
117 if version_cmp(platform
.release(), "4.19") < 0:
119 "BGP vrf dynamic route leak tests will not run "
120 '(have kernel "{}", but it requires >= 4.19)'.format(platform
.release())
122 pytest
.skip(error_msg
)
124 # Creating configuration from JSON
125 build_config_from_json(tgen
, topo
)
127 global BGP_CONVERGENCE
129 ADDR_TYPES
= check_address_types()
131 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
132 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
136 logger
.info("Running setup_module() done")
139 def teardown_module():
140 """Teardown the pytest environment"""
142 logger
.info("Running teardown_module to delete topology")
146 # Stop toplogy and Remove tmp files
150 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
152 logger
.info("=" * 40)
155 #####################################################
159 #####################################################
161 def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request
):
163 Verify ECMP for imported routes from different VRFs.
167 tc_name
= request
.node
.name
168 write_test_header(tc_name
)
169 if tgen
.routers_have_failure():
170 check_router_status(tgen
)
171 reset_config_on_routers(tgen
)
173 step("Configure same static routes in tenant vrfs RED and GREEN on router "
174 "R3 and redistribute in respective BGP process")
176 for vrf_name
in ["RED", "GREEN"]:
177 for addr_type
in ADDR_TYPES
:
178 if vrf_name
== "GREEN":
179 next_hop_vrf
= topo
["routers"]["r1"]["links"][
180 "r3-link3"][addr_type
].split("/")[0]
182 next_hop_vrf
= topo
["routers"]["r2"]["links"][
183 "r3-link1"][addr_type
].split("/")[0]
188 "network": [NETWORK1_1
[addr_type
]],
189 "next_hop": next_hop_vrf
,
196 result
= create_static_routes(tgen
, static_routes
)
197 assert result
is True, "Testcase {} :Failed \n Error: {}". \
198 format(tc_name
, result
)
200 step("Redistribute static route on BGP VRF : {}".format(vrf_name
))
202 for addr_type
in ADDR_TYPES
:
207 "redist_type": "static"
213 redist_dict
= {"r3": {"bgp": [{
214 "vrf": vrf_name
, "local_as": 3, "address_family": temp
217 result
= create_router_bgp(tgen
, topo
, redist_dict
)
218 assert result
is True, "Testcase {} :Failed \n Error: {}". \
219 format(tc_name
, result
)
221 step("Verify that configured static routes are installed in respective "
222 "BGP table for vrf RED & GREEN")
223 for vrf_name
in ["RED", "GREEN"]:
224 for addr_type
in ADDR_TYPES
:
225 if vrf_name
== "GREEN":
226 next_hop_vrf
= topo
["routers"]["r1"]["links"][
227 "r3-link3"][addr_type
].split("/")[0]
229 next_hop_vrf
= topo
["routers"]["r2"]["links"][
230 "r3-link1"][addr_type
].split("/")[0]
235 "network": [NETWORK1_1
[addr_type
]],
242 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
243 next_hop
=next_hop_vrf
)
244 assert result
is True, "Testcase {} : Failed \n Error {}". \
245 format(tc_name
, result
)
247 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
248 next_hop
=next_hop_vrf
)
249 assert result
is True, "Testcase {} : Failed \n Error {}". \
250 format(tc_name
, result
)
252 step("Import vrf RED and GREEN into default vrf and Configure ECMP")
254 for vrf_name
in ["RED", "GREEN"]:
256 for addr_type
in ADDR_TYPES
:
271 "local_as": 3, "address_family": temp
274 import_dict
= {"r3": {"bgp": bgp_val
}}
276 result
= create_router_bgp(tgen
, topo
, import_dict
)
277 assert result
is True, "Testcase {} :Failed \n Error: {}". \
278 format(tc_name
, result
)
280 step("Configure bgp bestpath on router r3")
285 "bgp bestpath as-path multipath-relax"
289 result
= apply_raw_config(tgen
, r3_raw_config
)
290 assert result
is True, "Testcase {} :Failed \n Error: {}". \
291 format(tc_name
, result
)
293 step("Verify that routes are imported with two different next-hop vrfs "
294 "and IPs. Additionally R3 must do ECMP for both the routes.")
296 for addr_type
in ADDR_TYPES
:
298 topo
["routers"]["r2"]["links"]["r3-link1"][addr_type
]. \
300 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
]. \
307 "network": [NETWORK1_1
[addr_type
]],
313 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
314 next_hop
=next_hop_vrf
)
315 assert result
is True, "Testcase {} : Failed \n Error {}". \
316 format(tc_name
, result
)
318 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
319 next_hop
=next_hop_vrf
)
320 assert result
is True, "Testcase {} : Failed \n Error {}". \
321 format(tc_name
, result
)
323 step("Now change the next-hop of static routes in vrf RED and GREEN to "
325 for addr_type
in ADDR_TYPES
:
326 next_hop_vrf
= topo
["routers"]["r1"]["links"][
327 "r3-link3"][addr_type
].split("/")[0]
332 "network": [NETWORK1_1
[addr_type
]],
333 "next_hop": next_hop_vrf
,
337 "network": [NETWORK1_1
[addr_type
]],
338 "next_hop": topo
["routers"]["r2"]["links"][
339 "r3-link1"][addr_type
].split("/")[0],
347 result
= create_static_routes(tgen
, static_routes
)
348 assert result
is True, "Testcase {} :Failed \n Error: {}". \
349 format(tc_name
, result
)
351 step("Verify that now routes are imported with two different next-hop "
352 "vrfs but same IPs. Additionally R3 must do ECMP for both the routes")
354 for addr_type
in ADDR_TYPES
:
356 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
].\
358 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
]. \
365 "network": [NETWORK1_1
[addr_type
]],
371 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
372 next_hop
=next_hop_vrf
)
373 assert result
is True, "Testcase {} : Failed \n Error {}". \
374 format(tc_name
, result
)
376 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
377 next_hop
=next_hop_vrf
)
378 assert result
is True, "Testcase {} : Failed \n Error {}". \
379 format(tc_name
, result
)
381 write_test_footer(tc_name
)
384 def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(request
):
386 Verify ECMP for imported routes from different VRFs.
390 tc_name
= request
.node
.name
391 write_test_header(tc_name
)
392 if tgen
.routers_have_failure():
393 check_router_status(tgen
)
394 reset_config_on_routers(tgen
)
396 step("Configure same static routes on R2 and R3 vrfs and redistribute in BGP "
397 "for GREEN and RED vrf instances")
398 for dut
, network
in zip(["r2", "r3"], [
399 [NETWORK1_1
, NETWORK1_2
], [NETWORK1_1
, NETWORK1_2
]]):
400 for vrf_name
, network_vrf
in zip(["RED", "GREEN"], network
):
401 step("Configure static route for VRF : {} on {}".format(vrf_name
,
403 for addr_type
in ADDR_TYPES
:
408 "network": [network_vrf
[addr_type
]],
409 "next_hop": "blackhole",
416 result
= create_static_routes(tgen
, static_routes
)
417 assert result
is True, "Testcase {} :Failed \n Error: {}". \
418 format(tc_name
, result
)
420 for dut
, as_num
in zip(["r2", "r3"], ["2", "3"]):
421 for vrf_name
in ["RED", "GREEN"]:
422 step("Redistribute static route on BGP VRF : {}".format(vrf_name
))
424 for addr_type
in ADDR_TYPES
:
429 "redist_type": "static"
435 redist_dict
= {dut
: {"bgp": [{
436 "vrf": vrf_name
, "local_as": as_num
, "address_family": temp
439 result
= create_router_bgp(tgen
, topo
, redist_dict
)
440 assert result
is True, "Testcase {} :Failed \n Error: {}". \
441 format(tc_name
, result
)
443 step("Verify that R2 and R3 has installed redistributed routes in default "
444 "and RED vrfs and GREEN respectively:")
445 for dut
, network
in zip(["r2", "r3"],
446 [[NETWORK1_1
, NETWORK1_2
],
447 [NETWORK1_1
, NETWORK1_2
]]):
448 for vrf_name
, network_vrf
in zip(["RED", "GREEN"], network
):
449 for addr_type
in ADDR_TYPES
:
454 "network": [network_vrf
[addr_type
]],
455 "next_hop": "blackhole",
461 result
= verify_bgp_rib(tgen
, addr_type
, dut
, static_routes
)
462 assert result
is True, "Testcase {} : Failed \n Error {}". \
463 format(tc_name
, result
)
465 step("Import vrf RED's route in vrf GREEN on R3")
467 for addr_type
in ADDR_TYPES
:
478 import_dict
= {"r3": {"bgp": [{
479 "vrf": "GREEN", "local_as": 3, "address_family": temp
482 result
= create_router_bgp(tgen
, topo
, import_dict
)
483 assert result
is True, "Testcase {} :Failed \n Error: {}". \
484 format(tc_name
, result
)
486 step("Verify that locally imported routes are installed over eBGP imported"
487 " routes from VRF RED into VRF GREEN")
488 for addr_type
in ADDR_TYPES
:
493 "network": [NETWORK1_2
[addr_type
]],
494 "next_hop": "blackhole",
505 "network": NETWORK1_2
[addr_type
],
506 "bestpath": BESTPATH
[addr_type
],
513 result
= verify_bgp_bestpath(tgen
, addr_type
, input_routes
)
514 assert result
is True, "Testcase {} : Failed \n Error {}". \
515 format(tc_name
, result
)
517 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
)
518 assert result
is True, "Testcase {} : Failed \n Error {}". \
519 format(tc_name
, result
)
521 write_test_footer(tc_name
)
524 if __name__
== "__main__":
525 args
= ["-s"] + sys
.argv
[1:]
526 sys
.exit(pytest
.main(args
))