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