Path: blob/master/tools/testing/selftests/drivers/net/netdevsim/nexthop.sh
26299 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# This test is for checking the nexthop offload API. It makes use of netdevsim4# which registers a listener to the nexthop notification chain.56lib_dir=$(dirname $0)/../../../net/forwarding78ALL_TESTS="9nexthop_single_add_test10nexthop_single_add_err_test11nexthop_group_add_test12nexthop_group_add_err_test13nexthop_res_group_add_test14nexthop_res_group_add_err_test15nexthop_group_replace_test16nexthop_group_replace_err_test17nexthop_res_group_replace_test18nexthop_res_group_replace_err_test19nexthop_res_group_idle_timer_test20nexthop_res_group_idle_timer_del_test21nexthop_res_group_increase_idle_timer_test22nexthop_res_group_decrease_idle_timer_test23nexthop_res_group_unbalanced_timer_test24nexthop_res_group_unbalanced_timer_del_test25nexthop_res_group_no_unbalanced_timer_test26nexthop_res_group_short_unbalanced_timer_test27nexthop_res_group_increase_unbalanced_timer_test28nexthop_res_group_decrease_unbalanced_timer_test29nexthop_res_group_force_migrate_busy_test30nexthop_single_replace_test31nexthop_single_replace_err_test32nexthop_single_in_group_replace_test33nexthop_single_in_group_replace_err_test34nexthop_single_in_res_group_replace_test35nexthop_single_in_res_group_replace_err_test36nexthop_single_in_group_delete_test37nexthop_single_in_group_delete_err_test38nexthop_single_in_res_group_delete_test39nexthop_single_in_res_group_delete_err_test40nexthop_replay_test41nexthop_replay_err_test42"43NETDEVSIM_PATH=/sys/bus/netdevsim/44DEV_ADDR=133745DEV=netdevsim${DEV_ADDR}46SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/47DEBUGFS_NET_DIR=/sys/kernel/debug/netdevsim/$DEV/48NUM_NETIFS=049source $lib_dir/lib.sh5051DEVLINK_DEV=52source $lib_dir/devlink_lib.sh53DEVLINK_DEV=netdevsim/${DEV}5455nexthop_check()56{57local nharg="$1"; shift58local expected="$1"; shift5960out=$($IP nexthop show ${nharg} | sed -e 's/ *$//')61if [[ "$out" != "$expected" ]]; then62return 163fi6465return 066}6768nexthop_bucket_nhid_count_check()69{70local group_id=$1; shift71local expected72local count73local nhid74local ret7576while (($# > 0)); do77nhid=$1; shift78expected=$1; shift7980count=$($IP nexthop bucket show id $group_id nhid $nhid |81grep "trap" | wc -l)82if ((expected != count)); then83return 184fi85done8687return 088}8990nexthop_resource_check()91{92local expected_occ=$1; shift9394occ=$($DEVLINK -jp resource show $DEVLINK_DEV \95| jq '.[][][] | select(.name=="nexthops") | .["occ"]')9697if [ $expected_occ -ne $occ ]; then98return 199fi100101return 0102}103104nexthop_resource_set()105{106local size=$1; shift107108$DEVLINK resource set $DEVLINK_DEV path nexthops size $size109$DEVLINK dev reload $DEVLINK_DEV110}111112nexthop_single_add_test()113{114RET=0115116$IP nexthop add id 1 via 192.0.2.2 dev dummy1117nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"118check_err $? "Unexpected nexthop entry"119120nexthop_resource_check 1121check_err $? "Wrong nexthop occupancy"122123$IP nexthop del id 1124nexthop_resource_check 0125check_err $? "Wrong nexthop occupancy after delete"126127log_test "Single nexthop add and delete"128}129130nexthop_single_add_err_test()131{132RET=0133134nexthop_resource_set 1135136$IP nexthop add id 1 via 192.0.2.2 dev dummy1137138$IP nexthop add id 2 via 192.0.2.3 dev dummy1 &> /dev/null139check_fail $? "Nexthop addition succeeded when should fail"140141nexthop_resource_check 1142check_err $? "Wrong nexthop occupancy"143144log_test "Single nexthop add failure"145146$IP nexthop flush &> /dev/null147nexthop_resource_set 9999148}149150nexthop_group_add_test()151{152RET=0153154$IP nexthop add id 1 via 192.0.2.2 dev dummy1155$IP nexthop add id 2 via 192.0.2.3 dev dummy1156157$IP nexthop add id 10 group 1/2158nexthop_check "id 10" "id 10 group 1/2 trap"159check_err $? "Unexpected nexthop group entry"160161nexthop_resource_check 4162check_err $? "Wrong nexthop occupancy"163164$IP nexthop del id 10165nexthop_resource_check 2166check_err $? "Wrong nexthop occupancy after delete"167168$IP nexthop add id 10 group 1,20/2,39169nexthop_check "id 10" "id 10 group 1,20/2,39 trap"170check_err $? "Unexpected weighted nexthop group entry"171172nexthop_resource_check 61173check_err $? "Wrong weighted nexthop occupancy"174175$IP nexthop del id 10176nexthop_resource_check 2177check_err $? "Wrong nexthop occupancy after delete"178179log_test "Nexthop group add and delete"180181$IP nexthop flush &> /dev/null182}183184nexthop_group_add_err_test()185{186RET=0187188nexthop_resource_set 2189190$IP nexthop add id 1 via 192.0.2.2 dev dummy1191$IP nexthop add id 2 via 192.0.2.3 dev dummy1192193$IP nexthop add id 10 group 1/2 &> /dev/null194check_fail $? "Nexthop group addition succeeded when should fail"195196nexthop_resource_check 2197check_err $? "Wrong nexthop occupancy"198199log_test "Nexthop group add failure"200201$IP nexthop flush &> /dev/null202nexthop_resource_set 9999203}204205nexthop_res_group_add_test()206{207RET=0208209$IP nexthop add id 1 via 192.0.2.2 dev dummy1210$IP nexthop add id 2 via 192.0.2.3 dev dummy1211212$IP nexthop add id 10 group 1/2 type resilient buckets 4213nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"214check_err $? "Unexpected nexthop group entry"215216nexthop_bucket_nhid_count_check 10 1 2217check_err $? "Wrong nexthop buckets count"218nexthop_bucket_nhid_count_check 10 2 2219check_err $? "Wrong nexthop buckets count"220221nexthop_resource_check 6222check_err $? "Wrong nexthop occupancy"223224$IP nexthop del id 10225nexthop_resource_check 2226check_err $? "Wrong nexthop occupancy after delete"227228$IP nexthop add id 10 group 1,3/2,2 type resilient buckets 5229nexthop_check "id 10" "id 10 group 1,3/2,2 type resilient buckets 5 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"230check_err $? "Unexpected weighted nexthop group entry"231232nexthop_bucket_nhid_count_check 10 1 3233check_err $? "Wrong nexthop buckets count"234nexthop_bucket_nhid_count_check 10 2 2235check_err $? "Wrong nexthop buckets count"236237nexthop_resource_check 7238check_err $? "Wrong weighted nexthop occupancy"239240$IP nexthop del id 10241nexthop_resource_check 2242check_err $? "Wrong nexthop occupancy after delete"243244log_test "Resilient nexthop group add and delete"245246$IP nexthop flush &> /dev/null247}248249nexthop_res_group_add_err_test()250{251RET=0252253nexthop_resource_set 2254255$IP nexthop add id 1 via 192.0.2.2 dev dummy1256$IP nexthop add id 2 via 192.0.2.3 dev dummy1257258$IP nexthop add id 10 group 1/2 type resilient buckets 4 &> /dev/null259check_fail $? "Nexthop group addition succeeded when should fail"260261nexthop_resource_check 2262check_err $? "Wrong nexthop occupancy"263264log_test "Resilient nexthop group add failure"265266$IP nexthop flush &> /dev/null267nexthop_resource_set 9999268}269270nexthop_group_replace_test()271{272RET=0273274$IP nexthop add id 1 via 192.0.2.2 dev dummy1275$IP nexthop add id 2 via 192.0.2.3 dev dummy1276$IP nexthop add id 3 via 192.0.2.4 dev dummy1277$IP nexthop add id 10 group 1/2278279$IP nexthop replace id 10 group 1/2/3280nexthop_check "id 10" "id 10 group 1/2/3 trap"281check_err $? "Unexpected nexthop group entry"282283nexthop_resource_check 6284check_err $? "Wrong nexthop occupancy"285286log_test "Nexthop group replace"287288$IP nexthop flush &> /dev/null289}290291nexthop_group_replace_err_test()292{293RET=0294295nexthop_resource_set 5296297$IP nexthop add id 1 via 192.0.2.2 dev dummy1298$IP nexthop add id 2 via 192.0.2.3 dev dummy1299$IP nexthop add id 3 via 192.0.2.4 dev dummy1300$IP nexthop add id 10 group 1/2301302$IP nexthop replace id 10 group 1/2/3 &> /dev/null303check_fail $? "Nexthop group replacement succeeded when should fail"304305nexthop_check "id 10" "id 10 group 1/2 trap"306check_err $? "Unexpected nexthop group entry after failure"307308nexthop_resource_check 5309check_err $? "Wrong nexthop occupancy after failure"310311log_test "Nexthop group replace failure"312313$IP nexthop flush &> /dev/null314nexthop_resource_set 9999315}316317nexthop_res_group_replace_test()318{319RET=0320321$IP nexthop add id 1 via 192.0.2.2 dev dummy1322$IP nexthop add id 2 via 192.0.2.3 dev dummy1323$IP nexthop add id 3 via 192.0.2.4 dev dummy1324$IP nexthop add id 10 group 1/2 type resilient buckets 6325326$IP nexthop replace id 10 group 1/2/3 type resilient327nexthop_check "id 10" "id 10 group 1/2/3 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"328check_err $? "Unexpected nexthop group entry"329330nexthop_bucket_nhid_count_check 10 1 2331check_err $? "Wrong nexthop buckets count"332nexthop_bucket_nhid_count_check 10 2 2333check_err $? "Wrong nexthop buckets count"334nexthop_bucket_nhid_count_check 10 3 2335check_err $? "Wrong nexthop buckets count"336337nexthop_resource_check 9338check_err $? "Wrong nexthop occupancy"339340log_test "Resilient nexthop group replace"341342$IP nexthop flush &> /dev/null343}344345nexthop_res_group_replace_err_test()346{347RET=0348349$IP nexthop add id 1 via 192.0.2.2 dev dummy1350$IP nexthop add id 2 via 192.0.2.3 dev dummy1351$IP nexthop add id 3 via 192.0.2.4 dev dummy1352$IP nexthop add id 10 group 1/2 type resilient buckets 6353354ip netns exec testns1 \355echo 1 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace356$IP nexthop replace id 10 group 1/2/3 type resilient &> /dev/null357check_fail $? "Nexthop group replacement succeeded when should fail"358359nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"360check_err $? "Unexpected nexthop group entry after failure"361362nexthop_bucket_nhid_count_check 10 1 3363check_err $? "Wrong nexthop buckets count"364nexthop_bucket_nhid_count_check 10 2 3365check_err $? "Wrong nexthop buckets count"366367nexthop_resource_check 9368check_err $? "Wrong nexthop occupancy after failure"369370log_test "Resilient nexthop group replace failure"371372$IP nexthop flush &> /dev/null373ip netns exec testns1 \374echo 0 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace375}376377nexthop_res_mark_buckets_busy()378{379local group_id=$1; shift380local nhid=$1; shift381local count=$1; shift382local index383384for index in $($IP -j nexthop bucket show id $group_id nhid $nhid |385jq '.[].bucket.index' | head -n ${count:--0})386do387echo $group_id $index \388> $DEBUGFS_NET_DIR/fib/nexthop_bucket_activity389done390}391392nexthop_res_num_nhid_buckets()393{394local group_id=$1; shift395local nhid=$1; shift396397$IP -j nexthop bucket show id $group_id nhid $nhid | jq length398}399400nexthop_res_group_idle_timer_test()401{402$IP nexthop add id 1 via 192.0.2.2 dev dummy1403$IP nexthop add id 2 via 192.0.2.3 dev dummy1404405RET=0406407$IP nexthop add id 10 group 1/2 type resilient buckets 8 idle_timer 4408nexthop_res_mark_buckets_busy 10 1409$IP nexthop replace id 10 group 1/2,3 type resilient410411nexthop_bucket_nhid_count_check 10 1 4 2 4412check_err $? "Group expected to be unbalanced"413414sleep 6415416nexthop_bucket_nhid_count_check 10 1 2 2 6417check_err $? "Group expected to be balanced"418419log_test "Bucket migration after idle timer"420421$IP nexthop flush &> /dev/null422}423424nexthop_res_group_idle_timer_del_test()425{426$IP nexthop add id 1 via 192.0.2.2 dev dummy1427$IP nexthop add id 2 via 192.0.2.3 dev dummy1428$IP nexthop add id 3 via 192.0.2.3 dev dummy1429430RET=0431432$IP nexthop add id 10 group 1,50/2,50/3,1 \433type resilient buckets 8 idle_timer 6434nexthop_res_mark_buckets_busy 10 1435$IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient436437nexthop_bucket_nhid_count_check 10 1 4 2 4 3 0438check_err $? "Group expected to be unbalanced"439440sleep 4441442# Deletion prompts group replacement. Check that the bucket timers443# are kept.444$IP nexthop delete id 3445446nexthop_bucket_nhid_count_check 10 1 4 2 4447check_err $? "Group expected to still be unbalanced"448449sleep 4450451nexthop_bucket_nhid_count_check 10 1 2 2 6452check_err $? "Group expected to be balanced"453454log_test "Bucket migration after idle timer (with delete)"455456$IP nexthop flush &> /dev/null457}458459__nexthop_res_group_increase_timer_test()460{461local timer=$1; shift462463$IP nexthop add id 1 via 192.0.2.2 dev dummy1464$IP nexthop add id 2 via 192.0.2.3 dev dummy1465466RET=0467468$IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 4469nexthop_res_mark_buckets_busy 10 1470$IP nexthop replace id 10 group 1/2,3 type resilient471472nexthop_bucket_nhid_count_check 10 2 6473check_fail $? "Group expected to be unbalanced"474475sleep 2476$IP nexthop replace id 10 group 1/2,3 type resilient $timer 8477sleep 4478479# 6 seconds, past the original timer.480nexthop_bucket_nhid_count_check 10 2 6481check_fail $? "Group still expected to be unbalanced"482483sleep 4484485# 10 seconds, past the new timer.486nexthop_bucket_nhid_count_check 10 2 6487check_err $? "Group expected to be balanced"488489log_test "Bucket migration after $timer increase"490491$IP nexthop flush &> /dev/null492}493494__nexthop_res_group_decrease_timer_test()495{496local timer=$1; shift497498$IP nexthop add id 1 via 192.0.2.2 dev dummy1499$IP nexthop add id 2 via 192.0.2.3 dev dummy1500501RET=0502503$IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 8504nexthop_res_mark_buckets_busy 10 1505$IP nexthop replace id 10 group 1/2,3 type resilient506507nexthop_bucket_nhid_count_check 10 2 6508check_fail $? "Group expected to be unbalanced"509510sleep 2511$IP nexthop replace id 10 group 1/2,3 type resilient $timer 4512sleep 4513514# 6 seconds, past the new timer, before the old timer.515nexthop_bucket_nhid_count_check 10 2 6516check_err $? "Group expected to be balanced"517518log_test "Bucket migration after $timer decrease"519520$IP nexthop flush &> /dev/null521}522523__nexthop_res_group_increase_timer_del_test()524{525local timer=$1; shift526527$IP nexthop add id 1 via 192.0.2.2 dev dummy1528$IP nexthop add id 2 via 192.0.2.3 dev dummy1529$IP nexthop add id 3 via 192.0.2.3 dev dummy1530531RET=0532533$IP nexthop add id 10 group 1,100/2,100/3,1 \534type resilient buckets 8 $timer 4535nexthop_res_mark_buckets_busy 10 1536$IP nexthop replace id 10 group 1,100/2,300/3,1 type resilient537538nexthop_bucket_nhid_count_check 10 2 6539check_fail $? "Group expected to be unbalanced"540541sleep 2542$IP nexthop replace id 10 group 1/2,3 type resilient $timer 8543sleep 4544545# 6 seconds, past the original timer.546nexthop_bucket_nhid_count_check 10 2 6547check_fail $? "Group still expected to be unbalanced"548549sleep 4550551# 10 seconds, past the new timer.552nexthop_bucket_nhid_count_check 10 2 6553check_err $? "Group expected to be balanced"554555log_test "Bucket migration after $timer increase"556557$IP nexthop flush &> /dev/null558}559560nexthop_res_group_increase_idle_timer_test()561{562__nexthop_res_group_increase_timer_test idle_timer563}564565nexthop_res_group_decrease_idle_timer_test()566{567__nexthop_res_group_decrease_timer_test idle_timer568}569570nexthop_res_group_unbalanced_timer_test()571{572local i573574$IP nexthop add id 1 via 192.0.2.2 dev dummy1575$IP nexthop add id 2 via 192.0.2.3 dev dummy1576577RET=0578579$IP nexthop add id 10 group 1/2 type resilient \580buckets 8 idle_timer 6 unbalanced_timer 10581nexthop_res_mark_buckets_busy 10 1582$IP nexthop replace id 10 group 1/2,3 type resilient583584for i in 1 2; do585sleep 4586nexthop_bucket_nhid_count_check 10 1 4 2 4587check_err $? "$i: Group expected to be unbalanced"588nexthop_res_mark_buckets_busy 10 1589done590591# 3 x sleep 4 > unbalanced timer 10592sleep 4593nexthop_bucket_nhid_count_check 10 1 2 2 6594check_err $? "Group expected to be balanced"595596log_test "Bucket migration after unbalanced timer"597598$IP nexthop flush &> /dev/null599}600601nexthop_res_group_unbalanced_timer_del_test()602{603local i604605$IP nexthop add id 1 via 192.0.2.2 dev dummy1606$IP nexthop add id 2 via 192.0.2.3 dev dummy1607$IP nexthop add id 3 via 192.0.2.3 dev dummy1608609RET=0610611$IP nexthop add id 10 group 1,50/2,50/3,1 type resilient \612buckets 8 idle_timer 6 unbalanced_timer 10613nexthop_res_mark_buckets_busy 10 1614$IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient615616# Check that NH delete does not reset unbalanced time.617sleep 4618$IP nexthop delete id 3619nexthop_bucket_nhid_count_check 10 1 4 2 4620check_err $? "1: Group expected to be unbalanced"621nexthop_res_mark_buckets_busy 10 1622623sleep 4624nexthop_bucket_nhid_count_check 10 1 4 2 4625check_err $? "2: Group expected to be unbalanced"626nexthop_res_mark_buckets_busy 10 1627628# 3 x sleep 4 > unbalanced timer 10629sleep 4630nexthop_bucket_nhid_count_check 10 1 2 2 6631check_err $? "Group expected to be balanced"632633log_test "Bucket migration after unbalanced timer (with delete)"634635$IP nexthop flush &> /dev/null636}637638nexthop_res_group_no_unbalanced_timer_test()639{640local i641642$IP nexthop add id 1 via 192.0.2.2 dev dummy1643$IP nexthop add id 2 via 192.0.2.3 dev dummy1644645RET=0646647$IP nexthop add id 10 group 1/2 type resilient buckets 8648nexthop_res_mark_buckets_busy 10 1649$IP nexthop replace id 10 group 1/2,3 type resilient650651for i in $(seq 3); do652sleep 60653nexthop_bucket_nhid_count_check 10 2 6654check_fail $? "$i: Group expected to be unbalanced"655nexthop_res_mark_buckets_busy 10 1656done657658log_test "Buckets never force-migrated without unbalanced timer"659660$IP nexthop flush &> /dev/null661}662663nexthop_res_group_short_unbalanced_timer_test()664{665$IP nexthop add id 1 via 192.0.2.2 dev dummy1666$IP nexthop add id 2 via 192.0.2.3 dev dummy1667668RET=0669670$IP nexthop add id 10 group 1/2 type resilient \671buckets 8 idle_timer 120 unbalanced_timer 4672nexthop_res_mark_buckets_busy 10 1673$IP nexthop replace id 10 group 1/2,3 type resilient674675nexthop_bucket_nhid_count_check 10 2 6676check_fail $? "Group expected to be unbalanced"677678sleep 5679680nexthop_bucket_nhid_count_check 10 2 6681check_err $? "Group expected to be balanced"682683log_test "Bucket migration after unbalanced < idle timer"684685$IP nexthop flush &> /dev/null686}687688nexthop_res_group_increase_unbalanced_timer_test()689{690__nexthop_res_group_increase_timer_test unbalanced_timer691}692693nexthop_res_group_decrease_unbalanced_timer_test()694{695__nexthop_res_group_decrease_timer_test unbalanced_timer696}697698nexthop_res_group_force_migrate_busy_test()699{700$IP nexthop add id 1 via 192.0.2.2 dev dummy1701$IP nexthop add id 2 via 192.0.2.3 dev dummy1702703RET=0704705$IP nexthop add id 10 group 1/2 type resilient \706buckets 8 idle_timer 120707nexthop_res_mark_buckets_busy 10 1708$IP nexthop replace id 10 group 1/2,3 type resilient709710nexthop_bucket_nhid_count_check 10 2 6711check_fail $? "Group expected to be unbalanced"712713$IP nexthop replace id 10 group 2 type resilient714nexthop_bucket_nhid_count_check 10 2 8715check_err $? "All buckets expected to have migrated"716717log_test "Busy buckets force-migrated when NH removed"718719$IP nexthop flush &> /dev/null720}721722nexthop_single_replace_test()723{724RET=0725726$IP nexthop add id 1 via 192.0.2.2 dev dummy1727728$IP nexthop replace id 1 via 192.0.2.3 dev dummy1729nexthop_check "id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap"730check_err $? "Unexpected nexthop entry"731732nexthop_resource_check 1733check_err $? "Wrong nexthop occupancy"734735log_test "Single nexthop replace"736737$IP nexthop flush &> /dev/null738}739740nexthop_single_replace_err_test()741{742RET=0743744# This is supposed to cause the replace to fail because the new nexthop745# is programmed before deleting the replaced one.746nexthop_resource_set 1747748$IP nexthop add id 1 via 192.0.2.2 dev dummy1749750$IP nexthop replace id 1 via 192.0.2.3 dev dummy1 &> /dev/null751check_fail $? "Nexthop replace succeeded when should fail"752753nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"754check_err $? "Unexpected nexthop entry after failure"755756nexthop_resource_check 1757check_err $? "Wrong nexthop occupancy after failure"758759log_test "Single nexthop replace failure"760761$IP nexthop flush &> /dev/null762nexthop_resource_set 9999763}764765nexthop_single_in_group_replace_test()766{767RET=0768769$IP nexthop add id 1 via 192.0.2.2 dev dummy1770$IP nexthop add id 2 via 192.0.2.3 dev dummy1771$IP nexthop add id 10 group 1/2772773$IP nexthop replace id 1 via 192.0.2.4 dev dummy1774check_err $? "Failed to replace nexthop when should not"775776nexthop_check "id 10" "id 10 group 1/2 trap"777check_err $? "Unexpected nexthop group entry"778779nexthop_resource_check 4780check_err $? "Wrong nexthop occupancy"781782log_test "Single nexthop replace while in group"783784$IP nexthop flush &> /dev/null785}786787nexthop_single_in_group_replace_err_test()788{789RET=0790791nexthop_resource_set 5792793$IP nexthop add id 1 via 192.0.2.2 dev dummy1794$IP nexthop add id 2 via 192.0.2.3 dev dummy1795$IP nexthop add id 10 group 1/2796797$IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null798check_fail $? "Nexthop replacement succeeded when should fail"799800nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"801check_err $? "Unexpected nexthop entry after failure"802803nexthop_check "id 10" "id 10 group 1/2 trap"804check_err $? "Unexpected nexthop group entry after failure"805806nexthop_resource_check 4807check_err $? "Wrong nexthop occupancy"808809log_test "Single nexthop replace while in group failure"810811$IP nexthop flush &> /dev/null812nexthop_resource_set 9999813}814815nexthop_single_in_res_group_replace_test()816{817RET=0818819$IP nexthop add id 1 via 192.0.2.2 dev dummy1820$IP nexthop add id 2 via 192.0.2.3 dev dummy1821$IP nexthop add id 10 group 1/2 type resilient buckets 4822823$IP nexthop replace id 1 via 192.0.2.4 dev dummy1824check_err $? "Failed to replace nexthop when should not"825826nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"827check_err $? "Unexpected nexthop group entry"828829nexthop_bucket_nhid_count_check 10 1 2 2 2830check_err $? "Wrong nexthop buckets count"831832nexthop_resource_check 6833check_err $? "Wrong nexthop occupancy"834835log_test "Single nexthop replace while in resilient group"836837$IP nexthop flush &> /dev/null838}839840nexthop_single_in_res_group_replace_err_test()841{842RET=0843844$IP nexthop add id 1 via 192.0.2.2 dev dummy1845$IP nexthop add id 2 via 192.0.2.3 dev dummy1846$IP nexthop add id 10 group 1/2 type resilient buckets 4847848ip netns exec testns1 \849echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace850$IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null851check_fail $? "Nexthop replacement succeeded when should fail"852853nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"854check_err $? "Unexpected nexthop entry after failure"855856nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"857check_err $? "Unexpected nexthop group entry after failure"858859nexthop_bucket_nhid_count_check 10 1 2 2 2860check_err $? "Wrong nexthop buckets count"861862nexthop_resource_check 6863check_err $? "Wrong nexthop occupancy"864865log_test "Single nexthop replace while in resilient group failure"866867$IP nexthop flush &> /dev/null868ip netns exec testns1 \869echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace870}871872nexthop_single_in_group_delete_test()873{874RET=0875876$IP nexthop add id 1 via 192.0.2.2 dev dummy1877$IP nexthop add id 2 via 192.0.2.3 dev dummy1878$IP nexthop add id 10 group 1/2879880$IP nexthop del id 1881nexthop_check "id 10" "id 10 group 2 trap"882check_err $? "Unexpected nexthop group entry"883884nexthop_resource_check 2885check_err $? "Wrong nexthop occupancy"886887log_test "Single nexthop delete while in group"888889$IP nexthop flush &> /dev/null890}891892nexthop_single_in_group_delete_err_test()893{894RET=0895896# First, nexthop 1 will be deleted, which will reduce the occupancy to897# 5. Afterwards, a replace notification will be sent for nexthop group898# 10 with only two nexthops. Since the new group is allocated before899# the old is deleted, the replacement will fail as it will result in an900# occupancy of 7.901nexthop_resource_set 6902903$IP nexthop add id 1 via 192.0.2.2 dev dummy1904$IP nexthop add id 2 via 192.0.2.3 dev dummy1905$IP nexthop add id 3 via 192.0.2.4 dev dummy1906$IP nexthop add id 10 group 1/2/3907908$IP nexthop del id 1909910nexthop_resource_check 5911check_err $? "Wrong nexthop occupancy"912913log_test "Single nexthop delete while in group failure"914915$IP nexthop flush &> /dev/null916nexthop_resource_set 9999917}918919nexthop_single_in_res_group_delete_test()920{921RET=0922923$IP nexthop add id 1 via 192.0.2.2 dev dummy1924$IP nexthop add id 2 via 192.0.2.3 dev dummy1925$IP nexthop add id 10 group 1/2 type resilient buckets 4926927$IP nexthop del id 1928nexthop_check "id 10" "id 10 group 2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"929check_err $? "Unexpected nexthop group entry"930931nexthop_bucket_nhid_count_check 10 2 4932check_err $? "Wrong nexthop buckets count"933934nexthop_resource_check 5935check_err $? "Wrong nexthop occupancy"936937log_test "Single nexthop delete while in resilient group"938939$IP nexthop flush &> /dev/null940}941942nexthop_single_in_res_group_delete_err_test()943{944RET=0945946$IP nexthop add id 1 via 192.0.2.2 dev dummy1947$IP nexthop add id 2 via 192.0.2.3 dev dummy1948$IP nexthop add id 3 via 192.0.2.4 dev dummy1949$IP nexthop add id 10 group 1/2/3 type resilient buckets 6950951ip netns exec testns1 \952echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace953$IP nexthop del id 1954955# We failed to replace the two nexthop buckets that were originally956# assigned to nhid 1.957nexthop_bucket_nhid_count_check 10 2 2 3 2958check_err $? "Wrong nexthop buckets count"959960nexthop_resource_check 8961check_err $? "Wrong nexthop occupancy"962963log_test "Single nexthop delete while in resilient group failure"964965$IP nexthop flush &> /dev/null966ip netns exec testns1 \967echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace968}969970nexthop_replay_test()971{972RET=0973974$IP nexthop add id 1 via 192.0.2.2 dev dummy1975$IP nexthop add id 2 via 192.0.2.3 dev dummy1976$IP nexthop add id 10 group 1/2977978$DEVLINK dev reload $DEVLINK_DEV979check_err $? "Failed to reload when should not"980981nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"982check_err $? "Unexpected nexthop entry after reload"983984nexthop_check "id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap"985check_err $? "Unexpected nexthop entry after reload"986987nexthop_check "id 10" "id 10 group 1/2 trap"988check_err $? "Unexpected nexthop group entry after reload"989990nexthop_resource_check 4991check_err $? "Wrong nexthop occupancy"992993log_test "Nexthop replay"994995$IP nexthop flush &> /dev/null996}997998nexthop_replay_err_test()999{1000RET=010011002$IP nexthop add id 1 via 192.0.2.2 dev dummy11003$IP nexthop add id 2 via 192.0.2.3 dev dummy11004$IP nexthop add id 10 group 1/210051006# Reduce size of nexthop resource so that reload will fail.1007$DEVLINK resource set $DEVLINK_DEV path nexthops size 31008$DEVLINK dev reload $DEVLINK_DEV &> /dev/null1009check_fail $? "Reload succeeded when should fail"10101011$DEVLINK resource set $DEVLINK_DEV path nexthops size 99991012$DEVLINK dev reload $DEVLINK_DEV1013check_err $? "Failed to reload when should not"10141015log_test "Nexthop replay failure"10161017$IP nexthop flush &> /dev/null1018}10191020setup_prepare()1021{1022local netdev10231024modprobe netdevsim &> /dev/null10251026echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device1027while [ ! -d $SYSFS_NET_DIR ] ; do :; done10281029set -e10301031ip netns add testns11032devlink dev reload $DEVLINK_DEV netns testns110331034IP="ip -netns testns1"1035DEVLINK="devlink -N testns1"10361037$IP link add name dummy1 up type dummy1038$IP address add 192.0.2.1/24 dev dummy110391040set +e1041}10421043cleanup()1044{1045pre_cleanup1046ip netns del testns11047echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device1048modprobe -r netdevsim &> /dev/null1049}10501051trap cleanup EXIT10521053setup_prepare10541055xfail_on_slow tests_run10561057exit $EXIT_STATUS105810591060