]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo2.py
4 # Copyright (c) 2021 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 VRF Lite:
25 1. Verify that locally imported routes are selected as best path over eBGP imported routes
27 2. Verify ECMP for imported routes from different VRFs.
35 from time
import sleep
37 # Save the Current Working Directory to find configuration files.
38 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
39 sys
.path
.append(os
.path
.join(CWD
, "../"))
40 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
42 # Required to instantiate the topology builder class.
44 # pylint: disable=C0413
45 # Import topogen and topotest helpers
46 from lib
.topogen
import Topogen
, get_topogen
47 from lib
.topotest
import version_cmp
49 from lib
.common_config
import (
54 reset_config_on_routers
,
62 from lib
.topolog
import logger
64 verify_bgp_convergence
,
69 from lib
.topojson
import build_config_from_json
71 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
74 NETWORK1_1
= {"ipv4": "11.11.11.1/32", "ipv6": "11:11::1/128"}
75 NETWORK1_2
= {"ipv4": "11.11.11.11/32", "ipv6": "11:11::11/128"}
76 NETWORK1_3
= {"ipv4": "10.10.10.1/32", "ipv6": "10:10::1/128"}
77 NETWORK1_4
= {"ipv4": "10.10.10.100/32", "ipv6": "10:10::100/128"}
78 NETWORK1_5
= {"ipv4": "110.110.110.1/32", "ipv6": "110:110::1/128"}
79 NETWORK1_6
= {"ipv4": "110.110.110.100/32", "ipv6": "110:110::100/128"}
81 NETWORK2_1
= {"ipv4": "22.22.22.2/32", "ipv6": "22:22::2/128"}
82 NETWORK2_2
= {"ipv4": "22.22.22.22/32", "ipv6": "22:22::22/128"}
83 NETWORK2_3
= {"ipv4": "20.20.20.20/32", "ipv6": "20:20::20/128"}
84 NETWORK2_4
= {"ipv4": "20.20.20.200/32", "ipv6": "20:20::200/128"}
85 NETWORK2_5
= {"ipv4": "220.220.220.20/32", "ipv6": "220:220::20/128"}
86 NETWORK2_6
= {"ipv4": "220.220.220.200/32", "ipv6": "220:220::200/128"}
88 NETWORK3_1
= {"ipv4": "30.30.30.3/32", "ipv6": "30:30::3/128"}
89 NETWORK3_2
= {"ipv4": "30.30.30.30/32", "ipv6": "30:30::30/128"}
92 "ipv4": ["11.11.11.1", "22.22.22.2", "22.22.22.22"],
93 "ipv6": ["11:11::1", "22:22::2", "22:22::22"],
95 PREFERRED_NEXT_HOP
= "global"
96 VRF_LIST
= ["RED", "BLUE", "GREEN"]
97 COMM_VAL_1
= "100:100"
98 COMM_VAL_2
= "500:500"
99 COMM_VAL_3
= "600:600"
105 def setup_module(mod
):
107 Sets up the pytest environment
112 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
113 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
114 logger
.info("=" * 40)
116 logger
.info("Running setup_module to create topology")
118 # This function initiates the topology build with Topogen...
119 json_file
= "{}/bgp_vrf_lite_best_path_topo2.json".format(CWD
)
120 tgen
= Topogen(json_file
, mod
.__name
__)
122 topo
= tgen
.json_topo
123 # ... and here it calls Mininet initialization functions.
125 # Starting topology, create tmp files which are loaded to routers
126 # to start daemons and then start routers
129 # Run these tests for kernel version 4.19 or above
130 if version_cmp(platform
.release(), "4.19") < 0:
132 "BGP vrf dynamic route leak tests will not run "
133 '(have kernel "{}", but it requires >= 4.19)'.format(platform
.release())
135 pytest
.skip(error_msg
)
137 # Creating configuration from JSON
138 build_config_from_json(tgen
, topo
)
140 global BGP_CONVERGENCE
142 ADDR_TYPES
= check_address_types()
144 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
145 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
149 logger
.info("Running setup_module() done")
152 def teardown_module():
153 """Teardown the pytest environment"""
155 logger
.info("Running teardown_module to delete topology")
159 # Stop toplogy and Remove tmp files
163 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
165 logger
.info("=" * 40)
168 #####################################################
172 #####################################################
174 def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request
):
176 Verify ECMP for imported routes from different VRFs.
180 tc_name
= request
.node
.name
181 write_test_header(tc_name
)
182 if tgen
.routers_have_failure():
183 check_router_status(tgen
)
184 reset_config_on_routers(tgen
)
186 step("Configure same static routes in tenant vrfs RED and GREEN on router "
187 "R3 and redistribute in respective BGP process")
189 for vrf_name
in ["RED", "GREEN"]:
190 for addr_type
in ADDR_TYPES
:
191 if vrf_name
== "GREEN":
192 next_hop_vrf
= topo
["routers"]["r1"]["links"][
193 "r3-link3"][addr_type
].split("/")[0]
195 next_hop_vrf
= topo
["routers"]["r2"]["links"][
196 "r3-link1"][addr_type
].split("/")[0]
201 "network": [NETWORK1_1
[addr_type
]],
202 "next_hop": next_hop_vrf
,
209 result
= create_static_routes(tgen
, static_routes
)
210 assert result
is True, "Testcase {} :Failed \n Error: {}". \
211 format(tc_name
, result
)
213 step("Redistribute static route on BGP VRF : {}".format(vrf_name
))
215 for addr_type
in ADDR_TYPES
:
220 "redist_type": "static"
226 redist_dict
= {"r3": {"bgp": [{
227 "vrf": vrf_name
, "local_as": 3, "address_family": temp
230 result
= create_router_bgp(tgen
, topo
, redist_dict
)
231 assert result
is True, "Testcase {} :Failed \n Error: {}". \
232 format(tc_name
, result
)
234 step("Verify that configured static routes are installed in respective "
235 "BGP table for vrf RED & GREEN")
236 for vrf_name
in ["RED", "GREEN"]:
237 for addr_type
in ADDR_TYPES
:
238 if vrf_name
== "GREEN":
239 next_hop_vrf
= topo
["routers"]["r1"]["links"][
240 "r3-link3"][addr_type
].split("/")[0]
242 next_hop_vrf
= topo
["routers"]["r2"]["links"][
243 "r3-link1"][addr_type
].split("/")[0]
248 "network": [NETWORK1_1
[addr_type
]],
255 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
256 next_hop
=next_hop_vrf
)
257 assert result
is True, "Testcase {} : Failed \n Error {}". \
258 format(tc_name
, result
)
260 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
261 next_hop
=next_hop_vrf
)
262 assert result
is True, "Testcase {} : Failed \n Error {}". \
263 format(tc_name
, result
)
265 step("Import vrf RED and GREEN into default vrf and Configure ECMP")
267 for vrf_name
in ["RED", "GREEN"]:
269 for addr_type
in ADDR_TYPES
:
284 "local_as": 3, "address_family": temp
287 import_dict
= {"r3": {"bgp": bgp_val
}}
289 result
= create_router_bgp(tgen
, topo
, import_dict
)
290 assert result
is True, "Testcase {} :Failed \n Error: {}". \
291 format(tc_name
, result
)
293 step("Configure bgp bestpath on router r3")
298 "bgp bestpath as-path multipath-relax"
302 result
= apply_raw_config(tgen
, r3_raw_config
)
303 assert result
is True, "Testcase {} :Failed \n Error: {}". \
304 format(tc_name
, result
)
306 step("Verify that routes are imported with two different next-hop vrfs "
307 "and IPs. Additionally R3 must do ECMP for both the routes.")
309 for addr_type
in ADDR_TYPES
:
311 topo
["routers"]["r2"]["links"]["r3-link1"][addr_type
]. \
313 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
]. \
320 "network": [NETWORK1_1
[addr_type
]],
326 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
327 next_hop
=next_hop_vrf
)
328 assert result
is True, "Testcase {} : Failed \n Error {}". \
329 format(tc_name
, result
)
331 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
332 next_hop
=next_hop_vrf
)
333 assert result
is True, "Testcase {} : Failed \n Error {}". \
334 format(tc_name
, result
)
336 step("Now change the next-hop of static routes in vrf RED and GREEN to "
338 for addr_type
in ADDR_TYPES
:
339 next_hop_vrf
= topo
["routers"]["r1"]["links"][
340 "r3-link3"][addr_type
].split("/")[0]
345 "network": [NETWORK1_1
[addr_type
]],
346 "next_hop": next_hop_vrf
,
350 "network": [NETWORK1_1
[addr_type
]],
351 "next_hop": topo
["routers"]["r2"]["links"][
352 "r3-link1"][addr_type
].split("/")[0],
360 result
= create_static_routes(tgen
, static_routes
)
361 assert result
is True, "Testcase {} :Failed \n Error: {}". \
362 format(tc_name
, result
)
364 step("Verify that now routes are imported with two different next-hop "
365 "vrfs but same IPs. Additionally R3 must do ECMP for both the routes")
367 for addr_type
in ADDR_TYPES
:
369 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
].\
371 topo
["routers"]["r1"]["links"]["r3-link3"][addr_type
]. \
378 "network": [NETWORK1_1
[addr_type
]],
384 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes
,
385 next_hop
=next_hop_vrf
)
386 assert result
is True, "Testcase {} : Failed \n Error {}". \
387 format(tc_name
, result
)
389 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
,
390 next_hop
=next_hop_vrf
)
391 assert result
is True, "Testcase {} : Failed \n Error {}". \
392 format(tc_name
, result
)
394 write_test_footer(tc_name
)
397 def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(request
):
399 Verify ECMP for imported routes from different VRFs.
403 tc_name
= request
.node
.name
404 write_test_header(tc_name
)
405 if tgen
.routers_have_failure():
406 check_router_status(tgen
)
407 reset_config_on_routers(tgen
)
409 step("Configure same static routes on R2 and R3 vrfs and redistribute in BGP "
410 "for GREEN and RED vrf instances")
411 for dut
, network
in zip(["r2", "r3"], [
412 [NETWORK1_1
, NETWORK1_2
], [NETWORK1_1
, NETWORK1_2
]]):
413 for vrf_name
, network_vrf
in zip(["RED", "GREEN"], network
):
414 step("Configure static route for VRF : {} on {}".format(vrf_name
,
416 for addr_type
in ADDR_TYPES
:
421 "network": [network_vrf
[addr_type
]],
422 "next_hop": "blackhole",
429 result
= create_static_routes(tgen
, static_routes
)
430 assert result
is True, "Testcase {} :Failed \n Error: {}". \
431 format(tc_name
, result
)
433 for dut
, as_num
in zip(["r2", "r3"], ["2", "3"]):
434 for vrf_name
in ["RED", "GREEN"]:
435 step("Redistribute static route on BGP VRF : {}".format(vrf_name
))
437 for addr_type
in ADDR_TYPES
:
442 "redist_type": "static"
448 redist_dict
= {dut
: {"bgp": [{
449 "vrf": vrf_name
, "local_as": as_num
, "address_family": temp
452 result
= create_router_bgp(tgen
, topo
, redist_dict
)
453 assert result
is True, "Testcase {} :Failed \n Error: {}". \
454 format(tc_name
, result
)
456 step("Verify that R2 and R3 has installed redistributed routes in default "
457 "and RED vrfs and GREEN respectively:")
458 for dut
, network
in zip(["r2", "r3"],
459 [[NETWORK1_1
, NETWORK1_2
],
460 [NETWORK1_1
, NETWORK1_2
]]):
461 for vrf_name
, network_vrf
in zip(["RED", "GREEN"], network
):
462 for addr_type
in ADDR_TYPES
:
467 "network": [network_vrf
[addr_type
]],
468 "next_hop": "blackhole",
474 result
= verify_bgp_rib(tgen
, addr_type
, dut
, static_routes
)
475 assert result
is True, "Testcase {} : Failed \n Error {}". \
476 format(tc_name
, result
)
478 step("Import vrf RED's route in vrf GREEN on R3")
480 for addr_type
in ADDR_TYPES
:
491 import_dict
= {"r3": {"bgp": [{
492 "vrf": "GREEN", "local_as": 3, "address_family": temp
495 result
= create_router_bgp(tgen
, topo
, import_dict
)
496 assert result
is True, "Testcase {} :Failed \n Error: {}". \
497 format(tc_name
, result
)
499 step("Verify that locally imported routes are installed over eBGP imported"
500 " routes from VRF RED into VRF GREEN")
501 for addr_type
in ADDR_TYPES
:
506 "network": [NETWORK1_2
[addr_type
]],
507 "next_hop": "blackhole",
518 "network": NETWORK1_2
[addr_type
],
519 "bestpath": BESTPATH
[addr_type
],
526 result
= verify_bgp_bestpath(tgen
, addr_type
, input_routes
)
527 assert result
is True, "Testcase {} : Failed \n Error {}". \
528 format(tc_name
, result
)
530 result
= verify_rib(tgen
, addr_type
, "r3", static_routes
)
531 assert result
is True, "Testcase {} : Failed \n Error {}". \
532 format(tc_name
, result
)
534 write_test_footer(tc_name
)
537 if __name__
== "__main__":
538 args
= ["-s"] + sys
.argv
[1:]
539 sys
.exit(pytest
.main(args
))