]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_gshut/test_bgp_gshut.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Vivek Venkatraman <vivek@nvidia.com>
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 Test the ability to initiate and stop BGP graceful shutdown.
27 Test both the vrf-specific and global configuration and operation.
37 r2 is UUT and peers with r1 and r3 in default bgp instance and
38 with r4 and r5 in vrf vrf1.
39 r1-r2 peering is iBGP and the other peerings are eBGP.
41 Check r2 initial convergence in default table
42 Define update-delay with max-delay in the default bgp instance on r2
43 Shutdown peering on r1 toward r2 so that delay timers can be exercised
44 Clear bgp neighbors on r2 and then check for the 'in progress' indicator
45 Check that r2 only installs route learned from r4 after the max-delay timer expires
46 Define update-delay with max-delay and estabish-wait and check json output showing set
47 Clear neighbors on r2 and check that r3 installs route from r4 after establish-wait time
48 Remove update-delay timer on r2 to verify that it goes back to normal behavior
49 Clear neighbors on r2 and check that route install time on r2 does not delay
50 Define global bgp update-delay with max-delay and establish-wait on r2
51 Check that r2 default instance and vrf1 have the max-delay and establish set
52 Clear neighbors on r2 and check route-install time is after the establish-wait timer
54 Note that the keepalive/hold times were changed to 3/9 and the connect retry timer
55 to 10 to improve the odds the convergence timing in this test case is useful in the
65 from functools
import partial
67 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
68 sys
.path
.append(os
.path
.join(CWD
, "../"))
70 # pylint: disable=C0413
71 from lib
import topotest
72 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
73 from lib
.topolog
import logger
75 pytestmark
= [pytest
.mark
.bgpd
]
79 for routern
in range(1, 6):
80 tgen
.add_router("r{}".format(routern
))
82 switch
= tgen
.add_switch("s1")
83 switch
.add_link(tgen
.gears
["r1"])
84 switch
.add_link(tgen
.gears
["r2"])
86 switch
= tgen
.add_switch("s2")
87 switch
.add_link(tgen
.gears
["r2"])
88 switch
.add_link(tgen
.gears
["r3"])
90 switch
= tgen
.add_switch("s3")
91 switch
.add_link(tgen
.gears
["r2"])
92 switch
.add_link(tgen
.gears
["r4"])
94 switch
= tgen
.add_switch("s4")
95 switch
.add_link(tgen
.gears
["r2"])
96 switch
.add_link(tgen
.gears
["r5"])
99 def _run_cmd_and_check(router
, cmd
, results_file
, retries
=100, intvl
=0.5):
100 json_file
= "{}/{}".format(CWD
, results_file
)
101 expected
= json
.loads(open(json_file
).read())
102 test_func
= partial(topotest
.router_json_cmp
, router
, cmd
, expected
)
103 return topotest
.run_and_expect(test_func
, None, retries
, intvl
)
106 def setup_module(mod
):
107 tgen
= Topogen(build_topo
, mod
.__name
__)
108 tgen
.start_topology()
110 router_list
= tgen
.routers()
111 krel
= platform
.release()
112 if topotest
.version_cmp(krel
, "4.5") < 0:
113 tgen
.errors
= "Linux kernel version of at least 4.5 needed for bgp-gshut tests"
114 pytest
.skip(tgen
.errors
)
116 # Configure vrf and its slaves in the kernel on r2
117 r2
= tgen
.gears
["r2"]
118 r2
.run("ip link add vrf1 type vrf table 1000")
119 r2
.run("ip link set vrf1 up")
120 r2
.run("ip link set r2-eth2 master vrf1")
121 r2
.run("ip link set r2-eth3 master vrf1")
123 # Load FRR config and initialize all routers
124 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
126 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
129 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
134 # Basic peering test to see if things are ok
135 _
, result
= _run_cmd_and_check(r2
, "show ip bgp summary json", "r2/bgp_sum_1.json")
136 assertmsg
= "R2: Basic sanity test after init failed -- global peerings not up"
137 assert result
is None, assertmsg
139 _
, result
= _run_cmd_and_check(
140 r2
, "show ip bgp vrf vrf1 summary json", "r2/bgp_sum_2.json"
142 assertmsg
= "R2: Basic sanity test after init failed -- VRF peerings not up"
143 assert result
is None, assertmsg
146 def teardown_module(mod
):
151 def test_bgp_gshut():
154 if tgen
.routers_have_failure():
155 pytest
.skip(tgen
.errors
)
157 r1
= tgen
.gears
["r1"]
158 r2
= tgen
.gears
["r2"]
159 r3
= tgen
.gears
["r3"]
160 r4
= tgen
.gears
["r4"]
161 r5
= tgen
.gears
["r5"]
163 # Verify initial route states
164 logger
.info("\nVerify initial route states")
166 _
, result
= _run_cmd_and_check(
167 r1
, "show ip bgp 13.1.1.1/32 json", "r1/bgp_route_1.json"
169 assertmsg
= "R1: Route 13.1.1.1/32 not present or has unexpected params"
170 assert result
is None, assertmsg
172 _
, result
= _run_cmd_and_check(
173 r3
, "show ip bgp 11.1.1.1/32 json", "r3/bgp_route_1.json"
175 assertmsg
= "R3: Route 11.1.1.1/32 not present or has unexpected params"
176 assert result
is None, assertmsg
178 _
, result
= _run_cmd_and_check(
179 r5
, "show ip bgp 14.1.1.1/32 json", "r5/bgp_route_1.json"
181 assertmsg
= "R5: Route 14.1.1.1/32 not present or has unexpected params"
182 assert result
is None, assertmsg
184 logger
.info("\nInitial route states are as expected")
186 # "Test #1: Enable BGP-wide graceful-shutdown on R2 and check routes on peers"
188 "\nTest #1: Enable BGP-wide graceful-shutdown on R2 and check routes on peers"
194 bgp graceful-shutdown
198 # R1, R3 and R5 should see routes from R2 with GSHUT. In addition,
199 # R1 should see LOCAL_PREF of 0
200 _
, result
= _run_cmd_and_check(
201 r1
, "show ip bgp 13.1.1.1/32 json", "r1/bgp_route_2.json"
203 assertmsg
= "R1: Route 13.1.1.1/32 not present or has unexpected params"
204 assert result
is None, assertmsg
206 _
, result
= _run_cmd_and_check(
207 r3
, "show ip bgp 11.1.1.1/32 json", "r3/bgp_route_2.json"
209 assertmsg
= "R3: Route 11.1.1.1/32 not present or has unexpected params"
210 assert result
is None, assertmsg
212 _
, result
= _run_cmd_and_check(
213 r5
, "show ip bgp 14.1.1.1/32 json", "r5/bgp_route_2.json"
215 assertmsg
= "R5: Route 14.1.1.1/32 not present or has unexpected params"
216 assert result
is None, assertmsg
219 "\nTest #1: Successful, routes have GSHUT and/or LPREF of 0 as expected"
222 # "Test #2: Turn off BGP-wide graceful-shutdown on R2 and check routes on peers"
224 "\nTest #2: Turn off BGP-wide graceful-shutdown on R2 and check routes on peers"
230 no bgp graceful-shutdown
234 # R1, R3 and R5 should see routes from R2 with their original attributes
235 _
, result
= _run_cmd_and_check(
236 r1
, "show ip bgp 13.1.1.1/32 json", "r1/bgp_route_1.json"
238 assertmsg
= "R1: Route 13.1.1.1/32 not present or has unexpected params"
239 assert result
is None, assertmsg
241 _
, result
= _run_cmd_and_check(
242 r3
, "show ip bgp 11.1.1.1/32 json", "r3/bgp_route_1.json"
244 assertmsg
= "R3: Route 11.1.1.1/32 not present or has unexpected params"
245 assert result
is None, assertmsg
247 _
, result
= _run_cmd_and_check(
248 r5
, "show ip bgp 14.1.1.1/32 json", "r5/bgp_route_1.json"
250 assertmsg
= "R5: Route 14.1.1.1/32 not present or has unexpected params"
251 assert result
is None, assertmsg
254 "\nTest #2: Successful, routes have their original attributes with default LPREF and without GSHUT"
257 # "Test #3: Enable graceful-shutdown on R2 only in VRF1 and check routes on peers"
259 "\nTest #3: Enable graceful-shutdown on R2 only in VRF1 and check routes on peers"
265 router bgp 65001 vrf vrf1
266 bgp graceful-shutdown
270 # R1 and R3 should see no change to their routes
271 _
, result
= _run_cmd_and_check(
272 r1
, "show ip bgp 13.1.1.1/32 json", "r1/bgp_route_1.json"
274 assertmsg
= "R1: Route 13.1.1.1/32 not present or has unexpected params"
275 assert result
is None, assertmsg
277 _
, result
= _run_cmd_and_check(
278 r3
, "show ip bgp 11.1.1.1/32 json", "r3/bgp_route_1.json"
280 assertmsg
= "R3: Route 11.1.1.1/32 not present or has unexpected params"
281 assert result
is None, assertmsg
283 # R5 should see routes from R2 with GSHUT.
284 _
, result
= _run_cmd_and_check(
285 r5
, "show ip bgp 14.1.1.1/32 json", "r5/bgp_route_2.json"
287 assertmsg
= "R5: Route 14.1.1.1/32 not present or has unexpected params"
288 assert result
is None, assertmsg
290 logger
.info("\nTest #3: Successful, only VRF peers like R5 see routes with GSHUT")
292 # "Test #4: Try to enable BGP-wide graceful-shutdown on R2 while it is configured in VRF1"
294 "\nTest #4: Try to enable BGP-wide graceful-shutdown on R2 while it is configured in VRF1"
300 bgp graceful-shutdown
305 assertmsg
= "R2: BGP-wide graceful-shutdown config not rejected even though it is enabled in VRF1"
307 re
.search("global graceful-shutdown not permitted", ret
) is not None
311 "\nTest #4: Successful, BGP-wide graceful-shutdown rejected as it is enabled in VRF"
314 # "Test #5: Turn off graceful-shutdown on R2 in VRF1 and check routes on peers"
316 "\nTest #5: Turn off graceful-shutdown on R2 in VRF1 and check routes on peers"
322 router bgp 65001 vrf vrf1
323 no bgp graceful-shutdown
327 # R1 and R3 should see no change to their routes
328 _
, result
= _run_cmd_and_check(
329 r1
, "show ip bgp 13.1.1.1/32 json", "r1/bgp_route_1.json"
331 assertmsg
= "R1: Route 13.1.1.1/32 not present or has unexpected params"
332 assert result
is None, assertmsg
334 _
, result
= _run_cmd_and_check(
335 r3
, "show ip bgp 11.1.1.1/32 json", "r3/bgp_route_1.json"
337 assertmsg
= "R3: Route 11.1.1.1/32 not present or has unexpected params"
338 assert result
is None, assertmsg
340 # R5 should see routes from R2 with original attributes.
341 _
, result
= _run_cmd_and_check(
342 r5
, "show ip bgp 14.1.1.1/32 json", "r5/bgp_route_1.json"
344 assertmsg
= "R5: Route 14.1.1.1/32 not present or has unexpected params"
345 assert result
is None, assertmsg
348 "\nTest #5: Successful, routes have their original attributes with default LPREF and without GSHUT"
354 if __name__
== "__main__":
355 args
= ["-s"] + sys
.argv
[1:]
356 sys
.exit(pytest
.main(args
))