]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_chaos.py
CommitLineData
a3276d2c 1#!/usr/bin/python
acddc0ed 2# SPDX-License-Identifier: ISC
a3276d2c 3
4#
5# Copyright (c) 2020 by VMware, Inc. ("VMware")
6# Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7# ("NetDEF") in this file.
8#
a3276d2c 9
10
11"""OSPF Basic Functionality Automation."""
12import os
13import sys
14import time
15import pytest
a3276d2c 16
17# Save the Current Working Directory to find configuration files.
18CWD = os.path.dirname(os.path.realpath(__file__))
19sys.path.append(os.path.join(CWD, "../"))
20sys.path.append(os.path.join(CWD, "../lib/"))
21
22# pylint: disable=C0413
23# Import topogen and topotest helpers
a3276d2c 24from lib.topogen import Topogen, get_topogen
25
26# Import topoJson from lib, to create topology and initial configuration
27from lib.common_config import (
28 start_topology,
29 write_test_header,
30 write_test_footer,
31 reset_config_on_routers,
32 step,
a3276d2c 33 verify_rib,
5980ad0a
DS
34 stop_router,
35 start_router,
a3276d2c 36 create_static_routes,
37 start_router_daemons,
5980ad0a 38 kill_router_daemons,
a3276d2c 39)
40
5980ad0a 41from lib.ospf import verify_ospf_neighbor, verify_ospf_rib, create_router_ospf
a3276d2c 42
43from lib.topolog import logger
4953ca97 44from lib.topojson import build_config_from_json
a3276d2c 45
efb62eed 46pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
a3276d2c 47
48# Global variables
49topo = None
50
51NETWORK = {
5980ad0a
DS
52 "ipv4": [
53 "11.0.20.1/32",
54 "11.0.20.2/32",
55 "11.0.20.3/32",
56 "11.0.20.4/32",
57 "11.0.20.5/32",
58 ]
a3276d2c 59}
60"""
61Topology:
62 Please view in a fixed-width font such as Courier.
63 +---+ A1 +---+
64 +R1 +------------+R2 |
65 +-+-+- +--++
66 | -- -- |
67 | -- A0 -- |
68 A0| ---- |
69 | ---- | A2
70 | -- -- |
71 | -- -- |
72 +-+-+- +-+-+
73 +R0 +-------------+R3 |
74 +---+ A3 +---+
75
76TESTCASES =
771. Verify ospf functionality after restart ospfd.
782. Verify ospf functionality after restart FRR service.
793. Verify ospf functionality when staticd is restarted.
80 """
81
a3276d2c 82
83def setup_module(mod):
84 """
85 Sets up the pytest environment
86
87 * `mod`: module name
88 """
a3276d2c 89 testsuite_run_time = time.asctime(time.localtime(time.time()))
90 logger.info("Testsuite start time: {}".format(testsuite_run_time))
91 logger.info("=" * 40)
92
93 logger.info("Running setup_module to create topology")
94
95 # This function initiates the topology build with Topogen...
e82b531d
CH
96 json_file = "{}/ospf_chaos.json".format(CWD)
97 tgen = Topogen(json_file, mod.__name__)
98 global topo
99 topo = tgen.json_topo
a3276d2c 100 # ... and here it calls Mininet initialization functions.
101
a3276d2c 102 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 103 # to start daemons and then start routers
991a971f 104 start_topology(tgen)
a3276d2c 105
106 # Creating configuration from JSON
107 build_config_from_json(tgen, topo)
108
109 # Don't run this test if we have any failure.
110 if tgen.routers_have_failure():
111 pytest.skip(tgen.errors)
112
113 ospf_covergence = verify_ospf_neighbor(tgen, topo)
114 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
115 ospf_covergence
116 )
117
118 logger.info("Running setup_module() done")
119
120
121def teardown_module(mod):
122 """
123 Teardown the pytest environment.
124
125 * `mod`: module name
126 """
127
128 logger.info("Running teardown_module to delete topology")
129
130 tgen = get_topogen()
131
132 # Stop toplogy and Remove tmp files
133 tgen.stop_topology()
134
135 logger.info(
136 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
137 )
138 logger.info("=" * 40)
139
140
141# ##################################
142# Test cases start here.
143# ##################################
144def test_ospf_chaos_tc31_p1(request):
145 """Verify ospf functionality after restart ospfd."""
146 tc_name = request.node.name
147 write_test_header(tc_name)
148 tgen = get_topogen()
149 global topo
150 step("Bring up the base config as per the topology")
151 reset_config_on_routers(tgen)
152
153 step(
154 "Create static routes(10.0.20.1/32) in R1 and redistribute "
5980ad0a
DS
155 "to OSPF using route map."
156 )
a3276d2c 157
158 # Create Static routes
159 input_dict = {
160 "r0": {
161 "static_routes": [
162 {
5980ad0a 163 "network": NETWORK["ipv4"][0],
a3276d2c 164 "no_of_ip": 5,
5980ad0a 165 "next_hop": "Null0",
a3276d2c 166 }
167 ]
168 }
169 }
170 result = create_static_routes(tgen, input_dict)
5980ad0a 171 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 172
5980ad0a 173 ospf_red_r0 = {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
a3276d2c 174 result = create_router_ospf(tgen, topo, ospf_red_r0)
5980ad0a 175 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 176
177 step("Verify OSPF neighbors after base config is done.")
178 # Api call verify whether OSPF is converged
179 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
180 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
181 ospf_covergence
182 )
a3276d2c 183
184 step("Verify that route is advertised to R1.")
5980ad0a
DS
185 dut = "r1"
186 protocol = "ospf"
187 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
a3276d2c 188 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 189 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 190
5980ad0a
DS
191 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
192 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 193
194 step("Kill OSPFd daemon on R0.")
195 kill_router_daemons(tgen, "r0", ["ospfd"])
196
197 step("Verify OSPF neighbors are down after killing ospfd in R0")
5980ad0a 198 dut = "r0"
a3276d2c 199 # Api call verify whether OSPF is converged
5980ad0a
DS
200 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
201 assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
202 ospf_covergence
203 )
a3276d2c 204
205 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
5980ad0a
DS
206 dut = "r1"
207 protocol = "ospf"
a3276d2c 208 result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
0b25370e
DS
209 assert (
210 result is not True
211 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
5980ad0a 212 tc_name, result
0b25370e 213 )
a3276d2c 214
0b25370e
DS
215 result = verify_rib(
216 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
217 )
218 assert (
219 result is not True
220 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
5980ad0a 221 tc_name, result
0b25370e 222 )
a3276d2c 223
224 step("Bring up OSPFd daemon on R0.")
225 start_router_daemons(tgen, "r0", ["ospfd"])
226
227 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
228 # Api call verify whether OSPF is converged
229 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
230 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
231 ospf_covergence
232 )
a3276d2c 233
234 step(
235 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
236 " restart. Verify OSPF route table and ip route table."
237 )
238 dut = "r1"
239 protocol = "ospf"
a3276d2c 240 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 241 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 242
5980ad0a
DS
243 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
244 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 245
246 step("Kill OSPFd daemon on R1.")
247 kill_router_daemons(tgen, "r1", ["ospfd"])
248
249 step("Verify OSPF neighbors are down after killing ospfd in R1")
5980ad0a 250 dut = "r1"
a3276d2c 251 # Api call verify whether OSPF is converged
5980ad0a
DS
252 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
253 assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
254 ospf_covergence
255 )
a3276d2c 256
257 step("Bring up OSPFd daemon on R1.")
258 start_router_daemons(tgen, "r1", ["ospfd"])
259
260 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
261 # Api call verify whether OSPF is converged
262 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
263 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
264 ospf_covergence
265 )
a3276d2c 266
267 step(
268 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
269 " restart. Verify OSPF route table and ip route table."
270 )
a3276d2c 271
5980ad0a
DS
272 dut = "r1"
273 protocol = "ospf"
a3276d2c 274 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 275 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 276
5980ad0a
DS
277 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
278 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 279
280 write_test_footer(tc_name)
281
282
283def test_ospf_chaos_tc32_p1(request):
a53c08bc 284 """Verify ospf functionality after restart FRR service."""
a3276d2c 285 tc_name = request.node.name
286 write_test_header(tc_name)
287 tgen = get_topogen()
288 global topo
289 step("Bring up the base config as per the topology")
290 reset_config_on_routers(tgen)
291
292 step(
293 "Create static routes(10.0.20.1/32) in R1 and redistribute "
5980ad0a
DS
294 "to OSPF using route map."
295 )
a3276d2c 296
297 # Create Static routes
298 input_dict = {
299 "r0": {
300 "static_routes": [
301 {
5980ad0a 302 "network": NETWORK["ipv4"][0],
a3276d2c 303 "no_of_ip": 5,
5980ad0a 304 "next_hop": "Null0",
a3276d2c 305 }
306 ]
307 }
308 }
309 result = create_static_routes(tgen, input_dict)
5980ad0a 310 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 311
5980ad0a 312 ospf_red_r0 = {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
a3276d2c 313 result = create_router_ospf(tgen, topo, ospf_red_r0)
5980ad0a 314 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 315
316 step("Verify OSPF neighbors after base config is done.")
317 # Api call verify whether OSPF is converged
318 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
319 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
320 ospf_covergence
321 )
a3276d2c 322
323 step("Verify that route is advertised to R1.")
5980ad0a
DS
324 dut = "r1"
325 protocol = "ospf"
a3276d2c 326
5980ad0a 327 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
a3276d2c 328 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 329 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 330
5980ad0a
DS
331 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
332 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 333
334 step("Restart frr on R0")
5980ad0a
DS
335 stop_router(tgen, "r0")
336 start_router(tgen, "r0")
a3276d2c 337
338 step("Verify OSPF neighbors are up after restarting R0")
339 # Api call verify whether OSPF is converged
340 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
341 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
342 ospf_covergence
343 )
a3276d2c 344
345 step(
346 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
347 " restart. Verify OSPF route table and ip route table."
348 )
349 dut = "r1"
350 protocol = "ospf"
a3276d2c 351 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 352 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 353
5980ad0a
DS
354 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
355 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 356
357 step("Restart frr on R1")
5980ad0a
DS
358 stop_router(tgen, "r1")
359 start_router(tgen, "r1")
a3276d2c 360
361 step("Verify OSPF neighbors are up after restarting R1")
362 # Api call verify whether OSPF is converged
363 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
364 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
365 ospf_covergence
366 )
a3276d2c 367
368 step(
369 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
370 " restart. Verify OSPF route table and ip route table."
371 )
372 dut = "r1"
373 protocol = "ospf"
a3276d2c 374 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 375 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 376
5980ad0a
DS
377 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
378 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 379
380 write_test_footer(tc_name)
381
382
383def test_ospf_chaos_tc34_p1(request):
384 """
385 verify ospf functionality when staticd is restarted.
386
387 Verify ospf functionalitywhen staticroutes are
388 redistributed & Staticd is restarted.
389 """
390 tc_name = request.node.name
391 write_test_header(tc_name)
392 tgen = get_topogen()
393 global topo
394 step("Bring up the base config as per the topology")
395 reset_config_on_routers(tgen)
396
397 step(
398 "Create static routes(10.0.20.1/32) in R1 and redistribute "
5980ad0a
DS
399 "to OSPF using route map."
400 )
a3276d2c 401
402 # Create Static routes
403 input_dict = {
404 "r0": {
405 "static_routes": [
406 {
5980ad0a 407 "network": NETWORK["ipv4"][0],
a3276d2c 408 "no_of_ip": 5,
5980ad0a 409 "next_hop": "Null0",
a3276d2c 410 }
411 ]
412 }
413 }
414 result = create_static_routes(tgen, input_dict)
5980ad0a 415 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 416
5980ad0a 417 ospf_red_r0 = {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
a3276d2c 418 result = create_router_ospf(tgen, topo, ospf_red_r0)
5980ad0a 419 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 420
421 step("Verify OSPF neighbors after base config is done.")
422 # Api call verify whether OSPF is converged
423 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
424 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
425 ospf_covergence
426 )
a3276d2c 427
428 step("Verify that route is advertised to R1.")
5980ad0a
DS
429 dut = "r1"
430 protocol = "ospf"
431 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
a3276d2c 432 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 433 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 434
5980ad0a
DS
435 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
436 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 437
438 step("Kill staticd daemon on R0.")
439 kill_router_daemons(tgen, "r0", ["staticd"])
440
441 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
5980ad0a
DS
442 dut = "r1"
443 protocol = "ospf"
a3276d2c 444 result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
0b25370e
DS
445 assert (
446 result is not True
447 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
5980ad0a 448 tc_name, result
0b25370e 449 )
a3276d2c 450
0b25370e
DS
451 result = verify_rib(
452 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
453 )
454 assert (
455 result is not True
456 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
5980ad0a 457 tc_name, result
0b25370e 458 )
a3276d2c 459
460 step("Bring up staticd daemon on R0.")
461 start_router_daemons(tgen, "r0", ["staticd"])
462
463 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
464 # Api call verify whether OSPF is converged
465 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
466 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
467 ospf_covergence
468 )
a3276d2c 469
470 step(
471 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
472 " restart. Verify OSPF route table and ip route table."
473 )
474 dut = "r1"
475 protocol = "ospf"
a3276d2c 476 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 477 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 478
5980ad0a
DS
479 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
480 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 481
482 step("Kill staticd daemon on R1.")
483 kill_router_daemons(tgen, "r1", ["staticd"])
484
485 step("Bring up staticd daemon on R1.")
486 start_router_daemons(tgen, "r1", ["staticd"])
487
488 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
489 # Api call verify whether OSPF is converged
490 ospf_covergence = verify_ospf_neighbor(tgen, topo)
5980ad0a
DS
491 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
492 ospf_covergence
493 )
a3276d2c 494
495 step(
496 "All the neighbours are up and routes are installed before the"
5980ad0a
DS
497 " restart. Verify OSPF route table and ip route table."
498 )
a3276d2c 499
5980ad0a
DS
500 dut = "r1"
501 protocol = "ospf"
a3276d2c 502 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
5980ad0a 503 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 504
5980ad0a
DS
505 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
506 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
a3276d2c 507
508 write_test_footer(tc_name)
509
510
511if __name__ == "__main__":
512 args = ["-s"] + sys.argv[1:]
513 sys.exit(pytest.main(args))