]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
12 Following tests are covered in the script.
14 - Verify static route are blocked from route-map and prefix-list
16 - Verify Static route when FRR connected to 2 TOR
25 from copy
import deepcopy
27 # Save the Current Working Directory to find configuration files.
28 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
29 sys
.path
.append(os
.path
.join(CWD
, "../"))
30 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
31 # pylint: disable=C0413
32 # Import topogen and topotest helpers
33 from lib
.topogen
import Topogen
, get_topogen
34 from lib
.topotest
import version_cmp
36 # Import topoJson from lib, to create topology and initial configuration
37 from lib
.common_config
import (
41 reset_config_on_routers
,
50 from lib
.topolog
import logger
52 verify_bgp_convergence
,
57 from lib
.topojson
import build_config_from_json
60 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
63 BGP_CONVERGENCE
= False
64 ADDR_TYPES
= check_address_types()
65 NETWORK
= {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
68 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
71 def setup_module(mod
):
73 Set up the pytest environment.
77 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
78 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
81 logger
.info("Running setup_module to create topology")
83 # This function initiates the topology build with Topogen...
84 json_file
= "{}/static_routes_topo4_ebgp.json".format(CWD
)
85 tgen
= Topogen(json_file
, mod
.__name
__)
88 # ... and here it calls Mininet initialization functions.
90 # Starting topology, create tmp files which are loaded to routers
91 # to start daemons and then start routers
94 # Creating configuration from JSON
95 build_config_from_json(tgen
, topo
)
97 if version_cmp(platform
.release(), "4.19") < 0:
99 'These tests will not run. (have kernel "{}", '
100 "requires kernel >= 4.19)".format(platform
.release())
102 pytest
.skip(error_msg
)
104 # Checking BGP convergence
106 # Don't run this test if we have any failure.
107 if tgen
.routers_have_failure():
108 pytest
.skip(tgen
.errors
)
109 # Api call verify whether BGP is converged
110 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
111 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
115 logger
.info("Running setup_module() done")
118 def teardown_module(mod
):
120 Teardown the pytest environment.
124 logger
.info("Running teardown_module to delete topology")
128 # Stop toplogy and Remove tmp files
132 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
134 logger
.info("=" * 40)
137 #####################################################
141 #####################################################
142 def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request
):
144 Verify static route are blocked from route-map & prefix-list applied in BGP
148 tc_name
= request
.node
.name
149 write_test_header(tc_name
)
151 # Don't run this test if we have any failure.
152 if tgen
.routers_have_failure():
153 pytest
.skip(tgen
.errors
)
154 reset_config_on_routers(tgen
)
155 step("Configure holddown timer = 1 keep alive = 3 in all the neighbors")
156 step("verify bgp convergence before starting test case")
158 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
159 assert bgp_convergence
is True, "Testcase {} : Failed \n Error: {}".format(
160 tc_name
, bgp_convergence
164 "Configure 4 IPv4 and 4 IPv6 nbrs with password with mismatch "
165 " authentication between FRR routers "
168 for addr_type
in ADDR_TYPES
:
169 # Api call to modify BGP timers
180 "r2-link0": {"password": "r2"},
181 "r2-link1": {"password": "r2"},
182 "r2-link2": {"password": "r2"},
183 "r2-link3": {"password": "r2"},
188 "r2-link0": {"password": "r2"},
189 "r2-link1": {"password": "r2"},
190 "r2-link2": {"password": "r2"},
191 "r2-link3": {"password": "r2"},
201 result
= create_router_bgp(tgen
, topo
, input_dict
)
202 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
205 clear_bgp(tgen
, addr_type
, "r2")
207 step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
209 bgp_convergence
= verify_bgp_convergence(tgen
, topo
, expected
=False)
211 bgp_convergence
is not True
212 ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
213 tc_name
, bgp_convergence
217 "Configure 4 IPv4 and 4 IPv6 nbrs with macthing password "
218 " authentication between FRR routers "
220 for addr_type
in ADDR_TYPES
:
231 "r2-link0": {"password": "r1"},
232 "r2-link1": {"password": "r1"},
233 "r2-link2": {"password": "r1"},
234 "r2-link3": {"password": "r1"},
239 "r2-link0": {"password": "r1"},
240 "r2-link1": {"password": "r1"},
241 "r2-link2": {"password": "r1"},
242 "r2-link3": {"password": "r1"},
252 result
= create_router_bgp(tgen
, topo
, deepcopy(input_dict
))
253 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
257 step("All BGP nbrs are up as authentication is matched now")
258 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
259 assert bgp_convergence
is True, "Testcase {} : Failed \n " "Error: {}".format(
260 tc_name
, bgp_convergence
263 step("Create prefix list P1 to permit VM3 & deny VM1 v4 & v6 routes")
264 step("Create prefix list P2 to permit VM6 IPv4 and IPv6 routes")
265 for addr_type
in ADDR_TYPES
:
270 "pf_list_1_{}".format(addr_type
): [
273 "network": topo
["routers"]["r2"]["links"]["vm3"][
280 "network": topo
["routers"]["r2"]["links"]["vm1"][
286 "pf_list_2_{}".format(addr_type
): [
289 "network": topo
["routers"]["r2"]["links"]["vm6"][
299 result
= create_prefix_lists(tgen
, input_dict_2
)
300 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
305 "Prefix list created with matching networks deny or permit "
306 "show ip prefix list"
308 result
= verify_prefix_lists(tgen
, input_dict_2
)
309 assert result
is not True, "Testcase {} : Failed \n" " Error: {}".format(
313 step("Redistribute all the routes (connected, static)")
319 "unicast": {"redistribute": [{"redist_type": "static"}]}
325 result
= create_router_bgp(tgen
, topo
, input_dict_2_r1
)
326 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
335 "unicast": {"redistribute": [{"redist_type": "static"}]}
341 result
= create_router_bgp(tgen
, topo
, input_dict_2_r2
)
342 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
351 "unicast": {"redistribute": [{"redist_type": "static"}]}
357 result
= create_router_bgp(tgen
, topo
, input_dict_2_r3
)
358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
362 step("configure redistribute connected in Router BGP")
369 "unicast": {"redistribute": [{"redist_type": "connected"}]}
375 result
= create_router_bgp(tgen
, topo
, input_dict_2_r1
)
376 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
385 "unicast": {"redistribute": [{"redist_type": "connected"}]}
391 result
= create_router_bgp(tgen
, topo
, input_dict_2_r3
)
392 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
401 "unicast": {"redistribute": [{"redist_type": "connected"}]}
407 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
408 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
412 step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
413 # Configure prefix list to bgp neighbor
426 "name": "pf_list_1_{}".format(
436 "name": "pf_list_1_{}".format(
446 "name": "pf_list_1_{}".format(
456 "name": "pf_list_1_{}".format(
472 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
473 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
477 step("Apply prefix list P2 on BGP nbrs 5 & 6 connected from FRR-2")
478 # Configure prefix list to bgp neighbor
491 "name": "pf_list_2_{}".format(
501 "name": "pf_list_2_{}".format(
511 "name": "pf_list_2_{}".format(
521 "name": "pf_list_2_{}".format(
537 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
538 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
542 clear_bgp_and_verify(tgen
, topo
, "r2")
545 "VM1 IPv4 and IPv6 Route which is denied using prefix list is "
546 "not present on FRR1 side routing table , also not able to "
547 "ping the routes show ip route"
553 ipaddress
.ip_interface(
554 u
"{}".format(topo
["routers"]["r2"]["links"]["vm1"][addr_type
])
557 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
558 result4
= verify_rib(
559 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
561 assert result4
is not True, (
562 "Testcase {} : Failed , VM1 route is "
563 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
567 "VM4 and VM6 IPV4 and IPv6 address are present in local and "
568 "FRR2 routing table show ip bgp show ip route"
573 ipaddress
.ip_interface(
574 u
"{}".format(topo
["routers"]["r2"]["links"]["vm6"][addr_type
])
577 input_dict
= {"r3": {"static_routes": [{"network": ntwk_r2_vm6
}]}}
578 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
579 assert result4
is True, "Testcase {} : Failed.\n Error: {}".format(
583 step("Remove prefix list from all the neighbors")
596 "name": "pf_list_1_{}".format(
607 "name": "pf_list_1_{}".format(
618 "name": "pf_list_1_{}".format(
629 "name": "pf_list_1_{}".format(
646 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
647 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
663 "name": "pf_list_2_{}".format(
674 "name": "pf_list_2_{}".format(
685 "name": "pf_list_2_{}".format(
696 "name": "pf_list_2_{}".format(
713 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
714 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
718 clear_bgp_and_verify(tgen
, topo
, "r2")
720 step("Create RouteMap_1 with prefix list P1 and weight 50")
725 "rmap_pf_list_1_{}".format(addr_type
): [
728 "set": {"weight": 50},
731 "prefix_lists": "pf_list_1_{}".format(addr_type
)
739 result
= create_route_maps(tgen
, rmap_dict
)
740 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
744 step("Create RouteMap_2 with prefix list P2 and weight 50")
749 "rmap_pf_list_2_{}".format(addr_type
): [
752 "set": {"weight": 50},
755 "prefix_lists": "pf_list_2_{}".format(addr_type
)
763 result
= create_route_maps(tgen
, rmap_dict
)
764 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
768 step("Verify Route-map created verify using show route-map")
769 # verify rmap_pf_list_1 and rmap_pf_list_2 are present in router r2
773 "rmap_pf_list_1_{}".format(addr_type
),
774 "rmap_pf_list_2_{}".format(addr_type
),
778 result
= verify_route_maps(tgen
, input_dict
, expected
=False)
779 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
783 step("Apply policy RouteMap_1 nbrs 1 2 3 4 to FRR 1")
784 # Configure prefix list to bgp neighbor
797 "name": "rmap_pf_list_1_"
798 "{}".format(addr_type
),
806 "name": "rmap_pf_list_1_"
807 "{}".format(addr_type
),
815 "name": "rmap_pf_list_1_"
816 "{}".format(addr_type
),
824 "name": "rmap_pf_list_1_"
825 "{}".format(addr_type
),
839 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
840 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
844 step("Apply policy RouteMap_2 nbrs 5 and 6 to FRR2")
845 # Configure prefix list to bgp neighbor
858 "name": "rmap_pf_list_2_"
859 "{}".format(addr_type
),
867 "name": "rmap_pf_list_2_"
868 "{}".format(addr_type
),
876 "name": "rmap_pf_list_2_"
877 "{}".format(addr_type
),
885 "name": "rmap_pf_list_2_"
886 "{}".format(addr_type
),
900 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
901 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
906 "After applying to BGP neighbors verify VM1 IPv4 and IPv6 Route"
907 " which is denied using prefix list is not present on FRR side"
908 " routing table , also not able to ping the routes show ip route"
909 " and VM4 and VM6 IPV4 and IPv6 address are present in local and"
910 " FRR routing table show ip bgp show ip route"
916 ipaddress
.ip_interface(
917 u
"{}".format(topo
["routers"]["r2"]["links"]["vm1"][addr_type
])
920 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
921 result4
= verify_rib(
922 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
926 ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
930 step("vm4 should be present in FRR1")
933 ipaddress
.ip_interface(
934 u
"{}".format(topo
["routers"]["r1"]["links"]["vm4"][addr_type
])
937 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
938 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
939 assert result4
is True, (
940 "Testcase {} : Failed , VM1 route is "
941 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
944 step("vm4 should be present in FRR2")
947 ipaddress
.ip_interface(
948 u
"{}".format(topo
["routers"]["r1"]["links"]["vm4"][addr_type
])
951 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
952 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
953 assert result4
is True, (
954 "Testcase {} : Failed , VM1 route is "
955 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
961 ipaddress
.ip_interface(
962 u
"{}".format(topo
["routers"]["r2"]["links"]["vm6"][addr_type
])
965 input_dict
= {"r3": {"static_routes": [{"network": ntwk_r2_vm6
}]}}
966 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
967 assert result4
is True, "Testcase {} : Failed.\n Error: {}".format(
971 write_test_footer(tc_name
)
974 if __name__
== "__main__":
975 args
= ["-s"] + sys
.argv
[1:]
976 sys
.exit(pytest
.main(args
))