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