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