]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 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."""
13 from lib
.ospf
import (
19 from lib
.topojson
import build_config_from_json
20 from lib
.topolog
import logger
21 from lib
.common_config
import (
25 reset_config_on_routers
,
30 from lib
.topogen
import Topogen
, get_topogen
36 # Save the Current Working Directory to find configuration files.
37 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
38 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
40 # pylint: disable=C0413
41 # Import topogen and topotest helpers
43 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
59 Please view in a fixed-width font such as Courier.
61 +R1 +------------+R2 |
70 +R0 +-------------+R3 |
76 1. OSPF Learning - Verify OSPF can learn different types of LSA and
77 processes them.[Edge learning different types of LSAs]
78 2. Verify that ospf non back bone area can be configured as NSSA area
79 3. Verify that ospf NSSA area DUT is capable receiving & processing
84 def setup_module(mod
):
86 Sets up the pytest environment
90 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
91 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
94 logger
.info("Running setup_module to create topology")
96 # This function initiates the topology build with Topogen...
97 json_file
= "{}/ospf_nssa.json".format(CWD
)
98 tgen
= Topogen(json_file
, mod
.__name
__)
100 topo
= tgen
.json_topo
101 # ... and here it calls Mininet initialization functions.
103 # Starting topology, create tmp files which are loaded to routers
104 # to start daemons and then start routers
107 # Creating configuration from JSON
108 build_config_from_json(tgen
, topo
)
110 # Don't run this test if we have any failure.
111 if tgen
.routers_have_failure():
112 pytest
.skip(tgen
.errors
)
113 # Api call verify whether OSPF is converged
114 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
115 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
119 logger
.info("Running setup_module() done")
122 def teardown_module(mod
):
124 Teardown the pytest environment.
129 logger
.info("Running teardown_module to delete topology")
133 # Stop toplogy and Remove tmp files
137 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
139 logger
.info("=" * 40)
142 # ##################################
143 # Test cases start here.
144 # ##################################
147 def test_ospf_learning_tc15_p0(request
):
148 """Verify OSPF can learn different types of LSA and processes them.
150 OSPF Learning : Edge learning different types of LSAs.
152 tc_name
= request
.node
.name
153 write_test_header(tc_name
)
156 # Don't run this test if we have any failure.
157 if tgen
.routers_have_failure():
158 pytest
.skip(tgen
.errors
)
161 step("Bring up the base config as per the topology")
162 step("Configure area 1 as NSSA Area")
164 reset_config_on_routers(tgen
)
166 step("Verify that Type 3 summary LSA is originated for the same Area 0")
167 ip
= topo
["routers"]["r1"]["links"]["r3-link0"]["ipv4"]
168 ip_net
= str(ipaddress
.ip_interface(u
"{}".format(ip
)).network
)
173 "static_routes": [{"network": ip_net
, "no_of_ip": 1, "routeType": "N IA"}]
178 result
= verify_ospf_rib(tgen
, dut
, input_dict
)
179 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
182 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
)
183 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
188 {"network": NETWORK
["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0"}
192 result
= create_static_routes(tgen
, input_dict
)
193 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
195 step("Redistribute static route in R2 ospf.")
197 redistribute_ospf(tgen
, topo
, dut
, "static")
199 step("Verify that Type 5 LSA is originated by R2.")
202 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
)
203 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
205 step("Verify that R0 receives Type 4 summary LSA.")
210 {"network": NETWORK
["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"}
216 result
= verify_ospf_rib(tgen
, dut
, input_dict
)
217 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
219 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
)
220 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
222 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
223 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
227 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
229 for rtr
in ["r1", "r2", "r3"]:
231 rtr
: {"ospf": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}}
233 result
= create_router_ospf(tgen
, topo
, input_dict
)
234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
238 step("Verify that OSPF neighbours are reset after changing area type.")
239 step("Verify that ABR R2 originates type 5 LSA in area 1.")
240 step("Verify that route is calculated and installed in R1.")
245 {"network": NETWORK
["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"}
251 result
= verify_ospf_rib(tgen
, dut
, input_dict
)
252 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
254 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
)
255 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
257 write_test_footer(tc_name
)
260 if __name__
== "__main__":
261 args
= ["-s"] + sys
.argv
[1:]
262 sys
.exit(pytest
.main(args
))