]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
Merge pull request #10803 from anlancs/bgpd-remove-dead-l2vpn
[mirror_frr.git] / tests / topotests / ospfv3_basic_functionality / test_ospfv3_nssa2.py
1 #!/usr/bin/python
2
3 #
4 # Copyright (c) 2021 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 os
26 import sys
27 import time
28 import pytest
29 from copy import deepcopy
30 import ipaddress
31 from lib.ospf import (
32 verify_ospf6_neighbor,
33 config_ospf6_interface,
34 clear_ospf,
35 verify_ospf6_rib,
36 verify_ospf6_interface,
37 verify_ospf6_database,
38 create_router_ospf,
39 )
40
41 # pylint: disable=C0413
42 # Import topogen and topotest helpers
43 from lib.topogen import Topogen, get_topogen
44
45 from lib.bgp import (
46 verify_bgp_convergence,
47 create_router_bgp,
48 clear_bgp_and_verify,
49 verify_bgp_rib,
50 )
51 from lib.topolog import logger
52 from lib.common_config import (
53 start_topology,
54 write_test_header,
55 write_test_footer,
56 reset_config_on_routers,
57 verify_rib,
58 create_static_routes,
59 step,
60 topo_daemons,
61 create_route_maps,
62 shutdown_bringup_interface,
63 create_interfaces_cfg,
64 check_router_status,
65 )
66 from ipaddress import IPv4Address
67 from lib.topolog import logger
68 from lib.topojson import build_config_from_json
69
70
71 # Save the Current Working Directory to find configuration files.
72 CWD = os.path.dirname(os.path.realpath(__file__))
73 sys.path.append(os.path.join(CWD, "../"))
74
75 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
76
77 # Global variables
78 topo = None
79 NETWORK = {
80 "ipv4": [
81 "11.0.20.1/32",
82 "11.0.20.2/32",
83 "11.0.20.3/32",
84 "11.0.20.4/32",
85 "11.0.20.5/32",
86 ],
87 "ipv6": [
88 "2011:0:20::1/128",
89 "2011:0:20::2/128",
90 "2011:0:20::3/128",
91 "2011:0:20::4/128",
92 "2011:0:20::5/128",
93 ],
94 }
95 """
96 TOPOOLOGY =
97 Please view in a fixed-width font such as Courier.
98 +---+ A1 +---+
99 +R1 +------------+R2 |
100 +-+-+- +--++
101 | -- -- |
102 | -- A0 -- |
103 A0| ---- |
104 | ---- | A2
105 | -- -- |
106 | -- -- |
107 +-+-+- +-+-+
108 +R0 +-------------+R3 |
109 +---+ A3 +---+
110
111
112
113 TESTCASES =
114 1. OSPF Learning - Verify OSPF can learn different types of LSA and
115 processes them.[Edge learning different types of LSAs]
116 2. Verify that ospf non back bone area can be configured as NSSA area
117 3. Verify that ospf NSSA area DUT is capable receiving & processing
118 Type7 N2 route.
119 """
120
121
122 def setup_module(mod):
123 """
124 Sets up the pytest environment
125
126 * `mod`: module name
127 """
128 global topo
129 testsuite_run_time = time.asctime(time.localtime(time.time()))
130 logger.info("Testsuite start time: {}".format(testsuite_run_time))
131 logger.info("=" * 40)
132
133 logger.info("Running setup_module to create topology")
134
135 # This function initiates the topology build with Topogen...
136 json_file = "{}/ospfv3_nssa2.json".format(CWD)
137 tgen = Topogen(json_file, mod.__name__)
138 global topo
139 topo = tgen.json_topo
140 # ... and here it calls Mininet initialization functions.
141
142 # get list of daemons needs to be started for this suite.
143 daemons = topo_daemons(tgen, topo)
144
145 # Starting topology, create tmp files which are loaded to routers
146 # to start deamons and then start routers
147 start_topology(tgen, daemons)
148
149 # Creating configuration from JSON
150 build_config_from_json(tgen, topo)
151
152 # Don't run this test if we have any failure.
153 if tgen.routers_have_failure():
154 pytest.skip(tgen.errors)
155
156 # Api call verify whether OSPF is converged
157 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
158 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
159 ospf_covergence
160 )
161
162 logger.info("Running setup_module() done")
163
164
165 def teardown_module():
166 """Teardown the pytest environment."""
167 logger.info("Running teardown_module to delete topology")
168
169 tgen = get_topogen()
170
171 # Stop toplogy and Remove tmp files
172 tgen.stop_topology()
173
174
175 def red_static(dut, config=True):
176 """Local def for Redstribute static routes inside ospf."""
177 global topo
178 tgen = get_topogen()
179 if config:
180 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
181 else:
182 ospf_red = {
183 dut: {
184 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
185 }
186 }
187 result = create_router_ospf(tgen, topo, ospf_red)
188 assert result is True, "Testcase : Failed \n Error: {}".format(result)
189
190
191 def red_connected(dut, config=True):
192 """Local def for Redstribute connected routes inside ospf."""
193 global topo
194 tgen = get_topogen()
195 if config:
196 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
197 else:
198 ospf_red = {
199 dut: {
200 "ospf6": {
201 "redistribute": [{"redist_type": "connected", "del_action": True}]
202 }
203 }
204 }
205 result = create_router_ospf(tgen, topo, ospf_red)
206 assert result is True, "Testcase: Failed \n Error: {}".format(result)
207
208
209 # ##################################
210 # Test cases start here.
211 # ##################################
212
213
214 def test_ospfv3_nssa_tc26_p0(request):
215 """Verify that ospf non back bone area can be configured as NSSA area"""
216 tc_name = request.node.name
217 write_test_header(tc_name)
218 tgen = get_topogen()
219
220 # Don't run this test if we have any failure.
221 if tgen.routers_have_failure():
222 check_router_status(tgen)
223
224 global topo
225 step("Bring up the base config as per the topology")
226 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
227
228 reset_config_on_routers(tgen)
229
230 input_dict = {
231 "r2": {
232 "static_routes": [
233 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
234 ]
235 }
236 }
237 result = create_static_routes(tgen, input_dict)
238 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
239
240 step("Redistribute static route in R2 ospf.")
241 dut = "r2"
242 red_static(dut)
243
244 step("Verify that Type 5 LSA is originated by R2.")
245 dut = "r0"
246 protocol = "ospf6"
247 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
248 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
249
250 step("Un configure redistribute command in R4")
251 dut = "r2"
252 red_static(dut, config=False)
253
254 input_dict = {
255 "r1": {
256 "static_routes": [
257 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
258 ]
259 }
260 }
261
262 step("Configure area 0 on interface of r2 connecting to r1")
263
264 input_dict = {
265 "r2": {
266 "links": {
267 "r1": {
268 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
269 "ospf6": {"area": "0.0.0.2"},
270 "delete": True,
271 }
272 }
273 }
274 }
275
276 result = create_interfaces_cfg(tgen, input_dict)
277 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
278
279 input_dict = {
280 "r2": {
281 "links": {
282 "r1": {
283 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
284 "ospf6": {"area": "0.0.0.0"},
285 }
286 }
287 }
288 }
289
290 result = create_interfaces_cfg(tgen, input_dict)
291 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
292
293 step("verify that ospf neighbor goes down between r2 and r1.")
294 result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
295 assert (
296 result is not True
297 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name, result)
298
299 step("Now configure area 0 on interface of r1 connecting to r2.")
300
301 input_dict = {
302 "r1": {
303 "links": {
304 "r2": {
305 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
306 "ospf6": {"area": "0.0.0.2"},
307 "delete": True,
308 }
309 }
310 }
311 }
312
313 result = create_interfaces_cfg(tgen, input_dict)
314 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
315
316 input_dict = {
317 "r1": {
318 "links": {
319 "r2": {
320 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
321 "ospf6": {"area": "0.0.0.0"},
322 }
323 }
324 }
325 }
326
327 result = create_interfaces_cfg(tgen, input_dict)
328 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
329
330 step("Verify that ospf neighbour comes up between r2 and r1.")
331 result = verify_ospf6_neighbor(tgen, topo, dut="r2")
332 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
333
334 step("Configure area 2 on interface of r2 connecting to r1.")
335
336 input_dict = {
337 "r2": {
338 "links": {
339 "r1": {
340 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
341 "ospf6": {"area": "0.0.0.0"},
342 "delete": True,
343 }
344 }
345 }
346 }
347
348 result = create_interfaces_cfg(tgen, input_dict)
349 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
350
351 input_dict = {
352 "r2": {
353 "links": {
354 "r1": {
355 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
356 "ospf6": {"area": "0.0.0.2"},
357 }
358 }
359 }
360 }
361
362 result = create_interfaces_cfg(tgen, input_dict)
363 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
364
365 step("verify that ospf neighbor goes down between r2 and r1.")
366 result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
367 assert (
368 result is not True
369 ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name, result)
370
371 step("Now configure area 2 on interface of r1 connecting to r2.")
372
373 input_dict = {
374 "r1": {
375 "links": {
376 "r2": {
377 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
378 "ospf6": {"area": "0.0.0.0"},
379 "delete": True,
380 }
381 }
382 }
383 }
384
385 result = create_interfaces_cfg(tgen, input_dict)
386 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
387
388 input_dict = {
389 "r1": {
390 "links": {
391 "r2": {
392 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
393 "ospf6": {"area": "0.0.0.2"},
394 }
395 }
396 }
397 }
398
399 result = create_interfaces_cfg(tgen, input_dict)
400 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
401
402 step("Verify that ospf neighbour comes up between r2 and r1.")
403 result = verify_ospf6_neighbor(tgen, topo, dut="r2")
404 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
405
406 write_test_footer(tc_name)
407
408
409 # As per internal discussion, this script has to be removed as translator
410 # function is not supported, for more details kindly check this PR 2565570
411 def ospfv3_nssa_tc27_p0(request):
412 """
413 OSPF NSSA.
414
415 Verify that ospf NSSA area DUT is capable receiving & processing
416 Type7 N2 route.
417 """
418 tc_name = request.node.name
419 write_test_header(tc_name)
420 tgen = get_topogen()
421
422 # Don't run this test if we have any failure.
423 if tgen.routers_have_failure():
424 check_router_status(tgen)
425
426 global topo
427 step("Bring up the base config as per the topology")
428 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
429
430 reset_config_on_routers(tgen)
431
432 input_dict = {
433 "r2": {
434 "static_routes": [
435 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
436 ]
437 }
438 }
439 result = create_static_routes(tgen, input_dict)
440 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
441
442 step("Redistribute static route in R2 ospf.")
443 dut = "r2"
444 red_static(dut)
445
446 step("Verify that Type 5 LSA is originated by R2.")
447 dut = "r0"
448 protocol = "ospf6"
449 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
450 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
451
452 step("Un configure redistribute command in R4")
453 dut = "r2"
454 red_static(dut, config=False)
455
456 input_dict = {
457 "r1": {
458 "static_routes": [
459 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
460 ]
461 }
462 }
463
464 dut = "r0"
465 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
466 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
467 tc_name, result
468 )
469
470 result = verify_rib(
471 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
472 )
473 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
474 tc_name, result
475 )
476
477 write_test_footer(tc_name)
478
479
480 if __name__ == "__main__":
481 args = ["-s"] + sys.argv[1:]
482 sys.exit(pytest.main(args))