]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_asn/test_bgp_local_asn_agg.py
2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
11 Following tests are covered to test BGP Multi-VRF Dynamic Route Leaking:
12 1. Verify the BGP Local AS functionality by aggregating routes in between eBGP Peers.
20 # Save the Current Working Directory to find configuration files.
21 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
22 sys
.path
.append(os
.path
.join(CWD
, "../"))
23 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib
.topogen
import Topogen
, get_topogen
28 from lib
.topotest
import version_cmp
30 from lib
.common_config
import (
34 reset_config_on_routers
,
41 from lib
.topolog
import logger
43 verify_bgp_convergence
,
47 from lib
.topojson
import build_config_from_json
49 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
52 BGP_CONVERGENCE
= False
53 ADDR_TYPES
= check_address_types()
54 NETWORK_1_1
= {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
55 NETWORK_1_2
= {"ipv4": "10.1.2.0/32", "ipv6": "10:1::2:0/128"}
56 AGGREGATE_NW
= {"ipv4": "10.1.0.0/16", "ipv6": "10:1::/96"}
57 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
60 def setup_module(mod
):
62 Sets up the pytest environment
67 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
68 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
71 logger
.info("Running setup_module to create topology")
73 # This function initiates the topology build with Topogen...
74 json_file
= "{}/bgp_local_asn_agg.json".format(CWD
)
75 tgen
= Topogen(json_file
, mod
.__name
__)
78 # ... and here it calls Mininet initialization functions.
80 # Starting topology, create tmp files which are loaded to routers
81 # to start daemons and then start routers
84 # Creating configuration from JSON
85 build_config_from_json(tgen
, topo
)
87 global BGP_CONVERGENCE
89 ADDR_TYPES
= check_address_types()
91 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
92 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
96 logger
.info("Running setup_module() done")
99 def teardown_module():
100 """Teardown the pytest environment"""
102 logger
.info("Running teardown_module to delete topology")
106 # Stop toplogy and Remove tmp files
110 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
112 logger
.info("=" * 40)
115 ####################################################################################################################
119 ####################################################################################################################
122 def test_verify_bgp_local_as_agg_in_EBGP_p0(request
):
124 Verify the BGP Local AS functionality by aggregating routes in between eBGP Peers.
127 global BGP_CONVERGENCE
129 if BGP_CONVERGENCE
!= True:
130 pytest
.skip("skipped because of BGP Convergence failure")
133 tc_name
= request
.node
.name
134 write_test_header(tc_name
)
135 if tgen
.routers_have_failure():
136 check_router_status(tgen
)
137 reset_config_on_routers(tgen
)
139 step("Base config is done as part of JSON")
140 step("Configure local-as at R3 towards R4.")
141 for addr_type
in ADDR_TYPES
:
142 for neighbor
in ["r2", "r4"]:
153 "r3": {"local_asn": {"local_as": "110"}}
163 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
164 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
168 for addr_type
in ADDR_TYPES
:
169 for dut
, asn
, neighbor
in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
180 dut
: {"local_asn": {"remote_as": "110"}}
190 result
= create_router_bgp(tgen
, topo
, input_dict_r2_r4
)
191 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
195 step("BGP neighborship is verified by following commands in R3 routers")
196 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
197 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
201 step("Done in base config: Advertise prefix 10.1.1.0/24 from Router-1(AS-100).")
203 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/120 from Router-1(AS-100)."
205 step("Verify that Static routes are redistributed in BGP process")
206 for addr_type
in ADDR_TYPES
:
207 input_static_verify_r1
= {
208 "r1": {"static_routes": [{"network": NETWORK_1_1
[addr_type
]}]}
211 input_static_verify_r2
= {
212 "r2": {"static_routes": [{"network": NETWORK_1_2
[addr_type
]}]}
214 result
= verify_rib(tgen
, addr_type
, "r1", input_static_verify_r1
)
215 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
219 result
= verify_rib(tgen
, addr_type
, "r2", input_static_verify_r2
)
220 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
224 step("Configure aggregate-address to summarise all the advertised routes.")
225 for addr_type
in ADDR_TYPES
:
232 "aggregate_address": [
234 "network": AGGREGATE_NW
[addr_type
],
246 result
= create_router_bgp(tgen
, topo
, route_aggregate
)
247 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
252 "Verify that we see a summarised route on advertising router R3 "
253 "and receiving router R4 for both AFIs"
256 for addr_type
in ADDR_TYPES
:
257 input_static_agg_r1
= {
258 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
261 "r1": {"static_routes": [{"network": [NETWORK_1_1
[addr_type
]]}]}
265 "r2": {"static_routes": [{"network": [NETWORK_1_2
[addr_type
]]}]}
268 for dut
in ["r3", "r4"]:
269 result
= verify_rib(tgen
, addr_type
, dut
, input_static_agg_r1
)
270 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
274 for dut
, input_routes
in zip(["r1", "r2"], [input_static_r1
, input_static_r2
]):
275 result
= verify_rib(tgen
, addr_type
, dut
, input_routes
)
276 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
281 "Verify that AS-110 is got added in the AS list 110 {100,110,200} by following "
282 "commands at R3 router."
285 aspath
= "{100,110,200}"
286 for addr_type
in ADDR_TYPES
:
287 input_static_agg_r1
= {
288 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
290 result
= verify_bgp_rib(
291 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
293 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
297 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
298 for addr_type
in ADDR_TYPES
:
299 for neighbor
in ["r2", "r4"]:
325 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
326 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
330 step("BGP neighborship is verified by following commands in R3 routers")
331 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
332 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
338 for addr_type
in ADDR_TYPES
:
339 input_static_agg_r1
= {
340 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
342 result
= verify_bgp_rib(
343 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
345 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
349 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
350 for addr_type
in ADDR_TYPES
:
351 for neighbor
in ["r2", "r4"]:
378 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
379 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
383 step("BGP neighborship is verified by following commands in R3 routers")
384 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
385 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
390 aspath
= "110 {100,200}"
391 for addr_type
in ADDR_TYPES
:
392 input_static_agg_r1
= {
393 "r1": {"static_routes": [{"network": AGGREGATE_NW
[addr_type
]}]}
395 result
= verify_bgp_rib(
396 tgen
, addr_type
, dut
, input_static_agg_r1
, aspath
=aspath
398 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
402 write_test_footer(tc_name
)
405 if __name__
== "__main__":
406 args
= ["-s"] + sys
.argv
[1:]
407 sys
.exit(pytest
.main(args
))