4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("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
25 Following tests are covered to test ecmp functionality on iBGP.
26 1. Verify bgp fast-convergence functionality
33 from time
import sleep
35 # Save the Current Working Directory to find configuration files.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
38 sys
.path
.append(os
.path
.join(CWD
, "../../"))
40 # pylint: disable=C0413
41 # Import topogen and topotest helpers
42 from lib
.topogen
import Topogen
, get_topogen
43 from mininet
.topo
import Topo
45 from lib
.common_config
import (
53 reset_config_on_routers
,
54 required_linux_kernel_version
,
55 shutdown_bringup_interface
,
58 from lib
.topolog
import logger
59 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, clear_bgp
60 from lib
.topojson
import build_topo_from_json
, build_config_from_json
63 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
66 # Reading the data from JSON File for topology and configuration creation
67 jsonFile
= "{}/ibgp_ecmp_topo3.json".format(CWD
)
70 with
open(jsonFile
, "r") as topoJson
:
71 topo
= json
.load(topoJson
)
73 assert False, "Could not read file {}".format(jsonFile
)
76 NEXT_HOPS
= {"ipv4": [], "ipv6": []}
77 NETWORK
= {"ipv4": "192.168.1.10/32", "ipv6": "fd00:0:0:1::10/128"}
78 NEXT_HOP_IP
= {"ipv4": "10.0.0.1", "ipv6": "fd00::1"}
79 BGP_CONVERGENCE
= False
82 class CreateTopo(Topo
):
84 Test topology builder.
86 * `Topo`: Topology object
89 def build(self
, *_args
, **_opts
):
91 tgen
= get_topogen(self
)
93 # Building topology from json file
94 build_topo_from_json(tgen
, topo
)
97 def setup_module(mod
):
99 Sets up the pytest environment.
103 global NEXT_HOPS
, INTF_LIST_R3
, INTF_LIST_R2
, TEST_STATIC
106 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
107 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
108 logger
.info("=" * 40)
110 logger
.info("Running setup_module to create topology")
112 # This function initiates the topology build with Topogen...
113 tgen
= Topogen(CreateTopo
, mod
.__name
__)
115 # Starting topology, create tmp files which are loaded to routers
116 # to start deamons and then start routers
119 # Creating configuration from JSON
120 build_config_from_json(tgen
, topo
)
122 # Don't run this test if we have any failure.
123 if tgen
.routers_have_failure():
124 pytest
.skip(tgen
.errors
)
126 # Api call verify whether BGP is converged
127 ADDR_TYPES
= check_address_types()
129 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
130 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error:" " {}".format(
134 # STATIC_ROUTE = True
135 logger
.info("Running setup_module() done")
138 def teardown_module():
140 Teardown the pytest environment.
145 logger
.info("Running teardown_module to delete topology")
149 # Stop toplogy and Remove tmp files
153 def static_or_nw(tgen
, topo
, tc_name
, test_type
, dut
):
155 if test_type
== "redist_static":
156 input_dict_static
= {
159 {"network": NETWORK
["ipv4"], "next_hop": NEXT_HOP_IP
["ipv4"]},
160 {"network": NETWORK
["ipv6"], "next_hop": NEXT_HOP_IP
["ipv6"]},
164 logger
.info("Configuring static route on router %s", dut
)
165 result
= create_static_routes(tgen
, input_dict_static
)
166 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
175 "unicast": {"redistribute": [{"redist_type": "static"}]}
178 "unicast": {"redistribute": [{"redist_type": "static"}]}
185 logger
.info("Configuring redistribute static route on router %s", dut
)
186 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
187 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
191 elif test_type
== "advertise_nw":
198 "advertise_networks": [{"network": NETWORK
["ipv4"]}]
203 "advertise_networks": [{"network": NETWORK
["ipv6"]}]
212 "Advertising networks %s %s from router %s",
217 result
= create_router_bgp(tgen
, topo
, input_dict_nw
)
218 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
223 @pytest.mark
.parametrize("test_type", ["redist_static"])
224 def test_ecmp_fast_convergence(request
, test_type
):
225 """This test is to verify bgp fast-convergence cli functionality"""
227 tc_name
= request
.node
.name
228 write_test_header(tc_name
)
231 # Verifying RIB routes
235 reset_config_on_routers(tgen
)
236 static_or_nw(tgen
, topo
, tc_name
, test_type
, "r2")
238 for addr_type
in ADDR_TYPES
:
239 input_dict
= {"r3": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
241 logger
.info("Verifying %s routes on r3", addr_type
)
249 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
253 intf1
= topo
["routers"]["r2"]["links"]["r3-link1"]["interface"]
254 intf2
= topo
["routers"]["r2"]["links"]["r3-link2"]["interface"]
256 logger
.info("Shutdown one of the link b/w r2 and r3")
257 shutdown_bringup_interface(tgen
, "r2", intf1
, False)
259 logger
.info("Verify bgp neighbors are still up")
260 result
= verify_bgp_convergence(tgen
, topo
)
261 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
263 logger
.info("Shutdown another link b/w r2 and r3")
264 shutdown_bringup_interface(tgen
, "r2", intf2
, False)
266 logger
.info("Wait for 10 sec and make sure bgp neighbors are still up")
268 result
= verify_bgp_convergence(tgen
, topo
)
269 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
271 logger
.info("No shut links b/w r2 and r3")
272 shutdown_bringup_interface(tgen
, "r2", intf1
, True)
273 shutdown_bringup_interface(tgen
, "r2", intf2
, True)
275 logger
.info("Enable bgp fast-convergence cli")
279 "router bgp {}".format(topo
["routers"]["r2"]["bgp"]["local_as"]),
280 "bgp fast-convergence",
284 result
= apply_raw_config(tgen
, raw_config
)
285 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
287 logger
.info("Shutdown one link b/w r2 and r3")
288 shutdown_bringup_interface(tgen
, "r2", intf1
, False)
290 logger
.info("Verify bgp neighbors goes down immediately")
291 result
= verify_bgp_convergence(tgen
, topo
, dut
="r2", expected
=False)
292 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
296 logger
.info("Shutdown second link b/w r2 and r3")
297 shutdown_bringup_interface(tgen
, "r2", intf2
, False)
299 logger
.info("Verify bgp neighbors goes down immediately")
300 result
= verify_bgp_convergence(tgen
, topo
, dut
="r2", expected
=False)
301 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
305 write_test_footer(tc_name
)
308 if __name__
== "__main__":
309 args
= ["-s"] + sys
.argv
[1:]
310 sys
.exit(pytest
.main(args
))