]>
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 daemons 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
449 ), "Testcase {} : Failed \nroutes are not present in rib \n Error: {}".format(
452 logger
.info("Expected behaviour: {}".format(result
))
454 # Verifying RIB routes
460 "network": [NETWORK
[adt
][0]],
462 "next_hop": NEXT_HOP
[adt
],
468 tgen
, adt
, dut
, input_dict
, protocol
=protocol
, expected
=False
472 ), "Testcase {} : Failed \nroutes are not present in rib \n Error: {}".format(
475 logger
.info("Expected behaviour: {}".format(result
))
477 write_test_footer(tc_name
)
480 @pytest.mark
.parametrize(
481 "prefix_action, rmap_action",
482 [("permit", "permit"), ("permit", "deny"), ("deny", "permit"), ("deny", "deny")],
484 def test_route_map_with_action_values_combination_of_prefix_action_p0(
485 request
, prefix_action
, rmap_action
489 Test permit/deny statements operation in route-maps with a permutation and
490 combination of permit/deny in prefix-lists
492 tc_name
= request
.node
.name
493 write_test_header(tc_name
)
496 # Don"t run this test if we have any failure.
497 if tgen
.routers_have_failure():
498 pytest
.skip(tgen
.errors
)
500 # Creating configuration from JSON
501 reset_config_on_routers(tgen
)
503 for adt
in ADDR_TYPES
:
504 # Create Static routes
509 "network": NETWORK
[adt
][0],
511 "next_hop": NEXT_HOP
[adt
],
517 result
= create_static_routes(tgen
, input_dict
)
518 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
522 # Api call to redistribute static routes
531 {"redist_type": "static"},
532 {"redist_type": "connected"},
539 {"redist_type": "static"},
540 {"redist_type": "connected"},
549 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
550 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
554 # Permit in perfix list and route-map
560 {"seqid": 10, "network": "any", "action": prefix_action
}
565 {"seqid": 100, "network": "any", "action": prefix_action
}
571 result
= create_prefix_lists(tgen
, input_dict_2
)
572 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
577 for addr_type
in ADDR_TYPES
:
581 "rmap_match_pf_1_{}".format(addr_type
): [
583 "action": rmap_action
,
586 "prefix_lists": "pf_list_1_{}".format(addr_type
)
594 result
= create_route_maps(tgen
, input_dict_3
)
595 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
599 # Configure neighbor for route map
612 "name": "rmap_match_pf_1_ipv4",
630 "name": "rmap_match_pf_1_ipv6",
645 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
646 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
656 "network": [NETWORK
[adt
][0]],
658 "next_hop": NEXT_HOP
[adt
],
665 if "deny" in [prefix_action
, rmap_action
]:
667 tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
, expected
=False
671 ), "Testcase {} : Failed \nRoutes are still present \n Error: {}".format(
674 logger
.info("Expected behaviour: {}".format(result
))
676 result
= verify_rib(tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
)
677 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
682 def test_route_map_multiple_seq_different_match_set_clause_p0(request
):
685 Test multiple sequence numbers in a single route-map for different
691 tc_name
= request
.node
.name
692 write_test_header(tc_name
)
694 # Creating configuration from JSON
695 reset_config_on_routers(tgen
)
697 for adt
in ADDR_TYPES
:
698 # Create Static routes
703 "network": NETWORK
[adt
][0],
705 "next_hop": NEXT_HOP
[adt
],
710 result
= create_static_routes(tgen
, input_dict
)
711 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
715 # Api call to redistribute static routes
723 {"redist_type": "static"},
724 {"redist_type": "connected"},
731 {"redist_type": "static"},
732 {"redist_type": "connected"},
740 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
741 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
745 # Create ip prefix list
751 {"seqid": 10, "network": "any", "action": "permit"}
756 {"seqid": 100, "network": "any", "action": "permit"}
762 result
= create_prefix_lists(tgen
, input_dict_2
)
763 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
768 for addr_type
in ADDR_TYPES
:
772 "rmap_match_pf_1_{}".format(addr_type
): [
777 "prefix_lists": "pf_list_2_{}".format(addr_type
)
780 "set": {"path": {"as_num": 500}},
786 "prefix_lists": "pf_list_2_{}".format(addr_type
)
797 "prefix_lists": "pf_list_1_{}".format(addr_type
)
800 "set": {"metric": 50},
806 result
= create_route_maps(tgen
, input_dict_3
)
807 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
811 # Configure neighbor for route map
824 "name": "rmap_match_pf_1_ipv4",
836 "name": "rmap_match_pf_1_ipv4",
854 "name": "rmap_match_pf_1_ipv6",
866 "name": "rmap_match_pf_1_ipv6",
880 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
881 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
885 for adt
in ADDR_TYPES
:
886 # Verifying RIB routes
892 "rmap_match_pf_list1": [
903 static_routes
= [NETWORK
[adt
][0]]
906 result
= verify_bgp_attributes(
907 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
909 assert result
is True, "Test case {} : Failed \n Error: {}".format(
914 result
= verify_bgp_attributes(
915 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
917 assert result
is True, "Test case {} : Failed \n Error: {}".format(
921 logger
.info("Testcase " + tc_name
+ " :Passed \n")
923 # Uncomment next line for debugging
927 def test_route_map_set_only_no_match_p0(request
):
930 Test add/remove route-maps with multiple set
931 clauses and without any match statement.(Set only)
936 tc_name
= request
.node
.name
937 write_test_header(tc_name
)
939 # Creating configuration from JSON
940 reset_config_on_routers(tgen
)
942 for adt
in ADDR_TYPES
:
943 # Create Static routes
948 "network": NETWORK
[adt
][0],
950 "next_hop": NEXT_HOP
[adt
],
955 result
= create_static_routes(tgen
, input_dict
)
956 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
960 # Api call to redistribute static routes
968 {"redist_type": "static"},
969 {"redist_type": "connected"},
976 {"redist_type": "static"},
977 {"redist_type": "connected"},
985 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
986 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
997 "set": {"metric": 50, "locPrf": 150, "weight": 4000},
1003 result
= create_route_maps(tgen
, input_dict_3
)
1004 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1008 # Configure neighbor for route map
1021 "name": "rmap_match_pf_1",
1033 "name": "rmap_match_pf_1",
1051 "name": "rmap_match_pf_1",
1063 "name": "rmap_match_pf_1",
1077 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1078 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1083 for adt
in ADDR_TYPES
:
1087 "rmap_match_pf_1": [
1098 # Verifying RIB routes
1099 static_routes
= [NETWORK
[adt
][0]]
1100 result
= verify_bgp_attributes(
1101 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1103 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1107 result
= verify_bgp_attributes(
1108 tgen
, adt
, "r4", static_routes
, "rmap_match_pf_1", input_dict_4
1110 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1114 logger
.info("Testcase " + tc_name
+ " :Passed \n")
1116 # Uncomment next line for debugging
1117 # tgen.mininet_cli()
1120 def test_route_map_match_only_no_set_p0(request
):
1123 Test add/remove route-maps with multiple match
1124 clauses and without any set statement.(Match only)
1127 tgen
= get_topogen()
1129 tc_name
= request
.node
.name
1130 write_test_header(tc_name
)
1132 # Creating configuration from JSON
1133 reset_config_on_routers(tgen
)
1135 for adt
in ADDR_TYPES
:
1136 # Create Static routes
1141 "network": NETWORK
[adt
][0],
1143 "next_hop": NEXT_HOP
[adt
],
1148 result
= create_static_routes(tgen
, input_dict
)
1149 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1153 # Api call to redistribute static routes
1161 {"redist_type": "static"},
1162 {"redist_type": "connected"},
1169 {"redist_type": "static"},
1170 {"redist_type": "connected"},
1178 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1179 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1183 # Create ip prefix list
1189 {"seqid": 10, "network": "any", "action": "permit"}
1194 {"seqid": 100, "network": "any", "action": "permit"}
1200 result
= create_prefix_lists(tgen
, input_dict_2
)
1201 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1206 for addr_type
in ADDR_TYPES
:
1210 "rmap_match_pf_1_{}".format(addr_type
): [
1222 result
= create_route_maps(tgen
, input_dict_3
)
1223 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1227 # Configure neighbor for route map
1240 "name": "rmap_match_pf_1_ipv4",
1258 "name": "rmap_match_pf_1_ipv6",
1272 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1273 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1277 # Create ip prefix list
1283 {"seqid": 10, "network": "any", "action": "permit"}
1288 {"seqid": 100, "network": "any", "action": "permit"}
1294 result
= create_prefix_lists(tgen
, input_dict_5
)
1295 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1300 for addr_type
in ADDR_TYPES
:
1304 "rmap_match_pf_2_{}".format(addr_type
): [
1309 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1317 result
= create_route_maps(tgen
, input_dict_6
)
1318 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1322 # Configure neighbor for route map
1335 "name": "rmap_match_pf_2_ipv4",
1347 "name": "rmap_match_pf_2_ipv4",
1365 "name": "rmap_match_pf_2_ipv6",
1377 "name": "rmap_match_pf_2_ipv6",
1391 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
1392 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1396 for adt
in ADDR_TYPES
:
1397 # Verifying RIB routes
1398 static_routes
= [NETWORK
[adt
][0]]
1399 result
= verify_bgp_attributes(
1400 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1402 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1407 if __name__
== "__main__":
1408 args
= ["-s"] + sys
.argv
[1:]
1409 sys
.exit(pytest
.main(args
))