]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ospf_basic_functionality/test_ospf_p2mp.py
tests: Fix spelling of kernel
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_p2mp.py
CommitLineData
dc5298d7 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
dc5298d7 29from copy import deepcopy
30from ipaddress import IPv4Address
31
32# Save the Current Working Directory to find configuration files.
33CWD = os.path.dirname(os.path.realpath(__file__))
34sys.path.append(os.path.join(CWD, "../"))
35sys.path.append(os.path.join(CWD, "../lib/"))
36
37# pylint: disable=C0413
38# Import topogen and topotest helpers
dc5298d7 39from lib.topogen import Topogen, get_topogen
dc5298d7 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 write_test_footer,
46 reset_config_on_routers,
dc5298d7 47 step,
dc5298d7 48 create_interfaces_cfg,
49 topo_daemons,
50)
51from lib.topolog import logger
4953ca97 52from lib.topojson import build_config_from_json
8db751b8 53from lib.topotest import frr_unicode
dc5298d7 54
55from lib.ospf import (
dc5298d7 56 verify_ospf_interface,
dc5298d7 57)
58
6ff492b1 59
e82b531d 60pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
6ff492b1 61
dc5298d7 62# Global variables
63topo = None
64
dc5298d7 65
66"""
67TOPOOLOGY =
68 Please view in a fixed-width font such as Courier.
69 +---+ A1 +---+
70 +R1 +------------+R2 |
71 +-+-+- +--++
72 | -- -- |
73 | -- A0 -- |
74 A0| ---- |
75 | ---- | A2
76 | -- -- |
77 | -- -- |
78 +-+-+- +-+-+
79 +R0 +-------------+R3 |
80 +---+ A3 +---+
81
82TESTCASES =
831. OSPF P2MP -Verify state change events on p2mp network.
84 """
85
86
dc5298d7 87def setup_module(mod):
88 """
89 Sets up the pytest environment
90
91 * `mod`: module name
92 """
dc5298d7 93 testsuite_run_time = time.asctime(time.localtime(time.time()))
94 logger.info("Testsuite start time: {}".format(testsuite_run_time))
95 logger.info("=" * 40)
96
97 logger.info("Running setup_module to create topology")
98
99 # This function initiates the topology build with Topogen...
e82b531d
CH
100 json_file = "{}/ospf_p2mp.json".format(CWD)
101 tgen = Topogen(json_file, mod.__name__)
102 global topo
103 topo = tgen.json_topo
dc5298d7 104 # ... and here it calls Mininet initialization functions.
105
106 # get list of daemons needs to be started for this suite.
107 daemons = topo_daemons(tgen, topo)
108
109 # Starting topology, create tmp files which are loaded to routers
110 # to start deamons and then start routers
111 start_topology(tgen, daemons)
112
113 # Creating configuration from JSON
114 build_config_from_json(tgen, topo)
115
116 # Don't run this test if we have any failure.
117 if tgen.routers_have_failure():
118 pytest.skip(tgen.errors)
119
dc5298d7 120 logger.info("Running setup_module() done")
121
122
123def teardown_module(mod):
124 """
125 Teardown the pytest environment.
126
127 * `mod`: module name
128 """
129
130 logger.info("Running teardown_module to delete topology")
131
132 tgen = get_topogen()
133
134 # Stop toplogy and Remove tmp files
135 tgen.stop_topology()
136
137 logger.info(
138 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
139 )
140 logger.info("=" * 40)
141
142
143# ##################################
144# Test cases start here.
145# ##################################
146
147
148def test_ospf_p2mp_tc1_p0(request):
149 """OSPF IFSM -Verify state change events on p2mp network."""
150 tc_name = request.node.name
151 write_test_header(tc_name)
152 tgen = get_topogen()
153
154 # Don't run this test if we have any failure.
155 if tgen.routers_have_failure():
156 pytest.skip(tgen.errors)
157
158 global topo
159 step("Bring up the base config as per the topology")
160 reset_config_on_routers(tgen)
161 step(
162 "Verify that OSPF is subscribed to multi cast services "
163 "(All SPF, all DR Routers)."
164 )
165 step("Verify that interface is enabled in ospf.")
166 step("Verify that config is successful.")
167 dut = "r0"
168 input_dict = {
169 "r0": {
170 "links": {
171 "r3": {"ospf": {"mcastMemberOspfAllRouters": True, "ospfEnabled": True}}
172 }
173 }
174 }
175 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
176 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
177
178 step("Delete the ip address")
179 topo1 = {
180 "r0": {
181 "links": {
182 "r3": {
183 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
184 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
185 "delete": True,
186 }
187 }
188 }
189 }
190
191 result = create_interfaces_cfg(tgen, topo1)
192 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
193
194 step("Change the ip on the R0 interface")
195
196 topo_modify_change_ip = deepcopy(topo)
197 intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
198 topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str(
d7d21c3a 199 IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3
dc5298d7 200 ) + "/{}".format(intf_ip.split("/")[1])
201
202 build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)
203 step("Verify that interface is enabled in ospf.")
204 dut = "r0"
205 input_dict = {
206 "r0": {
207 "links": {
208 "r3": {
209 "ospf": {
210 "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][
211 "r3"
212 ]["ipv4"].split("/")[0],
213 "ipAddressPrefixlen": int(
214 topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
215 "ipv4"
216 ].split("/")[1]
217 ),
218 }
219 }
220 }
221 }
222 }
223 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
224 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
225
226 step("Modify the mask on the R0 interface")
227 ip_addr = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
228 mask = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
229 step("Delete the ip address")
230 topo1 = {
231 "r0": {
232 "links": {
233 "r3": {
234 "ipv4": ip_addr,
235 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
236 "delete": True,
237 }
238 }
239 }
240 }
241
242 result = create_interfaces_cfg(tgen, topo1)
243 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
244
245 step("Change the ip on the R0 interface")
246
247 topo_modify_change_ip = deepcopy(topo)
248 intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
249 topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str(
d7d21c3a 250 IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3
dc5298d7 251 ) + "/{}".format(int(intf_ip.split("/")[1]) + 1)
252
253 build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)
254 step("Verify that interface is enabled in ospf.")
255 dut = "r0"
256 input_dict = {
257 "r0": {
258 "links": {
259 "r3": {
260 "ospf": {
261 "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][
262 "r3"
263 ]["ipv4"].split("/")[0],
264 "ipAddressPrefixlen": int(
265 topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
266 "ipv4"
267 ].split("/")[1]
268 ),
269 }
270 }
271 }
272 }
273 }
274 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
275 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
276
277 topo1 = {
278 "r0": {
279 "links": {
280 "r3": {
281 "ipv4": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
282 "ipv4"
283 ],
284 "interface": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
285 "interface"
286 ],
287 "delete": True,
288 }
289 }
290 }
291 }
292
293 result = create_interfaces_cfg(tgen, topo1)
294 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
295
296 build_config_from_json(tgen, topo, save_bkup=False)
297
298 step("Change the area id on the interface")
299 input_dict = {
300 "r0": {
301 "links": {
302 "r3": {
303 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
304 "ospf": {"area": "0.0.0.0"},
305 "delete": True,
306 }
307 }
308 }
309 }
310
311 result = create_interfaces_cfg(tgen, input_dict)
312 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
313
314 input_dict = {
315 "r0": {
316 "links": {
317 "r3": {
318 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
319 "ospf": {"area": "0.0.0.1"},
320 }
321 }
322 }
323 }
324
325 result = create_interfaces_cfg(tgen, input_dict)
326 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
327 step("Verify that interface is enabled in ospf.")
328 dut = "r0"
329 input_dict = {
330 "r0": {"links": {"r3": {"ospf": {"area": "0.0.0.1", "ospfEnabled": True}}}}
331 }
332 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
333 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
334
335 input_dict = {
336 "r0": {
337 "links": {
338 "r3": {
339 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
340 "ospf": {"area": "0.0.0.1"},
341 "delete": True,
342 }
343 }
344 }
345 }
346
347 result = create_interfaces_cfg(tgen, input_dict)
348 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
349
350 input_dict = {
351 "r0": {
352 "links": {
353 "r3": {
354 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
355 "ospf": {"area": "0.0.0.0"},
356 }
357 }
358 }
359 }
360
361 result = create_interfaces_cfg(tgen, input_dict)
362 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
363
364 step("Verify if interface is enabled with network type P2MP")
365 input_dict = {
366 "r0": {
367 "links": {
368 "r3": {
369 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
5980ad0a 370 "ospf": {"area": "0.0.0.0", "networkType": "POINTOMULTIPOINT"},
dc5298d7 371 }
372 }
373 }
374 }
375 result = create_interfaces_cfg(tgen, input_dict)
376 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
377
378 write_test_footer(tc_name)
379
380
381if __name__ == "__main__":
382 args = ["-s"] + sys.argv[1:]
383 sys.exit(pytest.main(args))