]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_rte_calc.py
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."""
25 import os
26 import sys
27 import time
28 import pytest
29 import ipaddress
30
31 # Save the Current Working Directory to find configuration files.
32 CWD = os.path.dirname(os.path.realpath(__file__))
33 sys.path.append(os.path.join(CWD, "../"))
34 sys.path.append(os.path.join(CWD, "../lib/"))
35
36 # pylint: disable=C0413
37 # Import topogen and topotest helpers
38 from lib.topogen import Topogen, get_topogen
39
40 # Import topoJson from lib, to create topology and initial configuration
41 from lib.common_config import (
42 start_topology,
43 write_test_header,
44 create_interfaces_cfg,
45 write_test_footer,
46 reset_config_on_routers,
47 verify_rib,
48 create_static_routes,
49 step,
50 shutdown_bringup_interface,
51 )
52 from lib.bgp import verify_bgp_convergence, create_router_bgp
53 from lib.topolog import logger
54 from lib.topojson import build_config_from_json
55
56 from lib.ospf import (
57 verify_ospf_neighbor,
58 clear_ospf,
59 verify_ospf_rib,
60 redistribute_ospf,
61 config_ospf_interface,
62 verify_ospf_interface,
63 )
64
65 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
66
67
68 # Global variables
69 topo = None
70
71 # number of retries.
72 nretry = 5
73
74 NETWORK = {
75 "ipv4": [
76 "11.0.20.1/32",
77 "11.0.20.2/32",
78 "11.0.20.3/32",
79 "11.0.20.4/32",
80 "11.0.20.5/32",
81 ]
82 }
83
84 NETWORK_APP_E = {"ipv4": ["12.0.0.0/24", "12.0.0.0/16", "12.0.0.0/8"]}
85 TOPOOLOGY = """
86 Please view in a fixed-width font such as Courier.
87 +---+ A1 +---+
88 +R1 +------------+R2 |
89 +-+-+- +--++
90 | -- -- |
91 | -- A0 -- |
92 A0| ---- |
93 | ---- | A2
94 | -- -- |
95 | -- -- |
96 +-+-+- +-+-+
97 +R0 +-------------+R3 |
98 +---+ A3 +---+
99 """
100
101 TESTCASES = """
102 1. Test OSPF intra area route calculations.
103 2. Test OSPF inter area route calculations.
104 3. Test OSPF redistribution of connected routes.
105 """
106
107
108 def setup_module(mod):
109 """
110 Sets up the pytest environment
111
112 * `mod`: module name
113 """
114 testsuite_run_time = time.asctime(time.localtime(time.time()))
115 logger.info("Testsuite start time: {}".format(testsuite_run_time))
116 logger.info("=" * 40)
117
118 logger.info("Running setup_module to create topology")
119
120 # This function initiates the topology build with Topogen...
121 json_file = "{}/ospf_rte_calc.json".format(CWD)
122 tgen = Topogen(json_file, mod.__name__)
123 global topo
124 topo = tgen.json_topo
125 # ... and here it calls Mininet initialization functions.
126
127 # Starting topology, create tmp files which are loaded to routers
128 # to start daemons and then start routers
129 start_topology(tgen)
130
131 # Creating configuration from JSON
132 build_config_from_json(tgen, topo)
133
134 # Don't run this test if we have any failure.
135 if tgen.routers_have_failure():
136 pytest.skip(tgen.errors)
137 # Api call verify whether OSPF is converged
138 ospf_covergence = verify_ospf_neighbor(tgen, topo)
139 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
140 ospf_covergence
141 )
142
143 logger.info("Running setup_module() done")
144
145
146 def teardown_module(mod):
147 """
148 Teardown the pytest environment.
149
150 * `mod`: module name
151 """
152
153 logger.info("Running teardown_module to delete topology")
154
155 tgen = get_topogen()
156
157 # Stop toplogy and Remove tmp files
158 tgen.stop_topology()
159
160 logger.info(
161 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
162 )
163 logger.info("=" * 40)
164
165
166 # ##################################
167 # Test cases start here.
168 # ##################################
169
170
171 def test_ospf_redistribution_tc5_p0(request):
172 """Test OSPF intra area route calculations."""
173 tc_name = request.node.name
174 write_test_header(tc_name)
175 tgen = get_topogen()
176
177 # Don't run this test if we have any failure.
178 if tgen.routers_have_failure():
179 pytest.skip(tgen.errors)
180
181 global topo
182 step("Bring up the base config.")
183 reset_config_on_routers(tgen)
184
185 step("Verify that OSPF neighbors are FULL.")
186 ospf_covergence = verify_ospf_neighbor(tgen, topo)
187 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
188 ospf_covergence
189 )
190
191 step("verify intra area route is calculated for r0-r3 interface ip in R1")
192 ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
193 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
194 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
195 input_dict = {
196 "r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}
197 }
198
199 dut = "r1"
200 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
201 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
202
203 protocol = "ospf"
204 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
205 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
206
207 step("Delete the ip address on newly configured interface of R0")
208 topo1 = {
209 "r0": {
210 "links": {
211 "r3": {
212 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
213 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
214 "delete": True,
215 }
216 }
217 }
218 }
219
220 result = create_interfaces_cfg(tgen, topo1)
221 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
222
223 dut = "r1"
224 for num in range(0, nretry):
225 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False)
226 if result is not True:
227 break
228
229 assert result is not True, (
230 "Testcase {} : Failed \n "
231 "r1: OSPF routes are present after deleting ip address of newly "
232 "configured interface of R0 \n Error: {}".format(tc_name, result)
233 )
234
235 protocol = "ospf"
236 result = verify_rib(
237 tgen,
238 "ipv4",
239 dut,
240 input_dict,
241 protocol=protocol,
242 next_hop=nh,
243 retry_timeout=10,
244 expected=False,
245 )
246 assert result is not True, (
247 "Testcase {} : Failed \n "
248 "r1: OSPF routes are present in fib after deleting ip address of newly "
249 "configured interface of R0 \n Error: {}".format(tc_name, result)
250 )
251
252 step("Add back the deleted ip address on newly configured interface of R0")
253 topo1 = {
254 "r0": {
255 "links": {
256 "r3": {
257 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
258 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
259 }
260 }
261 }
262 }
263
264 result = create_interfaces_cfg(tgen, topo1)
265 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
266
267 dut = "r1"
268 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
269 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
270
271 protocol = "ospf"
272 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
273 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
274
275 step("Shut no shut interface on R0")
276 dut = "r0"
277 intf = topo["routers"]["r0"]["links"]["r3"]["interface"]
278 shutdown_bringup_interface(tgen, dut, intf, False)
279
280 step("un shut the OSPF interface on R0")
281 dut = "r0"
282 shutdown_bringup_interface(tgen, dut, intf, True)
283
284 dut = "r1"
285 result = verify_ospf_rib(tgen, dut, input_dict)
286 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
287
288 protocol = "ospf"
289 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
290 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
291
292 write_test_footer(tc_name)
293
294
295 def test_ospf_redistribution_tc6_p0(request):
296 """Test OSPF inter area route calculations."""
297 tc_name = request.node.name
298 write_test_header(tc_name)
299 tgen = get_topogen()
300
301 # Don't run this test if we have any failure.
302 if tgen.routers_have_failure():
303 pytest.skip(tgen.errors)
304
305 global topo
306 step("Bring up the base config.")
307 reset_config_on_routers(tgen)
308
309 step("Verify that OSPF neighbors are FULL.")
310 ospf_covergence = verify_ospf_neighbor(tgen, topo)
311 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
312 ospf_covergence
313 )
314
315 step("verify intra area route is calculated for r0-r3 interface ip in R1")
316 ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
317 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
318 nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
319 input_dict = {
320 "r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}
321 }
322
323 dut = "r1"
324 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
325 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
326
327 protocol = "ospf"
328 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
329 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
330
331 step("Delete the ip address on newly configured loopback of R0")
332 topo1 = {
333 "r0": {
334 "links": {
335 "r3": {
336 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
337 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
338 "delete": True,
339 }
340 }
341 }
342 }
343
344 result = create_interfaces_cfg(tgen, topo1)
345 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
346
347 dut = "r1"
348 for num in range(0, nretry):
349 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False)
350 if result is not True:
351 break
352 assert result is not True, (
353 "Testcase {} : Failed \n "
354 "r1: OSPF routes are present after deleting ip address of newly "
355 "configured loopback of R0 \n Error: {}".format(tc_name, result)
356 )
357
358 protocol = "ospf"
359 result = verify_rib(
360 tgen,
361 "ipv4",
362 dut,
363 input_dict,
364 protocol=protocol,
365 next_hop=nh,
366 expected=False,
367 )
368 assert result is not True, (
369 "Testcase {} : Failed \n "
370 "r1: OSPF routes are present in fib after deleting ip address of newly "
371 "configured loopback of R0 \n Error: {}".format(tc_name, result)
372 )
373
374 step("Add back the deleted ip address on newly configured interface of R0")
375 topo1 = {
376 "r0": {
377 "links": {
378 "r3": {
379 "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
380 "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
381 }
382 }
383 }
384 }
385
386 result = create_interfaces_cfg(tgen, topo1)
387 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
388
389 dut = "r1"
390 result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
391 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
392
393 protocol = "ospf"
394 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
395 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
396
397 step("Shut no shut interface on R0")
398 dut = "r0"
399 intf = topo["routers"]["r0"]["links"]["r3"]["interface"]
400 shutdown_bringup_interface(tgen, dut, intf, False)
401
402 step("un shut the OSPF interface on R0")
403 dut = "r0"
404 shutdown_bringup_interface(tgen, dut, intf, True)
405
406 dut = "r1"
407 result = verify_ospf_rib(tgen, dut, input_dict)
408 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
409
410 protocol = "ospf"
411 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh)
412 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
413
414 write_test_footer(tc_name)
415
416
417 def test_ospf_redistribution_tc8_p1(request):
418 """
419 Test OSPF redistribution of connected routes.
420
421 Verify OSPF redistribution of connected routes when bgp multi hop
422 neighbor is configured using ospf routes
423
424 """
425 tc_name = request.node.name
426 write_test_header(tc_name)
427 tgen = get_topogen()
428 global topo
429 step("Bring up the base config.")
430 step(
431 "Configure loopback interface on all routers, and redistribut"
432 "e connected routes into ospf"
433 )
434 reset_config_on_routers(tgen)
435
436 step(
437 "verify that connected routes -loopback is found in all routers"
438 "advertised/exchaged via ospf"
439 )
440 for rtr in topo["routers"]:
441 redistribute_ospf(tgen, topo, rtr, "static")
442 redistribute_ospf(tgen, topo, rtr, "connected")
443 for node in topo["routers"]:
444 input_dict = {
445 "r0": {
446 "static_routes": [
447 {
448 "network": topo["routers"][node]["links"]["lo"]["ipv4"],
449 "no_of_ip": 1,
450 }
451 ]
452 }
453 }
454 for rtr in topo["routers"]:
455 result = verify_rib(tgen, "ipv4", rtr, input_dict)
456 assert result is True, "Testcase {} : Failed \n Error: {}".format(
457 tc_name, result
458 )
459
460 step("Configure E BGP multi hop using the loopback addresses.")
461 as_num = 100
462 for node in topo["routers"]:
463 as_num += 1
464 topo["routers"][node].update(
465 {
466 "bgp": {
467 "local_as": as_num,
468 "address_family": {"ipv4": {"unicast": {"neighbor": {}}}},
469 }
470 }
471 )
472 for node in topo["routers"]:
473 for rtr in topo["routers"]:
474 if node is not rtr:
475 topo["routers"][node]["bgp"]["address_family"]["ipv4"]["unicast"][
476 "neighbor"
477 ].update(
478 {
479 rtr: {
480 "dest_link": {
481 "lo": {"source_link": "lo", "ebgp_multihop": 2}
482 }
483 }
484 }
485 )
486
487 result = create_router_bgp(tgen, topo, topo["routers"])
488 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
489
490 step("Verify that BGP neighbor is ESTABLISHED")
491 result = verify_bgp_convergence(tgen, topo)
492 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
493 step(
494 "Configure couple of static routes in R0 and "
495 "Redistribute static routes in R1 bgp."
496 )
497
498 for rtr in topo["routers"]:
499 redistribute_ospf(tgen, topo, rtr, "static", delete=True)
500
501 input_dict = {
502 "r0": {
503 "static_routes": [
504 {
505 "network": NETWORK["ipv4"][0],
506 "no_of_ip": 5,
507 "next_hop": "Null0",
508 }
509 ]
510 }
511 }
512 result = create_static_routes(tgen, input_dict)
513 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
514
515 configure_bgp_on_r0 = {
516 "r0": {
517 "bgp": {
518 "address_family": {
519 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}
520 }
521 }
522 }
523 }
524 result = create_router_bgp(tgen, topo, configure_bgp_on_r0)
525 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
526 protocol = "bgp"
527 for rtr in ["r1", "r2", "r3"]:
528 result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
529 assert result is True, "Testcase {} : Failed \n Error: {}".format(
530 tc_name, result
531 )
532
533 step("Clear ospf neighbours in R0")
534 for rtr in topo["routers"]:
535 clear_ospf(tgen, rtr)
536
537 step("Verify that OSPF neighbours are reset and forms new adjacencies.")
538 # Api call verify whether OSPF is converged
539 ospf_covergence = verify_ospf_neighbor(tgen, topo)
540 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
541 ospf_covergence
542 )
543
544 step("Verify that BGP neighbours are reset and forms new adjacencies.")
545 result = verify_bgp_convergence(tgen, topo)
546 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
547
548 protocol = "bgp"
549 for rtr in ["r1", "r2", "r3"]:
550 result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
551 assert result is True, "Testcase {} : Failed \n Error: {}".format(
552 tc_name, result
553 )
554
555 write_test_footer(tc_name)
556
557
558 def test_ospf_rfc2328_appendinxE_p0(request):
559 """
560 Test OSPF appendinx E RFC2328.
561
562 """
563 tc_name = request.node.name
564 write_test_header(tc_name)
565 tgen = get_topogen()
566 global topo
567 step("Bring up the base config.")
568
569 reset_config_on_routers(tgen)
570
571 step("Verify that OSPF neighbours are Full.")
572 # Api call verify whether OSPF is converged
573 ospf_covergence = verify_ospf_neighbor(tgen, topo)
574 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
575 ospf_covergence
576 )
577
578 redistribute_ospf(tgen, topo, "r0", "static")
579
580 step("Configure static route with prefix 24, 16, 8 to check ")
581 input_dict = {
582 "r0": {
583 "static_routes": [
584 {
585 "network": NETWORK_APP_E["ipv4"][0],
586 "no_of_ip": 1,
587 "next_hop": "Null0",
588 }
589 ]
590 }
591 }
592 result = create_static_routes(tgen, input_dict)
593 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
594
595 input_dict = {
596 "r0": {
597 "static_routes": [
598 {
599 "network": NETWORK_APP_E["ipv4"][1],
600 "no_of_ip": 1,
601 "next_hop": "Null0",
602 }
603 ]
604 }
605 }
606 result = create_static_routes(tgen, input_dict)
607 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
608
609 input_dict = {
610 "r0": {
611 "static_routes": [
612 {
613 "network": NETWORK_APP_E["ipv4"][2],
614 "no_of_ip": 1,
615 "next_hop": "Null0",
616 }
617 ]
618 }
619 }
620 result = create_static_routes(tgen, input_dict)
621 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
622
623 step("Verify that ospf originates routes with mask 24, 16, 8")
624 ip_net = NETWORK_APP_E["ipv4"][0]
625 input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}}
626
627 dut = "r1"
628 result = verify_ospf_rib(tgen, dut, input_dict)
629 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
630
631 protocol = "ospf"
632 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
633 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
634
635 ip_net = NETWORK_APP_E["ipv4"][1]
636 input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}}
637
638 dut = "r1"
639 result = verify_ospf_rib(tgen, dut, input_dict)
640 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
641
642 protocol = "ospf"
643 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
644 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
645
646 ip_net = NETWORK_APP_E["ipv4"][2]
647 input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}}
648
649 dut = "r1"
650 result = verify_ospf_rib(tgen, dut, input_dict)
651 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
652
653 protocol = "ospf"
654 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
655 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
656
657 step("Delete static route with prefix 24, 16, 8 to check ")
658 input_dict = {
659 "r0": {
660 "static_routes": [
661 {
662 "network": NETWORK_APP_E["ipv4"][0],
663 "no_of_ip": 1,
664 "next_hop": "Null0",
665 "delete": True,
666 }
667 ]
668 }
669 }
670 result = create_static_routes(tgen, input_dict)
671 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
672
673 input_dict = {
674 "r0": {
675 "static_routes": [
676 {
677 "network": NETWORK_APP_E["ipv4"][1],
678 "no_of_ip": 1,
679 "next_hop": "Null0",
680 "delete": True,
681 }
682 ]
683 }
684 }
685 result = create_static_routes(tgen, input_dict)
686 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
687
688 input_dict = {
689 "r0": {
690 "static_routes": [
691 {
692 "network": NETWORK_APP_E["ipv4"][2],
693 "no_of_ip": 1,
694 "next_hop": "Null0",
695 "delete": True,
696 }
697 ]
698 }
699 }
700 result = create_static_routes(tgen, input_dict)
701 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
702
703 write_test_footer(tc_name)
704
705
706 def test_ospf_cost_tc52_p0(request):
707 """OSPF Cost - verifying ospf interface cost functionality"""
708 tc_name = request.node.name
709 write_test_header(tc_name)
710 tgen = get_topogen()
711 global topo
712 step("Bring up the base config.")
713 reset_config_on_routers(tgen)
714
715 step(
716 "Configure ospf cost as 20 on interface between R0 and R1. "
717 "Configure ospf cost as 30 between interface between R0 and R2."
718 )
719
720 r0_ospf_cost = {
721 "r0": {"links": {"r1": {"ospf": {"cost": 20}}, "r2": {"ospf": {"cost": 30}}}}
722 }
723 result = config_ospf_interface(tgen, topo, r0_ospf_cost)
724 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
725
726 step(
727 "Verify that cost is updated in the ospf interface between"
728 " r0 and r1 as 30 and r0 and r2 as 20"
729 )
730 dut = "r0"
731 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=r0_ospf_cost)
732 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
733
734 step(
735 "Swap the costs between interfaces on r0, between r0 and r1 to 30"
736 ", r0 and r2 to 20"
737 )
738
739 r0_ospf_cost = {
740 "r0": {"links": {"r1": {"ospf": {"cost": 30}}, "r2": {"ospf": {"cost": 20}}}}
741 }
742 result = config_ospf_interface(tgen, topo, r0_ospf_cost)
743 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
744
745 step(
746 "Verify that cost is updated in the ospf interface between r0 "
747 "and r1 as 30 and r0 and r2 as 20."
748 )
749 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=r0_ospf_cost)
750 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
751
752 step(" Un configure cost from the interface r0 - r1.")
753
754 r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 30, "del_action": True}}}}}
755 result = config_ospf_interface(tgen, topo, r0_ospf_cost)
756 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
757
758 input_dict = {
759 "r0": {"links": {"r1": {"ospf": {"cost": 10}}, "r2": {"ospf": {"cost": 20}}}}
760 }
761 step(
762 "Verify that cost is updated in the ospf interface between r0"
763 " and r1 as 10 and r0 and r2 as 20."
764 )
765
766 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
767 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
768
769 step(" Un configure cost from the interface r0 - r2.")
770
771 r0_ospf_cost = {"r0": {"links": {"r2": {"ospf": {"cost": 20, "del_action": True}}}}}
772 result = config_ospf_interface(tgen, topo, r0_ospf_cost)
773 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
774
775 step(
776 "Verify that cost is updated in the ospf interface between r0"
777 "and r1 as 10 and r0 and r2 as 10"
778 )
779
780 input_dict = {
781 "r0": {"links": {"r1": {"ospf": {"cost": 10}}, "r2": {"ospf": {"cost": 10}}}}
782 }
783 result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
784 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
785
786 write_test_footer(tc_name)
787
788
789 if __name__ == "__main__":
790 args = ["-s"] + sys.argv[1:]
791 sys.exit(pytest.main(args))