]>
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 from copy
import deepcopy
31 from ipaddress
import IPv4Address
32 from lib
.topotest
import frr_unicode
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/"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
.topogen
import Topogen
, get_topogen
44 # Import topoJson from lib, to create topology and initial configuration
45 from lib
.common_config
import (
49 reset_config_on_routers
,
56 get_frr_ipv6_linklocal
,
59 from lib
.topolog
import logger
60 from lib
.topojson
import build_topo_from_json
, build_config_from_json
62 from lib
.ospf
import (
63 verify_ospf6_neighbor
,
64 config_ospf_interface
,
68 verify_ospf6_interface
,
69 verify_ospf6_database
,
70 config_ospf6_interface
,
73 from ipaddress
import IPv6Address
75 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
81 # Reading the data from JSON File for topology creation
82 jsonFile
= "{}/ospfv3_routemaps.json".format(CWD
)
84 with
open(jsonFile
, "r") as topoJson
:
85 topo
= json
.load(topoJson
)
87 assert False, "Could not read file {}".format(jsonFile
)
97 "ipv6": ["2::1/128", "2::2/128", "2::3/128", "2::4/128", "2::5/128"],
100 routerids
= ["100.1.1.0", "100.1.1.1", "100.1.1.2", "100.1.1.3"]
104 Please view in a fixed-width font such as Courier.
106 +R1 +------------+R2 |
115 +R0 +-------------+R3 |
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
134 class CreateTopo(Topo
):
136 Test topology builder.
138 * `Topo`: Topology object
141 def build(self
, *_args
, **_opts
):
142 """Build function."""
143 tgen
= get_topogen(self
)
145 # Building topology from json file
146 build_topo_from_json(tgen
, topo
)
149 def setup_module(mod
):
151 Sets up the pytest environment
156 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
157 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
158 logger
.info("=" * 40)
160 logger
.info("Running setup_module to create topology")
162 # This function initiates the topology build with Topogen...
163 tgen
= Topogen(CreateTopo
, mod
.__name
__)
164 # ... and here it calls Mininet initialization functions.
166 # get list of daemons needs to be started for this suite.
167 daemons
= topo_daemons(tgen
, topo
)
169 # Starting topology, create tmp files which are loaded to routers
170 # to start deamons and then start routers
171 start_topology(tgen
, daemons
)
173 # Creating configuration from JSON
174 build_config_from_json(tgen
, topo
)
176 # Don't run this test if we have any failure.
177 if tgen
.routers_have_failure():
178 pytest
.skip(tgen
.errors
)
180 ospf_covergence
= verify_ospf6_neighbor(tgen
, topo
)
181 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
185 logger
.info("Running setup_module() done")
188 def teardown_module(mod
):
190 Teardown the pytest environment.
195 logger
.info("Running teardown_module to delete topology")
199 # Stop toplogy and Remove tmp files
203 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
205 logger
.info("=" * 40)
208 # ##################################
209 # Test cases start here.
210 # ##################################
213 def test_ospfv3_routemaps_functionality_tc20_p0(request
):
215 OSPF route map support functionality.
217 Verify OSPF route map support functionality when route map is not
218 configured at system level but configured in OSPF
221 tc_name
= request
.node
.name
222 write_test_header(tc_name
)
225 step("Bring up the base config as per the topology")
227 reset_config_on_routers(tgen
)
229 step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
230 # Create Static routes
235 "network": NETWORK
["ipv6"][0],
242 result
= create_static_routes(tgen
, input_dict
)
243 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
245 step("Redistribute to ospf using route map ( non existent route map)")
249 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
253 result
= create_router_ospf(tgen
, topo
, ospf_red_r1
)
254 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
257 "Verify that routes are not allowed in OSPF even tough no "
258 "matching routing map is configured."
263 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
266 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
270 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
273 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
278 "configure the route map with the same name that is used "
279 "in the ospf with deny rule."
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
)
287 step("verify that now route map is activated & routes are denied in OSPF.")
290 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
293 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
298 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
302 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
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
)
311 step("verify that now route map is activated & routes are denied in OSPF.")
314 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
317 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
322 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
326 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
330 step("Delete the route map.")
333 "r0": {"route_maps": {"rmap_ipv6": [{"action": "deny", "delete": True}]}}
335 result
= create_route_maps(tgen
, routemaps
)
336 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
339 "Verify that routes are allowed in OSPF even tough "
340 "no matching routing map is configured."
344 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
347 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
352 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
356 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
360 write_test_footer(tc_name
)
363 def test_ospfv3_routemaps_functionality_tc25_p0(request
):
365 OSPF route map support functionality.
367 Verify OSPF route map support functionality
368 when route map actions are toggled.
371 tc_name
= request
.node
.name
372 write_test_header(tc_name
)
375 step("Bring up the base config as per the topology")
377 reset_config_on_routers(tgen
)
380 "Create static routes(10.0.20.1/32) in R1 and redistribute "
381 "to OSPF using route map."
384 # Create Static routes
389 "network": NETWORK
["ipv6"][0],
396 result
= create_static_routes(tgen
, input_dict
)
397 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
402 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
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")
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
)
414 step("Verify that route is advertised to R1.")
417 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
418 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
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")
425 "r0": {"route_maps": {"rmap_ipv6": [{"seq_id": 10, "action": "deny"}]}}
427 result
= create_route_maps(tgen
, routemaps
)
428 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
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(
436 step("Verify that route is not advertised to R1.")
439 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
442 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
447 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
451 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
455 write_test_footer(tc_name
)
458 def test_ospfv3_routemaps_functionality_tc22_p0(request
):
460 OSPF Route map - Multiple sequence numbers.
462 Verify OSPF route map support functionality with multiple sequence
463 numbers in a single route-map for different match/set clauses.
466 tc_name
= request
.node
.name
467 write_test_header(tc_name
)
470 step("Bring up the base config as per the topology")
472 reset_config_on_routers(tgen
)
475 "Configure route map with seq number 10 to with ip prefix"
476 " permitting route 10.0.20.1/32 in R1"
479 "Configure route map with seq number 20 to with ip prefix"
480 " permitting route 10.0.20.2/32 in R1"
491 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
496 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
502 result
= create_route_maps(tgen
, input_dict_3
)
503 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
505 # Create ip prefix list
511 {"seqid": 10, "network": NETWORK
["ipv6"][0], "action": "permit"}
517 result
= create_prefix_lists(tgen
, input_dict_2
)
518 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
520 # Create ip prefix list
526 {"seqid": 10, "network": NETWORK
["ipv6"][1], "action": "permit"}
532 result
= create_prefix_lists(tgen
, input_dict_2
)
533 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
535 step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1")
536 # Create Static routes
541 "network": NETWORK
["ipv6"][0],
548 result
= create_static_routes(tgen
, input_dict
)
549 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
551 step("Configure redistribute static route with route map.")
555 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
559 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
560 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
566 "network": NETWORK
["ipv6"][0],
573 result
= create_static_routes(tgen
, input_dict
)
574 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
576 step("Verify that both routes are learned in R1 and R2")
579 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
580 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
582 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
583 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
587 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
588 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
590 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
591 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
593 step("Change route map with seq number 20 to deny.")
602 "match": {"ipv6": {"prefix_lists": "pf_list_2_ipv4"}},
608 result
= create_route_maps(tgen
, input_dict_3
)
609 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
612 "Verify the route 10.0.20.2/32 is withdrawn and not present "
613 "in the routing table of R0 and R1."
617 "r0": {"static_routes": [{"network": NETWORK
["ipv6"][1], "next_hop": "Null0"}]}
622 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
625 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
630 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
634 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
640 result
= verify_ospf6_rib(tgen
, dut
, input_dict
, expected
=False)
643 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
648 tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
, expected
=False
652 ), "Testcase {} : Failed \n Route found in the RIB, Error: {}".format(
656 write_test_footer(tc_name
)
659 def test_ospfv3_routemaps_functionality_tc24_p0(request
):
661 OSPF Route map - Multiple set clauses.
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)
668 tc_name
= request
.node
.name
669 write_test_header(tc_name
)
672 step("Bring up the base config as per the topology")
674 reset_config_on_routers(tgen
)
677 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
678 "OSPF using route map."
680 # Create Static routes
685 "network": NETWORK
["ipv6"][0],
692 result
= create_static_routes(tgen
, input_dict
)
693 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
698 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
702 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
703 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
705 # Create ip prefix list
711 {"seqid": 10, "network": "any", "action": "permit"}
717 result
= create_prefix_lists(tgen
, pfx_list
)
718 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
720 step("verify that prefix-list is created in R0.")
721 result
= verify_prefix_lists(tgen
, pfx_list
)
724 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
735 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
741 result
= create_route_maps(tgen
, routemaps
)
742 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
744 step("Verify that metric falls back to original metric for ospf routes.")
748 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
749 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
751 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
752 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
755 "Create static routes(10.0.20.1/32) in R1 and redistribute to "
756 "OSPF using route map."
758 # Create Static routes
763 "network": NETWORK
["ipv6"][1],
771 result
= create_static_routes(tgen
, input_dict
)
772 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
774 # Create ip prefix list
780 {"seqid": 10, "network": "any", "action": "permit"}
786 result
= create_prefix_lists(tgen
, pfx_list
)
787 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
789 step("verify that prefix-list is created in R0.")
790 result
= verify_prefix_lists(tgen
, pfx_list
)
793 ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
801 "rmap_ipv6": [{"action": "permit", "match": {"ipv6": {"tag": "1000"}}}]
805 result
= create_route_maps(tgen
, routemaps
)
806 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
808 step("Verify that metric falls back to original metric for ospf routes.")
812 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
813 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
815 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
816 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
818 step("Delete the match clause with tag in route map")
826 "match": {"ipv6": {"tag": "1000", "delete": True}},
832 result
= create_route_maps(tgen
, routemaps
)
833 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
835 step("Verify that metric falls back to original metric for ospf routes.")
839 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
840 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
842 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
843 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
845 step("Delete the match clause with metric in route map.")
854 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
860 result
= create_route_maps(tgen
, routemaps
)
861 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
863 result
= verify_ospf6_rib(tgen
, dut
, input_dict
)
864 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
866 result
= verify_rib(tgen
, "ipv6", dut
, input_dict
, protocol
=protocol
)
867 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
869 write_test_footer(tc_name
)
872 if __name__
== "__main__":
873 args
= ["-s"] + sys
.argv
[1:]
874 sys
.exit(pytest
.main(args
))