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