]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
tests: fix pylint cleanup damage
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_ecmp_lan.py
CommitLineData
4256a209 1#!/usr/bin/python
2
3#
4# Copyright (c) 2020 by VMware, Inc. ("VMware")
5# Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6# ("NetDEF") in this file.
7#
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
11# in all copies.
12#
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
20# OF THIS SOFTWARE.
21#
22
23
24"""OSPF Basic Functionality Automation."""
25import os
26import sys
27import time
28import pytest
29import json
4256a209 30
31# Save the Current Working Directory to find configuration files.
32CWD = os.path.dirname(os.path.realpath(__file__))
33sys.path.append(os.path.join(CWD, "../"))
34sys.path.append(os.path.join(CWD, "../lib/"))
35
36# pylint: disable=C0413
37# Import topogen and topotest helpers
38from mininet.topo import Topo
39from lib.topogen import Topogen, get_topogen
40
41# Import topoJson from lib, to create topology and initial configuration
42from lib.common_config import (
43 start_topology,
44 write_test_header,
45 create_interfaces_cfg,
46 write_test_footer,
47 reset_config_on_routers,
48 verify_rib,
49 create_static_routes,
50 check_address_types,
51 step,
52 create_route_maps,
53 shutdown_bringup_interface,
54 stop_router,
55 start_router,
701a0192 56 topo_daemons,
4256a209 57)
58from lib.bgp import verify_bgp_convergence, create_router_bgp
59from lib.topolog import logger
60from lib.topojson import build_topo_from_json, build_config_from_json
61
62from lib.ospf import (
63 verify_ospf_neighbor,
64 config_ospf_interface,
65 clear_ospf,
66 verify_ospf_rib,
67 create_router_ospf,
68 verify_ospf_interface,
88b7d3e7 69 redistribute_ospf,
4256a209 70)
71from ipaddress import IPv4Address
72
73# Global variables
74topo = None
75# Reading the data from JSON File for topology creation
76
77jsonFile = "{}/ospf_ecmp_lan.json".format(CWD)
78try:
79 with open(jsonFile, "r") as topoJson:
80 topo = json.load(topoJson)
81except IOError:
82 assert False, "Could not read file {}".format(jsonFile)
83
84NETWORK = {
85 "ipv4": [
86 "11.0.20.1/32",
87 "11.0.20.2/32",
88 "11.0.20.3/32",
89 "11.0.20.4/32",
90 "11.0.20.5/32",
91 ],
92 "ipv6": ["1::1/128", "1::2/128", "1::3/128", "1::4/128", "1::5/128"],
93}
94MASK = {"ipv4": "32", "ipv6": "128"}
95NEXT_HOP = {
96 "ipv4": ["10.0.0.1", "10.0.1.1", "10.0.2.1", "10.0.3.1", "10.0.4.1"],
97 "ipv6": ["Null0", "Null0", "Null0", "Null0", "Null0"],
98}
99"""
100TOPOOLOGY =
101 Please view in a fixed-width font such as Courier.
102 Topo : Broadcast Networks
103 +---+ +---+ +---+ +---+
104 |R0 + +R1 + +R2 + +R3 |
105 +-+-+ +-+-+ +-+-+ +-+-+
106 | | | |
107 | | | |
108 --+-----------+--------------+---------------+-----
109 Ethernet Segment
110
111TESTCASES =
1121. Verify OSPF ECMP with max path configured as 8
113 (Edge having 1 uplink port as broadcast network,
114 connect to 8 TORs - LAN case)
115
116 """
117
118
119class CreateTopo(Topo):
120 """
121 Test topology builder.
122
123 * `Topo`: Topology object
124 """
125
126 def build(self, *_args, **_opts):
127 """Build function."""
128 tgen = get_topogen(self)
129
130 # Building topology from json file
131 build_topo_from_json(tgen, topo)
132
133
134def setup_module(mod):
135 """
136 Sets up the pytest environment
137
138 * `mod`: module name
139 """
140 global topo
141 testsuite_run_time = time.asctime(time.localtime(time.time()))
142 logger.info("Testsuite start time: {}".format(testsuite_run_time))
143 logger.info("=" * 40)
144
145 logger.info("Running setup_module to create topology")
146
147 # This function initiates the topology build with Topogen...
148 tgen = Topogen(CreateTopo, mod.__name__)
149 # ... and here it calls Mininet initialization functions.
150
035267a3 151 # get list of daemons needs to be started for this suite.
152 daemons = topo_daemons(tgen, topo)
153
4256a209 154 # Starting topology, create tmp files which are loaded to routers
155 # to start deamons and then start routers
035267a3 156 start_topology(tgen, daemons)
157
4256a209 158 # Creating configuration from JSON
159 build_config_from_json(tgen, topo)
160
161 # Don't run this test if we have any failure.
162 if tgen.routers_have_failure():
163 pytest.skip(tgen.errors)
164 # Api call verify whether OSPF is converged
165 ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
166 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
167 ospf_covergence
168 )
169
170 logger.info("Running setup_module() done")
171
172
173def teardown_module():
174 """Teardown the pytest environment"""
175
176 logger.info("Running teardown_module to delete topology")
177
178 tgen = get_topogen()
179
180 try:
181 # Stop toplogy and Remove tmp files
182 tgen.stop_topology()
183
184 except OSError:
185 # OSError exception is raised when mininet tries to stop switch
186 # though switch is stopped once but mininet tries to stop same
187 # switch again, where it ended up with exception
188 pass
189
190
4256a209 191# ##################################
192# Test cases start here.
193# ##################################
194
195
196def test_ospf_lan_ecmp_tc18_p0(request):
197 """
198 OSPF ECMP.
199
200 Verify OSPF ECMP with max path configured as 8
201 (Edge having 1 uplink port as broadcast network,
202 connect to 8 TORs - LAN case)
203
204 """
205 tc_name = request.node.name
206 write_test_header(tc_name)
207 tgen = get_topogen()
208
209 # Don't run this test if we have any failure.
210 if tgen.routers_have_failure():
211 pytest.skip(tgen.errors)
212
213 global topo
214 step("Bring up the base config as per the topology")
215 step(". Configure ospf in all the routers on LAN interface.")
216 reset_config_on_routers(tgen)
217 step("Verify that OSPF is up with 8 neighborship sessions.")
218
219 ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
220 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
221 ospf_covergence
222 )
223
224 step(
225 "Configure a static route in all the routes and "
226 "redistribute static/connected in OSPF."
227 )
228
229 for rtr in topo["routers"]:
230 input_dict = {
231 rtr: {
232 "static_routes": [
233 {"network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0"}
234 ]
235 }
236 }
237 result = create_static_routes(tgen, input_dict)
238 assert result is True, "Testcase {} : Failed \n Error: {}".format(
239 tc_name, result
240 )
241
242 dut = rtr
88b7d3e7 243 redistribute_ospf(tgen, topo, dut, "static")
4256a209 244
245 step(
246 "Verify that route in R0 in stalled with 8 hops. "
247 "Verify ospf route table and ip route table."
248 )
249
250 nh = []
251 for rtr in topo["routers"]:
252 nh.append(topo["routers"][rtr]["links"]["s1"]["ipv4"].split("/")[0])
253 nh.remove(topo["routers"]["r1"]["links"]["s1"]["ipv4"].split("/")[0])
254 dut = "r1"
255 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
256 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
257
258 protocol = "ospf"
259 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
260 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
261
262 step(" clear ip ospf interface on DUT(r0)")
263 clear_ospf(tgen, "r0")
264
265 step(
266 "Verify that after clearing the ospf interface all the "
267 "neighbours are up and routes are installed with 8 next hop "
268 "in ospf and ip route tables on R0"
269 )
270
271 dut = "r0"
272 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
273 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
274 ospf_covergence
275 )
276
277 step(" clear ip ospf interface on R2")
278 clear_ospf(tgen, "r2")
279
280 dut = "r2"
281 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
282 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
283 ospf_covergence
284 )
285
286 step("Delete static/connected cmd in ospf in all the routes one by one.")
287 for rtr in topo["routers"]:
288 input_dict = {
289 rtr: {
290 "static_routes": [
291 {
292 "network": NETWORK["ipv4"][0],
293 "no_of_ip": 5,
294 "next_hop": "Null0",
295 "delete": True,
296 }
297 ]
298 }
299 }
300 result = create_static_routes(tgen, input_dict)
301 assert result is True, "Testcase {} : Failed \n Error: {}".format(
302 tc_name, result
303 )
304
305 step("Verify that all the routes are withdrawn from R0")
306 dut = "r1"
a81774ec 307 result = verify_ospf_rib(
308 tgen, dut, input_dict, next_hop=nh, attempts=5, expected=False
309 )
0b25370e
DS
310 assert (
311 result is not True
312 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
4256a209 313 tc_name, result
0b25370e 314 )
4256a209 315
316 protocol = "ospf"
a81774ec 317 result = verify_rib(
318 tgen,
319 "ipv4",
320 dut,
321 input_dict,
322 protocol=protocol,
323 next_hop=nh,
324 attempts=5,
325 expected=False,
326 )
0b25370e
DS
327 assert (
328 result is not True
329 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
4256a209 330 tc_name, result
0b25370e 331 )
4256a209 332
333 write_test_footer(tc_name)
334
335
336if __name__ == "__main__":
337 args = ["-s"] + sys.argv[1:]
338 sys.exit(pytest.main(args))