2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking the nexthop offload API. It makes use of netdevsim
5 # which registers a listener to the nexthop notification chain.
7 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
10 nexthop_single_add_test
11 nexthop_single_add_err_test
12 nexthop_group_add_test
13 nexthop_group_add_err_test
14 nexthop_group_replace_test
15 nexthop_group_replace_err_test
16 nexthop_single_replace_test
17 nexthop_single_replace_err_test
18 nexthop_single_in_group_replace_test
19 nexthop_single_in_group_replace_err_test
20 nexthop_single_in_group_delete_test
21 nexthop_single_in_group_delete_err_test
23 nexthop_replay_err_test
25 NETDEVSIM_PATH
=/sys
/bus
/netdevsim
/
27 DEV
=netdevsim
${DEV_ADDR}
28 DEVLINK_DEV
=netdevsim
/${DEV}
29 SYSFS_NET_DIR
=/sys
/bus
/netdevsim
/devices
/$DEV/net
/
31 source $lib_dir/lib.sh
32 source $lib_dir/devlink_lib.sh
36 local nharg
="$1"; shift
37 local expected
="$1"; shift
39 out
=$
($IP nexthop show
${nharg} |
sed -e 's/ *$//')
40 if [[ "$out" != "$expected" ]]; then
47 nexthop_resource_check
()
49 local expected_occ
=$1; shift
51 occ
=$
($DEVLINK -jp resource show
$DEVLINK_DEV \
52 | jq
'.[][][] | select(.name=="nexthops") | .["occ"]')
54 if [ $expected_occ -ne $occ ]; then
61 nexthop_resource_set
()
65 $DEVLINK resource
set $DEVLINK_DEV path nexthops size
$size
66 $DEVLINK dev reload
$DEVLINK_DEV
69 nexthop_single_add_test
()
73 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
74 nexthop_check
"id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
75 check_err $?
"Unexpected nexthop entry"
77 nexthop_resource_check
1
78 check_err $?
"Wrong nexthop occupancy"
81 nexthop_resource_check
0
82 check_err $?
"Wrong nexthop occupancy after delete"
84 log_test
"Single nexthop add and delete"
87 nexthop_single_add_err_test
()
91 nexthop_resource_set
1
93 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
95 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
&> /dev
/null
96 check_fail $?
"Nexthop addition succeeded when should fail"
98 nexthop_resource_check
1
99 check_err $?
"Wrong nexthop occupancy"
101 log_test
"Single nexthop add failure"
103 $IP nexthop flush
&> /dev
/null
104 nexthop_resource_set
9999
107 nexthop_group_add_test
()
111 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
112 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
114 $IP nexthop add id
10 group
1/2
115 nexthop_check
"id 10" "id 10 group 1/2 trap"
116 check_err $?
"Unexpected nexthop group entry"
118 nexthop_resource_check
4
119 check_err $?
"Wrong nexthop occupancy"
121 $IP nexthop del id
10
122 nexthop_resource_check
2
123 check_err $?
"Wrong nexthop occupancy after delete"
125 $IP nexthop add id
10 group
1,20/2,39
126 nexthop_check
"id 10" "id 10 group 1,20/2,39 trap"
127 check_err $?
"Unexpected weighted nexthop group entry"
129 nexthop_resource_check
61
130 check_err $?
"Wrong weighted nexthop occupancy"
132 $IP nexthop del id
10
133 nexthop_resource_check
2
134 check_err $?
"Wrong nexthop occupancy after delete"
136 log_test
"Nexthop group add and delete"
138 $IP nexthop flush
&> /dev
/null
141 nexthop_group_add_err_test
()
145 nexthop_resource_set
2
147 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
148 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
150 $IP nexthop add id
10 group
1/2 &> /dev
/null
151 check_fail $?
"Nexthop group addition succeeded when should fail"
153 nexthop_resource_check
2
154 check_err $?
"Wrong nexthop occupancy"
156 log_test
"Nexthop group add failure"
158 $IP nexthop flush
&> /dev
/null
159 nexthop_resource_set
9999
162 nexthop_group_replace_test
()
166 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
167 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
168 $IP nexthop add id
3 via
192.0.2.4 dev dummy1
169 $IP nexthop add id
10 group
1/2
171 $IP nexthop replace id
10 group
1/2/3
172 nexthop_check
"id 10" "id 10 group 1/2/3 trap"
173 check_err $?
"Unexpected nexthop group entry"
175 nexthop_resource_check
6
176 check_err $?
"Wrong nexthop occupancy"
178 log_test
"Nexthop group replace"
180 $IP nexthop flush
&> /dev
/null
183 nexthop_group_replace_err_test
()
187 nexthop_resource_set
5
189 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
190 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
191 $IP nexthop add id
3 via
192.0.2.4 dev dummy1
192 $IP nexthop add id
10 group
1/2
194 $IP nexthop replace id
10 group
1/2/3 &> /dev
/null
195 check_fail $?
"Nexthop group replacement succeeded when should fail"
197 nexthop_check
"id 10" "id 10 group 1/2 trap"
198 check_err $?
"Unexpected nexthop group entry after failure"
200 nexthop_resource_check
5
201 check_err $?
"Wrong nexthop occupancy after failure"
203 log_test
"Nexthop group replace failure"
205 $IP nexthop flush
&> /dev
/null
206 nexthop_resource_set
9999
209 nexthop_single_replace_test
()
213 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
215 $IP nexthop replace id
1 via
192.0.2.3 dev dummy1
216 nexthop_check
"id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap"
217 check_err $?
"Unexpected nexthop entry"
219 nexthop_resource_check
1
220 check_err $?
"Wrong nexthop occupancy"
222 log_test
"Single nexthop replace"
224 $IP nexthop flush
&> /dev
/null
227 nexthop_single_replace_err_test
()
231 # This is supposed to cause the replace to fail because the new nexthop
232 # is programmed before deleting the replaced one.
233 nexthop_resource_set
1
235 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
237 $IP nexthop replace id
1 via
192.0.2.3 dev dummy1
&> /dev
/null
238 check_fail $?
"Nexthop replace succeeded when should fail"
240 nexthop_check
"id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
241 check_err $?
"Unexpected nexthop entry after failure"
243 nexthop_resource_check
1
244 check_err $?
"Wrong nexthop occupancy after failure"
246 log_test
"Single nexthop replace failure"
248 $IP nexthop flush
&> /dev
/null
249 nexthop_resource_set
9999
252 nexthop_single_in_group_replace_test
()
256 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
257 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
258 $IP nexthop add id
10 group
1/2
260 $IP nexthop replace id
1 via
192.0.2.4 dev dummy1
261 check_err $?
"Failed to replace nexthop when should not"
263 nexthop_check
"id 10" "id 10 group 1/2 trap"
264 check_err $?
"Unexpected nexthop group entry"
266 nexthop_resource_check
4
267 check_err $?
"Wrong nexthop occupancy"
269 log_test
"Single nexthop replace while in group"
271 $IP nexthop flush
&> /dev
/null
274 nexthop_single_in_group_replace_err_test
()
278 nexthop_resource_set
5
280 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
281 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
282 $IP nexthop add id
10 group
1/2
284 $IP nexthop replace id
1 via
192.0.2.4 dev dummy1
&> /dev
/null
285 check_fail $?
"Nexthop replacement succeeded when should fail"
287 nexthop_check
"id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
288 check_err $?
"Unexpected nexthop entry after failure"
290 nexthop_check
"id 10" "id 10 group 1/2 trap"
291 check_err $?
"Unexpected nexthop group entry after failure"
293 nexthop_resource_check
4
294 check_err $?
"Wrong nexthop occupancy"
296 log_test
"Single nexthop replace while in group failure"
298 $IP nexthop flush
&> /dev
/null
299 nexthop_resource_set
9999
302 nexthop_single_in_group_delete_test
()
306 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
307 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
308 $IP nexthop add id
10 group
1/2
311 nexthop_check
"id 10" "id 10 group 2 trap"
312 check_err $?
"Unexpected nexthop group entry"
314 nexthop_resource_check
2
315 check_err $?
"Wrong nexthop occupancy"
317 log_test
"Single nexthop delete while in group"
319 $IP nexthop flush
&> /dev
/null
322 nexthop_single_in_group_delete_err_test
()
326 # First, nexthop 1 will be deleted, which will reduce the occupancy to
327 # 5. Afterwards, a replace notification will be sent for nexthop group
328 # 10 with only two nexthops. Since the new group is allocated before
329 # the old is deleted, the replacement will fail as it will result in an
331 nexthop_resource_set
6
333 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
334 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
335 $IP nexthop add id
3 via
192.0.2.4 dev dummy1
336 $IP nexthop add id
10 group
1/2/3
340 nexthop_resource_check
5
341 check_err $?
"Wrong nexthop occupancy"
343 log_test
"Single nexthop delete while in group failure"
345 $IP nexthop flush
&> /dev
/null
346 nexthop_resource_set
9999
349 nexthop_replay_test
()
353 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
354 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
355 $IP nexthop add id
10 group
1/2
357 $DEVLINK dev reload
$DEVLINK_DEV
358 check_err $?
"Failed to reload when should not"
360 nexthop_check
"id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
361 check_err $?
"Unexpected nexthop entry after reload"
363 nexthop_check
"id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap"
364 check_err $?
"Unexpected nexthop entry after reload"
366 nexthop_check
"id 10" "id 10 group 1/2 trap"
367 check_err $?
"Unexpected nexthop group entry after reload"
369 nexthop_resource_check
4
370 check_err $?
"Wrong nexthop occupancy"
372 log_test
"Nexthop replay"
374 $IP nexthop flush
&> /dev
/null
377 nexthop_replay_err_test
()
381 $IP nexthop add id
1 via
192.0.2.2 dev dummy1
382 $IP nexthop add id
2 via
192.0.2.3 dev dummy1
383 $IP nexthop add id
10 group
1/2
385 # Reduce size of nexthop resource so that reload will fail.
386 $DEVLINK resource
set $DEVLINK_DEV path nexthops size
3
387 $DEVLINK dev reload
$DEVLINK_DEV &> /dev
/null
388 check_fail $?
"Reload succeeded when should fail"
390 $DEVLINK resource
set $DEVLINK_DEV path nexthops size
9999
391 $DEVLINK dev reload
$DEVLINK_DEV
392 check_err $?
"Failed to reload when should not"
394 log_test
"Nexthop replay failure"
396 $IP nexthop flush
&> /dev
/null
403 modprobe netdevsim
&> /dev
/null
405 echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
406 while [ ! -d $SYSFS_NET_DIR ] ; do :; done
411 devlink dev reload
$DEVLINK_DEV netns testns1
413 IP
="ip -netns testns1"
414 DEVLINK
="devlink -N testns1"
416 $IP link add name dummy1 up
type dummy
417 $IP address add
192.0.2.1/24 dev dummy1
426 echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
427 modprobe
-r netdevsim
&> /dev
/null