]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
Merge pull request #12516 from mjstapp/fix_debug_dpdk
[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 daemons 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 def test_ospfv3_learning_tc15_p0(request):
410 """Verify OSPF can learn different types of LSA and processes them.
411
412 OSPF Learning : Edge learning different types of LSAs.
413 """
414 tc_name = request.node.name
415 write_test_header(tc_name)
416 tgen = get_topogen()
417
418 # Don't run this test if we have any failure.
419 if tgen.routers_have_failure():
420 check_router_status(tgen)
421
422 global topo
423 step("Bring up the base config as per the topology")
424 step("Configure area 1 as NSSA Area")
425
426 reset_config_on_routers(tgen)
427
428 step("Verify that Type 3 summary LSA is originated for the same Area 0")
429 ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
430 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
431
432 input_dict = {
433 "r1": {
434 "static_routes": [
435 {
436 "network": ip_net,
437 "no_of_ip": 1,
438 "routeType": "Network",
439 "pathtype": "Inter-Area",
440 }
441 ]
442 }
443 }
444
445 dut = "r0"
446 result = verify_ospf6_rib(tgen, dut, input_dict)
447 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
448
449 protocol = "ospf6"
450 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
451 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
452
453 input_dict = {
454 "r2": {
455 "static_routes": [
456 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
457 ]
458 }
459 }
460 result = create_static_routes(tgen, input_dict)
461 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
462
463 step("Redistribute static route in R2 ospf.")
464 dut = "r2"
465 red_static(dut)
466
467 step("Verify that Type 5 LSA is originated by R2.")
468 dut = "r0"
469 protocol = "ospf6"
470 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
471 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
472
473 input_dict = {
474 "r1": {
475 "static_routes": [
476 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
477 ]
478 }
479 }
480
481 dut = "r1"
482 result = verify_ospf6_rib(tgen, dut, input_dict)
483 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
484
485 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
486 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
487
488 result = verify_ospf6_neighbor(tgen, topo)
489 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
490
491 step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
492
493 for rtr in ["r1", "r2", "r3"]:
494 input_dict = {
495 rtr: {
496 "ospf6": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}
497 }
498 }
499 result = create_router_ospf(tgen, topo, input_dict)
500 assert result is True, "Testcase {} : Failed \n Error: {}".format(
501 tc_name, result
502 )
503
504 step("Verify that OSPF neighbours are reset after changing area type.")
505 step("Verify that ABR R2 originates type 5 LSA in area 1.")
506 step("Verify that R1 installs type 5 lsa in its database.")
507 step("Verify that route is calculated and installed in R1.")
508
509 input_dict = {
510 "r1": {
511 "static_routes": [
512 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
513 ]
514 }
515 }
516
517 dut = "r1"
518 result = verify_ospf6_rib(tgen, dut, input_dict)
519 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
520
521 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
522 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
523
524 write_test_footer(tc_name)
525
526
527 # As per internal discussion, this script has to be removed as translator
528 # function is not supported, for more details kindly check this PR 2565570
529 def ospfv3_nssa_tc27_p0(request):
530 """
531 OSPF NSSA.
532
533 Verify that ospf NSSA area DUT is capable receiving & processing
534 Type7 N2 route.
535 """
536 tc_name = request.node.name
537 write_test_header(tc_name)
538 tgen = get_topogen()
539
540 # Don't run this test if we have any failure.
541 if tgen.routers_have_failure():
542 check_router_status(tgen)
543
544 global topo
545 step("Bring up the base config as per the topology")
546 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
547
548 reset_config_on_routers(tgen)
549
550 input_dict = {
551 "r2": {
552 "static_routes": [
553 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
554 ]
555 }
556 }
557 result = create_static_routes(tgen, input_dict)
558 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
559
560 step("Redistribute static route in R2 ospf.")
561 dut = "r2"
562 red_static(dut)
563
564 step("Verify that Type 5 LSA is originated by R2.")
565 dut = "r0"
566 protocol = "ospf6"
567 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
568 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
569
570 step("Un configure redistribute command in R4")
571 dut = "r2"
572 red_static(dut, config=False)
573
574 input_dict = {
575 "r1": {
576 "static_routes": [
577 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
578 ]
579 }
580 }
581
582 dut = "r0"
583 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
584 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
585 tc_name, result
586 )
587
588 result = verify_rib(
589 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
590 )
591 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
592 tc_name, result
593 )
594
595 write_test_footer(tc_name)
596
597
598 if __name__ == "__main__":
599 args = ["-s"] + sys.argv[1:]
600 sys.exit(pytest.main(args))