]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
Merge pull request #8262 from reubendowle/fixes/nhrp-misc-fixes
[mirror_frr.git] / tests / topotests / ospf_basic_functionality / test_ospf_nssa.py
1 #!/usr/bin/python
2
3 #
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
7 #
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
11 # in all copies.
12 #
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
20 # OF THIS SOFTWARE.
21 #
22
23
24 """OSPF Basic Functionality Automation."""
25 import ipaddress
26 from lib.ospf import (
27 verify_ospf_neighbor,
28 config_ospf_interface,
29 clear_ospf,
30 verify_ospf_rib,
31 create_router_ospf,
32 verify_ospf_interface,
33 redistribute_ospf,
34 )
35 from lib.topojson import build_topo_from_json, build_config_from_json
36 from lib.topolog import logger
37 from lib.common_config import (
38 start_topology,
39 write_test_header,
40 write_test_footer,
41 reset_config_on_routers,
42 verify_rib,
43 create_static_routes,
44 step,
45 create_route_maps,
46 shutdown_bringup_interface,
47 create_interfaces_cfg,
48 topo_daemons,
49 )
50 from ipaddress import IPv4Address
51 from lib.topogen import Topogen, get_topogen
52 from mininet.topo import Topo
53 import os
54 import sys
55 import time
56 import pytest
57 import json
58
59 # Save the Current Working Directory to find configuration files.
60 CWD = os.path.dirname(os.path.realpath(__file__))
61 sys.path.append(os.path.join(CWD, "../"))
62 sys.path.append(os.path.join(CWD, "../lib/"))
63 # pylint: disable=C0413
64 # Import topogen and topotest helpers
65
66 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
67
68
69 # Global variables
70 topo = None
71 # Reading the data from JSON File for topology creation
72 jsonFile = "{}/ospf_nssa.json".format(CWD)
73 try:
74 with open(jsonFile, "r") as topoJson:
75 topo = json.load(topoJson)
76 except IOError:
77 assert False, "Could not read file {}".format(jsonFile)
78 NETWORK = {
79 "ipv4": [
80 "11.0.20.1/32",
81 "11.0.20.2/32",
82 "11.0.20.3/32",
83 "11.0.20.4/32",
84 "11.0.20.5/32",
85 ]
86 }
87 """
88 TOPOOLOGY =
89 Please view in a fixed-width font such as Courier.
90 +---+ A1 +---+
91 +R1 +------------+R2 |
92 +-+-+- +--++
93 | -- -- |
94 | -- A0 -- |
95 A0| ---- |
96 | ---- | A2
97 | -- -- |
98 | -- -- |
99 +-+-+- +-+-+
100 +R0 +-------------+R3 |
101 +---+ A3 +---+
102
103
104
105 TESTCASES =
106 1. OSPF Learning - Verify OSPF can learn different types of LSA and
107 processes them.[Edge learning different types of LSAs]
108 2. Verify that ospf non back bone area can be configured as NSSA area
109 3. Verify that ospf NSSA area DUT is capable receiving & processing
110 Type7 N2 route.
111 """
112
113
114 class CreateTopo(Topo):
115 """
116 Test topology builder.
117
118 * `Topo`: Topology object
119 """
120
121 def build(self, *_args, **_opts):
122 """Build function."""
123 tgen = get_topogen(self)
124
125 # Building topology from json file
126 build_topo_from_json(tgen, topo)
127
128
129 def setup_module(mod):
130 """
131 Sets up the pytest environment
132
133 * `mod`: module name
134 """
135 global topo
136 testsuite_run_time = time.asctime(time.localtime(time.time()))
137 logger.info("Testsuite start time: {}".format(testsuite_run_time))
138 logger.info("=" * 40)
139
140 logger.info("Running setup_module to create topology")
141
142 # This function initiates the topology build with Topogen...
143 tgen = Topogen(CreateTopo, mod.__name__)
144 # ... and here it calls Mininet initialization functions.
145
146 # get list of daemons needs to be started for this suite.
147 daemons = topo_daemons(tgen, topo)
148
149 # Starting topology, create tmp files which are loaded to routers
150 # to start deamons and then start routers
151 start_topology(tgen, daemons)
152
153 # Creating configuration from JSON
154 build_config_from_json(tgen, topo)
155
156 # Don't run this test if we have any failure.
157 if tgen.routers_have_failure():
158 pytest.skip(tgen.errors)
159 # Api call verify whether OSPF is converged
160 ospf_covergence = verify_ospf_neighbor(tgen, topo)
161 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
162 ospf_covergence
163 )
164
165 logger.info("Running setup_module() done")
166
167
168 def teardown_module(mod):
169 """
170 Teardown the pytest environment.
171
172 * `mod`: module name
173 """
174
175 logger.info("Running teardown_module to delete topology")
176
177 tgen = get_topogen()
178
179 # Stop toplogy and Remove tmp files
180 tgen.stop_topology()
181
182 logger.info(
183 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
184 )
185 logger.info("=" * 40)
186
187
188 # ##################################
189 # Test cases start here.
190 # ##################################
191
192
193 def test_ospf_learning_tc15_p0(request):
194 """Verify OSPF can learn different types of LSA and processes them.
195
196 OSPF Learning : Edge learning different types of LSAs.
197 """
198 tc_name = request.node.name
199 write_test_header(tc_name)
200 tgen = get_topogen()
201
202 # Don't run this test if we have any failure.
203 if tgen.routers_have_failure():
204 pytest.skip(tgen.errors)
205
206 global topo
207 step("Bring up the base config as per the topology")
208 step("Configure area 1 as NSSA Area")
209
210 reset_config_on_routers(tgen)
211
212 step("Verify that Type 3 summary LSA is originated for the same Area 0")
213 ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv4"]
214 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
215
216 dut = "r0"
217 input_dict = {
218 "r1": {
219 "static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N IA"}]
220 }
221 }
222
223 dut = "r0"
224 result = verify_ospf_rib(tgen, dut, input_dict)
225 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
226
227 protocol = "ospf"
228 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
229 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
230
231 input_dict = {
232 "r2": {
233 "static_routes": [
234 {"network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0"}
235 ]
236 }
237 }
238 result = create_static_routes(tgen, input_dict)
239 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
240
241 step("Redistribute static route in R2 ospf.")
242 dut = "r2"
243 redistribute_ospf(tgen, topo, dut, "static")
244
245 step("Verify that Type 5 LSA is originated by R2.")
246 dut = "r0"
247 protocol = "ospf"
248 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
249 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
250
251 step("Verify that R0 receives Type 4 summary LSA.")
252 dut = "r0"
253 input_dict = {
254 "r1": {
255 "static_routes": [
256 {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"}
257 ]
258 }
259 }
260
261 dut = "r1"
262 result = verify_ospf_rib(tgen, dut, input_dict)
263 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
264
265 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
266 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
267
268 ospf_covergence = verify_ospf_neighbor(tgen, topo)
269 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
270 ospf_covergence
271 )
272
273 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
274
275 for rtr in ["r1", "r2", "r3"]:
276 input_dict = {
277 rtr: {"ospf": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}}
278 }
279 result = create_router_ospf(tgen, topo, input_dict)
280 assert result is True, "Testcase {} : Failed \n Error: {}".format(
281 tc_name, result
282 )
283
284 step("Verify that OSPF neighbours are reset after changing area type.")
285 step("Verify that ABR R2 originates type 5 LSA in area 1.")
286 step("Verify that route is calculated and installed in R1.")
287
288 input_dict = {
289 "r1": {
290 "static_routes": [
291 {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"}
292 ]
293 }
294 }
295
296 dut = "r1"
297 result = verify_ospf_rib(tgen, dut, input_dict)
298 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
299
300 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
301 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
302
303 write_test_footer(tc_name)
304
305
306 if __name__ == "__main__":
307 args = ["-s"] + sys.argv[1:]
308 sys.exit(pytest.main(args))