2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2021 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """RFC5549 Automation."""
17 # Save the Current Working Directory to find configuration files.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
20 sys
.path
.append(os
.path
.join(CWD
, "../../"))
22 # pylint: disable=C0413
23 # Import topogen and topotest helpers
24 from lib
.topogen
import Topogen
, get_topogen
26 from lib
.common_config
import (
34 reset_config_on_routers
,
35 get_frr_ipv6_linklocal
,
37 from lib
.topolog
import logger
38 from lib
.bgp
import create_router_bgp
, verify_bgp_convergence
39 from lib
.topojson
import build_config_from_json
44 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
47 NETWORK_CMD_IP
= "1.0.1.17/32"
56 "ipv6": ["1::1/128", "1::2/128", "1::3/128", "1::4/128", "1::5/128"],
58 MASK
= {"ipv4": "32", "ipv6": "128"}
60 "ipv4": ["10.0.0.1", "10.0.1.1", "10.0.2.1", "10.0.3.1", "10.0.4.1"],
61 "ipv6": ["Null0", "Null0", "Null0", "Null0", "Null0"],
63 ADDR_TYPES
= check_address_types()
66 Please view in a fixed-width font such as Courier.
74 +----+ 2links +----+ 8links +--+-+ +----+
75 |R0 +----------+ R1 + + R2 | ipv6 nbr |R3 |
76 | +----------+ +------------+ +-------------+ |
77 +----+ +----+ ipv6 nbr +----+ +----+
81 1. Verify IPv4 routes are deleted after un-configuring "network command
82 " and "redistribute static knob" with Unnumbered IPv6 IBGP session
86 def setup_module(mod
):
87 """Set up the pytest environment."""
90 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
91 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
94 logger
.info("Running setup_module to create topology")
96 # This function initiates the topology build with Topogen...
97 json_file
= "{}/rfc5549_ibgp_unnumbered_nbr.json".format(CWD
)
98 tgen
= Topogen(json_file
, mod
.__name
__)
100 topo
= tgen
.json_topo
102 # Starting topology, create tmp files which are loaded to routers
103 # to start daemons and then start routers
106 # Creating configuration from JSON
107 build_config_from_json(tgen
, topo
)
108 # Don't run this test if we have any failure.
109 if tgen
.routers_have_failure():
110 pytest
.skip(tgen
.errors
)
112 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
113 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error:" " {}".format(
117 logger
.info("Running setup_module() done")
120 def teardown_module():
121 """Teardown the pytest environment."""
122 logger
.info("Running teardown_module to delete topology")
126 # Stop toplogy and Remove tmp files
130 def get_llip(onrouter
, intf
):
132 API to get the link local ipv6 address of a particular interface
136 * `fromnode`: Source node
137 * `tonode` : interface for which link local ip needs to be returned.
141 result = get_llip('r1', 'r2-link0')
145 1) link local ipv6 address from the interface.
146 2) errormsg - when link local ip not found.
149 intf
= topo
["routers"][onrouter
]["links"][intf
]["interface"]
150 llip
= get_frr_ipv6_linklocal(tgen
, onrouter
, intf
)
153 logger
.info("llip ipv6 address to be set as NH is %s", llip
)
158 def get_glipv6(onrouter
, intf
):
160 API to get the global ipv6 address of a particular interface
164 * `onrouter`: Source node
165 * `intf` : interface for which link local ip needs to be returned.
169 result = get_glipv6('r1', 'r2-link0')
173 1) global ipv6 address from the interface.
174 2) errormsg - when link local ip not found.
176 glipv6
= (topo
["routers"][onrouter
]["links"][intf
]["ipv6"]).split("/")[0]
178 logger
.info("Global ipv6 address to be set as NH is %s", glipv6
)
183 # ##################################
184 # Test cases start here.
185 # ##################################
188 def test_ext_nh_cap_red_static_network_ebgp_peer_unnumbered_nbr_p1(request
):
191 Test extended capability nexthop.
193 Verify IPv4 routes advertise using "redistribute static" and
194 "network command" are received on EBGP peer with IPv6 nexthop
196 tc_name
= request
.node
.name
197 write_test_header(tc_name
)
199 # Don't run this test if we have any failure.
200 if tgen
.routers_have_failure():
201 pytest
.skip(tgen
.errors
)
202 reset_config_on_routers(tgen
)
204 "Configure IPv6 IBGP Unnumbered session between R1 and R2 and enable "
205 "ipv6 nd ra-interval 10 in the interface"
209 "Enable capability extended-nexthop"
210 "on the neighbor from both the routers and "
211 "ipv6 nd ra-interval 10 on link connected between R1 and R2"
214 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
215 assert bgp_convergence
is True, "Testcase :Failed \n Error:" " {}".format(
219 for rte
in range(0, NO_OF_RTES
):
220 # Create Static routes
225 "network": NETWORK
["ipv4"][rte
],
227 "next_hop": NEXT_HOP
["ipv4"][rte
],
232 result
= create_static_routes(tgen
, input_dict
)
233 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
237 "Advertise static routes from IPv4 unicast family and IPv6 unicast "
238 "family respectively from R1 "
239 "Configure loopback on R1 with IPv4 address Advertise loopback "
240 "from IPv4 unicast family using network cmd from R1 "
243 configure_bgp_on_r1
= {
249 "redistribute": [{"redist_type": "static"}],
250 "advertise_networks": [
251 {"network": NETWORK_CMD_IP
, "no_of_network": 1}
259 result
= create_router_bgp(tgen
, topo
, configure_bgp_on_r1
)
260 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
262 llip
= get_llip("r1", "r2-link0")
263 assert llip
is not None, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
265 " IPv4 and IPv6 routes advertised using static and network command are"
266 " received on R2 BGP and routing table , verify using show ip bgp"
267 " show ip route for IPv4 routes and show bgp show ipv6 routes"
273 verify_nh_for_static_rtes
= {
277 "network": NETWORK
["ipv4"][0],
278 "no_of_ip": NO_OF_RTES
,
285 tgen
, "ipv4", dut
, verify_nh_for_static_rtes
, next_hop
=llip
, protocol
=protocol
287 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
289 verify_nh_for_nw_cmd_rtes
= {
293 "network": NETWORK_CMD_IP
,
302 tgen
, "ipv4", dut
, verify_nh_for_nw_cmd_rtes
, next_hop
=llip
, protocol
=protocol
304 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
306 write_test_footer(tc_name
)
309 if __name__
== "__main__":
310 args
= ["-s"] + sys
.argv
[1:]
311 sys
.exit(pytest
.main(args
))