4 # Copyright (c) 2021 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
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
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
24 """OSPF Basic Functionality Automation."""
29 from copy
import deepcopy
31 from lib
.ospf
import (
32 verify_ospf6_neighbor
,
33 config_ospf6_interface
,
36 verify_ospf6_interface
,
37 verify_ospf6_database
,
41 # pylint: disable=C0413
42 # Import topogen and topotest helpers
43 from lib
.topogen
import Topogen
, get_topogen
46 verify_bgp_convergence
,
51 from lib
.topolog
import logger
52 from lib
.common_config
import (
56 reset_config_on_routers
,
62 shutdown_bringup_interface
,
63 create_interfaces_cfg
,
66 from ipaddress
import IPv4Address
67 from lib
.topolog
import logger
68 from lib
.topojson
import build_config_from_json
71 # Save the Current Working Directory to find configuration files.
72 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
73 sys
.path
.append(os
.path
.join(CWD
, "../"))
75 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
97 Please view in a fixed-width font such as Courier.
99 +R1 +------------+R2 |
108 +R0 +-------------+R3 |
114 1. OSPF Learning - Verify OSPF can learn different types of LSA and
115 processes them.[Edge learning different types of LSAs]
116 2. Verify that ospf non back bone area can be configured as NSSA area
117 3. Verify that ospf NSSA area DUT is capable receiving & processing
122 def setup_module(mod
):
124 Sets up the pytest environment
129 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
130 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
131 logger
.info("=" * 40)
133 logger
.info("Running setup_module to create topology")
135 # This function initiates the topology build with Topogen...
136 json_file
= "{}/ospfv3_nssa2.json".format(CWD
)
137 tgen
= Topogen(json_file
, mod
.__name
__)
139 topo
= tgen
.json_topo
140 # ... and here it calls Mininet initialization functions.
142 # get list of daemons needs to be started for this suite.
143 daemons
= topo_daemons(tgen
, topo
)
145 # Starting topology, create tmp files which are loaded to routers
146 # to start daemons and then start routers
147 start_topology(tgen
, daemons
)
149 # Creating configuration from JSON
150 build_config_from_json(tgen
, topo
)
152 # Don't run this test if we have any failure.
153 if tgen
.routers_have_failure():
154 pytest
.skip(tgen
.errors
)
156 # Api call verify whether OSPF is converged
157 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
158 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
162 logger
.info("Running setup_module() done")
165 def teardown_module():
166 """Teardown the pytest environment."""
167 logger
.info("Running teardown_module to delete topology")
171 # Stop toplogy and Remove tmp files
175 def red_static(dut
, config
=True):
176 """Local def for Redstribute static routes inside ospf."""
180 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
184 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
187 result
= create_router_ospf(tgen
, topo
, ospf_red
)
188 assert result
is True, "Testcase : Failed \n Error: {}".format(result
)
191 def red_connected(dut
, config
=True):
192 """Local def for Redstribute connected routes inside ospf."""
196 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
201 "redistribute": [{"redist_type": "connected", "del_action": True}]
205 result
= create_router_ospf(tgen
, topo
, ospf_red
)
206 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
209 # ##################################
210 # Test cases start here.
211 # ##################################
214 def test_ospfv3_nssa_tc26_p0(request
):
215 """Verify that ospf non back bone area can be configured as NSSA area"""
216 tc_name
= request
.node
.name
217 write_test_header(tc_name
)
220 # Don't run this test if we have any failure.
221 if tgen
.routers_have_failure():
222 check_router_status(tgen
)
225 step("Bring up the base config as per the topology")
226 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
228 reset_config_on_routers(tgen
)
233 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
237 result
= create_static_routes(tgen
, input_dict
)
238 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
240 step("Redistribute static route in R2 ospf.")
244 step("Verify that Type 5 LSA is originated by R2.")
247 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
248 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
250 step("Un configure redistribute command in R4")
252 red_static(dut
, config
=False)
257 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
262 step("Configure area 0 on interface of r2 connecting to r1")
268 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
269 "ospf6": {"area": "0.0.0.2"},
276 result
= create_interfaces_cfg(tgen
, input_dict
)
277 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
283 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
284 "ospf6": {"area": "0.0.0.0"},
290 result
= create_interfaces_cfg(tgen
, input_dict
)
291 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
293 step("verify that ospf neighbor goes down between r2 and r1.")
294 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
297 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
299 step("Now configure area 0 on interface of r1 connecting to r2.")
305 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
306 "ospf6": {"area": "0.0.0.2"},
313 result
= create_interfaces_cfg(tgen
, input_dict
)
314 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
320 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
321 "ospf6": {"area": "0.0.0.0"},
327 result
= create_interfaces_cfg(tgen
, input_dict
)
328 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
330 step("Verify that ospf neighbour comes up between r2 and r1.")
331 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
332 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
334 step("Configure area 2 on interface of r2 connecting to r1.")
340 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
341 "ospf6": {"area": "0.0.0.0"},
348 result
= create_interfaces_cfg(tgen
, input_dict
)
349 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
355 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
356 "ospf6": {"area": "0.0.0.2"},
362 result
= create_interfaces_cfg(tgen
, input_dict
)
363 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
365 step("verify that ospf neighbor goes down between r2 and r1.")
366 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
369 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
371 step("Now configure area 2 on interface of r1 connecting to r2.")
377 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
378 "ospf6": {"area": "0.0.0.0"},
385 result
= create_interfaces_cfg(tgen
, input_dict
)
386 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
392 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
393 "ospf6": {"area": "0.0.0.2"},
399 result
= create_interfaces_cfg(tgen
, input_dict
)
400 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
402 step("Verify that ospf neighbour comes up between r2 and r1.")
403 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
404 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
406 write_test_footer(tc_name
)
409 def test_ospfv3_learning_tc15_p0(request
):
410 """Verify OSPF can learn different types of LSA and processes them.
412 OSPF Learning : Edge learning different types of LSAs.
414 tc_name
= request
.node
.name
415 write_test_header(tc_name
)
418 # Don't run this test if we have any failure.
419 if tgen
.routers_have_failure():
420 check_router_status(tgen
)
423 step("Bring up the base config as per the topology")
424 step("Configure area 1 as NSSA Area")
426 reset_config_on_routers(tgen
)
428 step("Verify that Type 3 summary LSA is originated for the same Area 0")
429 ip
= topo
["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
430 ip_net
= str(ipaddress
.ip_interface(u
"{}".format(ip
)).network
)
438 "routeType": "Network",
439 "pathtype": "Inter-Area",
446 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
447 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
450 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
451 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
456 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
460 result
= create_static_routes(tgen
, input_dict
)
461 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
463 step("Redistribute static route in R2 ospf.")
467 step("Verify that Type 5 LSA is originated by R2.")
470 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
471 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
476 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
482 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
483 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
485 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
486 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
488 result
= verify_ospf6_neighbor(tgen
, topo
)
489 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
491 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
493 for rtr
in ["r1", "r2", "r3"]:
496 "ospf6": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}
499 result
= create_router_ospf(tgen
, topo
, input_dict
)
500 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
504 step("Verify that OSPF neighbours are reset after changing area type.")
505 step("Verify that ABR R2 originates type 5 LSA in area 1.")
506 step("Verify that R1 installs type 5 lsa in its database.")
507 step("Verify that route is calculated and installed in R1.")
512 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
518 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
521 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
522 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
524 write_test_footer(tc_name
)
527 # As per internal discussion, this script has to be removed as translator
528 # function is not supported, for more details kindly check this PR 2565570
529 def ospfv3_nssa_tc27_p0(request
):
533 Verify that ospf NSSA area DUT is capable receiving & processing
536 tc_name
= request
.node
.name
537 write_test_header(tc_name
)
540 # Don't run this test if we have any failure.
541 if tgen
.routers_have_failure():
542 check_router_status(tgen
)
545 step("Bring up the base config as per the topology")
546 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
548 reset_config_on_routers(tgen
)
553 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
557 result
= create_static_routes(tgen
, input_dict
)
558 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
560 step("Redistribute static route in R2 ospf.")
564 step("Verify that Type 5 LSA is originated by R2.")
567 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
568 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
570 step("Un configure redistribute command in R4")
572 red_static(dut
, config
=False)
577 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
583 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
584 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
589 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
591 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
595 write_test_footer(tc_name
)
598 if __name__
== "__main__":
599 args
= ["-s"] + sys
.argv
[1:]
600 sys
.exit(pytest
.main(args
))