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
21 ##########################################################################################################
25 ##########################################################################################################
26 ##########################################################################################################
28 # 1.10.1.2. Verify the BGP Local AS functionality by configuring 4 Byte AS in between eBGP Peers.
30 # 1.10.1.4. Verify the BGP Local AS functionality by configuring Old AS(local as) in 2 bytes and New AS in 4 bytes in between eBGP Peers.
32 ###############################################################################################################
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
,
62 from lib
.topolog
import logger
64 verify_bgp_convergence
,
67 verify_bgp_advertised_routes_from_neighbor
,
69 from lib
.topojson
import build_config_from_json
71 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
74 BGP_CONVERGENCE
= False
75 ADDR_TYPES
= check_address_types()
76 NETWORK
= {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
77 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
80 def setup_module(mod
):
82 Sets up the pytest environment
87 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
88 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
91 logger
.info("Running setup_module to create topology")
93 # This function initiates the topology build with Topogen...
94 json_file
= "{}/bgp_local_asn_topo2.json".format(CWD
)
95 tgen
= Topogen(json_file
, mod
.__name
__)
98 # ... and here it calls Mininet initialization functions.
100 # Starting topology, create tmp files which are loaded to routers
101 # to start daemons and then start routers
104 # Creating configuration from JSON
105 build_config_from_json(tgen
, topo
)
107 global BGP_CONVERGENCE
109 ADDR_TYPES
= check_address_types()
111 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
112 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error: {}".format(
116 logger
.info("Running setup_module() done")
119 def teardown_module():
120 """Teardown the pytest environment"""
122 logger
.info("Running teardown_module to delete topology")
126 # Stop toplogy and Remove tmp files
130 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
132 logger
.info("=" * 40)
135 ##########################################################################################################
139 ##########################################################################################################
142 def test_verify_bgp_local_as_in_4_Byte_AS_EBGP_p0(request
):
144 Verify the BGP Local AS functionality by configuring 4 Byte AS in between eBGP Peers.
148 global BGP_CONVERGENCE
150 if BGP_CONVERGENCE
!= True:
151 pytest
.skip("skipped because of BGP Convergence failure")
154 tc_name
= request
.node
.name
155 write_test_header(tc_name
)
156 if tgen
.routers_have_failure():
157 check_router_status(tgen
)
158 reset_config_on_routers(tgen
)
160 step("Base config is done as part of JSON")
161 step("Configure local-as at R3 towards R4.")
162 for addr_type
in ADDR_TYPES
:
163 for neighbor
in ["r2", "r4"]:
167 "local_as": "12000300",
176 "local_as": "12000110"
188 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
189 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
193 for addr_type
in ADDR_TYPES
:
194 for dut
, asn
, neighbor
in zip(
195 ["r2", "r4"], ["12000200", "12000400"], ["r3", "r3"]
209 "remote_as": "12000110"
221 result
= create_router_bgp(tgen
, topo
, input_dict_r2_r4
)
222 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
226 step("BGP neighborship is verified by following commands in R3 routers")
227 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
228 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
232 # configure static routes
234 "Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-12000100)."
237 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-12000100)."
239 step("Verify that Static routes are redistributed in BGP process")
243 for addr_type
in ADDR_TYPES
:
244 # Enable static routes
248 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
253 logger
.info("Configure static routes")
254 result
= create_static_routes(tgen
, input_static_r1
)
255 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
259 step("configure redistribute static in Router BGP in R1")
261 input_static_redist_r1
= {
266 "unicast": {"redistribute": [{"redist_type": "static"}]}
272 result
= create_router_bgp(tgen
, topo
, input_static_redist_r1
)
273 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
277 step("Verify that Static routes are redistributed in BGP process")
278 for addr_type
in ADDR_TYPES
:
279 input_static_verify_r1
= {
280 "r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}
283 result
= verify_rib(tgen
, addr_type
, "r1", input_static_verify_r1
)
284 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
288 for dut
in ["r2", "r3", "r4"]:
289 result
= verify_rib(tgen
, addr_type
, dut
, input_static_r1
)
290 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
295 "Verify that AS-12000110 is got added in the AS list 12000110 12000200 12000100 by following"
296 "commands at R3 router."
299 aspath
= "12000110 12000200 12000100"
300 for addr_type
in ADDR_TYPES
:
301 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
302 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
303 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
307 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
308 for addr_type
in ADDR_TYPES
:
309 for neighbor
in ["r2", "r4"]:
313 "local_as": "12000300",
322 "local_as": "12000110",
335 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
336 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
340 step("BGP neighborship is verified by following commands in R3 routers")
341 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
342 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
346 step("Verify advertised routes to R4 at R3")
349 {"network": "10.1.1.0/32", "nexthop": ""},
352 {"network": "10:1::1:0/128", "nexthop": ""},
355 result
= verify_bgp_advertised_routes_from_neighbor(
356 tgen
, topo
, dut
="r3", peer
="r4", expected_routes
=expected_routes
358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
361 aspath
= "12000200 12000100"
362 for addr_type
in ADDR_TYPES
:
363 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
364 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
365 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
369 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
370 for addr_type
in ADDR_TYPES
:
371 for neighbor
in ["r2", "r4"]:
375 "local_as": "12000300",
384 "local_as": "12000110",
398 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
399 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
403 step("BGP neighborship is verified by following commands in R3 routers")
404 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
405 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
410 aspath
= "12000110 12000200 12000100"
411 for addr_type
in ADDR_TYPES
:
412 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
413 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
414 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
418 write_test_footer(tc_name
)
421 def test_verify_bgp_local_as_in_old_AS2_new_AS4_EBGP_p0(request
):
423 Verify the BGP Local AS functionality by configuring Old AS(local as) in
424 2 bytes and New AS in 4 bytes in between eBGP Peers.
427 global BGP_CONVERGENCE
429 if BGP_CONVERGENCE
!= True:
430 pytest
.skip("skipped because of BGP Convergence failure")
432 tc_name
= request
.node
.name
433 write_test_header(tc_name
)
434 if tgen
.routers_have_failure():
435 check_router_status(tgen
)
436 reset_config_on_routers(tgen
)
438 step("Base config is done as part of JSON")
439 step("Configure local-as at R3 towards R4.")
440 for addr_type
in ADDR_TYPES
:
441 for neighbor
in ["r2", "r4"]:
445 "local_as": "12000300",
452 "r3": {"local_asn": {"local_as": "110"}}
462 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
463 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
467 for addr_type
in ADDR_TYPES
:
468 for dut
, asn
, neighbor
in zip(
469 ["r2", "r4"], ["12000200", "12000400"], ["r3", "r3"]
481 dut
: {"local_asn": {"remote_as": "110"}}
491 result
= create_router_bgp(tgen
, topo
, input_dict_r2_r4
)
492 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
496 step("BGP neighborship is verified by following commands in R3 routers")
497 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
498 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
502 # configure static routes
504 "Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-12000100)."
507 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-12000100)."
509 step("Verify that Static routes are redistributed in BGP process")
513 for addr_type
in ADDR_TYPES
:
514 # Enable static routes
518 {"network": NETWORK
[addr_type
], "next_hop": NEXT_HOP_IP
[addr_type
]}
523 logger
.info("Configure static routes")
524 result
= create_static_routes(tgen
, input_static_r1
)
525 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
529 step("configure redistribute static in Router BGP in R1")
531 input_static_redist_r1
= {
536 "unicast": {"redistribute": [{"redist_type": "static"}]}
542 result
= create_router_bgp(tgen
, topo
, input_static_redist_r1
)
543 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
547 step("Verify that Static routes are redistributed in BGP process")
548 for addr_type
in ADDR_TYPES
:
549 input_static_verify_r1
= {
550 "r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}
553 result
= verify_rib(tgen
, addr_type
, "r1", input_static_verify_r1
)
554 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
558 for dut
in ["r3", "r4"]:
559 result
= verify_rib(tgen
, addr_type
, dut
, input_static_r1
)
560 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
564 for dut
, input_routes
in zip(["r1"], [input_static_r1
]):
565 result
= verify_rib(tgen
, addr_type
, dut
, input_routes
)
566 assert result
is True, "Testcase {}: Failed \n Error: {}".format(
571 "Verify that AS-110 is got added in the AS list 110 12000200 12000100 by following"
572 "commands at R3 router."
575 aspath
= "110 12000200 12000100"
576 for addr_type
in ADDR_TYPES
:
577 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
578 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
579 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
583 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
584 for addr_type
in ADDR_TYPES
:
585 for neighbor
in ["r2", "r4"]:
589 "local_as": "12000300",
611 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
612 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
616 step("BGP neighborship is verified by following commands in R3 routers")
617 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
618 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
622 step("Verify advertised routes to R4 at R3")
625 {"network": "10.1.1.0/32", "nexthop": ""},
628 {"network": "10:1::1:0/128", "nexthop": ""},
631 result
= verify_bgp_advertised_routes_from_neighbor(
632 tgen
, topo
, dut
="r3", peer
="r4", expected_routes
=expected_routes
634 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
637 aspath
= "12000200 12000100"
638 for addr_type
in ADDR_TYPES
:
639 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
640 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
641 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
645 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
646 for addr_type
in ADDR_TYPES
:
647 for neighbor
in ["r2", "r4"]:
651 "local_as": "12000300",
674 result
= create_router_bgp(tgen
, topo
, input_dict_r3
)
675 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
679 step("BGP neighborship is verified by following commands in R3 routers")
680 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
681 assert BGP_CONVERGENCE
is True, "BGP convergence :Failed \n Error: {}".format(
686 aspath
= "110 12000200 12000100"
687 for addr_type
in ADDR_TYPES
:
688 input_static_r1
= {"r1": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
689 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_static_r1
, aspath
=aspath
)
690 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
694 write_test_footer(tc_name
)
697 if __name__
== "__main__":
698 args
= ["-s"] + sys
.argv
[1:]
699 sys
.exit(pytest
.main(args
))