]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
tests: micronet: adapt tests
[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 import json
30 from copy import deepcopy
31 from ipaddress import IPv4Address
32 from lib.topotest import frr_unicode
33
34 # Save the Current Working Directory to find configuration files.
35 CWD = os.path.dirname(os.path.realpath(__file__))
36 sys.path.append(os.path.join(CWD, "../"))
37 sys.path.append(os.path.join(CWD, "../lib/"))
38
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib.topogen import Topogen, get_topogen
42 import ipaddress
43
44 # Import topoJson from lib, to create topology and initial configuration
45 from lib.common_config import (
46 start_topology,
47 write_test_header,
48 write_test_footer,
49 reset_config_on_routers,
50 create_prefix_lists,
51 verify_rib,
52 create_static_routes,
53 step,
54 create_route_maps,
55 verify_prefix_lists,
56 get_frr_ipv6_linklocal,
57 topo_daemons,
58 )
59 from lib.topolog import logger
60 from lib.topojson import build_topo_from_json, build_config_from_json
61
62 from lib.ospf import (
63 verify_ospf6_neighbor,
64 config_ospf_interface,
65 clear_ospf,
66 verify_ospf6_rib,
67 create_router_ospf,
68 verify_ospf6_interface,
69 verify_ospf6_database,
70 config_ospf6_interface,
71 )
72
73 from ipaddress import IPv6Address
74
75 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
76
77
78 # Global variables
79 topo = None
80
81 # Reading the data from JSON File for topology creation
82 jsonFile = "{}/ospfv3_routemaps.json".format(CWD)
83 try:
84 with open(jsonFile, "r") as topoJson:
85 topo = json.load(topoJson)
86 except IOError:
87 assert False, "Could not read file {}".format(jsonFile)
88
89 NETWORK = {
90 "ipv4": [
91 "11.0.20.1/32",
92 "11.0.20.2/32",
93 "11.0.20.3/32",
94 "11.0.20.4/32",
95 "11.0.20.5/32",
96 ],
97 "ipv6": ["2::1/128", "2::2/128", "2::3/128", "2::4/128", "2::5/128"],
98 }
99
100 routerids = ["100.1.1.0", "100.1.1.1", "100.1.1.2", "100.1.1.3"]
101
102 """
103 TOPOOLOGY =
104 Please view in a fixed-width font such as Courier.
105 +---+ A1 +---+
106 +R1 +------------+R2 |
107 +-+-+- +--++
108 | -- -- |
109 | -- A0 -- |
110 A0| ---- |
111 | ---- | A2
112 | -- -- |
113 | -- -- |
114 +-+-+- +-+-+
115 +R0 +-------------+R3 |
116 +---+ A3 +---+
117
118 TESTCASES =
119 2. Verify OSPF route map support functionality when route map is not
120 configured at system level but configured in OSPF
121 4. Verify OSPF route map support functionality
122 when route map actions are toggled.
123 5. Verify OSPF route map support functionality with multiple sequence
124 numbers in a single route-map for different match/set clauses.
125 6. Verify OSPF route map support functionality when we add/remove route-maps
126 with multiple set clauses and without any match statement.(Set only)
127 7. Verify OSPF route map support functionality when we
128 add/remove route-maps with multiple match clauses and without
129 any set statement.(Match only)
130 8. Verify OSPF route map applied to ospf redistribution with ipv6 prefix list
131 """
132
133
134 class CreateTopo(Topo):
135 """
136 Test topology builder.
137
138 * `Topo`: Topology object
139 """
140
141 def build(self, *_args, **_opts):
142 """Build function."""
143 tgen = get_topogen(self)
144
145 # Building topology from json file
146 build_topo_from_json(tgen, topo)
147
148
149 def setup_module(mod):
150 """
151 Sets up the pytest environment
152
153 * `mod`: module name
154 """
155 global topo
156 testsuite_run_time = time.asctime(time.localtime(time.time()))
157 logger.info("Testsuite start time: {}".format(testsuite_run_time))
158 logger.info("=" * 40)
159
160 logger.info("Running setup_module to create topology")
161
162 # This function initiates the topology build with Topogen...
163 tgen = Topogen(CreateTopo, mod.__name__)
164 # ... and here it calls Mininet initialization functions.
165
166 # get list of daemons needs to be started for this suite.
167 daemons = topo_daemons(tgen, topo)
168
169 # Starting topology, create tmp files which are loaded to routers
170 # to start deamons and then start routers
171 start_topology(tgen, daemons)
172
173 # Creating configuration from JSON
174 build_config_from_json(tgen, topo)
175
176 # Don't run this test if we have any failure.
177 if tgen.routers_have_failure():
178 pytest.skip(tgen.errors)
179
180 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
181 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
182 ospf_covergence
183 )
184
185 logger.info("Running setup_module() done")
186
187
188 def teardown_module(mod):
189 """
190 Teardown the pytest environment.
191
192 * `mod`: module name
193 """
194
195 logger.info("Running teardown_module to delete topology")
196
197 tgen = get_topogen()
198
199 # Stop toplogy and Remove tmp files
200 tgen.stop_topology()
201
202 logger.info(
203 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
204 )
205 logger.info("=" * 40)
206
207
208 # ##################################
209 # Test cases start here.
210 # ##################################
211
212
213 def test_ospfv3_routemaps_functionality_tc20_p0(request):
214 """
215 OSPF route map support functionality.
216
217 Verify OSPF route map support functionality when route map is not
218 configured at system level but configured in OSPF
219
220 """
221 tc_name = request.node.name
222 write_test_header(tc_name)
223 tgen = get_topogen()
224 global topo
225 step("Bring up the base config as per the topology")
226
227 reset_config_on_routers(tgen)
228
229 step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
230 # Create Static routes
231 input_dict = {
232 "r0": {
233 "static_routes": [
234 {
235 "network": NETWORK["ipv6"][0],
236 "no_of_ip": 5,
237 "next_hop": "Null0",
238 }
239 ]
240 }
241 }
242 result = create_static_routes(tgen, input_dict)
243 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
244
245 step("Redistribute to ospf using route map ( non existent route map)")
246 ospf_red_r1 = {
247 "r0": {
248 "ospf6": {
249 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
250 }
251 }
252 }
253 result = create_router_ospf(tgen, topo, ospf_red_r1)
254 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
255
256 step(
257 "Verify that routes are not allowed in OSPF even tough no "
258 "matching routing map is configured."
259 )
260
261 dut = "r1"
262 protocol = "ospf"
263 result = verify_ospf6_rib(tgen, dut, input_dict)
264 assert (
265 result is not True
266 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
267 tc_name, result
268 )
269
270 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
271 assert (
272 result is not True
273 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
274 tc_name, result
275 )
276
277 step(
278 "configure the route map with the same name that is used "
279 "in the ospf with deny rule."
280 )
281
282 # Create route map
283 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
284 result = create_route_maps(tgen, routemaps)
285 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
286
287 step("verify that now route map is activated & routes are denied in OSPF.")
288 dut = "r1"
289 protocol = "ospf"
290 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
291 assert (
292 result is not True
293 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
294 tc_name, result
295 )
296
297 result = verify_rib(
298 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
299 )
300 assert (
301 result is not True
302 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
303 tc_name, result
304 )
305
306 # Create route map
307 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
308 result = create_route_maps(tgen, routemaps)
309 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
310
311 step("verify that now route map is activated & routes are denied in OSPF.")
312 dut = "r1"
313 protocol = "ospf"
314 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
315 assert (
316 result is not True
317 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
318 tc_name, result
319 )
320
321 result = verify_rib(
322 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
323 )
324 assert (
325 result is not True
326 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
327 tc_name, result
328 )
329
330 step("Delete the route map.")
331 # Create route map
332 routemaps = {
333 "r0": {"route_maps": {"rmap_ipv6": [{"action": "deny", "delete": True}]}}
334 }
335 result = create_route_maps(tgen, routemaps)
336 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
337
338 step(
339 "Verify that routes are allowed in OSPF even tough "
340 "no matching routing map is configured."
341 )
342 dut = "r1"
343 protocol = "ospf"
344 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
345 assert (
346 result is not True
347 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
348 tc_name, result
349 )
350
351 result = verify_rib(
352 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
353 )
354 assert (
355 result is not True
356 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
357 tc_name, result
358 )
359
360 write_test_footer(tc_name)
361
362
363 def test_ospfv3_routemaps_functionality_tc25_p0(request):
364 """
365 OSPF route map support functionality.
366
367 Verify OSPF route map support functionality
368 when route map actions are toggled.
369
370 """
371 tc_name = request.node.name
372 write_test_header(tc_name)
373 tgen = get_topogen()
374 global topo
375 step("Bring up the base config as per the topology")
376
377 reset_config_on_routers(tgen)
378
379 step(
380 "Create static routes(10.0.20.1/32) in R1 and redistribute "
381 "to OSPF using route map."
382 )
383
384 # Create Static routes
385 input_dict = {
386 "r0": {
387 "static_routes": [
388 {
389 "network": NETWORK["ipv6"][0],
390 "no_of_ip": 5,
391 "next_hop": "Null0",
392 }
393 ]
394 }
395 }
396 result = create_static_routes(tgen, input_dict)
397 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
398
399 ospf_red_r0 = {
400 "r0": {
401 "ospf6": {
402 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
403 }
404 }
405 }
406 result = create_router_ospf(tgen, topo, ospf_red_r0)
407 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
408 step("Configure route map with permit rule")
409 # Create route map
410 routemaps = {"r0": {"route_maps": {"rmap_ipv6": [{"action": "permit"}]}}}
411 result = create_route_maps(tgen, routemaps)
412 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
413
414 step("Verify that route is advertised to R1.")
415 dut = "r1"
416 protocol = "ospf"
417 result = verify_ospf6_rib(tgen, dut, input_dict)
418 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
419
420 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
421 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
422 step("Configure route map with deny rule")
423 # Create route map
424 routemaps = {
425 "r0": {"route_maps": {"rmap_ipv6": [{"seq_id": 10, "action": "deny"}]}}
426 }
427 result = create_route_maps(tgen, routemaps)
428 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
429
430 # Api call verify whether OSPF is converged
431 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
432 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
433 ospf_covergence
434 )
435
436 step("Verify that route is not advertised to R1.")
437 dut = "r1"
438 protocol = "ospf"
439 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
440 assert (
441 result is not True
442 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
443 tc_name, result
444 )
445
446 result = verify_rib(
447 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
448 )
449 assert (
450 result is not True
451 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
452 tc_name, result
453 )
454
455 write_test_footer(tc_name)
456
457
458 def test_ospfv3_routemaps_functionality_tc22_p0(request):
459 """
460 OSPF Route map - Multiple sequence numbers.
461
462 Verify OSPF route map support functionality with multiple sequence
463 numbers in a single route-map for different match/set clauses.
464
465 """
466 tc_name = request.node.name
467 write_test_header(tc_name)
468 tgen = get_topogen()
469 global topo
470 step("Bring up the base config as per the topology")
471
472 reset_config_on_routers(tgen)
473
474 step(
475 "Configure route map with seq number 10 to with ip prefix"
476 " permitting route 10.0.20.1/32 in R1"
477 )
478 step(
479 "Configure route map with seq number 20 to with ip prefix"
480 " permitting route 10.0.20.2/32 in R1"
481 )
482
483 # Create route map
484 input_dict_3 = {
485 "r0": {
486 "route_maps": {
487 "rmap_ipv6": [
488 {
489 "action": "permit",
490 "seq_id": "10",
491 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
492 },
493 {
494 "action": "permit",
495 "seq_id": "20",
496 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
497 },
498 ]
499 }
500 }
501 }
502 result = create_route_maps(tgen, input_dict_3)
503 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
504
505 # Create ip prefix list
506 input_dict_2 = {
507 "r0": {
508 "prefix_lists": {
509 "ipv4": {
510 "pf_list_1_ipv6": [
511 {"seqid": 10, "network": NETWORK["ipv6"][0], "action": "permit"}
512 ]
513 }
514 }
515 }
516 }
517 result = create_prefix_lists(tgen, input_dict_2)
518 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
519
520 # Create ip prefix list
521 input_dict_2 = {
522 "r0": {
523 "prefix_lists": {
524 "ipv4": {
525 "pf_list_2_ipv4": [
526 {"seqid": 10, "network": NETWORK["ipv6"][1], "action": "permit"}
527 ]
528 }
529 }
530 }
531 }
532 result = create_prefix_lists(tgen, input_dict_2)
533 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
534
535 step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1")
536 # Create Static routes
537 input_dict = {
538 "r0": {
539 "static_routes": [
540 {
541 "network": NETWORK["ipv6"][0],
542 "no_of_ip": 5,
543 "next_hop": "Null0",
544 }
545 ]
546 }
547 }
548 result = create_static_routes(tgen, input_dict)
549 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
550
551 step("Configure redistribute static route with route map.")
552 ospf_red_r0 = {
553 "r0": {
554 "ospf6": {
555 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
556 }
557 }
558 }
559 result = create_router_ospf(tgen, topo, ospf_red_r0)
560 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
561
562 input_dict = {
563 "r0": {
564 "static_routes": [
565 {
566 "network": NETWORK["ipv6"][0],
567 "no_of_ip": 2,
568 "next_hop": "Null0",
569 }
570 ]
571 }
572 }
573 result = create_static_routes(tgen, input_dict)
574 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
575
576 step("Verify that both routes are learned in R1 and R2")
577 dut = "r1"
578 protocol = "ospf"
579 result = verify_ospf6_rib(tgen, dut, input_dict)
580 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
581
582 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
583 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
584
585 dut = "r2"
586 protocol = "ospf"
587 result = verify_ospf6_rib(tgen, dut, input_dict)
588 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
589
590 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
591 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
592
593 step("Change route map with seq number 20 to deny.")
594 # Create route map
595 input_dict_3 = {
596 "r0": {
597 "route_maps": {
598 "rmap_ipv6": [
599 {
600 "action": "deny",
601 "seq_id": "20",
602 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
603 }
604 ]
605 }
606 }
607 }
608 result = create_route_maps(tgen, input_dict_3)
609 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
610
611 step(
612 "Verify the route 10.0.20.2/32 is withdrawn and not present "
613 "in the routing table of R0 and R1."
614 )
615
616 input_dict = {
617 "r0": {"static_routes": [{"network": NETWORK["ipv6"][1], "next_hop": "Null0"}]}
618 }
619
620 dut = "r1"
621 protocol = "ospf"
622 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
623 assert (
624 result is not True
625 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
626 tc_name, result
627 )
628
629 result = verify_rib(
630 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
631 )
632 assert (
633 result is not True
634 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
635 tc_name, result
636 )
637
638 dut = "r2"
639 protocol = "ospf"
640 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
641 assert (
642 result is not True
643 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
644 tc_name, result
645 )
646
647 result = verify_rib(
648 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
649 )
650 assert (
651 result is not True
652 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
653 tc_name, result
654 )
655
656 write_test_footer(tc_name)
657
658
659 def test_ospfv3_routemaps_functionality_tc24_p0(request):
660 """
661 OSPF Route map - Multiple set clauses.
662
663 Verify OSPF route map support functionality when we
664 add/remove route-maps with multiple match clauses and without
665 any set statement.(Match only)
666
667 """
668 tc_name = request.node.name
669 write_test_header(tc_name)
670 tgen = get_topogen()
671 global topo
672 step("Bring up the base config as per the topology")
673
674 reset_config_on_routers(tgen)
675
676 step(
677 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
678 "OSPF using route map."
679 )
680 # Create Static routes
681 input_dict = {
682 "r0": {
683 "static_routes": [
684 {
685 "network": NETWORK["ipv6"][0],
686 "no_of_ip": 1,
687 "next_hop": "Null0",
688 }
689 ]
690 }
691 }
692 result = create_static_routes(tgen, input_dict)
693 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
694
695 ospf_red_r0 = {
696 "r0": {
697 "ospf6": {
698 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
699 }
700 }
701 }
702 result = create_router_ospf(tgen, topo, ospf_red_r0)
703 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
704
705 # Create ip prefix list
706 pfx_list = {
707 "r0": {
708 "prefix_lists": {
709 "ipv6": {
710 "pf_list_1_ipv6": [
711 {"seqid": 10, "network": "any", "action": "permit"}
712 ]
713 }
714 }
715 }
716 }
717 result = create_prefix_lists(tgen, pfx_list)
718 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
719
720 step("verify that prefix-list is created in R0.")
721 result = verify_prefix_lists(tgen, pfx_list)
722 assert (
723 result is not True
724 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
725 tc_name, result
726 )
727
728 # Create route map
729 routemaps = {
730 "r0": {
731 "route_maps": {
732 "rmap_ipv6": [
733 {
734 "action": "permit",
735 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
736 }
737 ]
738 }
739 }
740 }
741 result = create_route_maps(tgen, routemaps)
742 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
743
744 step("Verify that metric falls back to original metric for ospf routes.")
745 dut = "r1"
746 protocol = "ospf"
747
748 result = verify_ospf6_rib(tgen, dut, input_dict)
749 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
750
751 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
752 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
753
754 step(
755 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
756 "OSPF using route map."
757 )
758 # Create Static routes
759 input_dict = {
760 "r0": {
761 "static_routes": [
762 {
763 "network": NETWORK["ipv6"][1],
764 "no_of_ip": 1,
765 "next_hop": "Null0",
766 "tag": 1000,
767 }
768 ]
769 }
770 }
771 result = create_static_routes(tgen, input_dict)
772 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
773
774 # Create ip prefix list
775 pfx_list = {
776 "r0": {
777 "prefix_lists": {
778 "ipv6": {
779 "pf_list_1_ipv6": [
780 {"seqid": 10, "network": "any", "action": "permit"}
781 ]
782 }
783 }
784 }
785 }
786 result = create_prefix_lists(tgen, pfx_list)
787 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
788
789 step("verify that prefix-list is created in R0.")
790 result = verify_prefix_lists(tgen, pfx_list)
791 assert (
792 result is not True
793 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
794 tc_name, result
795 )
796
797 # Create route map
798 routemaps = {
799 "r0": {
800 "route_maps": {
801 "rmap_ipv6": [{"action": "permit", "match": {"ipv6": {"tag": "1000"}}}]
802 }
803 }
804 }
805 result = create_route_maps(tgen, routemaps)
806 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
807
808 step("Verify that metric falls back to original metric for ospf routes.")
809 dut = "r1"
810 protocol = "ospf"
811
812 result = verify_ospf6_rib(tgen, dut, input_dict)
813 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
814
815 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
816 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
817
818 step("Delete the match clause with tag in route map")
819 # Create route map
820 routemaps = {
821 "r0": {
822 "route_maps": {
823 "rmap_ipv6": [
824 {
825 "action": "permit",
826 "match": {"ipv6": {"tag": "1000", "delete": True}},
827 }
828 ]
829 }
830 }
831 }
832 result = create_route_maps(tgen, routemaps)
833 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
834
835 step("Verify that metric falls back to original metric for ospf routes.")
836 dut = "r1"
837 protocol = "ospf"
838
839 result = verify_ospf6_rib(tgen, dut, input_dict)
840 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
841
842 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
843 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
844
845 step("Delete the match clause with metric in route map.")
846
847 # Create route map
848 routemaps = {
849 "r0": {
850 "route_maps": {
851 "rmap_ipv6": [
852 {
853 "action": "permit",
854 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
855 }
856 ]
857 }
858 }
859 }
860 result = create_route_maps(tgen, routemaps)
861 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
862
863 result = verify_ospf6_rib(tgen, dut, input_dict)
864 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
865
866 result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol)
867 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
868
869 write_test_footer(tc_name)
870
871
872 if __name__ == "__main__":
873 args = ["-s"] + sys.argv[1:]
874 sys.exit(pytest.main(args))