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 # As per internal discussion, this script has to be removed as translator
410 # function is not supported, for more details kindly check this PR 2565570
411 def ospfv3_nssa_tc27_p0(request
):
415 Verify that ospf NSSA area DUT is capable receiving & processing
418 tc_name
= request
.node
.name
419 write_test_header(tc_name
)
422 # Don't run this test if we have any failure.
423 if tgen
.routers_have_failure():
424 check_router_status(tgen
)
427 step("Bring up the base config as per the topology")
428 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
430 reset_config_on_routers(tgen
)
435 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
439 result
= create_static_routes(tgen
, input_dict
)
440 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
442 step("Redistribute static route in R2 ospf.")
446 step("Verify that Type 5 LSA is originated by R2.")
449 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
450 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
452 step("Un configure redistribute command in R4")
454 red_static(dut
, config
=False)
459 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
465 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
466 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
471 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
473 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
477 write_test_footer(tc_name
)
480 if __name__
== "__main__":
481 args
= ["-s"] + sys
.argv
[1:]
482 sys
.exit(pytest
.main(args
))