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
22 ##########################################################################################################################################
26 ###########################################################################################################################################
27 ###########################################################################################################################################
29 # 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.
31 #################################################################################################################################################
39 # Save the Current Working Directory to find configuration files.
40 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
41 sys
.path
.append(os
.path
.join(CWD
, "../"))
42 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
44 # pylint: disable=C0413
45 # Import topogen and topotest helpers
46 from lib
.topogen
import Topogen
, get_topogen
47 from lib
.topotest
import version_cmp
49 from lib
.common_config
import (
54 reset_config_on_routers
,
63 from lib
.topolog
import logger
65 verify_bgp_convergence
,
69 from lib
.topojson
import build_config_from_json
71 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
74 BGP_CONVERGENCE
= False
75 NETWORK
= {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
76 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
79 def setup_module(mod
):
81 Sets up the pytest environment
86 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
87 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
90 logger
.info("Running setup_module to create topology")
92 # This function initiates the topology build with Topogen...
93 json_file
= "{}/bgp_local_asn_ecmp.json".format(CWD
)
94 tgen
= Topogen(json_file
, mod
.__name
__)
97 # ... and here it calls Mininet initialization functions.
99 # Starting topology, create tmp files which are loaded to routers
100 # to start daemons and then start routers
103 # Creating configuration from JSON
104 build_config_from_json(tgen
, topo
)
106 global BGP_CONVERGENCE
108 ADDR_TYPES
= check_address_types()
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():
119 """Teardown the pytest environment"""
121 logger
.info("Running teardown_module to delete topology")
125 # Stop toplogy and Remove tmp files
129 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
131 logger
.info("=" * 40)
134 ##########################################################################################################################################
138 ###########################################################################################################################################
141 def test_verify_bgp_local_as_in_ecmp_EBGP_p0(request
):
143 Verify the BGP Local AS functionality with ECMP on 8 links by
144 adding no-prepend and replace-as command in between eBGP Peers.
148 global BGP_CONVERGENCE
149 if BGP_CONVERGENCE
!= True:
150 pytest
.skip("skipped because of BGP Convergence failure")
152 tc_name
= request
.node
.name
153 write_test_header(tc_name
)
154 if tgen
.routers_have_failure():
155 check_router_status(tgen
)
156 reset_config_on_routers(tgen
)
158 step("Base config is done as part of JSON")
160 for addr_type
in ADDR_TYPES
:
161 # Enable static routes
162 input_dict_static_route
= {
165 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
170 logger
.info("Configure static routes")
171 result
= create_static_routes(tgen
, input_dict_static_route
)
172 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
176 step("configure redistribute static in Router BGP in R1")
177 input_dict_static_route_redist
= {
183 "unicast": {"redistribute": [{"redist_type": "static"}]}
190 result
= create_router_bgp(tgen
, topo
, input_dict_static_route_redist
)
191 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
195 step("Verify IPv4 and IPv6 static routes received on R1")
196 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_static_route
)
197 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
200 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_dict_static_route
)
201 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
204 result
= verify_fib_routes(tgen
, addr_type
, "r1", input_dict_static_route
)
205 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
209 step("Configure local-as at R3 towards R2.")
210 for addr_type
in ADDR_TYPES
:
211 input_dict_r3_to_r2
= {
223 "local_asn": {"local_as": "110"}
235 result
= create_router_bgp(tgen
, topo
, input_dict_r3_to_r2
)
236 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
240 step("Configure local-as at R3 towards R4.")
242 for link_no
in range(1, 9):
243 link
= "r3-link" + str(link_no
)
244 dest_link
[link
] = {"local_asn": {"local_as": "110"}}
245 for addr_type
in ADDR_TYPES
:
246 input_dict_r3_to_r4
= {
254 "neighbor": {"r4": {"dest_link": dest_link
}}
262 result
= create_router_bgp(tgen
, topo
, input_dict_r3_to_r4
)
263 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
267 step("Configure remote-as at R2 towards R3.")
268 for addr_type
in ADDR_TYPES
:
269 input_dict_r2_to_r3
= {
281 "local_asn": {"remote_as": "110"}
293 result
= create_router_bgp(tgen
, topo
, input_dict_r2_to_r3
)
294 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
298 step("Configure remote-as at R4 towards R3.")
300 for link_no
in range(1, 9):
301 link
= "r4-link" + str(link_no
)
302 dest_link
[link
] = {"local_asn": {"remote_as": "110"}}
303 for addr_type
in ADDR_TYPES
:
304 input_dict_r4_to_r3
= {
312 "neighbor": {"r3": {"dest_link": dest_link
}}
320 result
= create_router_bgp(tgen
, topo
, input_dict_r4_to_r3
)
321 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
325 step("BGP neighborship is verified by following commands in R3 routers")
326 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
327 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
331 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
332 for addr_type
in ADDR_TYPES
:
333 static_routes_input
= {
336 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
340 for dut
in ["r3", "r4"]:
341 result
= verify_fib_routes(tgen
, addr_type
, dut
, static_routes_input
)
342 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
346 result
= verify_bgp_rib(tgen
, addr_type
, dut
, static_routes_input
)
347 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
352 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
353 " commands at R3 router."
356 aspath
= "110 200 100"
357 for addr_type
in ADDR_TYPES
:
358 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
359 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
360 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
364 step("Configure local-as with no-prepend at R3 towards R2.")
365 for addr_type
in ADDR_TYPES
:
366 input_dict_no_prep_r3_to_r2
= {
393 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_r3_to_r2
)
394 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
398 step("Configure local-as with no-prepend at R3 towards R4.")
400 for link_no
in range(1, 9):
401 link
= "r3-link" + str(link_no
)
402 dest_link
[link
] = {"local_asn": {"local_as": "110"}}
403 for addr_type
in ADDR_TYPES
:
404 input_dict_no_prep_r3_to_r4
= {
412 "neighbor": {"r4": {"dest_link": dest_link
}}
420 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_r3_to_r4
)
421 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
425 step("BGP neighborship is verified by following commands in R3 routers")
426 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
427 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
433 for addr_type
in ADDR_TYPES
:
434 input_static_r1
= {"r2": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
435 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
436 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
440 step("Configure local-as with no-prepend and replace-as at R3 towards R2")
441 for addr_type
in ADDR_TYPES
:
442 input_dict_no_prep_rep_as_r3_to_r2
= {
470 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_rep_as_r3_to_r2
)
471 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
475 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
477 for link_no
in range(1, 9):
478 link
= "r3-link" + str(link_no
)
480 "local_asn": {"local_as": "110", "no_prepend": True, "replace_as": True}
482 for addr_type
in ADDR_TYPES
:
483 input_dict_no_prep_rep_as_r3_to_r4
= {
491 "neighbor": {"r4": {"dest_link": dest_link
}}
499 result
= create_router_bgp(tgen
, topo
, input_dict_no_prep_rep_as_r3_to_r4
)
500 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
504 step("BGP neighborship is verified by following commands in R3 routers")
505 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
506 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
511 aspath
= "110 200 100"
512 for addr_type
in ADDR_TYPES
:
513 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
514 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
515 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
519 write_test_footer(tc_name
)
522 if __name__
== "__main__":
523 args
= ["-s"] + sys
.argv
[1:]
524 sys
.exit(pytest
.main(args
))