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
32 from time
import sleep
34 # Save the Current Working Directory to find configuration files.
35 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 sys
.path
.append(os
.path
.join(CWD
, "../../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
.topogen
import get_topogen
42 from lib
import topojson
44 from lib
.common_config
import (
50 reset_config_on_routers
,
51 shutdown_bringup_interface
,
54 from lib
.topolog
import logger
55 from lib
.bgp
import create_router_bgp
, verify_bgp_convergence
58 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
62 NEXT_HOPS
= {"ipv4": [], "ipv6": []}
63 NETWORK
= {"ipv4": "192.168.1.10/32", "ipv6": "fd00:0:0:1::10/128"}
64 NEXT_HOP_IP
= {"ipv4": "10.0.0.1", "ipv6": "fd00::1"}
65 BGP_CONVERGENCE
= False
68 def setup_module(mod
):
70 Sets up the pytest environment.
76 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
77 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
80 tgen
= topojson
.setup_module_from_json(mod
.__file
__)
83 # Don't run this test if we have any failure.
84 if tgen
.routers_have_failure():
85 pytest
.skip(tgen
.errors
)
87 # Api call verify whether BGP is converged
88 ADDR_TYPES
= check_address_types()
90 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
91 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error:" " {}".format(
96 logger
.info("Running setup_module() done")
99 def teardown_module():
100 get_topogen().stop_topology()
103 def static_or_nw(tgen
, topo
, tc_name
, test_type
, dut
):
105 if test_type
== "redist_static":
106 input_dict_static
= {
109 {"network": NETWORK
["ipv4"], "next_hop": NEXT_HOP_IP
["ipv4"]},
110 {"network": NETWORK
["ipv6"], "next_hop": NEXT_HOP_IP
["ipv6"]},
114 logger
.info("Configuring static route on router %s", dut
)
115 result
= create_static_routes(tgen
, input_dict_static
)
116 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
125 "unicast": {"redistribute": [{"redist_type": "static"}]}
128 "unicast": {"redistribute": [{"redist_type": "static"}]}
135 logger
.info("Configuring redistribute static route on router %s", dut
)
136 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
137 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
141 elif test_type
== "advertise_nw":
148 "advertise_networks": [{"network": NETWORK
["ipv4"]}]
153 "advertise_networks": [{"network": NETWORK
["ipv6"]}]
162 "Advertising networks %s %s from router %s",
167 result
= create_router_bgp(tgen
, topo
, input_dict_nw
)
168 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
173 @pytest.mark
.parametrize("test_type", ["redist_static"])
174 def test_ecmp_fast_convergence(request
, test_type
, tgen
, topo
):
175 """This test is to verify bgp fast-convergence cli functionality"""
177 tc_name
= request
.node
.name
178 write_test_header(tc_name
)
180 # Verifying RIB routes
184 reset_config_on_routers(tgen
)
185 static_or_nw(tgen
, topo
, tc_name
, test_type
, "r2")
187 for addr_type
in ADDR_TYPES
:
188 input_dict
= {"r3": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
190 logger
.info("Verifying %s routes on r3", addr_type
)
198 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
202 intf1
= topo
["routers"]["r2"]["links"]["r3-link1"]["interface"]
203 intf2
= topo
["routers"]["r2"]["links"]["r3-link2"]["interface"]
205 logger
.info("Shutdown one of the link b/w r2 and r3")
206 shutdown_bringup_interface(tgen
, "r2", intf1
, False)
208 logger
.info("Verify bgp neighbors are still up")
209 result
= verify_bgp_convergence(tgen
, topo
)
210 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
212 logger
.info("Shutdown another link b/w r2 and r3")
213 shutdown_bringup_interface(tgen
, "r2", intf2
, False)
215 logger
.info("Wait for 10 sec and make sure bgp neighbors are still up")
217 result
= verify_bgp_convergence(tgen
, topo
)
218 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
220 logger
.info("No shut links b/w r2 and r3")
221 shutdown_bringup_interface(tgen
, "r2", intf1
, True)
222 shutdown_bringup_interface(tgen
, "r2", intf2
, True)
224 logger
.info("Enable bgp fast-convergence cli")
228 "router bgp {}".format(topo
["routers"]["r2"]["bgp"]["local_as"]),
229 "bgp fast-convergence",
233 result
= apply_raw_config(tgen
, raw_config
)
234 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
236 logger
.info("Shutdown one link b/w r2 and r3")
237 shutdown_bringup_interface(tgen
, "r2", intf1
, False)
239 logger
.info("Verify bgp neighbors goes down immediately")
240 result
= verify_bgp_convergence(tgen
, topo
, dut
="r2", expected
=False)
241 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
245 logger
.info("Shutdown second link b/w r2 and r3")
246 shutdown_bringup_interface(tgen
, "r2", intf2
, False)
248 logger
.info("Verify bgp neighbors goes down immediately")
249 result
= verify_bgp_convergence(tgen
, topo
, dut
="r2", expected
=False)
250 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
254 write_test_footer(tc_name
)
257 if __name__
== "__main__":
258 args
= ["-s"] + sys
.argv
[1:]
259 sys
.exit(pytest
.main(args
))