]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map/test_route_map_topo1.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2019 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
15 # Save the Current Working Directory to find configuration files.
16 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
17 sys
.path
.append(os
.path
.join(CWD
, "../"))
19 # pylint: disable=C0413
20 # Import topogen and topotest helpers
21 from lib
.topogen
import Topogen
, get_topogen
23 # Required to instantiate the topology builder class.
24 from lib
.common_config
import (
33 reset_config_on_routers
,
35 from lib
.topolog
import logger
37 verify_bgp_convergence
,
39 verify_bgp_attributes
,
41 from lib
.topojson
import build_config_from_json
43 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
46 #################################
48 #################################
60 +---------- | R3 |----------| R4 |
65 #################################
67 #################################
69 Following tests are covered to test route-map functionality:
71 Verify if route-maps is applied in both inbound and
72 outbound direction to same neighbor/interface.
74 Test permit/deny statements operation in route-maps with a
75 permutation and combination of permit/deny in prefix-lists
77 Test multiple sequence numbers in a single route-map for different
80 Test add/remove route-maps with multiple set
81 clauses and without any match statement.(Set only)
83 Test add/remove route-maps with multiple match
84 clauses and without any set statement.(Match only)
88 bgp_convergence
= False
89 BGP_CONVERGENCE
= False
90 ADDR_TYPES
= check_address_types()
93 bgp_convergence
= False
94 NETWORK
= {"ipv4": ["11.0.20.1/32", "20.0.20.1/32"], "ipv6": ["1::1/128", "2::1/128"]}
95 MASK
= {"ipv4": "32", "ipv6": "128"}
96 NEXT_HOP
= {"ipv4": "10.0.0.2", "ipv6": "fd00::2"}
97 ADDR_TYPES
= check_address_types()
100 def setup_module(mod
):
102 Sets up the pytest environment
107 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
108 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
109 logger
.info("=" * 40)
111 logger
.info("Running setup_module to create topology")
113 # This function initiates the topology build with Topogen...
114 json_file
= "{}/bgp_route_map_topo1.json".format(CWD
)
115 tgen
= Topogen(json_file
, mod
.__name
__)
117 topo
= tgen
.json_topo
118 # ... and here it calls Mininet initialization functions.
120 # Starting topology, create tmp files which are loaded to routers
121 # to start daemons and then start routers
124 # Creating configuration from JSON
125 build_config_from_json(tgen
, topo
)
127 # Checking BGP convergence
128 global bgp_convergence
130 # Don"t run this test if we have any failure.
131 if tgen
.routers_have_failure():
132 pytest
.skip(tgen
.errors
)
134 # Api call verify whether BGP is converged
135 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
136 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
140 logger
.info("Running setup_module() done")
143 def teardown_module():
145 Teardown the pytest environment
150 logger
.info("Running teardown_module to delete topology")
154 # Stop toplogy and Remove tmp files
158 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
160 logger
.info("=" * 40)
163 def test_route_map_inbound_outbound_same_neighbor_p0(request
):
166 Verify if route-maps is applied in both inbound and
167 outbound direction to same neighbor/interface.
170 tc_name
= request
.node
.name
171 write_test_header(tc_name
)
174 # Don"t run this test if we have any failure.
175 if tgen
.routers_have_failure():
176 pytest
.skip(tgen
.errors
)
178 # Creating configuration from JSON
179 reset_config_on_routers(tgen
)
181 for adt
in ADDR_TYPES
:
183 # Create Static routes
188 "network": NETWORK
[adt
][0],
190 "next_hop": NEXT_HOP
[adt
],
196 result
= create_static_routes(tgen
, input_dict
)
197 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
201 # Api call to redistribute static routes
210 {"redist_type": "static"},
211 {"redist_type": "connected"},
218 {"redist_type": "static"},
219 {"redist_type": "connected"},
228 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
229 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
237 "network": NETWORK
[adt
][1],
239 "next_hop": NEXT_HOP
[adt
],
245 result
= create_static_routes(tgen
, input_dict_2
)
246 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
250 # Api call to redistribute static routes
258 {"redist_type": "static"},
259 {"redist_type": "connected"},
266 {"redist_type": "static"},
267 {"redist_type": "connected"},
275 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
276 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
288 "network": NETWORK
["ipv4"][0],
295 "network": NETWORK
["ipv4"][1],
304 "network": NETWORK
["ipv6"][0],
311 "network": NETWORK
["ipv6"][1],
318 result
= create_prefix_lists(tgen
, input_dict_2
)
319 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
324 for addr_type
in ADDR_TYPES
:
328 "rmap_match_tag_1_{}".format(addr_type
): [
333 "prefix_lists": "pf_list_1_{}".format(addr_type
)
338 "rmap_match_tag_2_{}".format(addr_type
): [
343 "prefix_lists": "pf_list_2_{}".format(addr_type
)
351 result
= create_route_maps(tgen
, input_dict_6
)
352 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
356 # Configure neighbor for route map
369 "name": "rmap_match_tag_1_ipv4",
373 "name": "rmap_match_tag_1_ipv4",
391 "name": "rmap_match_tag_1_ipv6",
395 "name": "rmap_match_tag_1_ipv6",
410 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
411 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
415 for adt
in ADDR_TYPES
:
416 # Verifying RIB routes
423 "network": [NETWORK
[adt
][1]],
425 "next_hop": NEXT_HOP
[adt
],
432 tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
, expected
=False
434 assert result
is not True, (
435 "Testcase {} : Failed \n "
436 "Expected: Routes should not be present in {} BGP RIB \n "
437 "Found: {}".format(tc_name
, dut
, result
)
440 # Verifying RIB routes
446 "network": [NETWORK
[adt
][0]],
448 "next_hop": NEXT_HOP
[adt
],
454 tgen
, adt
, dut
, input_dict
, protocol
=protocol
, expected
=False
456 assert result
is not True, (
457 "Testcase {} : Failed \n "
458 "Expected: Routes should not be present in {} FIB \n "
459 "Found: {}".format(tc_name
, dut
, result
)
462 write_test_footer(tc_name
)
465 @pytest.mark
.parametrize(
466 "prefix_action, rmap_action",
467 [("permit", "permit"), ("permit", "deny"), ("deny", "permit"), ("deny", "deny")],
469 def test_route_map_with_action_values_combination_of_prefix_action_p0(
470 request
, prefix_action
, rmap_action
474 Test permit/deny statements operation in route-maps with a permutation and
475 combination of permit/deny in prefix-lists
477 tc_name
= request
.node
.name
478 write_test_header(tc_name
)
481 # Don"t run this test if we have any failure.
482 if tgen
.routers_have_failure():
483 pytest
.skip(tgen
.errors
)
485 # Creating configuration from JSON
486 reset_config_on_routers(tgen
)
488 for adt
in ADDR_TYPES
:
489 # Create Static routes
494 "network": NETWORK
[adt
][0],
496 "next_hop": NEXT_HOP
[adt
],
502 result
= create_static_routes(tgen
, input_dict
)
503 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
507 # Api call to redistribute static routes
516 {"redist_type": "static"},
517 {"redist_type": "connected"},
524 {"redist_type": "static"},
525 {"redist_type": "connected"},
534 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
535 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
539 # Permit in perfix list and route-map
545 {"seqid": 10, "network": "any", "action": prefix_action
}
550 {"seqid": 100, "network": "any", "action": prefix_action
}
556 result
= create_prefix_lists(tgen
, input_dict_2
)
557 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
562 for addr_type
in ADDR_TYPES
:
566 "rmap_match_pf_1_{}".format(addr_type
): [
568 "action": rmap_action
,
571 "prefix_lists": "pf_list_1_{}".format(addr_type
)
579 result
= create_route_maps(tgen
, input_dict_3
)
580 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
584 # Configure neighbor for route map
597 "name": "rmap_match_pf_1_ipv4",
615 "name": "rmap_match_pf_1_ipv6",
630 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
631 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
641 "network": [NETWORK
[adt
][0]],
643 "next_hop": NEXT_HOP
[adt
],
650 if "deny" in [prefix_action
, rmap_action
]:
652 tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
, expected
=False
654 assert result
is not True, (
655 "Testcase {} : Failed \n "
656 "Expected: Routes should not be present in {} FIB \n "
657 "Found: {}".format(tc_name
, dut
, result
)
660 result
= verify_rib(tgen
, adt
, dut
, input_dict_2
, protocol
=protocol
)
661 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
666 def test_route_map_multiple_seq_different_match_set_clause_p0(request
):
669 Test multiple sequence numbers in a single route-map for different
675 tc_name
= request
.node
.name
676 write_test_header(tc_name
)
678 # Creating configuration from JSON
679 reset_config_on_routers(tgen
)
681 for adt
in ADDR_TYPES
:
682 # Create Static routes
687 "network": NETWORK
[adt
][0],
689 "next_hop": NEXT_HOP
[adt
],
694 result
= create_static_routes(tgen
, input_dict
)
695 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
699 # Api call to redistribute static routes
707 {"redist_type": "static"},
708 {"redist_type": "connected"},
715 {"redist_type": "static"},
716 {"redist_type": "connected"},
724 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
725 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
729 # Create ip prefix list
735 {"seqid": 10, "network": "any", "action": "permit"}
740 {"seqid": 100, "network": "any", "action": "permit"}
746 result
= create_prefix_lists(tgen
, input_dict_2
)
747 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
752 for addr_type
in ADDR_TYPES
:
756 "rmap_match_pf_1_{}".format(addr_type
): [
761 "prefix_lists": "pf_list_2_{}".format(addr_type
)
764 "set": {"path": {"as_num": 500}},
770 "prefix_lists": "pf_list_2_{}".format(addr_type
)
781 "prefix_lists": "pf_list_1_{}".format(addr_type
)
784 "set": {"metric": 50},
790 result
= create_route_maps(tgen
, input_dict_3
)
791 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
795 # Configure neighbor for route map
808 "name": "rmap_match_pf_1_ipv4",
820 "name": "rmap_match_pf_1_ipv4",
838 "name": "rmap_match_pf_1_ipv6",
850 "name": "rmap_match_pf_1_ipv6",
864 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
865 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
869 for adt
in ADDR_TYPES
:
870 # Verifying RIB routes
876 "rmap_match_pf_list1": [
887 static_routes
= [NETWORK
[adt
][0]]
890 result
= verify_bgp_attributes(
891 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
893 assert result
is True, "Test case {} : Failed \n Error: {}".format(
898 result
= verify_bgp_attributes(
899 tgen
, adt
, dut
, static_routes
, "rmap_match_pf_list1", input_dict
901 assert result
is True, "Test case {} : Failed \n Error: {}".format(
905 logger
.info("Testcase " + tc_name
+ " :Passed \n")
907 # Uncomment next line for debugging
911 def test_route_map_set_only_no_match_p0(request
):
914 Test add/remove route-maps with multiple set
915 clauses and without any match statement.(Set only)
920 tc_name
= request
.node
.name
921 write_test_header(tc_name
)
923 # Creating configuration from JSON
924 reset_config_on_routers(tgen
)
926 for adt
in ADDR_TYPES
:
927 # Create Static routes
932 "network": NETWORK
[adt
][0],
934 "next_hop": NEXT_HOP
[adt
],
939 result
= create_static_routes(tgen
, input_dict
)
940 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
944 # Api call to redistribute static routes
952 {"redist_type": "static"},
953 {"redist_type": "connected"},
960 {"redist_type": "static"},
961 {"redist_type": "connected"},
969 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
970 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
981 "set": {"metric": 50, "locPrf": 150, "weight": 4000},
987 result
= create_route_maps(tgen
, input_dict_3
)
988 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
992 # Configure neighbor for route map
1005 "name": "rmap_match_pf_1",
1017 "name": "rmap_match_pf_1",
1035 "name": "rmap_match_pf_1",
1047 "name": "rmap_match_pf_1",
1061 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1062 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1067 for adt
in ADDR_TYPES
:
1071 "rmap_match_pf_1": [
1082 # Verifying RIB routes
1083 static_routes
= [NETWORK
[adt
][0]]
1084 result
= verify_bgp_attributes(
1085 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1087 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1091 result
= verify_bgp_attributes(
1092 tgen
, adt
, "r4", static_routes
, "rmap_match_pf_1", input_dict_4
1094 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1098 logger
.info("Testcase " + tc_name
+ " :Passed \n")
1100 # Uncomment next line for debugging
1101 # tgen.mininet_cli()
1104 def test_route_map_match_only_no_set_p0(request
):
1107 Test add/remove route-maps with multiple match
1108 clauses and without any set statement.(Match only)
1111 tgen
= get_topogen()
1113 tc_name
= request
.node
.name
1114 write_test_header(tc_name
)
1116 # Creating configuration from JSON
1117 reset_config_on_routers(tgen
)
1119 for adt
in ADDR_TYPES
:
1120 # Create Static routes
1125 "network": NETWORK
[adt
][0],
1127 "next_hop": NEXT_HOP
[adt
],
1132 result
= create_static_routes(tgen
, input_dict
)
1133 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1137 # Api call to redistribute static routes
1145 {"redist_type": "static"},
1146 {"redist_type": "connected"},
1153 {"redist_type": "static"},
1154 {"redist_type": "connected"},
1162 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1163 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1167 # Create ip prefix list
1173 {"seqid": 10, "network": "any", "action": "permit"}
1178 {"seqid": 100, "network": "any", "action": "permit"}
1184 result
= create_prefix_lists(tgen
, input_dict_2
)
1185 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1190 for addr_type
in ADDR_TYPES
:
1194 "rmap_match_pf_1_{}".format(addr_type
): [
1206 result
= create_route_maps(tgen
, input_dict_3
)
1207 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1211 # Configure neighbor for route map
1224 "name": "rmap_match_pf_1_ipv4",
1242 "name": "rmap_match_pf_1_ipv6",
1256 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1257 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1261 # Create ip prefix list
1267 {"seqid": 10, "network": "any", "action": "permit"}
1272 {"seqid": 100, "network": "any", "action": "permit"}
1278 result
= create_prefix_lists(tgen
, input_dict_5
)
1279 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1284 for addr_type
in ADDR_TYPES
:
1288 "rmap_match_pf_2_{}".format(addr_type
): [
1293 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1301 result
= create_route_maps(tgen
, input_dict_6
)
1302 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1306 # Configure neighbor for route map
1319 "name": "rmap_match_pf_2_ipv4",
1331 "name": "rmap_match_pf_2_ipv4",
1349 "name": "rmap_match_pf_2_ipv6",
1361 "name": "rmap_match_pf_2_ipv6",
1375 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
1376 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1380 for adt
in ADDR_TYPES
:
1381 # Verifying RIB routes
1382 static_routes
= [NETWORK
[adt
][0]]
1383 result
= verify_bgp_attributes(
1384 tgen
, adt
, "r3", static_routes
, "rmap_match_pf_1", input_dict_3
1386 assert result
is True, "Test case {} : Failed \n Error: {}".format(
1391 if __name__
== "__main__":
1392 args
= ["-s"] + sys
.argv
[1:]
1393 sys
.exit(pytest
.main(args
))