]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
tests: [topojson] Update assert/error messages
[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 create_route_maps,
61 shutdown_bringup_interface,
62 create_interfaces_cfg,
63 check_router_status,
64 )
65 from ipaddress import IPv4Address
66 from lib.topolog import logger
67 from lib.topojson import build_config_from_json
68
69
70 # Save the Current Working Directory to find configuration files.
71 CWD = os.path.dirname(os.path.realpath(__file__))
72 sys.path.append(os.path.join(CWD, "../"))
73
74 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
75
76 # Global variables
77 topo = None
78 NETWORK = {
79 "ipv4": [
80 "11.0.20.1/32",
81 "11.0.20.2/32",
82 "11.0.20.3/32",
83 "11.0.20.4/32",
84 "11.0.20.5/32",
85 ],
86 "ipv6": [
87 "2011:0:20::1/128",
88 "2011:0:20::2/128",
89 "2011:0:20::3/128",
90 "2011:0:20::4/128",
91 "2011:0:20::5/128",
92 ],
93 }
94 """
95 TOPOOLOGY =
96 Please view in a fixed-width font such as Courier.
97 +---+ A1 +---+
98 +R1 +------------+R2 |
99 +-+-+- +--++
100 | -- -- |
101 | -- A0 -- |
102 A0| ---- |
103 | ---- | A2
104 | -- -- |
105 | -- -- |
106 +-+-+- +-+-+
107 +R0 +-------------+R3 |
108 +---+ A3 +---+
109
110
111
112 TESTCASES =
113 1. OSPF Learning - Verify OSPF can learn different types of LSA and
114 processes them.[Edge learning different types of LSAs]
115 2. Verify that ospf non back bone area can be configured as NSSA area
116 3. Verify that ospf NSSA area DUT is capable receiving & processing
117 Type7 N2 route.
118 """
119
120
121 def setup_module(mod):
122 """
123 Sets up the pytest environment
124
125 * `mod`: module name
126 """
127 global topo
128 testsuite_run_time = time.asctime(time.localtime(time.time()))
129 logger.info("Testsuite start time: {}".format(testsuite_run_time))
130 logger.info("=" * 40)
131
132 logger.info("Running setup_module to create topology")
133
134 # This function initiates the topology build with Topogen...
135 json_file = "{}/ospfv3_nssa2.json".format(CWD)
136 tgen = Topogen(json_file, mod.__name__)
137 global topo
138 topo = tgen.json_topo
139 # ... and here it calls Mininet initialization functions.
140
141 # Starting topology, create tmp files which are loaded to routers
142 # to start daemons and then start routers
143 start_topology(tgen)
144
145 # Creating configuration from JSON
146 build_config_from_json(tgen, topo)
147
148 # Don't run this test if we have any failure.
149 if tgen.routers_have_failure():
150 pytest.skip(tgen.errors)
151
152 # Api call verify whether OSPF is converged
153 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
154 assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
155 ospf_covergence
156 )
157
158 logger.info("Running setup_module() done")
159
160
161 def teardown_module():
162 """Teardown the pytest environment."""
163 logger.info("Running teardown_module to delete topology")
164
165 tgen = get_topogen()
166
167 # Stop toplogy and Remove tmp files
168 tgen.stop_topology()
169
170
171 def red_static(dut, config=True):
172 """Local def for Redstribute static routes inside ospf."""
173 global topo
174 tgen = get_topogen()
175 if config:
176 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
177 else:
178 ospf_red = {
179 dut: {
180 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
181 }
182 }
183 result = create_router_ospf(tgen, topo, ospf_red)
184 assert result is True, "Testcase : Failed \n Error: {}".format(result)
185
186
187 def red_connected(dut, config=True):
188 """Local def for Redstribute connected routes inside ospf."""
189 global topo
190 tgen = get_topogen()
191 if config:
192 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
193 else:
194 ospf_red = {
195 dut: {
196 "ospf6": {
197 "redistribute": [{"redist_type": "connected", "del_action": True}]
198 }
199 }
200 }
201 result = create_router_ospf(tgen, topo, ospf_red)
202 assert result is True, "Testcase: Failed \n Error: {}".format(result)
203
204
205 # ##################################
206 # Test cases start here.
207 # ##################################
208
209
210 def test_ospfv3_nssa_tc26_p0(request):
211 """Verify that ospf non back bone area can be configured as NSSA area"""
212 tc_name = request.node.name
213 write_test_header(tc_name)
214 tgen = get_topogen()
215
216 # Don't run this test if we have any failure.
217 if tgen.routers_have_failure():
218 check_router_status(tgen)
219
220 global topo
221 step("Bring up the base config as per the topology")
222 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
223
224 reset_config_on_routers(tgen)
225
226 input_dict = {
227 "r2": {
228 "static_routes": [
229 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
230 ]
231 }
232 }
233 result = create_static_routes(tgen, input_dict)
234 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
235
236 step("Redistribute static route in R2 ospf.")
237 dut = "r2"
238 red_static(dut)
239
240 step("Verify that Type 5 LSA is originated by R2.")
241 dut = "r0"
242 protocol = "ospf6"
243 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
244 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
245
246 step("Un configure redistribute command in R4")
247 dut = "r2"
248 red_static(dut, config=False)
249
250 input_dict = {
251 "r1": {
252 "static_routes": [
253 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
254 ]
255 }
256 }
257
258 step("Configure area 0 on interface of r2 connecting to r1")
259
260 input_dict = {
261 "r2": {
262 "links": {
263 "r1": {
264 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
265 "ospf6": {"area": "0.0.0.2"},
266 "delete": True,
267 }
268 }
269 }
270 }
271
272 result = create_interfaces_cfg(tgen, input_dict)
273 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
274
275 input_dict = {
276 "r2": {
277 "links": {
278 "r1": {
279 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
280 "ospf6": {"area": "0.0.0.0"},
281 }
282 }
283 }
284 }
285
286 result = create_interfaces_cfg(tgen, input_dict)
287 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
288
289 step("verify that ospf neighbor goes down between r2 and r1.")
290 result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
291 assert (
292 result is not True
293 ), "Testcase {} : Failed \n Nbrs are not down Error: {}".format(tc_name, result)
294
295 step("Now configure area 0 on interface of r1 connecting to r2.")
296
297 input_dict = {
298 "r1": {
299 "links": {
300 "r2": {
301 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
302 "ospf6": {"area": "0.0.0.2"},
303 "delete": True,
304 }
305 }
306 }
307 }
308
309 result = create_interfaces_cfg(tgen, input_dict)
310 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
311
312 input_dict = {
313 "r1": {
314 "links": {
315 "r2": {
316 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
317 "ospf6": {"area": "0.0.0.0"},
318 }
319 }
320 }
321 }
322
323 result = create_interfaces_cfg(tgen, input_dict)
324 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
325
326 step("Verify that ospf neighbour comes up between r2 and r1.")
327 result = verify_ospf6_neighbor(tgen, topo, dut="r2")
328 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
329
330 step("Configure area 2 on interface of r2 connecting to r1.")
331
332 input_dict = {
333 "r2": {
334 "links": {
335 "r1": {
336 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
337 "ospf6": {"area": "0.0.0.0"},
338 "delete": True,
339 }
340 }
341 }
342 }
343
344 result = create_interfaces_cfg(tgen, input_dict)
345 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
346
347 input_dict = {
348 "r2": {
349 "links": {
350 "r1": {
351 "interface": topo["routers"]["r2"]["links"]["r1"]["interface"],
352 "ospf6": {"area": "0.0.0.2"},
353 }
354 }
355 }
356 }
357
358 result = create_interfaces_cfg(tgen, input_dict)
359 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
360
361 step("verify that ospf neighbor goes down between r2 and r1.")
362 result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
363 assert (
364 result is not True
365 ), "Testcase {} : Failed \n Nbrs are not down Error: {}".format(tc_name, result)
366
367 step("Now configure area 2 on interface of r1 connecting to r2.")
368
369 input_dict = {
370 "r1": {
371 "links": {
372 "r2": {
373 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
374 "ospf6": {"area": "0.0.0.0"},
375 "delete": True,
376 }
377 }
378 }
379 }
380
381 result = create_interfaces_cfg(tgen, input_dict)
382 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
383
384 input_dict = {
385 "r1": {
386 "links": {
387 "r2": {
388 "interface": topo["routers"]["r1"]["links"]["r2"]["interface"],
389 "ospf6": {"area": "0.0.0.2"},
390 }
391 }
392 }
393 }
394
395 result = create_interfaces_cfg(tgen, input_dict)
396 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
397
398 step("Verify that ospf neighbour comes up between r2 and r1.")
399 result = verify_ospf6_neighbor(tgen, topo, dut="r2")
400 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
401
402 write_test_footer(tc_name)
403
404
405 def test_ospfv3_learning_tc15_p0(request):
406 """Verify OSPF can learn different types of LSA and processes them.
407
408 OSPF Learning : Edge learning different types of LSAs.
409 """
410 tc_name = request.node.name
411 write_test_header(tc_name)
412 tgen = get_topogen()
413
414 # Don't run this test if we have any failure.
415 if tgen.routers_have_failure():
416 check_router_status(tgen)
417
418 global topo
419 step("Bring up the base config as per the topology")
420 step("Configure area 1 as NSSA Area")
421
422 reset_config_on_routers(tgen)
423
424 step("Verify that Type 3 summary LSA is originated for the same Area 0")
425 ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
426 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
427
428 input_dict = {
429 "r1": {
430 "static_routes": [
431 {
432 "network": ip_net,
433 "no_of_ip": 1,
434 "routeType": "Network",
435 "pathtype": "Inter-Area",
436 }
437 ]
438 }
439 }
440
441 dut = "r0"
442 result = verify_ospf6_rib(tgen, dut, input_dict)
443 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
444
445 protocol = "ospf6"
446 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
447 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
448
449 input_dict = {
450 "r2": {
451 "static_routes": [
452 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
453 ]
454 }
455 }
456 result = create_static_routes(tgen, input_dict)
457 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
458
459 step("Redistribute static route in R2 ospf.")
460 dut = "r2"
461 red_static(dut)
462
463 step("Verify that Type 5 LSA is originated by R2.")
464 dut = "r0"
465 protocol = "ospf6"
466 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
467 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468
469 input_dict = {
470 "r1": {
471 "static_routes": [
472 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
473 ]
474 }
475 }
476
477 dut = "r1"
478 result = verify_ospf6_rib(tgen, dut, input_dict)
479 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
480
481 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
482 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
483
484 result = verify_ospf6_neighbor(tgen, topo)
485 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
486
487 step("Change area 1 as non nssa area (on the fly changing area type on DUT).")
488
489 for rtr in ["r1", "r2", "r3"]:
490 input_dict = {
491 rtr: {
492 "ospf6": {"area": [{"id": "0.0.0.2", "type": "nssa", "delete": True}]}
493 }
494 }
495 result = create_router_ospf(tgen, topo, input_dict)
496 assert result is True, "Testcase {} : Failed \n Error: {}".format(
497 tc_name, result
498 )
499
500 step("Verify that OSPF neighbours are reset after changing area type.")
501 step("Verify that ABR R2 originates type 5 LSA in area 1.")
502 step("Verify that R1 installs type 5 lsa in its database.")
503 step("Verify that route is calculated and installed in R1.")
504
505 input_dict = {
506 "r1": {
507 "static_routes": [
508 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
509 ]
510 }
511 }
512
513 dut = "r1"
514 result = verify_ospf6_rib(tgen, dut, input_dict)
515 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
516
517 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
518 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
519
520 write_test_footer(tc_name)
521
522
523 # As per internal discussion, this script has to be removed as translator
524 # function is not supported, for more details kindly check this PR 2565570
525 def ospfv3_nssa_tc27_p0(request):
526 """
527 OSPF NSSA.
528
529 Verify that ospf NSSA area DUT is capable receiving & processing
530 Type7 N2 route.
531 """
532 tc_name = request.node.name
533 write_test_header(tc_name)
534 tgen = get_topogen()
535
536 # Don't run this test if we have any failure.
537 if tgen.routers_have_failure():
538 check_router_status(tgen)
539
540 global topo
541 step("Bring up the base config as per the topology")
542 step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area")
543
544 reset_config_on_routers(tgen)
545
546 input_dict = {
547 "r2": {
548 "static_routes": [
549 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
550 ]
551 }
552 }
553 result = create_static_routes(tgen, input_dict)
554 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
555
556 step("Redistribute static route in R2 ospf.")
557 dut = "r2"
558 red_static(dut)
559
560 step("Verify that Type 5 LSA is originated by R2.")
561 dut = "r0"
562 protocol = "ospf6"
563 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
564 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
565
566 step("Un configure redistribute command in R4")
567 dut = "r2"
568 red_static(dut, config=False)
569
570 input_dict = {
571 "r1": {
572 "static_routes": [
573 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network"}
574 ]
575 }
576 }
577
578 dut = "r0"
579 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
580 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
581 tc_name, result
582 )
583
584 result = verify_rib(
585 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
586 )
587 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
588 tc_name, result
589 )
590
591 write_test_footer(tc_name)
592
593
594 if __name__ == "__main__":
595 args = ["-s"] + sys.argv[1:]
596 sys.exit(pytest.main(args))