]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / ospfv3_basic_functionality / test_ospfv3_routemaps.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
30 # Save the Current Working Directory to find configuration files.
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33 sys.path.append(os.path.join(CWD, "../lib/"))
34
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib.topogen import Topogen, get_topogen
38
39 # Import topoJson from lib, to create topology and initial configuration
40 from lib.common_config import (
41 start_topology,
42 write_test_header,
43 write_test_footer,
44 reset_config_on_routers,
45 create_prefix_lists,
46 verify_rib,
47 create_static_routes,
48 step,
49 create_route_maps,
50 verify_prefix_lists,
51 )
52 from lib.topolog import logger
53 from lib.topojson import build_config_from_json
54
55 from lib.ospf import (
56 verify_ospf6_neighbor,
57 verify_ospf6_rib,
58 create_router_ospf,
59 )
60
61
62 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
63
64
65 # Global variables
66 topo = None
67
68
69 NETWORK = {
70 "ipv4": [
71 "11.0.20.1/32",
72 "11.0.20.2/32",
73 "11.0.20.3/32",
74 "11.0.20.4/32",
75 "11.0.20.5/32",
76 ],
77 "ipv6": ["2::1/128", "2::2/128", "2::3/128", "2::4/128", "2::5/128"],
78 }
79
80 routerids = ["100.1.1.0", "100.1.1.1", "100.1.1.2", "100.1.1.3"]
81
82 """
83 TOPOOLOGY =
84 Please view in a fixed-width font such as Courier.
85 +---+ A1 +---+
86 +R1 +------------+R2 |
87 +-+-+- +--++
88 | -- -- |
89 | -- A0 -- |
90 A0| ---- |
91 | ---- | A2
92 | -- -- |
93 | -- -- |
94 +-+-+- +-+-+
95 +R0 +-------------+R3 |
96 +---+ A3 +---+
97
98 TESTCASES =
99 2. Verify OSPF route map support functionality when route map is not
100 configured at system level but configured in OSPF
101 4. Verify OSPF route map support functionality
102 when route map actions are toggled.
103 5. Verify OSPF route map support functionality with multiple sequence
104 numbers in a single route-map for different match/set clauses.
105 6. Verify OSPF route map support functionality when we add/remove route-maps
106 with multiple set clauses and without any match statement.(Set only)
107 7. Verify OSPF route map support functionality when we
108 add/remove route-maps with multiple match clauses and without
109 any set statement.(Match only)
110 8. Verify OSPF route map applied to ospf redistribution with ipv6 prefix list
111 """
112
113
114 def setup_module(mod):
115 """
116 Sets up the pytest environment
117
118 * `mod`: module name
119 """
120 testsuite_run_time = time.asctime(time.localtime(time.time()))
121 logger.info("Testsuite start time: {}".format(testsuite_run_time))
122 logger.info("=" * 40)
123
124 logger.info("Running setup_module to create topology")
125
126 # This function initiates the topology build with Topogen...
127 json_file = "{}/ospfv3_routemaps.json".format(CWD)
128 tgen = Topogen(json_file, mod.__name__)
129 global topo
130 topo = tgen.json_topo
131 # ... and here it calls Mininet initialization functions.
132
133 # Starting topology, create tmp files which are loaded to routers
134 # to start daemons and then start routers
135 start_topology(tgen)
136
137 # Creating configuration from JSON
138 build_config_from_json(tgen, topo)
139
140 # Don't run this test if we have any failure.
141 if tgen.routers_have_failure():
142 pytest.skip(tgen.errors)
143
144 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
145 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
146 ospf_covergence
147 )
148
149 logger.info("Running setup_module() done")
150
151
152 def teardown_module(mod):
153 """
154 Teardown the pytest environment.
155
156 * `mod`: module name
157 """
158
159 logger.info("Running teardown_module to delete topology")
160
161 tgen = get_topogen()
162
163 # Stop toplogy and Remove tmp files
164 tgen.stop_topology()
165
166 logger.info(
167 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
168 )
169 logger.info("=" * 40)
170
171
172 # ##################################
173 # Test cases start here.
174 # ##################################
175
176
177 def test_ospfv3_routemaps_functionality_tc19_p0(request):
178 """
179 OSPF Route map - Verify OSPF route map support functionality.
180
181 """
182 tc_name = request.node.name
183 write_test_header(tc_name)
184 tgen = get_topogen()
185 global topo
186 step("Bring up the base config as per the topology")
187 reset_config_on_routers(tgen)
188
189 step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
190 # Create Static routes
191 input_dict = {
192 "r0": {
193 "static_routes": [
194 {
195 "network": NETWORK["ipv6"][0],
196 "no_of_ip": 5,
197 "next_hop": "Null0",
198 }
199 ]
200 }
201 }
202 result = create_static_routes(tgen, input_dict)
203 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
204
205 ospf_red_r1 = {"r0": {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
206 result = create_router_ospf(tgen, topo, ospf_red_r1)
207 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
208
209 dut = "r1"
210 lsid = NETWORK["ipv6"][0].split("/")[0]
211 rid = routerids[0]
212
213 protocol = "ospf"
214 result = verify_ospf6_rib(tgen, dut, input_dict)
215 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
216
217 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
218 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
219
220 ospf_red_r1 = {
221 "r0": {
222 "ospf6": {"redistribute": [{"redist_type": "static", "del_action": True}]}
223 }
224 }
225 result = create_router_ospf(tgen, topo, ospf_red_r1)
226 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
227
228 step(
229 "Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32"
230 )
231
232 # Create ip prefix list
233 pfx_list = {
234 "r0": {
235 "prefix_lists": {
236 "ipv6": {
237 "pf_list_1_ipv6": [
238 {
239 "seqid": 10,
240 "network": NETWORK["ipv6"][0],
241 "action": "permit",
242 },
243 {"seqid": 11, "network": "any", "action": "deny"},
244 ]
245 }
246 }
247 }
248 }
249 result = create_prefix_lists(tgen, pfx_list)
250 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
251
252 step("verify that prefix-list is created in R0.")
253 result = verify_prefix_lists(tgen, pfx_list)
254 assert (
255 result is not True
256 ), "Testcase {} : Failed \n, prefix list creation failed. Error: {}".format(
257 tc_name, result
258 )
259
260 # Create route map
261 routemaps = {
262 "r0": {
263 "route_maps": {
264 "rmap_ipv6": [
265 {
266 "action": "permit",
267 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
268 }
269 ]
270 }
271 }
272 }
273 result = create_route_maps(tgen, routemaps)
274 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
275
276 step(
277 "Configure route map rmap1 and redistribute static routes to"
278 " ospf using route map rmap1"
279 )
280
281 ospf_red_r1 = {
282 "r0": {
283 "ospf6": {
284 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
285 }
286 }
287 }
288 result = create_router_ospf(tgen, topo, ospf_red_r1)
289 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
290 step("Verify that route map is activated in OSPF.")
291
292 step("Verify that route 10.0.20.1 is allowed and 10.0.20.2 is denied.")
293 dut = "r1"
294 input_dict = {
295 "r0": {
296 "static_routes": [
297 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "next_hop": "Null0"}
298 ]
299 }
300 }
301 result = verify_ospf6_rib(tgen, dut, input_dict)
302 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
303
304 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
305 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
306
307 dut = "r1"
308 lsid = NETWORK["ipv6"][1].split("/")[0]
309 rid = routerids[0]
310
311 step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1")
312 # Create ip prefix list
313 pfx_list = {
314 "r0": {
315 "prefix_lists": {
316 "ipv6": {
317 "pf_list_1_ipv6": [
318 {
319 "seqid": 10,
320 "network": NETWORK["ipv6"][1],
321 "action": "permit",
322 },
323 {"seqid": 11, "network": "any", "action": "deny"},
324 ]
325 }
326 }
327 }
328 }
329 result = create_prefix_lists(tgen, pfx_list)
330 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
331
332 step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.")
333 dut = "r1"
334 input_dict = {
335 "r0": {
336 "static_routes": [
337 {"network": NETWORK["ipv6"][1], "no_of_ip": 1, "next_hop": "Null0"}
338 ]
339 }
340 }
341 result = verify_ospf6_rib(tgen, dut, input_dict)
342 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
343
344 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
345 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
346
347 input_dict = {
348 "r0": {
349 "static_routes": [
350 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "next_hop": "Null0"}
351 ]
352 }
353 }
354 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
355 assert (
356 result is not True
357 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
358 tc_name, result
359 )
360
361 result = verify_rib(
362 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
363 )
364 assert (
365 result is not True
366 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
367 tc_name, result
368 )
369
370 step("Delete and reconfigure prefix list.")
371 # Create ip prefix list
372 pfx_list = {
373 "r0": {
374 "prefix_lists": {
375 "ipv6": {
376 "pf_list_1_ipv6": [
377 {
378 "seqid": 10,
379 "network": NETWORK["ipv6"][1],
380 "action": "permit",
381 "delete": True,
382 },
383 {
384 "seqid": 11,
385 "network": "any",
386 "action": "deny",
387 "delete": True,
388 },
389 ]
390 }
391 }
392 }
393 }
394 result = create_prefix_lists(tgen, pfx_list)
395 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
396
397 result = verify_prefix_lists(tgen, pfx_list)
398 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
399
400 input_dict = {
401 "r0": {
402 "static_routes": [
403 {"network": NETWORK["ipv6"][0], "no_of_ip": 5, "next_hop": "Null0"}
404 ]
405 }
406 }
407 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
408 assert (
409 result is not True
410 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
411 tc_name, result
412 )
413
414 result = verify_rib(
415 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
416 )
417 assert (
418 result is not True
419 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
420 tc_name, result
421 )
422
423 pfx_list = {
424 "r0": {
425 "prefix_lists": {
426 "ipv6": {
427 "pf_list_1_ipv6": [
428 {
429 "seqid": 10,
430 "network": NETWORK["ipv6"][1],
431 "action": "permit",
432 },
433 {"seqid": 11, "network": "any", "action": "deny"},
434 ]
435 }
436 }
437 }
438 }
439 result = create_prefix_lists(tgen, pfx_list)
440 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
441
442 step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.")
443 dut = "r1"
444 input_dict = {
445 "r0": {
446 "static_routes": [
447 {"network": NETWORK["ipv6"][1], "no_of_ip": 1, "next_hop": "Null0"}
448 ]
449 }
450 }
451 result = verify_ospf6_rib(tgen, dut, input_dict)
452 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
453
454 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
455 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
456
457 input_dict = {
458 "r0": {
459 "static_routes": [
460 {"network": NETWORK["ipv6"][0], "no_of_ip": 1, "next_hop": "Null0"}
461 ]
462 }
463 }
464 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
465 assert (
466 result is not True
467 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
468 tc_name, result
469 )
470
471 result = verify_rib(
472 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
473 )
474 assert (
475 result is not True
476 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
477 tc_name, result
478 )
479
480 write_test_footer(tc_name)
481
482
483 def test_ospfv3_routemaps_functionality_tc20_p0(request):
484 """
485 OSPF route map support functionality.
486
487 Verify OSPF route map support functionality when route map is not
488 configured at system level but configured in OSPF
489
490 """
491 tc_name = request.node.name
492 write_test_header(tc_name)
493 tgen = get_topogen()
494 global topo
495 step("Bring up the base config as per the topology")
496
497 reset_config_on_routers(tgen)
498
499 step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
500 # Create Static routes
501 input_dict = {
502 "r0": {
503 "static_routes": [
504 {
505 "network": NETWORK["ipv6"][0],
506 "no_of_ip": 5,
507 "next_hop": "Null0",
508 }
509 ]
510 }
511 }
512 result = create_static_routes(tgen, input_dict)
513 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
514
515 step("Redistribute to ospf using route map ( non existent route map)")
516 ospf_red_r1 = {
517 "r0": {
518 "ospf6": {
519 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
520 }
521 }
522 }
523 result = create_router_ospf(tgen, topo, ospf_red_r1)
524 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
525
526 step(
527 "Verify that routes are not allowed in OSPF even tough no "
528 "matching routing map is configured."
529 )
530
531 dut = "r1"
532 protocol = "ospf"
533 result = verify_ospf6_rib(tgen, dut, input_dict)
534 assert (
535 result is not True
536 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
537 tc_name, result
538 )
539
540 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
541 assert (
542 result is not True
543 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
544 tc_name, result
545 )
546
547 step(
548 "configure the route map with the same name that is used "
549 "in the ospf with deny rule."
550 )
551
552 # Create route map
553 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
554 result = create_route_maps(tgen, routemaps)
555 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
556
557 step("verify that now route map is activated & routes are denied in OSPF.")
558 dut = "r1"
559 protocol = "ospf"
560 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
561 assert (
562 result is not True
563 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
564 tc_name, result
565 )
566
567 result = verify_rib(
568 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
569 )
570 assert (
571 result is not True
572 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
573 tc_name, result
574 )
575
576 # Create route map
577 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
578 result = create_route_maps(tgen, routemaps)
579 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
580
581 step("verify that now route map is activated & routes are denied in OSPF.")
582 dut = "r1"
583 protocol = "ospf"
584 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
585 assert (
586 result is not True
587 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
588 tc_name, result
589 )
590
591 result = verify_rib(
592 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
593 )
594 assert (
595 result is not True
596 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
597 tc_name, result
598 )
599
600 step("Delete the route map.")
601 # Create route map
602 routemaps = {
603 "r0": {"route_maps": {"rmap_ipv6": [{"action": "deny", "delete": True}]}}
604 }
605 result = create_route_maps(tgen, routemaps)
606 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
607
608 step(
609 "Verify that routes are allowed in OSPF even tough "
610 "no matching routing map is configured."
611 )
612 dut = "r1"
613 protocol = "ospf"
614 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
615 assert (
616 result is not True
617 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
618 tc_name, result
619 )
620
621 result = verify_rib(
622 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
623 )
624 assert (
625 result is not True
626 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
627 tc_name, result
628 )
629
630 write_test_footer(tc_name)
631
632
633 def test_ospfv3_routemaps_functionality_tc25_p0(request):
634 """
635 OSPF route map support functionality.
636
637 Verify OSPF route map support functionality
638 when route map actions are toggled.
639
640 """
641 tc_name = request.node.name
642 write_test_header(tc_name)
643 tgen = get_topogen()
644 global topo
645 step("Bring up the base config as per the topology")
646
647 reset_config_on_routers(tgen)
648
649 step(
650 "Create static routes(10.0.20.1/32) in R1 and redistribute "
651 "to OSPF using route map."
652 )
653
654 # Create Static routes
655 input_dict = {
656 "r0": {
657 "static_routes": [
658 {
659 "network": NETWORK["ipv6"][0],
660 "no_of_ip": 5,
661 "next_hop": "Null0",
662 }
663 ]
664 }
665 }
666 result = create_static_routes(tgen, input_dict)
667 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
668
669 ospf_red_r0 = {
670 "r0": {
671 "ospf6": {
672 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
673 }
674 }
675 }
676 result = create_router_ospf(tgen, topo, ospf_red_r0)
677 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
678 step("Configure route map with permit rule")
679 # Create route map
680 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "permit"}]}}}
681 result = create_route_maps(tgen, routemaps)
682 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
683
684 step("Verify that route is advertised to R1.")
685 dut = "r1"
686 protocol = "ospf"
687 result = verify_ospf6_rib(tgen, dut, input_dict)
688 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
689
690 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
691 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
692 step("Configure route map with deny rule")
693 # Create route map
694 routemaps = {
695 "r0": {"route_maps": {"rmap_ipv6": [{"seq_id": 10, "action": "deny"}]}}
696 }
697 result = create_route_maps(tgen, routemaps)
698 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
699
700 # Api call verify whether OSPF is converged
701 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
702 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
703 ospf_covergence
704 )
705
706 step("Verify that route is not advertised to R1.")
707 dut = "r1"
708 protocol = "ospf"
709 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
710 assert (
711 result is not True
712 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
713 tc_name, result
714 )
715
716 result = verify_rib(
717 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
718 )
719 assert (
720 result is not True
721 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
722 tc_name, result
723 )
724
725 write_test_footer(tc_name)
726
727
728 def test_ospfv3_routemaps_functionality_tc22_p0(request):
729 """
730 OSPF Route map - Multiple sequence numbers.
731
732 Verify OSPF route map support functionality with multiple sequence
733 numbers in a single route-map for different match/set clauses.
734
735 """
736 tc_name = request.node.name
737 write_test_header(tc_name)
738 tgen = get_topogen()
739 global topo
740 step("Bring up the base config as per the topology")
741
742 reset_config_on_routers(tgen)
743
744 step(
745 "Configure route map with seq number 10 to with ip prefix"
746 " permitting route 10.0.20.1/32 in R1"
747 )
748 step(
749 "Configure route map with seq number 20 to with ip prefix"
750 " permitting route 10.0.20.2/32 in R1"
751 )
752
753 # Create route map
754 input_dict_3 = {
755 "r0": {
756 "route_maps": {
757 "rmap_ipv6": [
758 {
759 "action": "permit",
760 "seq_id": "10",
761 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
762 },
763 {
764 "action": "permit",
765 "seq_id": "20",
766 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv6"}},
767 },
768 ]
769 }
770 }
771 }
772 result = create_route_maps(tgen, input_dict_3)
773 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
774
775 # Create ip prefix list
776 input_dict_2 = {
777 "r0": {
778 "prefix_lists": {
779 "ipv6": {
780 "pf_list_1_ipv6": [
781 {"seqid": 10, "network": NETWORK["ipv6"][0], "action": "permit"}
782 ]
783 }
784 }
785 }
786 }
787 result = create_prefix_lists(tgen, input_dict_2)
788 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
789
790 # Create ip prefix list
791 input_dict_2 = {
792 "r0": {
793 "prefix_lists": {
794 "ipv6": {
795 "pf_list_2_ipv6": [
796 {"seqid": 10, "network": NETWORK["ipv6"][1], "action": "permit"}
797 ]
798 }
799 }
800 }
801 }
802 result = create_prefix_lists(tgen, input_dict_2)
803 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
804
805 step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1")
806 # Create Static routes
807 input_dict = {
808 "r0": {
809 "static_routes": [
810 {
811 "network": NETWORK["ipv6"][0],
812 "no_of_ip": 5,
813 "next_hop": "Null0",
814 }
815 ]
816 }
817 }
818 result = create_static_routes(tgen, input_dict)
819 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
820
821 step("Configure redistribute static route with route map.")
822 ospf_red_r0 = {
823 "r0": {
824 "ospf6": {
825 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
826 }
827 }
828 }
829 result = create_router_ospf(tgen, topo, ospf_red_r0)
830 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
831
832 input_dict = {
833 "r0": {
834 "static_routes": [
835 {
836 "network": NETWORK["ipv6"][0],
837 "no_of_ip": 2,
838 "next_hop": "Null0",
839 }
840 ]
841 }
842 }
843 result = create_static_routes(tgen, input_dict)
844 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
845
846 step("Verify that both routes are learned in R1 and R2")
847 dut = "r1"
848 protocol = "ospf"
849 result = verify_ospf6_rib(tgen, dut, input_dict)
850 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
851
852 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
853 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
854
855 dut = "r2"
856 protocol = "ospf"
857 result = verify_ospf6_rib(tgen, dut, input_dict)
858 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
859
860 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
861 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
862
863 step("Change route map with seq number 20 to deny.")
864 # Create route map
865 input_dict_3 = {
866 "r0": {
867 "route_maps": {
868 "rmap_ipv6": [
869 {
870 "action": "deny",
871 "seq_id": "20",
872 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv6"}},
873 }
874 ]
875 }
876 }
877 }
878 result = create_route_maps(tgen, input_dict_3)
879 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
880
881 step(
882 "Verify the route 10.0.20.2/32 is withdrawn and not present "
883 "in the routing table of R0 and R1."
884 )
885
886 input_dict = {
887 "r0": {"static_routes": [{"network": NETWORK["ipv6"][1], "next_hop": "Null0"}]}
888 }
889
890 dut = "r1"
891 protocol = "ospf"
892 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
893 assert (
894 result is not True
895 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
896 tc_name, result
897 )
898
899 result = verify_rib(
900 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
901 )
902 assert (
903 result is not True
904 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
905 tc_name, result
906 )
907
908 dut = "r2"
909 protocol = "ospf"
910 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
911 assert (
912 result is not True
913 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
914 tc_name, result
915 )
916
917 result = verify_rib(
918 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
919 )
920 assert (
921 result is not True
922 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
923 tc_name, result
924 )
925
926 write_test_footer(tc_name)
927
928
929 def test_ospfv3_routemaps_functionality_tc23_p0(request):
930 """
931 OSPF Route map - Multiple set clauses.
932
933 Verify OSPF route map support functionality when we add/remove route-maps
934 with multiple set clauses and without any match statement.(Set only)
935
936 """
937 tc_name = request.node.name
938 write_test_header(tc_name)
939 tgen = get_topogen()
940 global topo
941 step("Bring up the base config as per the topology")
942
943 reset_config_on_routers(tgen)
944
945 step(
946 " Create static routes(10.0.20.1/32) in R1 and "
947 "redistribute to OSPF using route map."
948 )
949 # Create Static routes
950 input_dict = {
951 "r0": {
952 "static_routes": [
953 {
954 "network": NETWORK["ipv6"][0],
955 "no_of_ip": 5,
956 "next_hop": "Null0",
957 }
958 ]
959 }
960 }
961 result = create_static_routes(tgen, input_dict)
962 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
963
964 ospf_red_r0 = {
965 "r0": {
966 "ospf6": {
967 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
968 }
969 }
970 }
971 result = create_router_ospf(tgen, topo, ospf_red_r0)
972 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
973
974 step("Configure route map with set clause (set metric)")
975 # Create route map
976 routemaps = {
977 "r0": {
978 "route_maps": {
979 "rmap_ipv6": [
980 {"action": "permit", "seq_id": 10, "set": {"metric": 123}}
981 ]
982 }
983 }
984 }
985 result = create_route_maps(tgen, routemaps)
986 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
987
988 step("Verify that configured metric is applied to ospf routes.")
989 dut = "r1"
990 protocol = "ospf"
991
992 result = verify_ospf6_rib(tgen, dut, input_dict, metric=123)
993 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
994
995 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, metric=123)
996 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
997
998 step("un configure the set clause")
999 # Create route map
1000 routemaps = {
1001 "r0": {
1002 "route_maps": {
1003 "rmap_ipv6": [
1004 {
1005 "action": "permit",
1006 "seq_id": 10,
1007 "set": {"metric": 123, "delete": True},
1008 }
1009 ]
1010 }
1011 }
1012 }
1013 result = create_route_maps(tgen, routemaps)
1014 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1015
1016 step("Verify that metric falls back to original metric for ospf routes.")
1017 dut = "r1"
1018 protocol = "ospf"
1019
1020 result = verify_ospf6_rib(tgen, dut, input_dict, metric=20)
1021 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1022
1023 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, metric=20)
1024 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1025
1026 write_test_footer(tc_name)
1027
1028
1029 def test_ospfv3_routemaps_functionality_tc24_p0(request):
1030 """
1031 OSPF Route map - Multiple set clauses.
1032
1033 Verify OSPF route map support functionality when we
1034 add/remove route-maps with multiple match clauses and without
1035 any set statement.(Match only)
1036
1037 """
1038 tc_name = request.node.name
1039 write_test_header(tc_name)
1040 tgen = get_topogen()
1041 global topo
1042 step("Bring up the base config as per the topology")
1043
1044 reset_config_on_routers(tgen)
1045
1046 step(
1047 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
1048 "OSPF using route map."
1049 )
1050 # Create Static routes
1051 input_dict = {
1052 "r0": {
1053 "static_routes": [
1054 {
1055 "network": NETWORK["ipv6"][0],
1056 "no_of_ip": 1,
1057 "next_hop": "Null0",
1058 }
1059 ]
1060 }
1061 }
1062 result = create_static_routes(tgen, input_dict)
1063 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1064
1065 ospf_red_r0 = {
1066 "r0": {
1067 "ospf6": {
1068 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
1069 }
1070 }
1071 }
1072 result = create_router_ospf(tgen, topo, ospf_red_r0)
1073 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1074
1075 # Create ip prefix list
1076 pfx_list = {
1077 "r0": {
1078 "prefix_lists": {
1079 "ipv6": {
1080 "pf_list_1_ipv6": [
1081 {"seqid": 10, "network": "any", "action": "permit"}
1082 ]
1083 }
1084 }
1085 }
1086 }
1087 result = create_prefix_lists(tgen, pfx_list)
1088 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1089
1090 step("verify that prefix-list is created in R0.")
1091 result = verify_prefix_lists(tgen, pfx_list)
1092 assert (
1093 result is not True
1094 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
1095 tc_name, result
1096 )
1097
1098 # Create route map
1099 routemaps = {
1100 "r0": {
1101 "route_maps": {
1102 "rmap_ipv6": [
1103 {
1104 "action": "permit",
1105 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
1106 }
1107 ]
1108 }
1109 }
1110 }
1111 result = create_route_maps(tgen, routemaps)
1112 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1113
1114 step("Verify that metric falls back to original metric for ospf routes.")
1115 dut = "r1"
1116 protocol = "ospf"
1117
1118 result = verify_ospf6_rib(tgen, dut, input_dict)
1119 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1120
1121 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
1122 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1123
1124 step(
1125 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
1126 "OSPF using route map."
1127 )
1128 # Create Static routes
1129 input_dict = {
1130 "r0": {
1131 "static_routes": [
1132 {
1133 "network": NETWORK["ipv6"][1],
1134 "no_of_ip": 1,
1135 "next_hop": "Null0",
1136 "tag": 1000,
1137 }
1138 ]
1139 }
1140 }
1141 result = create_static_routes(tgen, input_dict)
1142 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1143
1144 # Create ip prefix list
1145 pfx_list = {
1146 "r0": {
1147 "prefix_lists": {
1148 "ipv6": {
1149 "pf_list_1_ipv6": [
1150 {"seqid": 10, "network": "any", "action": "permit"}
1151 ]
1152 }
1153 }
1154 }
1155 }
1156 result = create_prefix_lists(tgen, pfx_list)
1157 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1158
1159 step("verify that prefix-list is created in R0.")
1160 result = verify_prefix_lists(tgen, pfx_list)
1161 assert (
1162 result is not True
1163 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
1164 tc_name, result
1165 )
1166
1167 # Create route map
1168 routemaps = {
1169 "r0": {
1170 "route_maps": {
1171 "rmap_ipv6": [{"action": "permit", "match": {"ipv6": {"tag": "1000"}}}]
1172 }
1173 }
1174 }
1175 result = create_route_maps(tgen, routemaps)
1176 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1177
1178 step("Verify that metric falls back to original metric for ospf routes.")
1179 dut = "r1"
1180 protocol = "ospf"
1181
1182 result = verify_ospf6_rib(tgen, dut, input_dict)
1183 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1184
1185 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
1186 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1187
1188 step("Delete the match clause with tag in route map")
1189 # Create route map
1190 routemaps = {
1191 "r0": {
1192 "route_maps": {
1193 "rmap_ipv6": [
1194 {
1195 "action": "permit",
1196 "match": {"ipv6": {"tag": "1000", "delete": True}},
1197 }
1198 ]
1199 }
1200 }
1201 }
1202 result = create_route_maps(tgen, routemaps)
1203 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1204
1205 step("Verify that metric falls back to original metric for ospf routes.")
1206 dut = "r1"
1207 protocol = "ospf"
1208
1209 result = verify_ospf6_rib(tgen, dut, input_dict)
1210 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1211
1212 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
1213 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1214
1215 step("Delete the match clause with metric in route map.")
1216
1217 # Create route map
1218 routemaps = {
1219 "r0": {
1220 "route_maps": {
1221 "rmap_ipv6": [
1222 {
1223 "action": "permit",
1224 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
1225 }
1226 ]
1227 }
1228 }
1229 }
1230 result = create_route_maps(tgen, routemaps)
1231 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1232
1233 result = verify_ospf6_rib(tgen, dut, input_dict)
1234 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1235
1236 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
1237 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1238
1239 write_test_footer(tc_name)
1240
1241
1242 if __name__ == "__main__":
1243 args = ["-s"] + sys.argv[1:]
1244 sys.exit(pytest.main(args))