]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
4 # Copyright (c) 2020 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
25 Following tests are covered in the script.
27 - Verify static route are blocked from route-map and prefix-list
38 from copy
import deepcopy
40 # Save the Current Working Directory to find configuration files.
41 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
42 sys
.path
.append(os
.path
.join(CWD
, "../"))
43 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
44 # pylint: disable=C0413
45 # Import topogen and topotest helpers
46 from mininet
.topo
import Topo
47 from lib
.topogen
import Topogen
, get_topogen
49 from lib
.common_config
import (
53 reset_config_on_routers
,
59 create_interfaces_cfg
,
63 from lib
.topolog
import logger
65 verify_bgp_convergence
,
70 from lib
.topojson
import build_topo_from_json
, build_config_from_json
71 from lib
.topotest
import version_cmp
73 # Reading the data from JSON File for topology creation
74 jsonFile
= "{}/static_routes_topo4_ibgp.json".format(CWD
)
76 with
open(jsonFile
, "r") as topoJson
:
77 topo
= json
.load(topoJson
)
79 assert False, "Could not read file {}".format(jsonFile
)
82 BGP_CONVERGENCE
= False
83 ADDR_TYPES
= check_address_types()
84 NETWORK
= {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
87 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
90 class CreateTopo(Topo
):
92 Test CreateTopo - topology 1.
94 * `Topo`: Topology object
97 def build(self
, *_args
, **_opts
):
99 tgen
= get_topogen(self
)
101 # Building topology from json file
102 build_topo_from_json(tgen
, topo
)
105 def setup_module(mod
):
107 Set up the pytest environment.
111 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
112 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
113 logger
.info("=" * 40)
115 logger
.info("Running setup_module to create topology")
117 # This function initiates the topology build with Topogen...
118 tgen
= Topogen(CreateTopo
, mod
.__name
__)
119 # ... and here it calls Mininet initialization functions.
121 # Starting topology, create tmp files which are loaded to routers
122 # to start deamons and then start routers
125 # Creating configuration from JSON
126 build_config_from_json(tgen
, topo
)
128 if version_cmp(platform
.release(), "4.19") < 0:
130 'These tests will not run. (have kernel "{}", '
131 "requires kernel >= 4.19)".format(platform
.release())
133 pytest
.skip(error_msg
)
135 # Checking BGP convergence
136 global BGP_CONVERGENCE
138 # Don't run this test if we have any failure.
139 if tgen
.routers_have_failure():
140 pytest
.skip(tgen
.errors
)
141 # Api call verify whether BGP is converged
142 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
143 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
147 logger
.info("Running setup_module() done")
150 def teardown_module(mod
):
152 Teardown the pytest environment.
156 logger
.info("Running teardown_module to delete topology")
160 # Stop toplogy and Remove tmp files
164 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
166 logger
.info("=" * 40)
169 #####################################################
173 #####################################################
174 def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request
):
176 Verify static route are blocked from route-map & prefix-list applied in BGP
180 tc_name
= request
.node
.name
181 write_test_header(tc_name
)
183 # Don't run this test if we have any failure.
184 if tgen
.routers_have_failure():
185 pytest
.skip(tgen
.errors
)
186 reset_config_on_routers(tgen
)
187 step("Configure holddown timer = 1 keep alive = 3 in all the neighbors")
188 step("verify bgp convergence before starting test case")
190 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
191 assert bgp_convergence
is True, "Testcase {} : Failed \n Error: {}".format(
192 tc_name
, bgp_convergence
196 "Configure 4 IPv4 and 4 IPv6 nbrs with password with mismatch "
197 " authentication between FRR routers "
200 for addr_type
in ADDR_TYPES
:
201 # Api call to modfiy BGP timerse
212 "r2-link0": {"password": "r2"},
213 "r2-link1": {"password": "r2"},
214 "r2-link2": {"password": "r2"},
215 "r2-link3": {"password": "r2"},
220 "r2-link0": {"password": "r2"},
221 "r2-link1": {"password": "r2"},
222 "r2-link2": {"password": "r2"},
223 "r2-link3": {"password": "r2"},
233 result
= create_router_bgp(tgen
, topo
, deepcopy(input_dict
))
234 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
237 clear_bgp(tgen
, addr_type
, "r2")
239 step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
241 bgp_convergence
= verify_bgp_convergence(tgen
, topo
, expected
=False)
243 bgp_convergence
is not True
244 ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
245 tc_name
, bgp_convergence
249 "Configure 4 IPv4 and 4 IPv6 nbrs with macthing password "
250 " authentication between FRR routers "
252 for addr_type
in ADDR_TYPES
:
263 "r2-link0": {"password": "r1"},
264 "r2-link1": {"password": "r1"},
265 "r2-link2": {"password": "r1"},
266 "r2-link3": {"password": "r1"},
271 "r2-link0": {"password": "r1"},
272 "r2-link1": {"password": "r1"},
273 "r2-link2": {"password": "r1"},
274 "r2-link3": {"password": "r1"},
284 result
= create_router_bgp(tgen
, topo
, deepcopy(input_dict
))
285 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
289 step("All BGP nbrs are up as authentication is matched now")
290 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
291 assert bgp_convergence
is True, "Testcase {} : Failed \n " "Error: {}".format(
292 tc_name
, bgp_convergence
295 step("Create prefix list P1 to permit VM3 & deny VM1 v4 & v6 routes")
296 step("Create prefix list P2 to permit VM6 IPv4 and IPv6 routes")
297 for addr_type
in ADDR_TYPES
:
302 "pf_list_1_{}".format(addr_type
): [
305 "network": topo
["routers"]["r2"]["links"]["vm3"][
312 "network": topo
["routers"]["r2"]["links"]["vm1"][
318 "pf_list_2_{}".format(addr_type
): [
321 "network": topo
["routers"]["r2"]["links"]["vm6"][
331 result
= create_prefix_lists(tgen
, input_dict_2
)
332 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
337 "Prefix list created with matching networks deny or permit "
338 "show ip prefix list"
340 result
= verify_prefix_lists(tgen
, input_dict_2
)
341 assert result
is not True, "Testcase {} : Failed \n" " Error: {}".format(
345 step("Redistribute all the routes (connected, static)")
351 "unicast": {"redistribute": [{"redist_type": "static"}]}
357 result
= create_router_bgp(tgen
, topo
, input_dict_2_r1
)
358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
367 "unicast": {"redistribute": [{"redist_type": "static"}]}
373 result
= create_router_bgp(tgen
, topo
, input_dict_2_r2
)
374 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
383 "unicast": {"redistribute": [{"redist_type": "static"}]}
389 result
= create_router_bgp(tgen
, topo
, input_dict_2_r3
)
390 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
394 step("configure redistribute connected in Router BGP")
401 "unicast": {"redistribute": [{"redist_type": "connected"}]}
407 result
= create_router_bgp(tgen
, topo
, input_dict_2_r1
)
408 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
417 "unicast": {"redistribute": [{"redist_type": "connected"}]}
423 result
= create_router_bgp(tgen
, topo
, input_dict_2_r3
)
424 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
433 "unicast": {"redistribute": [{"redist_type": "connected"}]}
439 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
440 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
444 step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
445 # Configure prefix list to bgp neighbor
458 "name": "pf_list_1_{}".format(
468 "name": "pf_list_1_{}".format(
478 "name": "pf_list_1_{}".format(
488 "name": "pf_list_1_{}".format(
504 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
505 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
509 step("Apply prefix list P2 on BGP nbrs 5 & 6 connected from FRR-2")
510 # Configure prefix list to bgp neighbor
523 "name": "pf_list_2_{}".format(
533 "name": "pf_list_2_{}".format(
543 "name": "pf_list_2_{}".format(
553 "name": "pf_list_2_{}".format(
569 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
570 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
574 clear_bgp_and_verify(tgen
, topo
, "r2")
577 "VM1 IPv4 and IPv6 Route which is denied using prefix list is "
578 "not present on FRR1 side routing table , also not able to "
579 "ping the routes show ip route"
585 ipaddress
.ip_interface(
586 u
"{}".format(topo
["routers"]["r2"]["links"]["vm1"][addr_type
])
589 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
590 result4
= verify_rib(
591 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
593 assert result4
is not True, (
594 "Testcase {} : Failed , VM1 route is "
595 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
599 "VM4 and VM6 IPV4 and IPv6 address are present in local and "
600 "FRR2 routing table show ip bgp show ip route"
605 ipaddress
.ip_interface(
606 u
"{}".format(topo
["routers"]["r2"]["links"]["vm6"][addr_type
])
609 input_dict
= {"r3": {"static_routes": [{"network": ntwk_r2_vm6
}]}}
610 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
611 assert result4
is True, "Testcase {} : Failed.\n Error: {}".format(
615 step("Remove prefix list from all the neighbors")
628 "name": "pf_list_1_{}".format(
639 "name": "pf_list_1_{}".format(
650 "name": "pf_list_1_{}".format(
661 "name": "pf_list_1_{}".format(
678 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
679 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
695 "name": "pf_list_2_{}".format(
706 "name": "pf_list_2_{}".format(
717 "name": "pf_list_2_{}".format(
728 "name": "pf_list_2_{}".format(
745 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
746 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
750 clear_bgp_and_verify(tgen
, topo
, "r2")
752 step("Create RouteMap_1 with prefix list P1 and weight 50")
757 "rmap_pf_list_1_{}".format(addr_type
): [
760 "set": {"weight": 50},
763 "prefix_lists": "pf_list_1_{}".format(addr_type
)
771 result
= create_route_maps(tgen
, rmap_dict
)
772 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
776 step("Create RouteMap_2 with prefix list P2 and weight 50")
781 "rmap_pf_list_2_{}".format(addr_type
): [
784 "set": {"weight": 50},
787 "prefix_lists": "pf_list_2_{}".format(addr_type
)
795 result
= create_route_maps(tgen
, rmap_dict
)
796 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
800 step("Verify Route-map created verify using show route-map")
801 # verify rmap_pf_list_1 and rmap_pf_list_2 are present in router r2
805 "rmap_pf_list_1_{}".format(addr_type
),
806 "rmap_pf_list_2_{}".format(addr_type
),
810 result
= verify_route_maps(tgen
, input_dict
, expected
=False)
811 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
815 step("Apply policy RouteMap_1 nbrs 1 2 3 4 to FRR 1")
816 # Configure prefix list to bgp neighbor
829 "name": "rmap_pf_list_1_"
830 "{}".format(addr_type
),
838 "name": "rmap_pf_list_1_"
839 "{}".format(addr_type
),
847 "name": "rmap_pf_list_1_"
848 "{}".format(addr_type
),
856 "name": "rmap_pf_list_1_"
857 "{}".format(addr_type
),
871 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
872 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
876 step("Apply policy RouteMap_2 nbrs 5 and 6 to FRR2")
877 # Configure prefix list to bgp neighbor
890 "name": "rmap_pf_list_2_"
891 "{}".format(addr_type
),
899 "name": "rmap_pf_list_2_"
900 "{}".format(addr_type
),
908 "name": "rmap_pf_list_2_"
909 "{}".format(addr_type
),
917 "name": "rmap_pf_list_2_"
918 "{}".format(addr_type
),
932 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
933 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
938 "After applying to BGP neighbors verify VM1 IPv4 and IPv6 Route"
939 " which is denied using prefix list is not present on FRR side"
940 " routing table , also not able to ping the routes show ip route"
941 " and VM4 and VM6 IPV4 and IPv6 address are present in local and"
942 " FRR routing table show ip bgp show ip route"
948 ipaddress
.ip_interface(
949 u
"{}".format(topo
["routers"]["r2"]["links"]["vm1"][addr_type
])
952 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
953 result4
= verify_rib(
954 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
958 ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
962 step("vm4 should be present in FRR1")
965 ipaddress
.ip_interface(
966 u
"{}".format(topo
["routers"]["r1"]["links"]["vm4"][addr_type
])
969 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
970 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
971 assert result4
is True, (
972 "Testcase {} : Failed , VM1 route is "
973 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
976 step("vm4 should be present in FRR2")
979 ipaddress
.ip_interface(
980 u
"{}".format(topo
["routers"]["r1"]["links"]["vm4"][addr_type
])
983 input_dict
= {"r1": {"static_routes": [{"network": ntwk_r2_vm1
}]}}
984 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
985 assert result4
is True, (
986 "Testcase {} : Failed , VM1 route is "
987 "not filtered out via prefix list. \n Error: {}".format(tc_name
, result4
)
993 ipaddress
.ip_interface(
994 u
"{}".format(topo
["routers"]["r2"]["links"]["vm6"][addr_type
])
997 input_dict
= {"r3": {"static_routes": [{"network": ntwk_r2_vm6
}]}}
998 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
999 assert result4
is True, "Testcase {} : Failed.\n Error: {}".format(
1003 write_test_footer(tc_name
)
1006 if __name__
== "__main__":
1007 args
= ["-s"] + sys
.argv
[1:]
1008 sys
.exit(pytest
.main(args
))