]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
4 # Copyright (c) 2021 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
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
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
24 """OSPF Basic Functionality Automation."""
30 # Save the Current Working Directory to find configuration files.
31 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
32 sys
.path
.append(os
.path
.join(CWD
, "../"))
33 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib
.topogen
import Topogen
, get_topogen
39 # Import topoJson from lib, to create topology and initial configuration
40 from lib
.common_config
import (
44 reset_config_on_routers
,
53 from lib
.topolog
import logger
54 from lib
.topojson
import build_config_from_json
56 from lib
.ospf
import (
57 verify_ospf6_neighbor
,
63 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
78 "ipv6": ["2::1/128", "2::2/128", "2::3/128", "2::4/128", "2::5/128"],
81 routerids
= ["100.1.1.0", "100.1.1.1", "100.1.1.2", "100.1.1.3"]
85 Please view in a fixed-width font such as Courier.
87 +R1 +------------+R2 |
96 +R0 +-------------+R3 |
100 2. Verify OSPF route map support functionality when route map is not
101 configured at system level but configured in OSPF
102 4. Verify OSPF route map support functionality
103 when route map actions are toggled.
104 5. Verify OSPF route map support functionality with multiple sequence
105 numbers in a single route-map for different match/set clauses.
106 6. Verify OSPF route map support functionality when we add/remove route-maps
107 with multiple set clauses and without any match statement.(Set only)
108 7. Verify OSPF route map support functionality when we
109 add/remove route-maps with multiple match clauses and without
110 any set statement.(Match only)
111 8. Verify OSPF route map applied to ospf redistribution with ipv6 prefix list
115 def setup_module(mod
):
117 Sets up the pytest environment
121 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
122 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
123 logger
.info("=" * 40)
125 logger
.info("Running setup_module to create topology")
127 # This function initiates the topology build with Topogen...
128 json_file
= "{}/ospfv3_routemaps.json".format(CWD
)
129 tgen
= Topogen(json_file
, mod
.__name
__)
131 topo
= tgen
.json_topo
132 # ... and here it calls Mininet initialization functions.
134 # get list of daemons needs to be started for this suite.
135 daemons
= topo_daemons(tgen
, topo
)
137 # Starting topology, create tmp files which are loaded to routers
138 # to start deamons and then start routers
139 start_topology(tgen
, daemons
)
141 # Creating configuration from JSON
142 build_config_from_json(tgen
, topo
)
144 # Don't run this test if we have any failure.
145 if tgen
.routers_have_failure():
146 pytest
.skip(tgen
.errors
)
148 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
149 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
153 logger
.info("Running setup_module() done")
156 def teardown_module(mod
):
158 Teardown the pytest environment.
163 logger
.info("Running teardown_module to delete topology")
167 # Stop toplogy and Remove tmp files
171 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
173 logger
.info("=" * 40)
176 # ##################################
177 # Test cases start here.
178 # ##################################
181 def test_ospfv3_routemaps_functionality_tc20_p0(request
):
183 OSPF route map support functionality.
185 Verify OSPF route map support functionality when route map is not
186 configured at system level but configured in OSPF
189 tc_name
= request
.node
.name
190 write_test_header(tc_name
)
193 step("Bring up the base config as per the topology")
195 reset_config_on_routers(tgen
)
197 step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
198 # Create Static routes
203 "network": NETWORK
["ipv6"][0],
210 result
= create_static_routes(tgen
, input_dict
)
211 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
213 step("Redistribute to ospf using route map ( non existent route map)")
217 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
221 result
= create_router_ospf(tgen
, topo
, ospf_red_r1
)
222 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
225 "Verify that routes are not allowed in OSPF even tough no "
226 "matching routing map is configured."
231 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
234 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
238 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
241 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
246 "configure the route map with the same name that is used "
247 "in the ospf with deny rule."
251 routemaps
= {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
252 result
= create_route_maps(tgen
, routemaps
)
253 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
255 step("verify that now route map is activated & routes are denied in OSPF.")
258 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
261 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
266 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
270 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
275 routemaps
= {"r0": {"route_maps": {"rmap_ipv6": [{"action": "deny"}]}}}
276 result
= create_route_maps(tgen
, routemaps
)
277 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
279 step("verify that now route map is activated & routes are denied in OSPF.")
282 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
285 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
290 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
294 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
298 step("Delete the route map.")
301 "r0": {"route_maps": {"rmap_ipv6": [{"action": "deny", "delete": True}]}}
303 result
= create_route_maps(tgen
, routemaps
)
304 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
307 "Verify that routes are allowed in OSPF even tough "
308 "no matching routing map is configured."
312 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
315 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
320 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
324 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
328 write_test_footer(tc_name
)
331 def test_ospfv3_routemaps_functionality_tc25_p0(request
):
333 OSPF route map support functionality.
335 Verify OSPF route map support functionality
336 when route map actions are toggled.
339 tc_name
= request
.node
.name
340 write_test_header(tc_name
)
343 step("Bring up the base config as per the topology")
345 reset_config_on_routers(tgen
)
348 "Create static routes(10.0.20.1/32) in R1 and redistribute "
349 "to OSPF using route map."
352 # Create Static routes
357 "network": NETWORK
["ipv6"][0],
364 result
= create_static_routes(tgen
, input_dict
)
365 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
370 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
374 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
375 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
376 step("Configure route map with permit rule")
378 routemaps
= {"r0": {"route_maps": {"rmap_ipv6": [{"action": "permit"}]}}}
379 result
= create_route_maps(tgen
, routemaps
)
380 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
382 step("Verify that route is advertised to R1.")
385 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
386 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
388 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
389 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
390 step("Configure route map with deny rule")
393 "r0": {"route_maps": {"rmap_ipv6": [{"seq_id": 10, "action": "deny"}]}}
395 result
= create_route_maps(tgen
, routemaps
)
396 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
398 # Api call verify whether OSPF is converged
399 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
400 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
404 step("Verify that route is not advertised to R1.")
407 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
410 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
415 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
419 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
423 write_test_footer(tc_name
)
426 def test_ospfv3_routemaps_functionality_tc22_p0(request
):
428 OSPF Route map - Multiple sequence numbers.
430 Verify OSPF route map support functionality with multiple sequence
431 numbers in a single route-map for different match/set clauses.
434 tc_name
= request
.node
.name
435 write_test_header(tc_name
)
438 step("Bring up the base config as per the topology")
440 reset_config_on_routers(tgen
)
443 "Configure route map with seq number 10 to with ip prefix"
444 " permitting route 10.0.20.1/32 in R1"
447 "Configure route map with seq number 20 to with ip prefix"
448 " permitting route 10.0.20.2/32 in R1"
459 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
464 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
470 result
= create_route_maps(tgen
, input_dict_3
)
471 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
473 # Create ip prefix list
479 {"seqid": 10, "network": NETWORK
["ipv6"][0], "action": "permit"}
485 result
= create_prefix_lists(tgen
, input_dict_2
)
486 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
488 # Create ip prefix list
494 {"seqid": 10, "network": NETWORK
["ipv6"][1], "action": "permit"}
500 result
= create_prefix_lists(tgen
, input_dict_2
)
501 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
503 step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1")
504 # Create Static routes
509 "network": NETWORK
["ipv6"][0],
516 result
= create_static_routes(tgen
, input_dict
)
517 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
519 step("Configure redistribute static route with route map.")
523 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
527 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
528 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
534 "network": NETWORK
["ipv6"][0],
541 result
= create_static_routes(tgen
, input_dict
)
542 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
544 step("Verify that both routes are learned in R1 and R2")
547 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
548 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
550 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
551 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
555 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
556 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
558 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
559 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
561 step("Change route map with seq number 20 to deny.")
570 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
576 result
= create_route_maps(tgen
, input_dict_3
)
577 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
580 "Verify the route 10.0.20.2/32 is withdrawn and not present "
581 "in the routing table of R0 and R1."
585 "r0": {"static_routes": [{"network": NETWORK
["ipv6"][1], "next_hop": "Null0"}]}
590 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
593 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
598 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
602 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
608 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
611 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
616 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
620 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
624 write_test_footer(tc_name
)
627 def test_ospfv3_routemaps_functionality_tc24_p0(request
):
629 OSPF Route map - Multiple set clauses.
631 Verify OSPF route map support functionality when we
632 add/remove route-maps with multiple match clauses and without
633 any set statement.(Match only)
636 tc_name
= request
.node
.name
637 write_test_header(tc_name
)
640 step("Bring up the base config as per the topology")
642 reset_config_on_routers(tgen
)
645 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
646 "OSPF using route map."
648 # Create Static routes
653 "network": NETWORK
["ipv6"][0],
660 result
= create_static_routes(tgen
, input_dict
)
661 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
666 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
670 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
671 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
673 # Create ip prefix list
679 {"seqid": 10, "network": "any", "action": "permit"}
685 result
= create_prefix_lists(tgen
, pfx_list
)
686 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
688 step("verify that prefix-list is created in R0.")
689 result
= verify_prefix_lists(tgen
, pfx_list
)
692 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
703 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
709 result
= create_route_maps(tgen
, routemaps
)
710 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
712 step("Verify that metric falls back to original metric for ospf routes.")
716 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
717 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
719 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
720 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
723 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
724 "OSPF using route map."
726 # Create Static routes
731 "network": NETWORK
["ipv6"][1],
739 result
= create_static_routes(tgen
, input_dict
)
740 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
742 # Create ip prefix list
748 {"seqid": 10, "network": "any", "action": "permit"}
754 result
= create_prefix_lists(tgen
, pfx_list
)
755 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
757 step("verify that prefix-list is created in R0.")
758 result
= verify_prefix_lists(tgen
, pfx_list
)
761 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
769 "rmap_ipv6": [{"action": "permit", "match": {"ipv6": {"tag": "1000"}}}]
773 result
= create_route_maps(tgen
, routemaps
)
774 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
776 step("Verify that metric falls back to original metric for ospf routes.")
780 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
781 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
783 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
784 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
786 step("Delete the match clause with tag in route map")
794 "match": {"ipv6": {"tag": "1000", "delete": True}},
800 result
= create_route_maps(tgen
, routemaps
)
801 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
803 step("Verify that metric falls back to original metric for ospf routes.")
807 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
808 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
810 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
811 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
813 step("Delete the match clause with metric in route map.")
822 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
828 result
= create_route_maps(tgen
, routemaps
)
829 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
831 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
832 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
834 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
835 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
837 write_test_footer(tc_name
)
840 if __name__
== "__main__":
841 args
= ["-s"] + sys
.argv
[1:]
842 sys
.exit(pytest
.main(args
))