]>
Commit | Line | Data |
---|---|---|
4256a209 | 1 | #!/usr/bin/python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
4256a209 | 3 | |
4 | # | |
5 | # Copyright (c) 2020 by VMware, Inc. ("VMware") | |
6 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
7 | # ("NetDEF") in this file. | |
8 | # | |
4256a209 | 9 | |
10 | ||
11 | """OSPF Basic Functionality Automation.""" | |
12 | import ipaddress | |
13 | from lib.ospf import ( | |
14 | verify_ospf_neighbor, | |
4256a209 | 15 | verify_ospf_rib, |
16 | create_router_ospf, | |
88b7d3e7 | 17 | redistribute_ospf, |
4256a209 | 18 | ) |
4953ca97 | 19 | from lib.topojson import build_config_from_json |
4256a209 | 20 | from lib.topolog import logger |
21 | from lib.common_config import ( | |
22 | start_topology, | |
23 | write_test_header, | |
24 | write_test_footer, | |
25 | reset_config_on_routers, | |
26 | verify_rib, | |
27 | create_static_routes, | |
28 | step, | |
4256a209 | 29 | ) |
4256a209 | 30 | from lib.topogen import Topogen, get_topogen |
4256a209 | 31 | import os |
32 | import sys | |
33 | import time | |
34 | import pytest | |
4256a209 | 35 | |
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 | |
42 | ||
6ff492b1 DS |
43 | pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] |
44 | ||
45 | ||
4256a209 | 46 | # Global variables |
47 | topo = None | |
4256a209 | 48 | NETWORK = { |
49 | "ipv4": [ | |
50 | "11.0.20.1/32", | |
51 | "11.0.20.2/32", | |
52 | "11.0.20.3/32", | |
53 | "11.0.20.4/32", | |
54 | "11.0.20.5/32", | |
55 | ] | |
56 | } | |
57 | """ | |
58 | TOPOOLOGY = | |
59 | Please view in a fixed-width font such as Courier. | |
60 | +---+ A1 +---+ | |
61 | +R1 +------------+R2 | | |
62 | +-+-+- +--++ | |
63 | | -- -- | | |
64 | | -- A0 -- | | |
65 | A0| ---- | | |
66 | | ---- | A2 | |
67 | | -- -- | | |
68 | | -- -- | | |
69 | +-+-+- +-+-+ | |
70 | +R0 +-------------+R3 | | |
71 | +---+ A3 +---+ | |
72 | ||
73 | ||
74 | ||
75 | TESTCASES = | |
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 | |
80 | Type7 N2 route. | |
81 | """ | |
82 | ||
83 | ||
4256a209 | 84 | def setup_module(mod): |
85 | """ | |
86 | Sets up the pytest environment | |
87 | ||
88 | * `mod`: module name | |
89 | """ | |
4256a209 | 90 | testsuite_run_time = time.asctime(time.localtime(time.time())) |
91 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
92 | logger.info("=" * 40) | |
93 | ||
94 | logger.info("Running setup_module to create topology") | |
95 | ||
96 | # This function initiates the topology build with Topogen... | |
e82b531d CH |
97 | json_file = "{}/ospf_nssa.json".format(CWD) |
98 | tgen = Topogen(json_file, mod.__name__) | |
99 | global topo | |
100 | topo = tgen.json_topo | |
4256a209 | 101 | # ... and here it calls Mininet initialization functions. |
102 | ||
103 | # Starting topology, create tmp files which are loaded to routers | |
d60a3f0e | 104 | # to start daemons and then start routers |
991a971f | 105 | start_topology(tgen) |
035267a3 | 106 | |
4256a209 | 107 | # Creating configuration from JSON |
108 | build_config_from_json(tgen, topo) | |
109 | ||
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( | |
116 | ospf_covergence | |
117 | ) | |
118 | ||
119 | logger.info("Running setup_module() done") | |
120 | ||
121 | ||
122 | def teardown_module(mod): | |
123 | """ | |
124 | Teardown the pytest environment. | |
125 | ||
126 | * `mod`: module name | |
127 | """ | |
128 | ||
129 | logger.info("Running teardown_module to delete topology") | |
130 | ||
131 | tgen = get_topogen() | |
132 | ||
133 | # Stop toplogy and Remove tmp files | |
134 | tgen.stop_topology() | |
135 | ||
136 | logger.info( | |
137 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
138 | ) | |
139 | logger.info("=" * 40) | |
140 | ||
141 | ||
4256a209 | 142 | # ################################## |
143 | # Test cases start here. | |
144 | # ################################## | |
145 | ||
146 | ||
147 | def test_ospf_learning_tc15_p0(request): | |
148 | """Verify OSPF can learn different types of LSA and processes them. | |
149 | ||
150 | OSPF Learning : Edge learning different types of LSAs. | |
151 | """ | |
152 | tc_name = request.node.name | |
153 | write_test_header(tc_name) | |
154 | tgen = get_topogen() | |
155 | ||
156 | # Don't run this test if we have any failure. | |
157 | if tgen.routers_have_failure(): | |
158 | pytest.skip(tgen.errors) | |
159 | ||
160 | global topo | |
161 | step("Bring up the base config as per the topology") | |
162 | step("Configure area 1 as NSSA Area") | |
163 | ||
164 | reset_config_on_routers(tgen) | |
165 | ||
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) | |
169 | ||
170 | dut = "r0" | |
171 | input_dict = { | |
172 | "r1": { | |
173 | "static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N IA"}] | |
174 | } | |
175 | } | |
176 | ||
177 | dut = "r0" | |
178 | result = verify_ospf_rib(tgen, dut, input_dict) | |
179 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
180 | ||
181 | protocol = "ospf" | |
182 | result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) | |
183 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
184 | ||
185 | input_dict = { | |
186 | "r2": { | |
187 | "static_routes": [ | |
188 | {"network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0"} | |
189 | ] | |
190 | } | |
191 | } | |
192 | result = create_static_routes(tgen, input_dict) | |
193 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
194 | ||
195 | step("Redistribute static route in R2 ospf.") | |
196 | dut = "r2" | |
88b7d3e7 | 197 | redistribute_ospf(tgen, topo, dut, "static") |
4256a209 | 198 | |
199 | step("Verify that Type 5 LSA is originated by R2.") | |
200 | dut = "r0" | |
201 | protocol = "ospf" | |
202 | result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) | |
203 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
204 | ||
205 | step("Verify that R0 receives Type 4 summary LSA.") | |
206 | dut = "r0" | |
207 | input_dict = { | |
208 | "r1": { | |
209 | "static_routes": [ | |
210 | {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"} | |
211 | ] | |
212 | } | |
213 | } | |
214 | ||
215 | dut = "r1" | |
216 | result = verify_ospf_rib(tgen, dut, input_dict) | |
217 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
218 | ||
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 | ospf_covergence = verify_ospf_neighbor(tgen, topo) | |
223 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
224 | ospf_covergence | |
225 | ) | |
226 | ||
227 | step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).") | |
228 | ||
229 | for rtr in ["r1", "r2", "r3"]: | |
230 | input_dict = { | |
231 | rtr: {"ospf": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}} | |
232 | } | |
233 | result = create_router_ospf(tgen, topo, input_dict) | |
234 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
235 | tc_name, result | |
236 | ) | |
237 | ||
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.") | |
241 | ||
242 | input_dict = { | |
243 | "r1": { | |
244 | "static_routes": [ | |
245 | {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2"} | |
246 | ] | |
247 | } | |
248 | } | |
249 | ||
250 | dut = "r1" | |
251 | result = verify_ospf_rib(tgen, dut, input_dict) | |
252 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
253 | ||
254 | result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) | |
255 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
256 | ||
257 | write_test_footer(tc_name) | |
258 | ||
259 | ||
260 | if __name__ == "__main__": | |
261 | args = ["-s"] + sys.argv[1:] | |
262 | sys.exit(pytest.main(args)) |