]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_asn/test_bgp_local_asn_agg.py
3 # Copyright (c) 2022 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation,
5 # Inc. ("NetDEF") in this file.
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 Following tests are covered to test BGP Multi-VRF Dynamic Route Leaking:
25 1. Verify the BGP Local AS functionality by aggregating routes in between eBGP Peers.
33 # Save the Current Working Directory to find configuration files.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
38 # pylint: disable=C0413
39 # Import topogen and topotest helpers
40 from lib
.topogen
import Topogen
, get_topogen
41 from lib
.topotest
import version_cmp
43 from lib
.common_config
import (
47 reset_config_on_routers
,
54 from lib
.topolog
import logger
56 verify_bgp_convergence
,
60 from lib
.topojson
import build_config_from_json
62 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
65 BGP_CONVERGENCE
= False
66 ADDR_TYPES
= check_address_types()
67 NETWORK_1_1
= {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
68 NETWORK_1_2
= {"ipv4": "10.1.2.0/32", "ipv6": "10:1::2:0/128"}
69 AGGREGATE_NW
= {"ipv4": "10.1.0.0/16", "ipv6": "10:1::/96"}
70 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
73 def setup_module(mod
):
75 Sets up the pytest environment
80 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
81 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
84 logger
.info("Running setup_module to create topology")
86 # This function initiates the topology build with Topogen...
87 json_file
= "{}/bgp_local_asn_agg.json".format(CWD
)
88 tgen
= Topogen(json_file
, mod
.__name
__)
91 # ... and here it calls Mininet initialization functions.
93 # Starting topology, create tmp files which are loaded to routers
94 # to start daemons and then start routers
97 # Creating configuration from JSON
98 build_config_from_json(tgen
, topo
)
100 global BGP_CONVERGENCE
102 ADDR_TYPES
= check_address_types()
104 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
105 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
109 logger
.info("Running setup_module() done")
112 def teardown_module():
113 """Teardown the pytest environment"""
115 logger
.info("Running teardown_module to delete topology")
119 # Stop toplogy and Remove tmp files
123 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
125 logger
.info("=" * 40)
128 ####################################################################################################################
132 ####################################################################################################################
135 def test_verify_bgp_local_as_agg_in_EBGP_p0(request
):
137 Verify the BGP Local AS functionality by aggregating routes in between eBGP Peers.
140 global BGP_CONVERGENCE
142 if BGP_CONVERGENCE
!= True:
143 pytest
.skip("skipped because of BGP Convergence failure")
146 tc_name
= request
.node
.name
147 write_test_header(tc_name
)
148 if tgen
.routers_have_failure():
149 check_router_status(tgen
)
150 reset_config_on_routers(tgen
)
152 step("Base config is done as part of JSON")
153 step("Configure local-as at R3 towards R4.")
154 for addr_type
in ADDR_TYPES
:
155 for neighbor
in ["r2", "r4"]:
166 "r3": {"local_asn": {"local_as": "110"}}
176 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
177 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
181 for addr_type
in ADDR_TYPES
:
182 for dut
, asn
, neighbor
in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
193 dut
: {"local_asn": {"remote_as": "110"}}
203 result
= create_router_bgp(tgen
, topo
, input_dict_r2_r4
)
204 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
208 step("BGP neighborship is verified by following commands in R3 routers")
209 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
210 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
214 step("Done in base config: Advertise prefix 10.1.1.0/24 from Router-1(AS-100).")
216 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/120 from Router-1(AS-100)."
218 step("Verify that Static routes are redistributed in BGP process")
219 for addr_type
in ADDR_TYPES
:
220 input_static_verify_r1
= {
221 "r1": {"static_routes": [{"network": NETWORK_1_1
[addr_type
]}]}
224 input_static_verify_r2
= {
225 "r2": {"static_routes": [{"network": NETWORK_1_2
[addr_type
]}]}
227 result
= verify_rib(tgen
, addr_type
, "r1", input_static_verify_r1
)
228 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
232 result
= verify_rib(tgen
, addr_type
, "r2", input_static_verify_r2
)
233 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
237 step("Configure aggregate-address to summarise all the advertised routes.")
238 for addr_type
in ADDR_TYPES
:
245 "aggregate_address": [
247 "network": AGGREGATE_NW
[addr_type
],
259 result
= create_router_bgp(tgen
, topo
, route_aggregate
)
260 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
265 "Verify that we see a summarised route on advertising router R3 "
266 "and receiving router R4 for both AFIs"
269 for addr_type
in ADDR_TYPES
:
270 input_static_agg_r1
= {
271 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
274 "r1": {"static_routes": [{"network": [NETWORK_1_1
[addr_type
]]}]}
278 "r2": {"static_routes": [{"network": [NETWORK_1_2
[addr_type
]]}]}
281 for dut
in ["r3", "r4"]:
282 result
= verify_rib(tgen
, addr_type
, dut
, input_static_agg_r1
)
283 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
287 for dut
, input_routes
in zip(["r1", "r2"], [input_static_r1
, input_static_r2
]):
288 result
= verify_rib(tgen
, addr_type
, dut
, input_routes
)
289 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
294 "Verify that AS-110 is got added in the AS list 110 {100,110,200} by following "
295 "commands at R3 router."
298 aspath
= "{100,110,200}"
299 for addr_type
in ADDR_TYPES
:
300 input_static_agg_r1
= {
301 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
303 result
= verify_bgp_rib(
304 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
306 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
310 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
311 for addr_type
in ADDR_TYPES
:
312 for neighbor
in ["r2", "r4"]:
338 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
339 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
343 step("BGP neighborship is verified by following commands in R3 routers")
344 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
345 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
351 for addr_type
in ADDR_TYPES
:
352 input_static_agg_r1
= {
353 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
355 result
= verify_bgp_rib(
356 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
362 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
363 for addr_type
in ADDR_TYPES
:
364 for neighbor
in ["r2", "r4"]:
391 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
392 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
396 step("BGP neighborship is verified by following commands in R3 routers")
397 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
398 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
403 aspath
= "110 {100,200}"
404 for addr_type
in ADDR_TYPES
:
405 input_static_agg_r1
= {
406 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
408 result
= verify_bgp_rib(
409 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
411 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
415 write_test_footer(tc_name
)
418 if __name__
== "__main__":
419 args
= ["-s"] + sys
.argv
[1:]
420 sys
.exit(pytest
.main(args
))