]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ospf_basic_functionality/test_ospf_single_area.py
Merge pull request #13455 from sri-mohan1/srib-ldpd
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_single_area.py
CommitLineData
4256a209 1#!/usr/bin/python
acddc0ed 2# SPDX-License-Identifier: ISC
4256a209 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#
4256a209 9
10
11"""OSPF Basic Functionality Automation."""
12import os
13import sys
14import time
15import pytest
4256a209 16from copy import deepcopy
17from ipaddress import IPv4Address
9fd80543 18from lib.topotest import frr_unicode
4256a209 19
20# Save the Current Working Directory to find configuration files.
21CWD = os.path.dirname(os.path.realpath(__file__))
22sys.path.append(os.path.join(CWD, "../"))
23sys.path.append(os.path.join(CWD, "../lib/"))
24
25# pylint: disable=C0413
26# Import topogen and topotest helpers
4256a209 27from lib.topogen import Topogen, get_topogen
28import ipaddress
29
30# Import topoJson from lib, to create topology and initial configuration
31from lib.common_config import (
32 start_topology,
33 write_test_header,
34 write_test_footer,
35 reset_config_on_routers,
4256a209 36 step,
4256a209 37 create_interfaces_cfg,
38)
39from lib.topolog import logger
4953ca97 40from lib.topojson import build_config_from_json
4256a209 41
42from lib.ospf import (
43 verify_ospf_neighbor,
44 config_ospf_interface,
45 clear_ospf,
46 verify_ospf_rib,
4256a209 47 verify_ospf_interface,
4256a209 48)
49
6ff492b1 50pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
4256a209 51# Global variables
52topo = None
53
4256a209 54
55"""
56TOPOOLOGY =
57 Please view in a fixed-width font such as Courier.
58 +---+ A1 +---+
59 +R1 +------------+R2 |
60 +-+-+- +--++
61 | -- -- |
62 | -- A0 -- |
63 A0| ---- |
64 | ---- | A2
65 | -- -- |
66 | -- -- |
67 +-+-+- +-+-+
68 +R0 +-------------+R3 |
69 +---+ A3 +---+
70
71TESTCASES =
721. OSPF IFSM -Verify state change events on p2p network.
732. OSPF Timers - Verify OSPF interface timer hello interval functionality
743. OSPF Timers - Verify OSPF interface timer dead interval functionality
754. Verify ospf show commands with json output.
8694dd78 765. Verify NFSM events when ospf nbr changes with different MTU values.
4256a209 77 """
78
79
4256a209 80def setup_module(mod):
81 """
82 Sets up the pytest environment
83
84 * `mod`: module name
85 """
4256a209 86 testsuite_run_time = time.asctime(time.localtime(time.time()))
87 logger.info("Testsuite start time: {}".format(testsuite_run_time))
88 logger.info("=" * 40)
89
90 logger.info("Running setup_module to create topology")
91
92 # This function initiates the topology build with Topogen...
e82b531d
CH
93 json_file = "{}/ospf_single_area.json".format(CWD)
94 tgen = Topogen(json_file, mod.__name__)
95 global topo
96 topo = tgen.json_topo
4256a209 97 # ... and here it calls Mininet initialization functions.
98
99 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 100 # to start daemons and then start routers
991a971f 101 start_topology(tgen)
4256a209 102
103 # Creating configuration from JSON
104 build_config_from_json(tgen, topo)
105
106 # Don't run this test if we have any failure.
107 if tgen.routers_have_failure():
108 pytest.skip(tgen.errors)
109
110 ospf_covergence = verify_ospf_neighbor(tgen, topo)
74dd0c84 111 assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
4256a209 112 ospf_covergence
113 )
114
115 logger.info("Running setup_module() done")
116
117
118def teardown_module(mod):
119 """
120 Teardown the pytest environment.
121
122 * `mod`: module name
123 """
124
125 logger.info("Running teardown_module to delete topology")
126
127 tgen = get_topogen()
128
129 # Stop toplogy and Remove tmp files
130 tgen.stop_topology()
131
132 logger.info(
133 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
134 )
135 logger.info("=" * 40)
136
137
138# ##################################
139# Test cases start here.
140# ##################################
141
142
143def test_ospf_p2p_tc3_p0(request):
144 """OSPF IFSM -Verify state change events on p2p network."""
145 tc_name = request.node.name
146 write_test_header(tc_name)
147 tgen = get_topogen()
148
149 # Don't run this test if we have any failure.
150 if tgen.routers_have_failure():
151 pytest.skip(tgen.errors)
152
153 global topo
154 step("Bring up the base config as per the topology")
155 reset_config_on_routers(tgen)
156 step(
157 "Verify that OSPF is subscribed to multi cast services "
158 "(All SPF, all DR Routers)."
159 )
160 step("Verify that interface is enabled in ospf.")
161 step("Verify that config is successful.")
162 dut = "r0"
163 input_dict = {
164 "r0": {
165 "links": {
166 "r3": {"ospf": {"mcastMemberOspfAllRouters": True, "ospfEnabled": True}}
167 }
168 }
169 }
170 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
171 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
172
173 step("Delete the ip address")
174 topo1 = {
175 "r0": {
176 "links": {
177 "r3": {
178 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
179 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
180 "delete": True,
181 }
182 }
183 }
184 }
185
186 result = create_interfaces_cfg(tgen, topo1)
187 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
188
189 step("Change the ip on the R0 interface")
190
191 topo_modify_change_ip = deepcopy(topo)
192 intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
193 topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str(
9fd80543 194 IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3
4256a209 195 ) + "/{}".format(intf_ip.split("/")[1])
196
197 build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)
198 step("Verify that interface is enabled in ospf.")
199 dut = "r0"
200 input_dict = {
201 "r0": {
202 "links": {
203 "r3": {
204 "ospf": {
205 "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][
206 "r3"
207 ]["ipv4"].split("/")[0],
208 "ipAddressPrefixlen": int(
209 topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
210 "ipv4"
211 ].split("/")[1]
212 ),
213 }
214 }
215 }
216 }
217 }
218 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
219 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
220
221 step("Modify the mask on the R0 interface")
222 ip_addr = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
223 mask = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
224 step("Delete the ip address")
225 topo1 = {
226 "r0": {
227 "links": {
228 "r3": {
229 "ipv4": ip_addr,
230 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
231 "delete": True,
232 }
233 }
234 }
235 }
236
237 result = create_interfaces_cfg(tgen, topo1)
238 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
239
240 step("Change the ip on the R0 interface")
241
242 topo_modify_change_ip = deepcopy(topo)
243 intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"]
244 topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str(
9fd80543 245 IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3
4256a209 246 ) + "/{}".format(int(intf_ip.split("/")[1]) + 1)
247
248 build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)
249 step("Verify that interface is enabled in ospf.")
250 dut = "r0"
251 input_dict = {
252 "r0": {
253 "links": {
254 "r3": {
255 "ospf": {
256 "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][
257 "r3"
258 ]["ipv4"].split("/")[0],
259 "ipAddressPrefixlen": int(
260 topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
261 "ipv4"
262 ].split("/")[1]
263 ),
264 }
265 }
266 }
267 }
268 }
269 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
270 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
271
272 topo1 = {
273 "r0": {
274 "links": {
275 "r3": {
276 "ipv4": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
277 "ipv4"
278 ],
279 "interface": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][
280 "interface"
281 ],
282 "delete": True,
283 }
284 }
285 }
286 }
287
288 result = create_interfaces_cfg(tgen, topo1)
289 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
290
291 build_config_from_json(tgen, topo, save_bkup=False)
292
293 step("Change the area id on the interface")
294 input_dict = {
295 "r0": {
296 "links": {
297 "r3": {
298 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
299 "ospf": {"area": "0.0.0.0"},
300 "delete": True,
301 }
302 }
303 }
304 }
305
306 result = create_interfaces_cfg(tgen, input_dict)
307 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
308
309 input_dict = {
310 "r0": {
311 "links": {
312 "r3": {
313 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
314 "ospf": {"area": "0.0.0.1"},
315 }
316 }
317 }
318 }
319
320 result = create_interfaces_cfg(tgen, input_dict)
321 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
322 step("Verify that interface is enabled in ospf.")
323 dut = "r0"
324 input_dict = {
325 "r0": {"links": {"r3": {"ospf": {"area": "0.0.0.1", "ospfEnabled": True}}}}
326 }
327 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
328 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
329
330 input_dict = {
331 "r0": {
332 "links": {
333 "r3": {
334 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
335 "ospf": {"area": "0.0.0.1"},
336 "delete": True,
337 }
338 }
339 }
340 }
341
342 result = create_interfaces_cfg(tgen, input_dict)
343 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
344
345 input_dict = {
346 "r0": {
347 "links": {
348 "r3": {
349 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
350 "ospf": {"area": "0.0.0.0"},
351 }
352 }
353 }
354 }
355
356 result = create_interfaces_cfg(tgen, input_dict)
357 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
358
359 # Api call verify whether BGP is converged
360 ospf_covergence = verify_ospf_neighbor(tgen, topo)
74dd0c84 361 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 362 ospf_covergence
363 )
364
365 write_test_footer(tc_name)
366
367
368def test_ospf_hello_tc10_p0(request):
369 """
370 OSPF timers.
371
372 Verify OSPF interface timer hello interval functionality
373 """
374 tc_name = request.node.name
375 write_test_header(tc_name)
376 tgen = get_topogen()
377
378 # Don't run this test if we have any failure.
379 if tgen.routers_have_failure():
380 pytest.skip(tgen.errors)
381
382 global topo
383 step("Bring up the base config as per the topology")
384 reset_config_on_routers(tgen)
385
386 step("modify hello timer from default value to some other value on r1")
387
388 topo1 = {
389 "r1": {
390 "links": {
391 "r0": {
392 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
393 "ospf": {"hello_interval": 11, "dead_interval": 12},
394 }
395 }
396 }
397 }
398
399 result = create_interfaces_cfg(tgen, topo1)
400 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
401
402 step(
403 "verify that new timer value is configured and applied using "
404 "the show ip ospf interface command."
405 )
406 dut = "r1"
407 input_dict = {
408 "r1": {
409 "links": {"r0": {"ospf": {"timerMsecs": 11 * 1000, "timerDeadSecs": 12}}}
410 }
411 }
412 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
413 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
414
4256a209 415 step("modify hello timer from default value to r1 hello timer on r2")
416
417 topo1 = {
418 "r0": {
419 "links": {
420 "r1": {
421 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
422 "ospf": {"hello_interval": 11, "dead_interval": 12},
423 }
424 }
425 }
426 }
427
428 result = create_interfaces_cfg(tgen, topo1)
429 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
430
431 step("verify that new timer value is configured.")
432 input_dict = {
433 "r0": {
434 "links": {"r1": {"ospf": {"timerMsecs": 11 * 1000, "timerDeadSecs": 12}}}
435 }
436 }
437 dut = "r0"
438 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
439 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
440
441 step("verify that ospf neighbours are full")
442 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 443 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 444 ospf_covergence
445 )
446
447 step("reconfigure the default hello timer value to default on r1 and r2")
448
449 topo1 = {
450 "r0": {
451 "links": {
452 "r1": {
453 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
454 "ospf": {"hello_interval": 10, "dead_interval": 40},
455 }
456 }
457 }
458 }
459
460 result = create_interfaces_cfg(tgen, topo1)
461 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
462
463 topo1 = {
464 "r1": {
465 "links": {
466 "r0": {
467 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
468 "ospf": {"hello_interval": 10, "dead_interval": 40},
469 }
470 }
471 }
472 }
473
474 result = create_interfaces_cfg(tgen, topo1)
475 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
476
477 step("verify that new timer value is configured.")
478 input_dict = {
479 "r0": {
480 "links": {"r1": {"ospf": {"timerMsecs": 10 * 1000, "timerDeadSecs": 40}}}
481 }
482 }
483 dut = "r0"
484 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
485 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
486
487 step("verify that ospf neighbours are full")
488 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 489 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 490 ospf_covergence
491 )
492
493 step("reconfigure the default hello timer value to default on r1 and r2")
494
495 topo1 = {
496 "r0": {
497 "links": {
498 "r1": {
499 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
500 "ospf": {"hello_interval": 10, "dead_interval": 40},
501 }
502 }
503 }
504 }
505
506 result = create_interfaces_cfg(tgen, topo1)
507 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
508
509 topo1 = {
510 "r1": {
511 "links": {
512 "r0": {
513 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
514 "ospf": {"hello_interval": 10, "dead_interval": 40},
515 }
516 }
517 }
518 }
519
520 result = create_interfaces_cfg(tgen, topo1)
521 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
522
523 step("verify that new timer value is configured.")
524 input_dict = {
525 "r0": {
526 "links": {"r1": {"ospf": {"timerMsecs": 10 * 1000, "timerDeadSecs": 40}}}
527 }
528 }
529 dut = "r0"
530 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
531 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
532
533 step("verify that ospf neighbours are full")
534 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 535 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 536 ospf_covergence
537 )
538
539 step("configure hello timer = 1 on r1 and r2")
540 topo1 = {
541 "r0": {
542 "links": {
543 "r1": {
544 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
545 "ospf": {"hello_interval": 1, "dead_interval": 4},
546 }
547 }
548 }
549 }
550
551 result = create_interfaces_cfg(tgen, topo1)
552 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
553
554 topo1 = {
555 "r1": {
556 "links": {
557 "r0": {
558 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
559 "ospf": {"hello_interval": 1, "dead_interval": 4},
560 }
561 }
562 }
563 }
564
565 result = create_interfaces_cfg(tgen, topo1)
566 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
567
568 step("verify that new timer value is configured.")
569 input_dict = {
570 "r0": {"links": {"r1": {"ospf": {"timerMsecs": 1 * 1000, "timerDeadSecs": 4}}}}
571 }
572 dut = "r0"
573 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
574 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
575
576 step("verify that ospf neighbours are full")
577 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 578 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 579 ospf_covergence
580 )
581
4256a209 582 write_test_footer(tc_name)
583
584
4256a209 585def test_ospf_show_p1(request):
586 """Verify ospf show commands with json output."""
587 tc_name = request.node.name
588 write_test_header(tc_name)
589 tgen = get_topogen()
590
591 # Don't run this test if we have any failure.
592 if tgen.routers_have_failure():
593 pytest.skip(tgen.errors)
594
595 global topo
596 step(" Bring up the base config as per the topology")
597 reset_config_on_routers(tgen)
598
599 ospf_covergence = verify_ospf_neighbor(tgen, topo)
74dd0c84 600 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
4256a209 601 ospf_covergence
602 )
603 dut = "r1"
604 input_dict = {
605 "r1": {
606 "links": {
607 "r0": {
608 "ospf": {
609 "ifUp": True,
610 "ifFlags": "<UP,BROADCAST,RUNNING,MULTICAST>",
611 "ospfEnabled": True,
612 "ipAddressPrefixlen": 24,
613 "ospfIfType": "Broadcast",
614 "area": "0.0.0.0",
615 "networkType": "BROADCAST",
616 "cost": 10,
617 "transmitDelaySecs": 1,
618 "state": "DR",
619 "priority": 1,
620 "mcastMemberOspfAllRouters": True,
621 "timerMsecs": 1000,
622 "timerDeadSecs": 4,
623 "timerWaitSecs": 4,
624 "timerRetransmitSecs": 5,
625 "nbrCount": 1,
626 "nbrAdjacentCount": 1,
627 }
628 }
629 }
630 }
631 }
632 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
633 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
634
635 # show ip ospf route
636 ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
637 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
638 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
639 input_dict = {
640 "r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}
641 }
642
643 dut = "r1"
644 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
645 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
646
647 write_test_footer(tc_name)
648
649
816fdbbf 650def test_ospf_dead_tc11_p0(request):
651 """
652 OSPF timers.
653
654 Verify OSPF interface timer dead interval functionality
655 """
656 tc_name = request.node.name
657 write_test_header(tc_name)
658 tgen = get_topogen()
659
660 # Don't run this test if we have any failure.
661 if tgen.routers_have_failure():
662 pytest.skip(tgen.errors)
663
664 global topo
665 step("Bring up the base config as per the topology")
666 reset_config_on_routers(tgen)
667
668 step("modify dead interval from default value to some other value on r1")
669
670 topo1 = {
9fa6ec14 671 "r1": {
672 "links": {
673 "r0": {
674 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
675 "ospf": {"hello_interval": 12, "dead_interval": 48},
816fdbbf 676 }
677 }
678 }
679 }
680
816fdbbf 681 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 682 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 683
684 step(
685 "verify that new timer value is configured and applied using "
9fa6ec14 686 "the show ip ospf interface command."
687 )
688 dut = "r1"
689 input_dict = {"r1": {"links": {"r0": {"ospf": {"timerDeadSecs": 48}}}}}
816fdbbf 690 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
9fa6ec14 691 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 692
74dd0c84 693 step("modify dead interval from default value to r1 dead interval timer on r2")
816fdbbf 694
695 topo1 = {
9fa6ec14 696 "r0": {
697 "links": {
698 "r1": {
699 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
700 "ospf": {"dead_interval": 48, "hello_interval": 12},
816fdbbf 701 }
702 }
703 }
704 }
705
706 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 707 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 708
709 step("verify that new timer value is configured.")
9fa6ec14 710 input_dict = {"r0": {"links": {"r1": {"ospf": {"timerDeadSecs": 48}}}}}
711 dut = "r0"
816fdbbf 712 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
9fa6ec14 713 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 714
715 step("verify that ospf neighbours are full")
716 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 717 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
9fa6ec14 718 ospf_covergence
719 )
816fdbbf 720
74dd0c84 721 step("reconfigure the default dead interval timer value to default on r1 and r2")
816fdbbf 722 topo1 = {
9fa6ec14 723 "r0": {
724 "links": {
725 "r1": {
726 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
727 "ospf": {"dead_interval": 40},
816fdbbf 728 }
729 }
730 }
731 }
732
733 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 734 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 735
736 topo1 = {
9fa6ec14 737 "r1": {
738 "links": {
739 "r0": {
740 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
741 "ospf": {"dead_interval": 40},
816fdbbf 742 }
743 }
744 }
745 }
746
747 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 748 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 749
750 step("verify that new timer value is configured.")
9fa6ec14 751 input_dict = {"r0": {"links": {"r1": {"ospf": {"timerDeadSecs": 40}}}}}
752 dut = "r0"
816fdbbf 753 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
9fa6ec14 754 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 755
756 step("verify that ospf neighbours are full")
757 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 758 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
9fa6ec14 759 ospf_covergence
760 )
816fdbbf 761
762 step(" Configure dead timer = 65535 on r1 and r2")
763
764 topo1 = {
9fa6ec14 765 "r0": {
766 "links": {
767 "r1": {
768 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
769 "ospf": {"dead_interval": 65535},
816fdbbf 770 }
771 }
772 }
773 }
774
775 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 776 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 777
778 topo1 = {
9fa6ec14 779 "r1": {
780 "links": {
781 "r0": {
782 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
783 "ospf": {"dead_interval": 65535},
816fdbbf 784 }
785 }
786 }
787 }
788
789 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 790 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 791
792 step("verify that new timer value is configured.")
9fa6ec14 793 input_dict = {"r0": {"links": {"r1": {"ospf": {"timerDeadSecs": 65535}}}}}
794 dut = "r0"
816fdbbf 795 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
9fa6ec14 796 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 797
798 step("verify that ospf neighbours are full")
799 ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
74dd0c84 800 assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
9fa6ec14 801 ospf_covergence
802 )
816fdbbf 803
804 step(" Try configuring timer values outside range for example 65536")
805 topo1 = {
9fa6ec14 806 "r0": {
807 "links": {
808 "r1": {
809 "interface": topo["routers"]["r0"]["links"]["r1"]["interface"],
810 "ospf": {"dead_interval": 65536},
816fdbbf 811 }
812 }
813 }
814 }
815
816 result = create_interfaces_cfg(tgen, topo1)
817 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
9fa6ec14 818 tc_name, result
819 )
816fdbbf 820
821 step("Unconfigure the dead timer from the interface from r1 and r2.")
822
823 topo1 = {
9fa6ec14 824 "r1": {
825 "links": {
826 "r0": {
827 "interface": topo["routers"]["r1"]["links"]["r0"]["interface"],
828 "ospf": {"dead_interval": 65535},
829 "delete": True,
816fdbbf 830 }
831 }
832 }
833 }
834
835 result = create_interfaces_cfg(tgen, topo1)
9fa6ec14 836 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 837
74dd0c84 838 step("Verify that timer value is deleted from intf & set to default value 40 sec.")
9fa6ec14 839 input_dict = {"r1": {"links": {"r0": {"ospf": {"timerDeadSecs": 40}}}}}
840 dut = "r1"
816fdbbf 841 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
9fa6ec14 842 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
816fdbbf 843
844 write_test_footer(tc_name)
845
846
8694dd78 847def test_ospf_tc4_mtu_ignore_p0(request):
848 """
849 OSPF NFSM - MTU change
850
851 Verify NFSM events when ospf nbr changes with different MTU values
852 """
853 tc_name = request.node.name
854 write_test_header(tc_name)
855 tgen = get_topogen()
856
857 # Don't run this test if we have any failure.
858 if tgen.routers_have_failure():
859 pytest.skip(tgen.errors)
860
861 global topo
862 step(" Bring up the base config as per the topology")
863 step("Configure OSPF on all the routers of the topology.")
864 step("Verify that OSPF neighbors are FULL.")
865 reset_config_on_routers(tgen)
866 result = verify_ospf_neighbor(tgen, topo)
867 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
868
869 step(
870 "Modify the MTU to non default Value on R0 to R1 interface. "
871 "Reset ospf neighbors on R0."
872 )
873
874 rtr0 = tgen.routers()["r0"]
875 rtr1 = tgen.routers()["r1"]
876
877 r0_r1_intf = topo["routers"]["r0"]["links"]["r1"]["interface"]
878 r1_r0_intf = topo["routers"]["r1"]["links"]["r0"]["interface"]
879
6a95bfc8 880 rtr0.run("ip link set {} mtu 1200".format(r0_r1_intf))
8694dd78 881
882 clear_ospf(tgen, "r0")
883
74dd0c84 884 step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
8694dd78 885 result = verify_ospf_neighbor(tgen, topo, expected=False)
886 assert result is not True, (
887 "Testcase {} : Failed \n OSPF nbrs are Full "
888 "instead of Exstart. Error: {}".format(tc_name, result)
889 )
890
74dd0c84 891 step("Verify that configured MTU value is updated in the show ip ospf interface.")
8694dd78 892
893 dut = "r0"
894 input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuBytes": 1200}}}}}
895 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
896 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
897
898 step(
899 "Modify the MTU to non default Value on R0 to R1 interface. "
900 "Reset ospf neighbors on R0."
901 )
6a95bfc8 902 rtr0.run("ip link set {} mtu 1500".format(r0_r1_intf))
8694dd78 903
904 clear_ospf(tgen, "r0")
905
906 step("Verify that OSPF neighborship between R0 and R1 becomes full.")
907 result = verify_ospf_neighbor(tgen, topo)
908 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
909
910 step(
911 "Configure mtu ignore and change the value of the mtu to non default"
912 " on R0 to R1 interface. Reset ospf neighbors on R0."
913 )
914 r0_ospf_mtu = {"r0": {"links": {"r1": {"ospf": {"mtu_ignore": True}}}}}
915 result = config_ospf_interface(tgen, topo, r0_ospf_mtu)
916 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
917
918 dut = "r0"
919 input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuMismatchDetect": True}}}}}
920 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
921 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
922
923 r1_ospf_mtu = {"r1": {"links": {"r0": {"ospf": {"mtu_ignore": True}}}}}
924 result = config_ospf_interface(tgen, topo, r1_ospf_mtu)
925 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
926
6a95bfc8 927 rtr0.run("ip link set {} mtu 1200".format(r0_r1_intf))
8694dd78 928
929 clear_ospf(tgen, "r0")
930
931 step("Verify that OSPF neighborship between R0 and R1 becomes full.")
932 result = verify_ospf_neighbor(tgen, topo)
933 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
934
935 step(
936 "Unconfigure mtu-ignore command from the interface. "
937 "Reset ospf neighbors on R0."
938 )
939
940 r1_ospf_mtu = {
e83c0fb1 941 "r1": {"links": {"r0": {"ospf": {"mtu_ignore": True, "del_action": True}}}}
8694dd78 942 }
943 result = config_ospf_interface(tgen, topo, r1_ospf_mtu)
944 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
945
946 clear_ospf(tgen, "r0")
947
74dd0c84 948 step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
8694dd78 949 result = verify_ospf_neighbor(tgen, topo, expected=False)
950 assert result is not True, (
951 "Testcase {} : Failed \n OSPF nbrs are Full "
952 "instead of Exstart. Error: {}".format(tc_name, result)
953 )
954
955 step("Modify the MTU to again default valaue on R0 to R1 interface.")
956
6a95bfc8 957 rtr0.run("ip link set {} mtu 1500".format(r0_r1_intf))
8694dd78 958
959 clear_ospf(tgen, "r0")
960
961 step("Verify that OSPF neighborship between R0 and R1 becomes full.")
962 result = verify_ospf_neighbor(tgen, topo)
963 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
964
74dd0c84 965 step("Configure ospf interface with jumbo MTU (9216). Reset ospf neighbors on R0.")
8694dd78 966
6a95bfc8
CH
967 rtr0.run("ip link set {} mtu 9216".format(r0_r1_intf))
968 rtr1.run("ip link set {} mtu 9216".format(r1_r0_intf))
8694dd78 969
970 clear_ospf(tgen, "r0")
971 clear_ospf(tgen, "r1")
972
973 step("Verify that OSPF neighborship between R0 and R1 becomes full.")
974 result = verify_ospf_neighbor(tgen, topo)
975 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
976
977 step("Verify that jumbo MTU is updated in the show ip ospf interface.")
978 dut = "r0"
979 input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuBytes": 9216}}}}}
980 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
981 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
982
983 write_test_footer(tc_name)
984
985
4256a209 986if __name__ == "__main__":
987 args = ["-s"] + sys.argv[1:]
988 sys.exit(pytest.main(args))