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
,
61 shutdown_bringup_interface
,
62 create_interfaces_cfg
,
65 from ipaddress
import IPv4Address
66 from lib
.topolog
import logger
67 from lib
.topojson
import build_config_from_json
70 # Save the Current Working Directory to find configuration files.
71 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
72 sys
.path
.append(os
.path
.join(CWD
, "../"))
74 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
96 Please view in a fixed-width font such as Courier.
98 +R1 +------------+R2 |
107 +R0 +-------------+R3 |
113 1. OSPF Learning - Verify OSPF can learn different types of LSA and
114 processes them.[Edge learning different types of LSAs]
115 2. Verify that ospf non back bone area can be configured as NSSA area
116 3. Verify that ospf NSSA area DUT is capable receiving & processing
121 def setup_module(mod
):
123 Sets up the pytest environment
128 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
129 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
130 logger
.info("=" * 40)
132 logger
.info("Running setup_module to create topology")
134 # This function initiates the topology build with Topogen...
135 json_file
= "{}/ospfv3_nssa2.json".format(CWD
)
136 tgen
= Topogen(json_file
, mod
.__name
__)
138 topo
= tgen
.json_topo
139 # ... and here it calls Mininet initialization functions.
141 # Starting topology, create tmp files which are loaded to routers
142 # to start daemons and then start routers
145 # Creating configuration from JSON
146 build_config_from_json(tgen
, topo
)
148 # Don't run this test if we have any failure.
149 if tgen
.routers_have_failure():
150 pytest
.skip(tgen
.errors
)
152 # Api call verify whether OSPF is converged
153 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
154 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
158 logger
.info("Running setup_module() done")
161 def teardown_module():
162 """Teardown the pytest environment."""
163 logger
.info("Running teardown_module to delete topology")
167 # Stop toplogy and Remove tmp files
171 def red_static(dut
, config
=True):
172 """Local def for Redstribute static routes inside ospf."""
176 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
180 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
183 result
= create_router_ospf(tgen
, topo
, ospf_red
)
184 assert result
is True, "Testcase : Failed \n Error: {}".format(result
)
187 def red_connected(dut
, config
=True):
188 """Local def for Redstribute connected routes inside ospf."""
192 ospf_red
= {dut
: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
197 "redistribute": [{"redist_type": "connected", "del_action": True}]
201 result
= create_router_ospf(tgen
, topo
, ospf_red
)
202 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
205 # ##################################
206 # Test cases start here.
207 # ##################################
210 def test_ospfv3_nssa_tc26_p0(request
):
211 """Verify that ospf non back bone area can be configured as NSSA area"""
212 tc_name
= request
.node
.name
213 write_test_header(tc_name
)
216 # Don't run this test if we have any failure.
217 if tgen
.routers_have_failure():
218 check_router_status(tgen
)
221 step("Bring up the base config as per the topology")
222 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
224 reset_config_on_routers(tgen
)
229 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
233 result
= create_static_routes(tgen
, input_dict
)
234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
236 step("Redistribute static route in R2 ospf.")
240 step("Verify that Type 5 LSA is originated by R2.")
243 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
244 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
246 step("Un configure redistribute command in R4")
248 red_static(dut
, config
=False)
253 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
258 step("Configure area 0 on interface of r2 connecting to r1")
264 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
265 "ospf6": {"area": "0.0.0.2"},
272 result
= create_interfaces_cfg(tgen
, input_dict
)
273 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
279 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
280 "ospf6": {"area": "0.0.0.0"},
286 result
= create_interfaces_cfg(tgen
, input_dict
)
287 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
289 step("verify that ospf neighbor goes down between r2 and r1.")
290 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
293 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
295 step("Now configure area 0 on interface of r1 connecting to r2.")
301 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
302 "ospf6": {"area": "0.0.0.2"},
309 result
= create_interfaces_cfg(tgen
, input_dict
)
310 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
316 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
317 "ospf6": {"area": "0.0.0.0"},
323 result
= create_interfaces_cfg(tgen
, input_dict
)
324 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
326 step("Verify that ospf neighbour comes up between r2 and r1.")
327 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
328 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
330 step("Configure area 2 on interface of r2 connecting to r1.")
336 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
337 "ospf6": {"area": "0.0.0.0"},
344 result
= create_interfaces_cfg(tgen
, input_dict
)
345 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
351 "interface": topo
["routers"]["r2"]["links"]["r1"]["interface"],
352 "ospf6": {"area": "0.0.0.2"},
358 result
= create_interfaces_cfg(tgen
, input_dict
)
359 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
361 step("verify that ospf neighbor goes down between r2 and r1.")
362 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2", expected
=False)
365 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name
, result
)
367 step("Now configure area 2 on interface of r1 connecting to r2.")
373 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
374 "ospf6": {"area": "0.0.0.0"},
381 result
= create_interfaces_cfg(tgen
, input_dict
)
382 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
388 "interface": topo
["routers"]["r1"]["links"]["r2"]["interface"],
389 "ospf6": {"area": "0.0.0.2"},
395 result
= create_interfaces_cfg(tgen
, input_dict
)
396 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
398 step("Verify that ospf neighbour comes up between r2 and r1.")
399 result
= verify_ospf6_neighbor(tgen
, topo
, dut
="r2")
400 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
402 write_test_footer(tc_name
)
405 def test_ospfv3_learning_tc15_p0(request
):
406 """Verify OSPF can learn different types of LSA and processes them.
408 OSPF Learning : Edge learning different types of LSAs.
410 tc_name
= request
.node
.name
411 write_test_header(tc_name
)
414 # Don't run this test if we have any failure.
415 if tgen
.routers_have_failure():
416 check_router_status(tgen
)
419 step("Bring up the base config as per the topology")
420 step("Configure area 1 as NSSA Area")
422 reset_config_on_routers(tgen
)
424 step("Verify that Type 3 summary LSA is originated for the same Area 0")
425 ip
= topo
["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
426 ip_net
= str(ipaddress
.ip_interface(u
"{}".format(ip
)).network
)
434 "routeType": "Network",
435 "pathtype": "Inter-Area",
442 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
443 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
446 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
447 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
452 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
456 result
= create_static_routes(tgen
, input_dict
)
457 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
459 step("Redistribute static route in R2 ospf.")
463 step("Verify that Type 5 LSA is originated by R2.")
466 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
467 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
472 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
478 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
479 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
481 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
482 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
484 result
= verify_ospf6_neighbor(tgen
, topo
)
485 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
487 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
489 for rtr
in ["r1", "r2", "r3"]:
492 "ospf6": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}
495 result
= create_router_ospf(tgen
, topo
, input_dict
)
496 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
500 step("Verify that OSPF neighbours are reset after changing area type.")
501 step("Verify that ABR R2 originates type 5 LSA in area 1.")
502 step("Verify that R1 installs type 5 lsa in its database.")
503 step("Verify that route is calculated and installed in R1.")
508 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
514 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
515 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
517 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
518 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
520 write_test_footer(tc_name
)
523 # As per internal discussion, this script has to be removed as translator
524 # function is not supported, for more details kindly check this PR 2565570
525 def ospfv3_nssa_tc27_p0(request
):
529 Verify that ospf NSSA area DUT is capable receiving & processing
532 tc_name
= request
.node
.name
533 write_test_header(tc_name
)
536 # Don't run this test if we have any failure.
537 if tgen
.routers_have_failure():
538 check_router_status(tgen
)
541 step("Bring up the base config as per the topology")
542 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
544 reset_config_on_routers(tgen
)
549 {"network": NETWORK
["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
553 result
= create_static_routes(tgen
, input_dict
)
554 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
556 step("Redistribute static route in R2 ospf.")
560 step("Verify that Type 5 LSA is originated by R2.")
563 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
564 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
566 step("Un configure redistribute command in R4")
568 red_static(dut
, config
=False)
573 {"network": NETWORK
["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
579 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
580 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
585 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
587 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
591 write_test_footer(tc_name
)
594 if __name__
== "__main__":
595 args
= ["-s"] + sys
.argv
[1:]
596 sys
.exit(pytest
.main(args
))