0001
0002
0003
0004
0005
0006
0007 lib_dir=$(dirname $0)/../../../net/forwarding
0008
0009 ALL_TESTS="
0010 nexthop_single_add_test
0011 nexthop_single_add_err_test
0012 nexthop_group_add_test
0013 nexthop_group_add_err_test
0014 nexthop_res_group_add_test
0015 nexthop_res_group_add_err_test
0016 nexthop_group_replace_test
0017 nexthop_group_replace_err_test
0018 nexthop_res_group_replace_test
0019 nexthop_res_group_replace_err_test
0020 nexthop_res_group_idle_timer_test
0021 nexthop_res_group_idle_timer_del_test
0022 nexthop_res_group_increase_idle_timer_test
0023 nexthop_res_group_decrease_idle_timer_test
0024 nexthop_res_group_unbalanced_timer_test
0025 nexthop_res_group_unbalanced_timer_del_test
0026 nexthop_res_group_no_unbalanced_timer_test
0027 nexthop_res_group_short_unbalanced_timer_test
0028 nexthop_res_group_increase_unbalanced_timer_test
0029 nexthop_res_group_decrease_unbalanced_timer_test
0030 nexthop_res_group_force_migrate_busy_test
0031 nexthop_single_replace_test
0032 nexthop_single_replace_err_test
0033 nexthop_single_in_group_replace_test
0034 nexthop_single_in_group_replace_err_test
0035 nexthop_single_in_res_group_replace_test
0036 nexthop_single_in_res_group_replace_err_test
0037 nexthop_single_in_group_delete_test
0038 nexthop_single_in_group_delete_err_test
0039 nexthop_single_in_res_group_delete_test
0040 nexthop_single_in_res_group_delete_err_test
0041 nexthop_replay_test
0042 nexthop_replay_err_test
0043 "
0044 NETDEVSIM_PATH=/sys/bus/netdevsim/
0045 DEV_ADDR=1337
0046 DEV=netdevsim${DEV_ADDR}
0047 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
0048 DEBUGFS_NET_DIR=/sys/kernel/debug/netdevsim/$DEV/
0049 NUM_NETIFS=0
0050 source $lib_dir/lib.sh
0051
0052 DEVLINK_DEV=
0053 source $lib_dir/devlink_lib.sh
0054 DEVLINK_DEV=netdevsim/${DEV}
0055
0056 nexthop_check()
0057 {
0058 local nharg="$1"; shift
0059 local expected="$1"; shift
0060
0061 out=$($IP nexthop show ${nharg} | sed -e 's/ *$//')
0062 if [[ "$out" != "$expected" ]]; then
0063 return 1
0064 fi
0065
0066 return 0
0067 }
0068
0069 nexthop_bucket_nhid_count_check()
0070 {
0071 local group_id=$1; shift
0072 local expected
0073 local count
0074 local nhid
0075 local ret
0076
0077 while (($
0078 nhid=$1; shift
0079 expected=$1; shift
0080
0081 count=$($IP nexthop bucket show id $group_id nhid $nhid |
0082 grep "trap" | wc -l)
0083 if ((expected != count)); then
0084 return 1
0085 fi
0086 done
0087
0088 return 0
0089 }
0090
0091 nexthop_resource_check()
0092 {
0093 local expected_occ=$1; shift
0094
0095 occ=$($DEVLINK -jp resource show $DEVLINK_DEV \
0096 | jq '.[][][] | select(.name=="nexthops") | .["occ"]')
0097
0098 if [ $expected_occ -ne $occ ]; then
0099 return 1
0100 fi
0101
0102 return 0
0103 }
0104
0105 nexthop_resource_set()
0106 {
0107 local size=$1; shift
0108
0109 $DEVLINK resource set $DEVLINK_DEV path nexthops size $size
0110 $DEVLINK dev reload $DEVLINK_DEV
0111 }
0112
0113 nexthop_single_add_test()
0114 {
0115 RET=0
0116
0117 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0118 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
0119 check_err $? "Unexpected nexthop entry"
0120
0121 nexthop_resource_check 1
0122 check_err $? "Wrong nexthop occupancy"
0123
0124 $IP nexthop del id 1
0125 nexthop_resource_check 0
0126 check_err $? "Wrong nexthop occupancy after delete"
0127
0128 log_test "Single nexthop add and delete"
0129 }
0130
0131 nexthop_single_add_err_test()
0132 {
0133 RET=0
0134
0135 nexthop_resource_set 1
0136
0137 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0138
0139 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 &> /dev/null
0140 check_fail $? "Nexthop addition succeeded when should fail"
0141
0142 nexthop_resource_check 1
0143 check_err $? "Wrong nexthop occupancy"
0144
0145 log_test "Single nexthop add failure"
0146
0147 $IP nexthop flush &> /dev/null
0148 nexthop_resource_set 9999
0149 }
0150
0151 nexthop_group_add_test()
0152 {
0153 RET=0
0154
0155 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0156 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0157
0158 $IP nexthop add id 10 group 1/2
0159 nexthop_check "id 10" "id 10 group 1/2 trap"
0160 check_err $? "Unexpected nexthop group entry"
0161
0162 nexthop_resource_check 4
0163 check_err $? "Wrong nexthop occupancy"
0164
0165 $IP nexthop del id 10
0166 nexthop_resource_check 2
0167 check_err $? "Wrong nexthop occupancy after delete"
0168
0169 $IP nexthop add id 10 group 1,20/2,39
0170 nexthop_check "id 10" "id 10 group 1,20/2,39 trap"
0171 check_err $? "Unexpected weighted nexthop group entry"
0172
0173 nexthop_resource_check 61
0174 check_err $? "Wrong weighted nexthop occupancy"
0175
0176 $IP nexthop del id 10
0177 nexthop_resource_check 2
0178 check_err $? "Wrong nexthop occupancy after delete"
0179
0180 log_test "Nexthop group add and delete"
0181
0182 $IP nexthop flush &> /dev/null
0183 }
0184
0185 nexthop_group_add_err_test()
0186 {
0187 RET=0
0188
0189 nexthop_resource_set 2
0190
0191 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0192 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0193
0194 $IP nexthop add id 10 group 1/2 &> /dev/null
0195 check_fail $? "Nexthop group addition succeeded when should fail"
0196
0197 nexthop_resource_check 2
0198 check_err $? "Wrong nexthop occupancy"
0199
0200 log_test "Nexthop group add failure"
0201
0202 $IP nexthop flush &> /dev/null
0203 nexthop_resource_set 9999
0204 }
0205
0206 nexthop_res_group_add_test()
0207 {
0208 RET=0
0209
0210 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0211 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0212
0213 $IP nexthop add id 10 group 1/2 type resilient buckets 4
0214 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0215 check_err $? "Unexpected nexthop group entry"
0216
0217 nexthop_bucket_nhid_count_check 10 1 2
0218 check_err $? "Wrong nexthop buckets count"
0219 nexthop_bucket_nhid_count_check 10 2 2
0220 check_err $? "Wrong nexthop buckets count"
0221
0222 nexthop_resource_check 6
0223 check_err $? "Wrong nexthop occupancy"
0224
0225 $IP nexthop del id 10
0226 nexthop_resource_check 2
0227 check_err $? "Wrong nexthop occupancy after delete"
0228
0229 $IP nexthop add id 10 group 1,3/2,2 type resilient buckets 5
0230 nexthop_check "id 10" "id 10 group 1,3/2,2 type resilient buckets 5 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0231 check_err $? "Unexpected weighted nexthop group entry"
0232
0233 nexthop_bucket_nhid_count_check 10 1 3
0234 check_err $? "Wrong nexthop buckets count"
0235 nexthop_bucket_nhid_count_check 10 2 2
0236 check_err $? "Wrong nexthop buckets count"
0237
0238 nexthop_resource_check 7
0239 check_err $? "Wrong weighted nexthop occupancy"
0240
0241 $IP nexthop del id 10
0242 nexthop_resource_check 2
0243 check_err $? "Wrong nexthop occupancy after delete"
0244
0245 log_test "Resilient nexthop group add and delete"
0246
0247 $IP nexthop flush &> /dev/null
0248 }
0249
0250 nexthop_res_group_add_err_test()
0251 {
0252 RET=0
0253
0254 nexthop_resource_set 2
0255
0256 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0257 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0258
0259 $IP nexthop add id 10 group 1/2 type resilient buckets 4 &> /dev/null
0260 check_fail $? "Nexthop group addition succeeded when should fail"
0261
0262 nexthop_resource_check 2
0263 check_err $? "Wrong nexthop occupancy"
0264
0265 log_test "Resilient nexthop group add failure"
0266
0267 $IP nexthop flush &> /dev/null
0268 nexthop_resource_set 9999
0269 }
0270
0271 nexthop_group_replace_test()
0272 {
0273 RET=0
0274
0275 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0276 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0277 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0278 $IP nexthop add id 10 group 1/2
0279
0280 $IP nexthop replace id 10 group 1/2/3
0281 nexthop_check "id 10" "id 10 group 1/2/3 trap"
0282 check_err $? "Unexpected nexthop group entry"
0283
0284 nexthop_resource_check 6
0285 check_err $? "Wrong nexthop occupancy"
0286
0287 log_test "Nexthop group replace"
0288
0289 $IP nexthop flush &> /dev/null
0290 }
0291
0292 nexthop_group_replace_err_test()
0293 {
0294 RET=0
0295
0296 nexthop_resource_set 5
0297
0298 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0299 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0300 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0301 $IP nexthop add id 10 group 1/2
0302
0303 $IP nexthop replace id 10 group 1/2/3 &> /dev/null
0304 check_fail $? "Nexthop group replacement succeeded when should fail"
0305
0306 nexthop_check "id 10" "id 10 group 1/2 trap"
0307 check_err $? "Unexpected nexthop group entry after failure"
0308
0309 nexthop_resource_check 5
0310 check_err $? "Wrong nexthop occupancy after failure"
0311
0312 log_test "Nexthop group replace failure"
0313
0314 $IP nexthop flush &> /dev/null
0315 nexthop_resource_set 9999
0316 }
0317
0318 nexthop_res_group_replace_test()
0319 {
0320 RET=0
0321
0322 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0323 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0324 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0325 $IP nexthop add id 10 group 1/2 type resilient buckets 6
0326
0327 $IP nexthop replace id 10 group 1/2/3 type resilient
0328 nexthop_check "id 10" "id 10 group 1/2/3 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0329 check_err $? "Unexpected nexthop group entry"
0330
0331 nexthop_bucket_nhid_count_check 10 1 2
0332 check_err $? "Wrong nexthop buckets count"
0333 nexthop_bucket_nhid_count_check 10 2 2
0334 check_err $? "Wrong nexthop buckets count"
0335 nexthop_bucket_nhid_count_check 10 3 2
0336 check_err $? "Wrong nexthop buckets count"
0337
0338 nexthop_resource_check 9
0339 check_err $? "Wrong nexthop occupancy"
0340
0341 log_test "Resilient nexthop group replace"
0342
0343 $IP nexthop flush &> /dev/null
0344 }
0345
0346 nexthop_res_group_replace_err_test()
0347 {
0348 RET=0
0349
0350 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0351 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0352 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0353 $IP nexthop add id 10 group 1/2 type resilient buckets 6
0354
0355 ip netns exec testns1 \
0356 echo 1 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace
0357 $IP nexthop replace id 10 group 1/2/3 type resilient &> /dev/null
0358 check_fail $? "Nexthop group replacement succeeded when should fail"
0359
0360 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0361 check_err $? "Unexpected nexthop group entry after failure"
0362
0363 nexthop_bucket_nhid_count_check 10 1 3
0364 check_err $? "Wrong nexthop buckets count"
0365 nexthop_bucket_nhid_count_check 10 2 3
0366 check_err $? "Wrong nexthop buckets count"
0367
0368 nexthop_resource_check 9
0369 check_err $? "Wrong nexthop occupancy after failure"
0370
0371 log_test "Resilient nexthop group replace failure"
0372
0373 $IP nexthop flush &> /dev/null
0374 ip netns exec testns1 \
0375 echo 0 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace
0376 }
0377
0378 nexthop_res_mark_buckets_busy()
0379 {
0380 local group_id=$1; shift
0381 local nhid=$1; shift
0382 local count=$1; shift
0383 local index
0384
0385 for index in $($IP -j nexthop bucket show id $group_id nhid $nhid |
0386 jq '.[].bucket.index' | head -n ${count:--0})
0387 do
0388 echo $group_id $index \
0389 > $DEBUGFS_NET_DIR/fib/nexthop_bucket_activity
0390 done
0391 }
0392
0393 nexthop_res_num_nhid_buckets()
0394 {
0395 local group_id=$1; shift
0396 local nhid=$1; shift
0397
0398 $IP -j nexthop bucket show id $group_id nhid $nhid | jq length
0399 }
0400
0401 nexthop_res_group_idle_timer_test()
0402 {
0403 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0404 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0405
0406 RET=0
0407
0408 $IP nexthop add id 10 group 1/2 type resilient buckets 8 idle_timer 4
0409 nexthop_res_mark_buckets_busy 10 1
0410 $IP nexthop replace id 10 group 1/2,3 type resilient
0411
0412 nexthop_bucket_nhid_count_check 10 1 4 2 4
0413 check_err $? "Group expected to be unbalanced"
0414
0415 sleep 6
0416
0417 nexthop_bucket_nhid_count_check 10 1 2 2 6
0418 check_err $? "Group expected to be balanced"
0419
0420 log_test "Bucket migration after idle timer"
0421
0422 $IP nexthop flush &> /dev/null
0423 }
0424
0425 nexthop_res_group_idle_timer_del_test()
0426 {
0427 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0428 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0429 $IP nexthop add id 3 via 192.0.2.3 dev dummy1
0430
0431 RET=0
0432
0433 $IP nexthop add id 10 group 1,50/2,50/3,1 \
0434 type resilient buckets 8 idle_timer 6
0435 nexthop_res_mark_buckets_busy 10 1
0436 $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient
0437
0438 nexthop_bucket_nhid_count_check 10 1 4 2 4 3 0
0439 check_err $? "Group expected to be unbalanced"
0440
0441 sleep 4
0442
0443
0444
0445 $IP nexthop delete id 3
0446
0447 nexthop_bucket_nhid_count_check 10 1 4 2 4
0448 check_err $? "Group expected to still be unbalanced"
0449
0450 sleep 4
0451
0452 nexthop_bucket_nhid_count_check 10 1 2 2 6
0453 check_err $? "Group expected to be balanced"
0454
0455 log_test "Bucket migration after idle timer (with delete)"
0456
0457 $IP nexthop flush &> /dev/null
0458 }
0459
0460 __nexthop_res_group_increase_timer_test()
0461 {
0462 local timer=$1; shift
0463
0464 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0465 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0466
0467 RET=0
0468
0469 $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 4
0470 nexthop_res_mark_buckets_busy 10 1
0471 $IP nexthop replace id 10 group 1/2,3 type resilient
0472
0473 nexthop_bucket_nhid_count_check 10 2 6
0474 check_fail $? "Group expected to be unbalanced"
0475
0476 sleep 2
0477 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8
0478 sleep 4
0479
0480
0481 nexthop_bucket_nhid_count_check 10 2 6
0482 check_fail $? "Group still expected to be unbalanced"
0483
0484 sleep 4
0485
0486
0487 nexthop_bucket_nhid_count_check 10 2 6
0488 check_err $? "Group expected to be balanced"
0489
0490 log_test "Bucket migration after $timer increase"
0491
0492 $IP nexthop flush &> /dev/null
0493 }
0494
0495 __nexthop_res_group_decrease_timer_test()
0496 {
0497 local timer=$1; shift
0498
0499 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0500 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0501
0502 RET=0
0503
0504 $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 8
0505 nexthop_res_mark_buckets_busy 10 1
0506 $IP nexthop replace id 10 group 1/2,3 type resilient
0507
0508 nexthop_bucket_nhid_count_check 10 2 6
0509 check_fail $? "Group expected to be unbalanced"
0510
0511 sleep 2
0512 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 4
0513 sleep 4
0514
0515
0516 nexthop_bucket_nhid_count_check 10 2 6
0517 check_err $? "Group expected to be balanced"
0518
0519 log_test "Bucket migration after $timer decrease"
0520
0521 $IP nexthop flush &> /dev/null
0522 }
0523
0524 __nexthop_res_group_increase_timer_del_test()
0525 {
0526 local timer=$1; shift
0527
0528 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0529 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0530 $IP nexthop add id 3 via 192.0.2.3 dev dummy1
0531
0532 RET=0
0533
0534 $IP nexthop add id 10 group 1,100/2,100/3,1 \
0535 type resilient buckets 8 $timer 4
0536 nexthop_res_mark_buckets_busy 10 1
0537 $IP nexthop replace id 10 group 1,100/2,300/3,1 type resilient
0538
0539 nexthop_bucket_nhid_count_check 10 2 6
0540 check_fail $? "Group expected to be unbalanced"
0541
0542 sleep 2
0543 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8
0544 sleep 4
0545
0546
0547 nexthop_bucket_nhid_count_check 10 2 6
0548 check_fail $? "Group still expected to be unbalanced"
0549
0550 sleep 4
0551
0552
0553 nexthop_bucket_nhid_count_check 10 2 6
0554 check_err $? "Group expected to be balanced"
0555
0556 log_test "Bucket migration after $timer increase"
0557
0558 $IP nexthop flush &> /dev/null
0559 }
0560
0561 nexthop_res_group_increase_idle_timer_test()
0562 {
0563 __nexthop_res_group_increase_timer_test idle_timer
0564 }
0565
0566 nexthop_res_group_decrease_idle_timer_test()
0567 {
0568 __nexthop_res_group_decrease_timer_test idle_timer
0569 }
0570
0571 nexthop_res_group_unbalanced_timer_test()
0572 {
0573 local i
0574
0575 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0576 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0577
0578 RET=0
0579
0580 $IP nexthop add id 10 group 1/2 type resilient \
0581 buckets 8 idle_timer 6 unbalanced_timer 10
0582 nexthop_res_mark_buckets_busy 10 1
0583 $IP nexthop replace id 10 group 1/2,3 type resilient
0584
0585 for i in 1 2; do
0586 sleep 4
0587 nexthop_bucket_nhid_count_check 10 1 4 2 4
0588 check_err $? "$i: Group expected to be unbalanced"
0589 nexthop_res_mark_buckets_busy 10 1
0590 done
0591
0592
0593 sleep 4
0594 nexthop_bucket_nhid_count_check 10 1 2 2 6
0595 check_err $? "Group expected to be balanced"
0596
0597 log_test "Bucket migration after unbalanced timer"
0598
0599 $IP nexthop flush &> /dev/null
0600 }
0601
0602 nexthop_res_group_unbalanced_timer_del_test()
0603 {
0604 local i
0605
0606 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0607 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0608 $IP nexthop add id 3 via 192.0.2.3 dev dummy1
0609
0610 RET=0
0611
0612 $IP nexthop add id 10 group 1,50/2,50/3,1 type resilient \
0613 buckets 8 idle_timer 6 unbalanced_timer 10
0614 nexthop_res_mark_buckets_busy 10 1
0615 $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient
0616
0617
0618 sleep 4
0619 $IP nexthop delete id 3
0620 nexthop_bucket_nhid_count_check 10 1 4 2 4
0621 check_err $? "1: Group expected to be unbalanced"
0622 nexthop_res_mark_buckets_busy 10 1
0623
0624 sleep 4
0625 nexthop_bucket_nhid_count_check 10 1 4 2 4
0626 check_err $? "2: Group expected to be unbalanced"
0627 nexthop_res_mark_buckets_busy 10 1
0628
0629
0630 sleep 4
0631 nexthop_bucket_nhid_count_check 10 1 2 2 6
0632 check_err $? "Group expected to be balanced"
0633
0634 log_test "Bucket migration after unbalanced timer (with delete)"
0635
0636 $IP nexthop flush &> /dev/null
0637 }
0638
0639 nexthop_res_group_no_unbalanced_timer_test()
0640 {
0641 local i
0642
0643 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0644 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0645
0646 RET=0
0647
0648 $IP nexthop add id 10 group 1/2 type resilient buckets 8
0649 nexthop_res_mark_buckets_busy 10 1
0650 $IP nexthop replace id 10 group 1/2,3 type resilient
0651
0652 for i in $(seq 3); do
0653 sleep 60
0654 nexthop_bucket_nhid_count_check 10 2 6
0655 check_fail $? "$i: Group expected to be unbalanced"
0656 nexthop_res_mark_buckets_busy 10 1
0657 done
0658
0659 log_test "Buckets never force-migrated without unbalanced timer"
0660
0661 $IP nexthop flush &> /dev/null
0662 }
0663
0664 nexthop_res_group_short_unbalanced_timer_test()
0665 {
0666 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0667 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0668
0669 RET=0
0670
0671 $IP nexthop add id 10 group 1/2 type resilient \
0672 buckets 8 idle_timer 120 unbalanced_timer 4
0673 nexthop_res_mark_buckets_busy 10 1
0674 $IP nexthop replace id 10 group 1/2,3 type resilient
0675
0676 nexthop_bucket_nhid_count_check 10 2 6
0677 check_fail $? "Group expected to be unbalanced"
0678
0679 sleep 5
0680
0681 nexthop_bucket_nhid_count_check 10 2 6
0682 check_err $? "Group expected to be balanced"
0683
0684 log_test "Bucket migration after unbalanced < idle timer"
0685
0686 $IP nexthop flush &> /dev/null
0687 }
0688
0689 nexthop_res_group_increase_unbalanced_timer_test()
0690 {
0691 __nexthop_res_group_increase_timer_test unbalanced_timer
0692 }
0693
0694 nexthop_res_group_decrease_unbalanced_timer_test()
0695 {
0696 __nexthop_res_group_decrease_timer_test unbalanced_timer
0697 }
0698
0699 nexthop_res_group_force_migrate_busy_test()
0700 {
0701 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0702 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0703
0704 RET=0
0705
0706 $IP nexthop add id 10 group 1/2 type resilient \
0707 buckets 8 idle_timer 120
0708 nexthop_res_mark_buckets_busy 10 1
0709 $IP nexthop replace id 10 group 1/2,3 type resilient
0710
0711 nexthop_bucket_nhid_count_check 10 2 6
0712 check_fail $? "Group expected to be unbalanced"
0713
0714 $IP nexthop replace id 10 group 2 type resilient
0715 nexthop_bucket_nhid_count_check 10 2 8
0716 check_err $? "All buckets expected to have migrated"
0717
0718 log_test "Busy buckets force-migrated when NH removed"
0719
0720 $IP nexthop flush &> /dev/null
0721 }
0722
0723 nexthop_single_replace_test()
0724 {
0725 RET=0
0726
0727 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0728
0729 $IP nexthop replace id 1 via 192.0.2.3 dev dummy1
0730 nexthop_check "id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap"
0731 check_err $? "Unexpected nexthop entry"
0732
0733 nexthop_resource_check 1
0734 check_err $? "Wrong nexthop occupancy"
0735
0736 log_test "Single nexthop replace"
0737
0738 $IP nexthop flush &> /dev/null
0739 }
0740
0741 nexthop_single_replace_err_test()
0742 {
0743 RET=0
0744
0745
0746
0747 nexthop_resource_set 1
0748
0749 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0750
0751 $IP nexthop replace id 1 via 192.0.2.3 dev dummy1 &> /dev/null
0752 check_fail $? "Nexthop replace succeeded when should fail"
0753
0754 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
0755 check_err $? "Unexpected nexthop entry after failure"
0756
0757 nexthop_resource_check 1
0758 check_err $? "Wrong nexthop occupancy after failure"
0759
0760 log_test "Single nexthop replace failure"
0761
0762 $IP nexthop flush &> /dev/null
0763 nexthop_resource_set 9999
0764 }
0765
0766 nexthop_single_in_group_replace_test()
0767 {
0768 RET=0
0769
0770 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0771 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0772 $IP nexthop add id 10 group 1/2
0773
0774 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1
0775 check_err $? "Failed to replace nexthop when should not"
0776
0777 nexthop_check "id 10" "id 10 group 1/2 trap"
0778 check_err $? "Unexpected nexthop group entry"
0779
0780 nexthop_resource_check 4
0781 check_err $? "Wrong nexthop occupancy"
0782
0783 log_test "Single nexthop replace while in group"
0784
0785 $IP nexthop flush &> /dev/null
0786 }
0787
0788 nexthop_single_in_group_replace_err_test()
0789 {
0790 RET=0
0791
0792 nexthop_resource_set 5
0793
0794 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0795 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0796 $IP nexthop add id 10 group 1/2
0797
0798 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null
0799 check_fail $? "Nexthop replacement succeeded when should fail"
0800
0801 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
0802 check_err $? "Unexpected nexthop entry after failure"
0803
0804 nexthop_check "id 10" "id 10 group 1/2 trap"
0805 check_err $? "Unexpected nexthop group entry after failure"
0806
0807 nexthop_resource_check 4
0808 check_err $? "Wrong nexthop occupancy"
0809
0810 log_test "Single nexthop replace while in group failure"
0811
0812 $IP nexthop flush &> /dev/null
0813 nexthop_resource_set 9999
0814 }
0815
0816 nexthop_single_in_res_group_replace_test()
0817 {
0818 RET=0
0819
0820 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0821 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0822 $IP nexthop add id 10 group 1/2 type resilient buckets 4
0823
0824 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1
0825 check_err $? "Failed to replace nexthop when should not"
0826
0827 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0828 check_err $? "Unexpected nexthop group entry"
0829
0830 nexthop_bucket_nhid_count_check 10 1 2 2 2
0831 check_err $? "Wrong nexthop buckets count"
0832
0833 nexthop_resource_check 6
0834 check_err $? "Wrong nexthop occupancy"
0835
0836 log_test "Single nexthop replace while in resilient group"
0837
0838 $IP nexthop flush &> /dev/null
0839 }
0840
0841 nexthop_single_in_res_group_replace_err_test()
0842 {
0843 RET=0
0844
0845 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0846 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0847 $IP nexthop add id 10 group 1/2 type resilient buckets 4
0848
0849 ip netns exec testns1 \
0850 echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
0851 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null
0852 check_fail $? "Nexthop replacement succeeded when should fail"
0853
0854 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
0855 check_err $? "Unexpected nexthop entry after failure"
0856
0857 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0858 check_err $? "Unexpected nexthop group entry after failure"
0859
0860 nexthop_bucket_nhid_count_check 10 1 2 2 2
0861 check_err $? "Wrong nexthop buckets count"
0862
0863 nexthop_resource_check 6
0864 check_err $? "Wrong nexthop occupancy"
0865
0866 log_test "Single nexthop replace while in resilient group failure"
0867
0868 $IP nexthop flush &> /dev/null
0869 ip netns exec testns1 \
0870 echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
0871 }
0872
0873 nexthop_single_in_group_delete_test()
0874 {
0875 RET=0
0876
0877 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0878 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0879 $IP nexthop add id 10 group 1/2
0880
0881 $IP nexthop del id 1
0882 nexthop_check "id 10" "id 10 group 2 trap"
0883 check_err $? "Unexpected nexthop group entry"
0884
0885 nexthop_resource_check 2
0886 check_err $? "Wrong nexthop occupancy"
0887
0888 log_test "Single nexthop delete while in group"
0889
0890 $IP nexthop flush &> /dev/null
0891 }
0892
0893 nexthop_single_in_group_delete_err_test()
0894 {
0895 RET=0
0896
0897
0898
0899
0900
0901
0902 nexthop_resource_set 6
0903
0904 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0905 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0906 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0907 $IP nexthop add id 10 group 1/2/3
0908
0909 $IP nexthop del id 1
0910
0911 nexthop_resource_check 5
0912 check_err $? "Wrong nexthop occupancy"
0913
0914 log_test "Single nexthop delete while in group failure"
0915
0916 $IP nexthop flush &> /dev/null
0917 nexthop_resource_set 9999
0918 }
0919
0920 nexthop_single_in_res_group_delete_test()
0921 {
0922 RET=0
0923
0924 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0925 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0926 $IP nexthop add id 10 group 1/2 type resilient buckets 4
0927
0928 $IP nexthop del id 1
0929 nexthop_check "id 10" "id 10 group 2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
0930 check_err $? "Unexpected nexthop group entry"
0931
0932 nexthop_bucket_nhid_count_check 10 2 4
0933 check_err $? "Wrong nexthop buckets count"
0934
0935 nexthop_resource_check 5
0936 check_err $? "Wrong nexthop occupancy"
0937
0938 log_test "Single nexthop delete while in resilient group"
0939
0940 $IP nexthop flush &> /dev/null
0941 }
0942
0943 nexthop_single_in_res_group_delete_err_test()
0944 {
0945 RET=0
0946
0947 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0948 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0949 $IP nexthop add id 3 via 192.0.2.4 dev dummy1
0950 $IP nexthop add id 10 group 1/2/3 type resilient buckets 6
0951
0952 ip netns exec testns1 \
0953 echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
0954 $IP nexthop del id 1
0955
0956
0957
0958 nexthop_bucket_nhid_count_check 10 2 2 3 2
0959 check_err $? "Wrong nexthop buckets count"
0960
0961 nexthop_resource_check 8
0962 check_err $? "Wrong nexthop occupancy"
0963
0964 log_test "Single nexthop delete while in resilient group failure"
0965
0966 $IP nexthop flush &> /dev/null
0967 ip netns exec testns1 \
0968 echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
0969 }
0970
0971 nexthop_replay_test()
0972 {
0973 RET=0
0974
0975 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
0976 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
0977 $IP nexthop add id 10 group 1/2
0978
0979 $DEVLINK dev reload $DEVLINK_DEV
0980 check_err $? "Failed to reload when should not"
0981
0982 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
0983 check_err $? "Unexpected nexthop entry after reload"
0984
0985 nexthop_check "id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap"
0986 check_err $? "Unexpected nexthop entry after reload"
0987
0988 nexthop_check "id 10" "id 10 group 1/2 trap"
0989 check_err $? "Unexpected nexthop group entry after reload"
0990
0991 nexthop_resource_check 4
0992 check_err $? "Wrong nexthop occupancy"
0993
0994 log_test "Nexthop replay"
0995
0996 $IP nexthop flush &> /dev/null
0997 }
0998
0999 nexthop_replay_err_test()
1000 {
1001 RET=0
1002
1003 $IP nexthop add id 1 via 192.0.2.2 dev dummy1
1004 $IP nexthop add id 2 via 192.0.2.3 dev dummy1
1005 $IP nexthop add id 10 group 1/2
1006
1007
1008 $DEVLINK resource set $DEVLINK_DEV path nexthops size 3
1009 $DEVLINK dev reload $DEVLINK_DEV &> /dev/null
1010 check_fail $? "Reload succeeded when should fail"
1011
1012 $DEVLINK resource set $DEVLINK_DEV path nexthops size 9999
1013 $DEVLINK dev reload $DEVLINK_DEV
1014 check_err $? "Failed to reload when should not"
1015
1016 log_test "Nexthop replay failure"
1017
1018 $IP nexthop flush &> /dev/null
1019 }
1020
1021 setup_prepare()
1022 {
1023 local netdev
1024
1025 modprobe netdevsim &> /dev/null
1026
1027 echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
1028 while [ ! -d $SYSFS_NET_DIR ] ; do :; done
1029
1030 set -e
1031
1032 ip netns add testns1
1033 devlink dev reload $DEVLINK_DEV netns testns1
1034
1035 IP="ip -netns testns1"
1036 DEVLINK="devlink -N testns1"
1037
1038 $IP link add name dummy1 up type dummy
1039 $IP address add 192.0.2.1/24 dev dummy1
1040
1041 set +e
1042 }
1043
1044 cleanup()
1045 {
1046 pre_cleanup
1047 ip netns del testns1
1048 echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
1049 modprobe -r netdevsim &> /dev/null
1050 }
1051
1052 trap cleanup EXIT
1053
1054 setup_prepare
1055
1056 tests_run
1057
1058 exit $EXIT_STATUS