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