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.
9 ##########################################################################################################################################
13 ###########################################################################################################################################
14 ###########################################################################################################################################
16 # 1.10.1.7. Verify the BGP Local AS functionality with ECMP on 8 links by adding no-prepend and replace-as command in between eBGP Peers.
18 #################################################################################################################################################
26 # Save the Current Working Directory to find configuration files.
27 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
28 sys
.path
.append(os
.path
.join(CWD
, "../"))
29 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 from lib
.common_config
import (
41 reset_config_on_routers
,
50 from lib
.topolog
import logger
52 verify_bgp_convergence
,
56 from lib
.topojson
import build_config_from_json
58 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
61 BGP_CONVERGENCE
= False
62 NETWORK
= {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
63 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
66 def setup_module(mod
):
68 Sets up the pytest environment
73 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
74 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
77 logger
.info("Running setup_module to create topology")
79 # This function initiates the topology build with Topogen...
80 json_file
= "{}/bgp_local_asn_ecmp.json".format(CWD
)
81 tgen
= Topogen(json_file
, mod
.__name
__)
84 # ... and here it calls Mininet initialization functions.
86 # Starting topology, create tmp files which are loaded to routers
87 # to start daemons and then start routers
90 # Creating configuration from JSON
91 build_config_from_json(tgen
, topo
)
93 global BGP_CONVERGENCE
95 ADDR_TYPES
= check_address_types()
97 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
98 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
102 logger
.info("Running setup_module() done")
105 def teardown_module():
106 """Teardown the pytest environment"""
108 logger
.info("Running teardown_module to delete topology")
112 # Stop toplogy and Remove tmp files
116 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
118 logger
.info("=" * 40)
121 ##########################################################################################################################################
125 ###########################################################################################################################################
128 def test_verify_bgp_local_as_in_ecmp_EBGP_p0(request
):
130 Verify the BGP Local AS functionality with ECMP on 8 links by
131 adding no-prepend and replace-as command in between eBGP Peers.
135 global BGP_CONVERGENCE
136 if BGP_CONVERGENCE
!= True:
137 pytest
.skip("skipped because of BGP Convergence failure")
139 tc_name
= request
.node
.name
140 write_test_header(tc_name
)
141 if tgen
.routers_have_failure():
142 check_router_status(tgen
)
143 reset_config_on_routers(tgen
)
145 step("Base config is done as part of JSON")
147 for addr_type
in ADDR_TYPES
:
148 # Enable static routes
149 input_dict_static_route
= {
152 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
157 logger
.info("Configure static routes")
158 result
= create_static_routes(tgen
, input_dict_static_route
)
159 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
163 step("configure redistribute static in Router BGP in R1")
164 input_dict_static_route_redist
= {
170 "unicast": {"redistribute": [{"redist_type": "static"}]}
177 result
= create_router_bgp(tgen
, topo
, input_dict_static_route_redist
)
178 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
182 step("Verify IPv4 and IPv6 static routes received on R1")
183 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_static_route
)
184 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
187 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_dict_static_route
)
188 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
191 result
= verify_fib_routes(tgen
, addr_type
, "r1", input_dict_static_route
)
192 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
196 step("Configure local-as at R3 towards R2.")
197 for addr_type
in ADDR_TYPES
:
198 input_dict_r3_to_r2
= {
210 "local_asn": {"local_as": "110"}
222 result
= create_router_bgp(tgen
, topo
, input_dict_r3_to_r2
)
223 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
227 step("Configure local-as at R3 towards R4.")
229 for link_no
in range(1, 9):
230 link
= "r3-link" + str(link_no
)
231 dest_link
[link
] = {"local_asn": {"local_as": "110"}}
232 for addr_type
in ADDR_TYPES
:
233 input_dict_r3_to_r4
= {
241 "neighbor": {"r4": {"dest_link": dest_link
}}
249 result
= create_router_bgp(tgen
, topo
, input_dict_r3_to_r4
)
250 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
254 step("Configure remote-as at R2 towards R3.")
255 for addr_type
in ADDR_TYPES
:
256 input_dict_r2_to_r3
= {
268 "local_asn": {"remote_as": "110"}
280 result
= create_router_bgp(tgen
, topo
, input_dict_r2_to_r3
)
281 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
285 step("Configure remote-as at R4 towards R3.")
287 for link_no
in range(1, 9):
288 link
= "r4-link" + str(link_no
)
289 dest_link
[link
] = {"local_asn": {"remote_as": "110"}}
290 for addr_type
in ADDR_TYPES
:
291 input_dict_r4_to_r3
= {
299 "neighbor": {"r3": {"dest_link": dest_link
}}
307 result
= create_router_bgp(tgen
, topo
, input_dict_r4_to_r3
)
308 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
312 step("BGP neighborship is verified by following commands in R3 routers")
313 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
314 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
318 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
319 for addr_type
in ADDR_TYPES
:
320 static_routes_input
= {
323 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
327 for dut
in ["r3", "r4"]:
328 result
= verify_fib_routes(tgen
, addr_type
, dut
, static_routes_input
)
329 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
333 result
= verify_bgp_rib(tgen
, addr_type
, dut
, static_routes_input
)
334 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
339 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
340 " commands at R3 router."
343 aspath
= "110 200 100"
344 for addr_type
in ADDR_TYPES
:
345 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
346 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
347 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
351 step("Configure local-as with no-prepend at R3 towards R2.")
352 for addr_type
in ADDR_TYPES
:
353 input_dict_no_prep_r3_to_r2
= {
380 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_r3_to_r2
)
381 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
385 step("Configure local-as with no-prepend at R3 towards R4.")
387 for link_no
in range(1, 9):
388 link
= "r3-link" + str(link_no
)
389 dest_link
[link
] = {"local_asn": {"local_as": "110"}}
390 for addr_type
in ADDR_TYPES
:
391 input_dict_no_prep_r3_to_r4
= {
399 "neighbor": {"r4": {"dest_link": dest_link
}}
407 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_r3_to_r4
)
408 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
412 step("BGP neighborship is verified by following commands in R3 routers")
413 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
414 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
420 for addr_type
in ADDR_TYPES
:
421 input_static_r1
= {"r2": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
422 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
423 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
427 step("Configure local-as with no-prepend and replace-as at R3 towards R2")
428 for addr_type
in ADDR_TYPES
:
429 input_dict_no_prep_rep_as_r3_to_r2
= {
457 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_rep_as_r3_to_r2
)
458 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
462 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
464 for link_no
in range(1, 9):
465 link
= "r3-link" + str(link_no
)
467 "local_asn": {"local_as": "110", "no_prepend": True, "replace_as": True}
469 for addr_type
in ADDR_TYPES
:
470 input_dict_no_prep_rep_as_r3_to_r4
= {
478 "neighbor": {"r4": {"dest_link": dest_link
}}
486 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_rep_as_r3_to_r4
)
487 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
491 step("BGP neighborship is verified by following commands in R3 routers")
492 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
493 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
498 aspath
= "110 200 100"
499 for addr_type
in ADDR_TYPES
:
500 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
501 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
502 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
506 write_test_footer(tc_name
)
509 if __name__
== "__main__":
510 args
= ["-s"] + sys
.argv
[1:]
511 sys
.exit(pytest
.main(args
))