2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2021 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """OSPF Basic Functionality Automation."""
16 from copy
import deepcopy
18 from lib
.ospf
import (
19 verify_ospf6_neighbor
,
20 config_ospf6_interface
,
23 verify_ospf6_interface
,
24 verify_ospf6_database
,
28 # pylint: disable=C0413
29 # Import topogen and topotest helpers
30 from lib
.topogen
import Topogen
, get_topogen
33 verify_bgp_convergence
,
38 from lib
.topolog
import logger
39 from lib
.common_config
import (
43 reset_config_on_routers
,
48 shutdown_bringup_interface
,
49 create_interfaces_cfg
,
52 from ipaddress
import IPv4Address
53 from lib
.topolog
import logger
54 from lib
.topojson
import build_config_from_json
57 # Save the Current Working Directory to find configuration files.
58 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
59 sys
.path
.append(os
.path
.join(CWD
, "../"))
61 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
83 Please view in a fixed-width font such as Courier.
85 +R1 +------------+R2 |
94 +R0 +-------------+R3 |
100 1. OSPF Learning - Verify OSPF can learn different types of LSA and
101 processes them.[Edge learning different types of LSAs]
102 2. Verify that ospf non back bone area can be configured as NSSA area
103 3. Verify that ospf NSSA area DUT is capable receiving & processing
108 def setup_module(mod
):
110 Sets up the pytest environment
115 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
116 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
117 logger
.info("=" * 40)
119 logger
.info("Running setup_module to create topology")
121 # This function initiates the topology build with Topogen...
122 json_file
= "{}/ospfv3_nssa2.json".format(CWD
)
123 tgen
= Topogen(json_file
, mod
.__name
__)
125 topo
= tgen
.json_topo
126 # ... and here it calls Mininet initialization functions.
128 # Starting topology, create tmp files which are loaded to routers
129 # to start daemons and then start routers
132 # Creating configuration from JSON
133 build_config_from_json(tgen
, topo
)
135 # Don't run this test if we have any failure.
136 if tgen
.routers_have_failure():
137 pytest
.skip(tgen
.errors
)
139 # Api call verify whether OSPF is converged
140 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
141 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
145 logger
.info("Running setup_module() done")
148 def teardown_module():
149 """Teardown the pytest environment."""
150 logger
.info("Running teardown_module to delete topology")
154 # Stop toplogy and Remove tmp files
158 def red_static(dut
, config
=True):
159 """Local def for Redstribute static routes inside ospf."""
163 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
167 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
170 result
= create_router_ospf(tgen
, topo
, ospf_red
)
171 assert result
is True, "Testcase : Failed \n Error: {}".format(result
)
174 def red_connected(dut
, config
=True):
175 """Local def for Redstribute connected routes inside ospf."""
179 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
184 "redistribute": [{"redist_type": "connected", "del_action": True}]
188 result
= create_router_ospf(tgen
, topo
, ospf_red
)
189 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
192 # ##################################
193 # Test cases start here.
194 # ##################################
197 def test_ospfv3_nssa_tc26_p0(request
):
198 """Verify that ospf non back bone area can be configured as NSSA area"""
199 tc_name
= request
.node
.name
200 write_test_header(tc_name
)
203 # Don't run this test if we have any failure.
204 if tgen
.routers_have_failure():
205 check_router_status(tgen
)
208 step("Bring up the base config as per the topology")
209 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
211 reset_config_on_routers(tgen
)
216 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
220 result
= create_static_routes(tgen
, input_dict
)
221 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
223 step("Redistribute static route in R2 ospf.")
227 step("Verify that Type 5 LSA is originated by R2.")
230 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
231 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
233 step("Un configure redistribute command in R4")
235 red_static(dut
, config
=False)
240 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
245 step("Configure area 0 on interface of r2 connecting to r1")
251 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
252 "ospf6": {"area": "0.0.0.2"},
259 result
= create_interfaces_cfg(tgen
, input_dict
)
260 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
266 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
267 "ospf6": {"area": "0.0.0.0"},
273 result
= create_interfaces_cfg(tgen
, input_dict
)
274 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
276 step("verify that ospf neighbor goes down between r2 and r1.")
277 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
280 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
282 step("Now configure area 0 on interface of r1 connecting to r2.")
288 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
289 "ospf6": {"area": "0.0.0.2"},
296 result
= create_interfaces_cfg(tgen
, input_dict
)
297 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
303 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
304 "ospf6": {"area": "0.0.0.0"},
310 result
= create_interfaces_cfg(tgen
, input_dict
)
311 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
313 step("Verify that ospf neighbour comes up between r2 and r1.")
314 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
315 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
317 step("Configure area 2 on interface of r2 connecting to r1.")
323 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
324 "ospf6": {"area": "0.0.0.0"},
331 result
= create_interfaces_cfg(tgen
, input_dict
)
332 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
338 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
339 "ospf6": {"area": "0.0.0.2"},
345 result
= create_interfaces_cfg(tgen
, input_dict
)
346 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
348 step("verify that ospf neighbor goes down between r2 and r1.")
349 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
352 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
354 step("Now configure area 2 on interface of r1 connecting to r2.")
360 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
361 "ospf6": {"area": "0.0.0.0"},
368 result
= create_interfaces_cfg(tgen
, input_dict
)
369 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
375 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
376 "ospf6": {"area": "0.0.0.2"},
382 result
= create_interfaces_cfg(tgen
, input_dict
)
383 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
385 step("Verify that ospf neighbour comes up between r2 and r1.")
386 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
387 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
389 write_test_footer(tc_name
)
392 def test_ospfv3_learning_tc15_p0(request
):
393 """Verify OSPF can learn different types of LSA and processes them.
395 OSPF Learning : Edge learning different types of LSAs.
397 tc_name
= request
.node
.name
398 write_test_header(tc_name
)
401 # Don't run this test if we have any failure.
402 if tgen
.routers_have_failure():
403 check_router_status(tgen
)
406 step("Bring up the base config as per the topology")
407 step("Configure area 1 as NSSA Area")
409 reset_config_on_routers(tgen
)
411 step("Verify that Type 3 summary LSA is originated for the same Area 0")
412 ip
= topo
["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
413 ip_net
= str(ipaddress
.ip_interface(u
"{}".format(ip
)).network
)
421 "routeType": "Network",
422 "pathtype": "Inter-Area",
429 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
430 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
433 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
434 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
439 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
443 result
= create_static_routes(tgen
, input_dict
)
444 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
446 step("Redistribute static route in R2 ospf.")
450 step("Verify that Type 5 LSA is originated by R2.")
453 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
454 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
459 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
465 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
466 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
468 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
469 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
471 result
= verify_ospf6_neighbor(tgen
, topo
)
472 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
474 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
476 for rtr
in ["r1", "r2", "r3"]:
479 "ospf6": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}
482 result
= create_router_ospf(tgen
, topo
, input_dict
)
483 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
487 step("Verify that OSPF neighbours are reset after changing area type.")
488 step("Verify that ABR R2 originates type 5 LSA in area 1.")
489 step("Verify that R1 installs type 5 lsa in its database.")
490 step("Verify that route is calculated and installed in R1.")
495 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
501 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
502 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
504 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
505 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
507 write_test_footer(tc_name
)
510 # As per internal discussion, this script has to be removed as translator
511 # function is not supported, for more details kindly check this PR 2565570
512 def ospfv3_nssa_tc27_p0(request
):
516 Verify that ospf NSSA area DUT is capable receiving & processing
519 tc_name
= request
.node
.name
520 write_test_header(tc_name
)
523 # Don't run this test if we have any failure.
524 if tgen
.routers_have_failure():
525 check_router_status(tgen
)
528 step("Bring up the base config as per the topology")
529 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
531 reset_config_on_routers(tgen
)
536 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
540 result
= create_static_routes(tgen
, input_dict
)
541 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
543 step("Redistribute static route in R2 ospf.")
547 step("Verify that Type 5 LSA is originated by R2.")
550 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
551 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
553 step("Un configure redistribute command in R4")
555 red_static(dut
, config
=False)
560 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
566 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
567 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
572 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
574 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
578 write_test_footer(tc_name
)
581 if __name__
== "__main__":
582 args
= ["-s"] + sys
.argv
[1:]
583 sys
.exit(pytest
.main(args
))