]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map/test_route_map_topo1.py
4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("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
28 # Save the Current Working Directory to find configuration files.
29 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
30 sys
.path
.append(os
.path
.join(CWD
, "../"))
32 # pylint: disable=C0413
33 # Import topogen and topotest helpers
34 from lib
.topogen
import Topogen
, get_topogen
36 # Required to instantiate the topology builder class.
37 from lib
.common_config
import (
46 reset_config_on_routers
,
48 from lib
.topolog
import logger
50 verify_bgp_convergence
,
52 verify_bgp_attributes
,
54 from lib
.topojson
import build_config_from_json
56 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
59 #################################
61 #################################
73 +---------- | R3 |----------| R4 |
78 #################################
80 #################################
82 Following tests are covered to test route-map functionality:
84 Verify if route-maps is applied in both inbound and
85 outbound direction to same neighbor/interface.
87 Test permit/deny statements operation in route-maps with a
88 permutation and combination of permit/deny in prefix-lists
90 Test multiple sequence numbers in a single route-map for different
93 Test add/remove route-maps with multiple set
94 clauses and without any match statement.(Set only)
96 Test add/remove route-maps with multiple match
97 clauses and without any set statement.(Match only)
101 bgp_convergence
= False
102 BGP_CONVERGENCE
= False
103 ADDR_TYPES
= check_address_types()
106 bgp_convergence
= False
107 NETWORK
= {"ipv4": ["11.0.20.1/32", "20.0.20.1/32"], "ipv6": ["1::1/128", "2::1/128"]}
108 MASK
= {"ipv4": "32", "ipv6": "128"}
109 NEXT_HOP
= {"ipv4": "10.0.0.2", "ipv6": "fd00::2"}
110 ADDR_TYPES
= check_address_types()
113 def setup_module(mod
):
115 Sets up the pytest environment
120 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
121 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
122 logger
.info("=" * 40)
124 logger
.info("Running setup_module to create topology")
126 # This function initiates the topology build with Topogen...
127 json_file
= "{}/bgp_route_map_topo1.json".format(CWD
)
128 tgen
= Topogen(json_file
, mod
.__name
__)
130 topo
= tgen
.json_topo
131 # ... and here it calls Mininet initialization functions.
133 # Starting topology, create tmp files which are loaded to routers
134 # to start deamons and then start routers
137 # Creating configuration from JSON
138 build_config_from_json(tgen
, topo
)
140 # Checking BGP convergence
141 global bgp_convergence
143 # Don"t run this test if we have any failure.
144 if tgen
.routers_have_failure():
145 pytest
.skip(tgen
.errors
)
147 # Api call verify whether BGP is converged
148 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
149 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
153 logger
.info("Running setup_module() done")
156 def teardown_module():
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 def test_route_map_inbound_outbound_same_neighbor_p0(request
):
179 Verify if route-maps is applied in both inbound and
180 outbound direction to same neighbor/interface.
183 tc_name
= request
.node
.name
184 write_test_header(tc_name
)
187 # Don"t run this test if we have any failure.
188 if tgen
.routers_have_failure():
189 pytest
.skip(tgen
.errors
)
191 # Creating configuration from JSON
192 reset_config_on_routers(tgen
)
194 for adt
in ADDR_TYPES
:
196 # Create Static routes
201 "network": NETWORK
[adt
][0],
203 "next_hop": NEXT_HOP
[adt
],
209 result
= create_static_routes(tgen
, input_dict
)
210 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
214 # Api call to redistribute static routes
223 {"redist_type": "static"},
224 {"redist_type": "connected"},
231 {"redist_type": "static"},
232 {"redist_type": "connected"},
241 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
242 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
250 "network": NETWORK
[adt
][1],
252 "next_hop": NEXT_HOP
[adt
],
258 result
= create_static_routes(tgen
, input_dict_2
)
259 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
263 # Api call to redistribute static routes
271 {"redist_type": "static"},
272 {"redist_type": "connected"},
279 {"redist_type": "static"},
280 {"redist_type": "connected"},
288 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
289 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
301 "network": NETWORK
["ipv4"][0],
308 "network": NETWORK
["ipv4"][1],
317 "network": NETWORK
["ipv6"][0],
324 "network": NETWORK
["ipv6"][1],
331 result
= create_prefix_lists(tgen
, input_dict_2
)
332 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
337 for addr_type
in ADDR_TYPES
:
341 "rmap_match_tag_1_{}".format(addr_type
): [
346 "prefix_lists": "pf_list_1_{}".format(addr_type
)
351 "rmap_match_tag_2_{}".format(addr_type
): [
356 "prefix_lists": "pf_list_2_{}".format(addr_type
)
364 result
= create_route_maps(tgen
, input_dict_6
)
365 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
369 # Configure neighbor for route map
382 "name": "rmap_match_tag_1_ipv4",
386 "name": "rmap_match_tag_1_ipv4",
404 "name": "rmap_match_tag_1_ipv6",
408 "name": "rmap_match_tag_1_ipv6",
423 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
424 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
428 for adt
in ADDR_TYPES
:
429 # Verifying RIB routes
436 "network": [NETWORK
[adt
][1]],
438 "next_hop": NEXT_HOP
[adt
],
445 tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
, expected
=False
447 assert result
is not True, (
448 "Testcase {} : Failed \n"
449 "routes are not present in rib \n Error: {}".format(tc_name
, result
)
451 logger
.info("Expected behaviour: {}".format(result
))
453 # Verifying RIB routes
459 "network": [NETWORK
[adt
][0]],
461 "next_hop": NEXT_HOP
[adt
],
467 tgen
, adt
, dut
, input_dict
, protocol
=protocol
, expected
=False
469 assert result
is not True, (
470 "Testcase {} : Failed \n "
471 "routes are not present in rib \n Error: {}".format(tc_name
, result
)
473 logger
.info("Expected behaviour: {}".format(result
))
475 write_test_footer(tc_name
)
478 @pytest.mark
.parametrize(
479 "prefix_action, rmap_action",
480 [("permit", "permit"), ("permit", "deny"), ("deny", "permit"), ("deny", "deny")],
482 def test_route_map_with_action_values_combination_of_prefix_action_p0(
483 request
, prefix_action
, rmap_action
487 Test permit/deny statements operation in route-maps with a permutation and
488 combination of permit/deny in prefix-lists
490 tc_name
= request
.node
.name
491 write_test_header(tc_name
)
494 # Don"t run this test if we have any failure.
495 if tgen
.routers_have_failure():
496 pytest
.skip(tgen
.errors
)
498 # Creating configuration from JSON
499 reset_config_on_routers(tgen
)
501 for adt
in ADDR_TYPES
:
502 # Create Static routes
507 "network": NETWORK
[adt
][0],
509 "next_hop": NEXT_HOP
[adt
],
515 result
= create_static_routes(tgen
, input_dict
)
516 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
520 # Api call to redistribute static routes
529 {"redist_type": "static"},
530 {"redist_type": "connected"},
537 {"redist_type": "static"},
538 {"redist_type": "connected"},
547 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
548 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
552 # Permit in perfix list and route-map
558 {"seqid": 10, "network": "any", "action": prefix_action
}
563 {"seqid": 100, "network": "any", "action": prefix_action
}
569 result
= create_prefix_lists(tgen
, input_dict_2
)
570 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
575 for addr_type
in ADDR_TYPES
:
579 "rmap_match_pf_1_{}".format(addr_type
): [
581 "action": rmap_action
,
584 "prefix_lists": "pf_list_1_{}".format(addr_type
)
592 result
= create_route_maps(tgen
, input_dict_3
)
593 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
597 # Configure neighbor for route map
610 "name": "rmap_match_pf_1_ipv4",
628 "name": "rmap_match_pf_1_ipv6",
643 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
644 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
654 "network": [NETWORK
[adt
][0]],
656 "next_hop": NEXT_HOP
[adt
],
663 if "deny" in [prefix_action
, rmap_action
]:
665 tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
, expected
=False
667 assert result
is not True, (
668 "Testcase {} : Failed \n "
669 "Routes are still present \n Error: {}".format(tc_name
, result
)
671 logger
.info("Expected behaviour: {}".format(result
))
673 result
= verify_rib(tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
)
674 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
679 def test_route_map_multiple_seq_different_match_set_clause_p0(request
):
682 Test multiple sequence numbers in a single route-map for different
688 tc_name
= request
.node
.name
689 write_test_header(tc_name
)
691 # Creating configuration from JSON
692 reset_config_on_routers(tgen
)
694 for adt
in ADDR_TYPES
:
695 # Create Static routes
700 "network": NETWORK
[adt
][0],
702 "next_hop": NEXT_HOP
[adt
],
707 result
= create_static_routes(tgen
, input_dict
)
708 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
712 # Api call to redistribute static routes
720 {"redist_type": "static"},
721 {"redist_type": "connected"},
728 {"redist_type": "static"},
729 {"redist_type": "connected"},
737 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
738 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
742 # Create ip prefix list
748 {"seqid": 10, "network": "any", "action": "permit"}
753 {"seqid": 100, "network": "any", "action": "permit"}
759 result
= create_prefix_lists(tgen
, input_dict_2
)
760 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
765 for addr_type
in ADDR_TYPES
:
769 "rmap_match_pf_1_{}".format(addr_type
): [
774 "prefix_lists": "pf_list_2_{}".format(addr_type
)
777 "set": {"path": {"as_num": 500}},
783 "prefix_lists": "pf_list_2_{}".format(addr_type
)
794 "prefix_lists": "pf_list_1_{}".format(addr_type
)
797 "set": {"metric": 50},
803 result
= create_route_maps(tgen
, input_dict_3
)
804 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
808 # Configure neighbor for route map
821 "name": "rmap_match_pf_1_ipv4",
833 "name": "rmap_match_pf_1_ipv4",
851 "name": "rmap_match_pf_1_ipv6",
863 "name": "rmap_match_pf_1_ipv6",
877 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
878 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
882 for adt
in ADDR_TYPES
:
883 # Verifying RIB routes
889 "rmap_match_pf_list1": [
900 static_routes
= [NETWORK
[adt
][0]]
903 result
= verify_bgp_attributes(
904 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
906 assert result
is True, "Test case {} : Failed \n Error: {}".format(
911 result
= verify_bgp_attributes(
912 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
914 assert result
is True, "Test case {} : Failed \n Error: {}".format(
918 logger
.info("Testcase " + tc_name
+ " :Passed \n")
920 # Uncomment next line for debugging
924 def test_route_map_set_only_no_match_p0(request
):
927 Test add/remove route-maps with multiple set
928 clauses and without any match statement.(Set only)
933 tc_name
= request
.node
.name
934 write_test_header(tc_name
)
936 # Creating configuration from JSON
937 reset_config_on_routers(tgen
)
939 for adt
in ADDR_TYPES
:
940 # Create Static routes
945 "network": NETWORK
[adt
][0],
947 "next_hop": NEXT_HOP
[adt
],
952 result
= create_static_routes(tgen
, input_dict
)
953 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
957 # Api call to redistribute static routes
965 {"redist_type": "static"},
966 {"redist_type": "connected"},
973 {"redist_type": "static"},
974 {"redist_type": "connected"},
982 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
983 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
994 "set": {"metric": 50, "locPrf": 150, "weight": 4000},
1000 result
= create_route_maps(tgen
, input_dict_3
)
1001 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1005 # Configure neighbor for route map
1018 "name": "rmap_match_pf_1",
1030 "name": "rmap_match_pf_1",
1048 "name": "rmap_match_pf_1",
1060 "name": "rmap_match_pf_1",
1074 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1075 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1080 for adt
in ADDR_TYPES
:
1084 "rmap_match_pf_1": [
1095 # Verifying RIB routes
1096 static_routes
= [NETWORK
[adt
][0]]
1097 result
= verify_bgp_attributes(
1098 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1100 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1104 result
= verify_bgp_attributes(
1105 tgen
, adt
, "r4", static_routes
, "rmap_match_pf_1", input_dict_4
1107 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1111 logger
.info("Testcase " + tc_name
+ " :Passed \n")
1113 # Uncomment next line for debugging
1114 # tgen.mininet_cli()
1117 def test_route_map_match_only_no_set_p0(request
):
1120 Test add/remove route-maps with multiple match
1121 clauses and without any set statement.(Match only)
1124 tgen
= get_topogen()
1126 tc_name
= request
.node
.name
1127 write_test_header(tc_name
)
1129 # Creating configuration from JSON
1130 reset_config_on_routers(tgen
)
1132 for adt
in ADDR_TYPES
:
1133 # Create Static routes
1138 "network": NETWORK
[adt
][0],
1140 "next_hop": NEXT_HOP
[adt
],
1145 result
= create_static_routes(tgen
, input_dict
)
1146 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1150 # Api call to redistribute static routes
1158 {"redist_type": "static"},
1159 {"redist_type": "connected"},
1166 {"redist_type": "static"},
1167 {"redist_type": "connected"},
1175 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1176 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1180 # Create ip prefix list
1186 {"seqid": 10, "network": "any", "action": "permit"}
1191 {"seqid": 100, "network": "any", "action": "permit"}
1197 result
= create_prefix_lists(tgen
, input_dict_2
)
1198 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1203 for addr_type
in ADDR_TYPES
:
1207 "rmap_match_pf_1_{}".format(addr_type
): [
1219 result
= create_route_maps(tgen
, input_dict_3
)
1220 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1224 # Configure neighbor for route map
1237 "name": "rmap_match_pf_1_ipv4",
1255 "name": "rmap_match_pf_1_ipv6",
1269 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1270 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1274 # Create ip prefix list
1280 {"seqid": 10, "network": "any", "action": "permit"}
1285 {"seqid": 100, "network": "any", "action": "permit"}
1291 result
= create_prefix_lists(tgen
, input_dict_5
)
1292 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1297 for addr_type
in ADDR_TYPES
:
1301 "rmap_match_pf_2_{}".format(addr_type
): [
1306 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1314 result
= create_route_maps(tgen
, input_dict_6
)
1315 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1319 # Configure neighbor for route map
1332 "name": "rmap_match_pf_2_ipv4",
1344 "name": "rmap_match_pf_2_ipv4",
1362 "name": "rmap_match_pf_2_ipv6",
1374 "name": "rmap_match_pf_2_ipv6",
1388 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
1389 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1393 for adt
in ADDR_TYPES
:
1394 # Verifying RIB routes
1395 static_routes
= [NETWORK
[adt
][0]]
1396 result
= verify_bgp_attributes(
1397 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1399 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1404 if __name__
== "__main__":
1405 args
= ["-s"] + sys
.argv
[1:]
1406 sys
.exit(pytest
.main(args
))