blob: be0c1b5ee6b8ab903898aa0cd6a9c33d7751cd8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# This test is for checking the nexthop offload API. It makes use of netdevsim
# which registers a listener to the nexthop notification chain.
lib_dir=$(dirname $0)/../../../net/forwarding
ALL_TESTS="
nexthop_single_add_test
nexthop_single_add_err_test
nexthop_group_add_test
nexthop_group_add_err_test
nexthop_group_replace_test
nexthop_group_replace_err_test
nexthop_single_replace_test
nexthop_single_replace_err_test
nexthop_single_in_group_replace_test
nexthop_single_in_group_replace_err_test
nexthop_single_in_group_delete_test
nexthop_single_in_group_delete_err_test
nexthop_replay_test
nexthop_replay_err_test
"
NETDEVSIM_PATH=/sys/bus/netdevsim/
DEV_ADDR=1337
DEV=netdevsim${DEV_ADDR}
DEVLINK_DEV=netdevsim/${DEV}
SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
NUM_NETIFS=0
source $lib_dir/lib.sh
source $lib_dir/devlink_lib.sh
nexthop_check()
{
local nharg="$1"; shift
local expected="$1"; shift
out=$($IP nexthop show ${nharg} | sed -e 's/ *$//')
if [[ "$out" != "$expected" ]]; then
return 1
fi
return 0
}
nexthop_resource_check()
{
local expected_occ=$1; shift
occ=$($DEVLINK -jp resource show $DEVLINK_DEV \
| jq '.[][][] | select(.name=="nexthops") | .["occ"]')
if [ $expected_occ -ne $occ ]; then
return 1
fi
return 0
}
nexthop_resource_set()
{
local size=$1; shift
$DEVLINK resource set $DEVLINK_DEV path nexthops size $size
$DEVLINK dev reload $DEVLINK_DEV
}
nexthop_single_add_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry"
nexthop_resource_check 1
check_err $? "Wrong nexthop occupancy"
$IP nexthop del id 1
nexthop_resource_check 0
check_err $? "Wrong nexthop occupancy after delete"
log_test "Single nexthop add and delete"
}
nexthop_single_add_err_test()
{
RET=0
nexthop_resource_set 1
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1 &> /dev/null
check_fail $? "Nexthop addition succeeded when should fail"
nexthop_resource_check 1
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop add failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_group_add_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
nexthop_check "id 10" "id 10 group 1/2 trap"
check_err $? "Unexpected nexthop group entry"
nexthop_resource_check 4
check_err $? "Wrong nexthop occupancy"
$IP nexthop del id 10
nexthop_resource_check 2
check_err $? "Wrong nexthop occupancy after delete"
$IP nexthop add id 10 group 1,20/2,39
nexthop_check "id 10" "id 10 group 1,20/2,39 trap"
check_err $? "Unexpected weighted nexthop group entry"
nexthop_resource_check 61
check_err $? "Wrong weighted nexthop occupancy"
$IP nexthop del id 10
nexthop_resource_check 2
check_err $? "Wrong nexthop occupancy after delete"
log_test "Nexthop group add and delete"
$IP nexthop flush &> /dev/null
}
nexthop_group_add_err_test()
{
RET=0
nexthop_resource_set 2
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2 &> /dev/null
check_fail $? "Nexthop group addition succeeded when should fail"
nexthop_resource_check 2
check_err $? "Wrong nexthop occupancy"
log_test "Nexthop group add failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_group_replace_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 3 via 192.0.2.4 dev dummy1
$IP nexthop add id 10 group 1/2
$IP nexthop replace id 10 group 1/2/3
nexthop_check "id 10" "id 10 group 1/2/3 trap"
check_err $? "Unexpected nexthop group entry"
nexthop_resource_check 6
check_err $? "Wrong nexthop occupancy"
log_test "Nexthop group replace"
$IP nexthop flush &> /dev/null
}
nexthop_group_replace_err_test()
{
RET=0
nexthop_resource_set 5
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 3 via 192.0.2.4 dev dummy1
$IP nexthop add id 10 group 1/2
$IP nexthop replace id 10 group 1/2/3 &> /dev/null
check_fail $? "Nexthop group replacement succeeded when should fail"
nexthop_check "id 10" "id 10 group 1/2 trap"
check_err $? "Unexpected nexthop group entry after failure"
nexthop_resource_check 5
check_err $? "Wrong nexthop occupancy after failure"
log_test "Nexthop group replace failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_single_replace_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop replace id 1 via 192.0.2.3 dev dummy1
nexthop_check "id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry"
nexthop_resource_check 1
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop replace"
$IP nexthop flush &> /dev/null
}
nexthop_single_replace_err_test()
{
RET=0
# This is supposed to cause the replace to fail because the new nexthop
# is programmed before deleting the replaced one.
nexthop_resource_set 1
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop replace id 1 via 192.0.2.3 dev dummy1 &> /dev/null
check_fail $? "Nexthop replace succeeded when should fail"
nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry after failure"
nexthop_resource_check 1
check_err $? "Wrong nexthop occupancy after failure"
log_test "Single nexthop replace failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_single_in_group_replace_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
$IP nexthop replace id 1 via 192.0.2.4 dev dummy1
check_err $? "Failed to replace nexthop when should not"
nexthop_check "id 10" "id 10 group 1/2 trap"
check_err $? "Unexpected nexthop group entry"
nexthop_resource_check 4
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop replace while in group"
$IP nexthop flush &> /dev/null
}
nexthop_single_in_group_replace_err_test()
{
RET=0
nexthop_resource_set 5
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
$IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null
check_fail $? "Nexthop replacement succeeded when should fail"
nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry after failure"
nexthop_check "id 10" "id 10 group 1/2 trap"
check_err $? "Unexpected nexthop group entry after failure"
nexthop_resource_check 4
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop replace while in group failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_single_in_group_delete_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
$IP nexthop del id 1
nexthop_check "id 10" "id 10 group 2 trap"
check_err $? "Unexpected nexthop group entry"
nexthop_resource_check 2
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop delete while in group"
$IP nexthop flush &> /dev/null
}
nexthop_single_in_group_delete_err_test()
{
RET=0
# First, nexthop 1 will be deleted, which will reduce the occupancy to
# 5. Afterwards, a replace notification will be sent for nexthop group
# 10 with only two nexthops. Since the new group is allocated before
# the old is deleted, the replacement will fail as it will result in an
# occupancy of 7.
nexthop_resource_set 6
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 3 via 192.0.2.4 dev dummy1
$IP nexthop add id 10 group 1/2/3
$IP nexthop del id 1
nexthop_resource_check 5
check_err $? "Wrong nexthop occupancy"
log_test "Single nexthop delete while in group failure"
$IP nexthop flush &> /dev/null
nexthop_resource_set 9999
}
nexthop_replay_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
$DEVLINK dev reload $DEVLINK_DEV
check_err $? "Failed to reload when should not"
nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry after reload"
nexthop_check "id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap"
check_err $? "Unexpected nexthop entry after reload"
nexthop_check "id 10" "id 10 group 1/2 trap"
check_err $? "Unexpected nexthop group entry after reload"
nexthop_resource_check 4
check_err $? "Wrong nexthop occupancy"
log_test "Nexthop replay"
$IP nexthop flush &> /dev/null
}
nexthop_replay_err_test()
{
RET=0
$IP nexthop add id 1 via 192.0.2.2 dev dummy1
$IP nexthop add id 2 via 192.0.2.3 dev dummy1
$IP nexthop add id 10 group 1/2
# Reduce size of nexthop resource so that reload will fail.
$DEVLINK resource set $DEVLINK_DEV path nexthops size 3
$DEVLINK dev reload $DEVLINK_DEV &> /dev/null
check_fail $? "Reload succeeded when should fail"
$DEVLINK resource set $DEVLINK_DEV path nexthops size 9999
$DEVLINK dev reload $DEVLINK_DEV
check_err $? "Failed to reload when should not"
log_test "Nexthop replay failure"
$IP nexthop flush &> /dev/null
}
setup_prepare()
{
local netdev
modprobe netdevsim &> /dev/null
echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
while [ ! -d $SYSFS_NET_DIR ] ; do :; done
set -e
ip netns add testns1
devlink dev reload $DEVLINK_DEV netns testns1
IP="ip -netns testns1"
DEVLINK="devlink -N testns1"
$IP link add name dummy1 up type dummy
$IP address add 192.0.2.1/24 dev dummy1
set +e
}
cleanup()
{
pre_cleanup
ip netns del testns1
echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
modprobe -r netdevsim &> /dev/null
}
trap cleanup EXIT
setup_prepare
tests_run
exit $EXIT_STATUS
|