]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """OSPF Basic Functionality Automation."""
17 # Save the Current Working Directory to find configuration files.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
20 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
22 # pylint: disable=C0413
23 # Import topogen and topotest helpers
24 from lib
.topogen
import Topogen
, get_topogen
26 # Import topoJson from lib, to create topology and initial configuration
27 from lib
.common_config
import (
31 reset_config_on_routers
,
36 from lib
.topolog
import logger
37 from lib
.topojson
import build_config_from_json
39 from lib
.ospf
import (
46 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
51 # Reading the data from JSON File for topology creation
60 "ipv6": ["1::1/128", "1::2/128", "1::3/128", "1::4/128", "1::5/128"],
62 MASK
= {"ipv4": "32", "ipv6": "128"}
64 "ipv4": ["10.0.0.1", "10.0.1.1", "10.0.2.1", "10.0.3.1", "10.0.4.1"],
65 "ipv6": ["Null0", "Null0", "Null0", "Null0", "Null0"],
69 Please view in a fixed-width font such as Courier.
70 Topo : Broadcast Networks
71 +---+ +---+ +---+ +---+
72 |R0 + +R1 + +R2 + +R3 |
73 +-+-+ +-+-+ +-+-+ +-+-+
76 --+-----------+--------------+---------------+-----
80 1. Verify OSPF ECMP with max path configured as 8
81 (Edge having 1 uplink port as broadcast network,
82 connect to 8 TORs - LAN case)
87 def setup_module(mod
):
89 Sets up the pytest environment
93 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
94 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
97 logger
.info("Running setup_module to create topology")
99 # This function initiates the topology build with Topogen...
100 json_file
= "{}/ospf_ecmp_lan.json".format(CWD
)
101 tgen
= Topogen(json_file
, mod
.__name
__)
103 topo
= tgen
.json_topo
104 # ... and here it calls Mininet initialization functions.
106 # Starting topology, create tmp files which are loaded to routers
107 # to start daemons and then start routers
110 # Creating configuration from JSON
111 build_config_from_json(tgen
, topo
)
113 # Don't run this test if we have any failure.
114 if tgen
.routers_have_failure():
115 pytest
.skip(tgen
.errors
)
116 # Api call verify whether OSPF is converged
117 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
118 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
122 logger
.info("Running setup_module() done")
125 def teardown_module():
126 """Teardown the pytest environment"""
128 logger
.info("Running teardown_module to delete topology")
133 # Stop toplogy and Remove tmp files
137 # OSError exception is raised when mininet tries to stop switch
138 # though switch is stopped once but mininet tries to stop same
139 # switch again, where it ended up with exception
143 # ##################################
144 # Test cases start here.
145 # ##################################
148 def test_ospf_lan_ecmp_tc18_p0(request
):
152 Verify OSPF ECMP with max path configured as 8
153 (Edge having 1 uplink port as broadcast network,
154 connect to 8 TORs - LAN case)
157 tc_name
= request
.node
.name
158 write_test_header(tc_name
)
161 # Don't run this test if we have any failure.
162 if tgen
.routers_have_failure():
163 pytest
.skip(tgen
.errors
)
166 step("Bring up the base config as per the topology")
167 step(". Configure ospf in all the routers on LAN interface.")
168 reset_config_on_routers(tgen
)
169 step("Verify that OSPF is up with 8 neighborship sessions.")
171 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
172 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
177 "Configure a static route in all the routes and "
178 "redistribute static/connected in OSPF."
181 for rtr
in topo
["routers"]:
185 {"network": NETWORK
["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0"}
189 result
= create_static_routes(tgen
, input_dict
)
190 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
195 redistribute_ospf(tgen
, topo
, dut
, "static")
198 "Verify that route in R0 in stalled with 8 hops. "
199 "Verify ospf route table and ip route table."
203 for rtr
in topo
["routers"]:
204 nh
.append(topo
["routers"][rtr
]["links"]["s1"]["ipv4"].split("/")[0])
205 nh
.remove(topo
["routers"]["r1"]["links"]["s1"]["ipv4"].split("/")[0])
207 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
208 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
211 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
212 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
214 step(" clear ip ospf interface on DUT(r0)")
215 clear_ospf(tgen
, "r0")
218 "Verify that after clearing the ospf interface all the "
219 "neighbours are up and routes are installed with 8 next hop "
220 "in ospf and ip route tables on R0"
224 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, lan
=True)
225 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
229 step(" clear ip ospf interface on R2")
230 clear_ospf(tgen
, "r2")
233 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, lan
=True)
234 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
238 step("Delete static/connected cmd in ospf in all the routes one by one.")
239 for rtr
in topo
["routers"]:
244 "network": NETWORK
["ipv4"][0],
252 result
= create_static_routes(tgen
, input_dict
)
253 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
257 step("Verify that all the routes are withdrawn from R0")
259 result
= verify_ospf_rib(
260 tgen
, dut
, input_dict
, next_hop
=nh
, retry_timeout
=10, expected
=False
264 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
281 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
285 write_test_footer(tc_name
)
288 if __name__
== "__main__":
289 args
= ["-s"] + sys
.argv
[1:]
290 sys
.exit(pytest
.main(args
))