1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # This test is for checking the nexthop offloa 4 # This test is for checking the nexthop offload API. It makes use of netdevsim 5 # which registers a listener to the nexthop no 5 # which registers a listener to the nexthop notification chain. 6 6 7 lib_dir=$(dirname $0)/../../../net/forwarding 7 lib_dir=$(dirname $0)/../../../net/forwarding 8 8 9 ALL_TESTS=" 9 ALL_TESTS=" 10 nexthop_single_add_test 10 nexthop_single_add_test 11 nexthop_single_add_err_test 11 nexthop_single_add_err_test 12 nexthop_group_add_test 12 nexthop_group_add_test 13 nexthop_group_add_err_test 13 nexthop_group_add_err_test 14 nexthop_res_group_add_test 14 nexthop_res_group_add_test 15 nexthop_res_group_add_err_test 15 nexthop_res_group_add_err_test 16 nexthop_group_replace_test 16 nexthop_group_replace_test 17 nexthop_group_replace_err_test 17 nexthop_group_replace_err_test 18 nexthop_res_group_replace_test 18 nexthop_res_group_replace_test 19 nexthop_res_group_replace_err_test 19 nexthop_res_group_replace_err_test 20 nexthop_res_group_idle_timer_test 20 nexthop_res_group_idle_timer_test 21 nexthop_res_group_idle_timer_del_test 21 nexthop_res_group_idle_timer_del_test 22 nexthop_res_group_increase_idle_timer_ 22 nexthop_res_group_increase_idle_timer_test 23 nexthop_res_group_decrease_idle_timer_ 23 nexthop_res_group_decrease_idle_timer_test 24 nexthop_res_group_unbalanced_timer_tes 24 nexthop_res_group_unbalanced_timer_test 25 nexthop_res_group_unbalanced_timer_del 25 nexthop_res_group_unbalanced_timer_del_test 26 nexthop_res_group_no_unbalanced_timer_ 26 nexthop_res_group_no_unbalanced_timer_test 27 nexthop_res_group_short_unbalanced_tim 27 nexthop_res_group_short_unbalanced_timer_test 28 nexthop_res_group_increase_unbalanced_ 28 nexthop_res_group_increase_unbalanced_timer_test 29 nexthop_res_group_decrease_unbalanced_ 29 nexthop_res_group_decrease_unbalanced_timer_test 30 nexthop_res_group_force_migrate_busy_t 30 nexthop_res_group_force_migrate_busy_test 31 nexthop_single_replace_test 31 nexthop_single_replace_test 32 nexthop_single_replace_err_test 32 nexthop_single_replace_err_test 33 nexthop_single_in_group_replace_test 33 nexthop_single_in_group_replace_test 34 nexthop_single_in_group_replace_err_te 34 nexthop_single_in_group_replace_err_test 35 nexthop_single_in_res_group_replace_te 35 nexthop_single_in_res_group_replace_test 36 nexthop_single_in_res_group_replace_er 36 nexthop_single_in_res_group_replace_err_test 37 nexthop_single_in_group_delete_test 37 nexthop_single_in_group_delete_test 38 nexthop_single_in_group_delete_err_tes 38 nexthop_single_in_group_delete_err_test 39 nexthop_single_in_res_group_delete_tes 39 nexthop_single_in_res_group_delete_test 40 nexthop_single_in_res_group_delete_err 40 nexthop_single_in_res_group_delete_err_test 41 nexthop_replay_test 41 nexthop_replay_test 42 nexthop_replay_err_test 42 nexthop_replay_err_test 43 " 43 " 44 NETDEVSIM_PATH=/sys/bus/netdevsim/ 44 NETDEVSIM_PATH=/sys/bus/netdevsim/ 45 DEV_ADDR=1337 45 DEV_ADDR=1337 46 DEV=netdevsim${DEV_ADDR} 46 DEV=netdevsim${DEV_ADDR} 47 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/ 47 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/ 48 DEBUGFS_NET_DIR=/sys/kernel/debug/netdevsim/$D 48 DEBUGFS_NET_DIR=/sys/kernel/debug/netdevsim/$DEV/ 49 NUM_NETIFS=0 49 NUM_NETIFS=0 50 source $lib_dir/lib.sh 50 source $lib_dir/lib.sh 51 51 52 DEVLINK_DEV= 52 DEVLINK_DEV= 53 source $lib_dir/devlink_lib.sh 53 source $lib_dir/devlink_lib.sh 54 DEVLINK_DEV=netdevsim/${DEV} 54 DEVLINK_DEV=netdevsim/${DEV} 55 55 56 nexthop_check() 56 nexthop_check() 57 { 57 { 58 local nharg="$1"; shift 58 local nharg="$1"; shift 59 local expected="$1"; shift 59 local expected="$1"; shift 60 60 61 out=$($IP nexthop show ${nharg} | sed 61 out=$($IP nexthop show ${nharg} | sed -e 's/ *$//') 62 if [[ "$out" != "$expected" ]]; then 62 if [[ "$out" != "$expected" ]]; then 63 return 1 63 return 1 64 fi 64 fi 65 65 66 return 0 66 return 0 67 } 67 } 68 68 69 nexthop_bucket_nhid_count_check() 69 nexthop_bucket_nhid_count_check() 70 { 70 { 71 local group_id=$1; shift 71 local group_id=$1; shift 72 local expected 72 local expected 73 local count 73 local count 74 local nhid 74 local nhid 75 local ret 75 local ret 76 76 77 while (($# > 0)); do 77 while (($# > 0)); do 78 nhid=$1; shift 78 nhid=$1; shift 79 expected=$1; shift 79 expected=$1; shift 80 80 81 count=$($IP nexthop bucket sho 81 count=$($IP nexthop bucket show id $group_id nhid $nhid | 82 grep "trap" | wc -l) 82 grep "trap" | wc -l) 83 if ((expected != count)); then 83 if ((expected != count)); then 84 return 1 84 return 1 85 fi 85 fi 86 done 86 done 87 87 88 return 0 88 return 0 89 } 89 } 90 90 91 nexthop_resource_check() 91 nexthop_resource_check() 92 { 92 { 93 local expected_occ=$1; shift 93 local expected_occ=$1; shift 94 94 95 occ=$($DEVLINK -jp resource show $DEVL 95 occ=$($DEVLINK -jp resource show $DEVLINK_DEV \ 96 | jq '.[][][] | select(.name== 96 | jq '.[][][] | select(.name=="nexthops") | .["occ"]') 97 97 98 if [ $expected_occ -ne $occ ]; then 98 if [ $expected_occ -ne $occ ]; then 99 return 1 99 return 1 100 fi 100 fi 101 101 102 return 0 102 return 0 103 } 103 } 104 104 105 nexthop_resource_set() 105 nexthop_resource_set() 106 { 106 { 107 local size=$1; shift 107 local size=$1; shift 108 108 109 $DEVLINK resource set $DEVLINK_DEV pat 109 $DEVLINK resource set $DEVLINK_DEV path nexthops size $size 110 $DEVLINK dev reload $DEVLINK_DEV 110 $DEVLINK dev reload $DEVLINK_DEV 111 } 111 } 112 112 113 nexthop_single_add_test() 113 nexthop_single_add_test() 114 { 114 { 115 RET=0 115 RET=0 116 116 117 $IP nexthop add id 1 via 192.0.2.2 dev 117 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 118 nexthop_check "id 1" "id 1 via 192.0.2 118 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap" 119 check_err $? "Unexpected nexthop entry 119 check_err $? "Unexpected nexthop entry" 120 120 121 nexthop_resource_check 1 121 nexthop_resource_check 1 122 check_err $? "Wrong nexthop occupancy" 122 check_err $? "Wrong nexthop occupancy" 123 123 124 $IP nexthop del id 1 124 $IP nexthop del id 1 125 nexthop_resource_check 0 125 nexthop_resource_check 0 126 check_err $? "Wrong nexthop occupancy 126 check_err $? "Wrong nexthop occupancy after delete" 127 127 128 log_test "Single nexthop add and delet 128 log_test "Single nexthop add and delete" 129 } 129 } 130 130 131 nexthop_single_add_err_test() 131 nexthop_single_add_err_test() 132 { 132 { 133 RET=0 133 RET=0 134 134 135 nexthop_resource_set 1 135 nexthop_resource_set 1 136 136 137 $IP nexthop add id 1 via 192.0.2.2 dev 137 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 138 138 139 $IP nexthop add id 2 via 192.0.2.3 dev 139 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 &> /dev/null 140 check_fail $? "Nexthop addition succee 140 check_fail $? "Nexthop addition succeeded when should fail" 141 141 142 nexthop_resource_check 1 142 nexthop_resource_check 1 143 check_err $? "Wrong nexthop occupancy" 143 check_err $? "Wrong nexthop occupancy" 144 144 145 log_test "Single nexthop add failure" 145 log_test "Single nexthop add failure" 146 146 147 $IP nexthop flush &> /dev/null 147 $IP nexthop flush &> /dev/null 148 nexthop_resource_set 9999 148 nexthop_resource_set 9999 149 } 149 } 150 150 151 nexthop_group_add_test() 151 nexthop_group_add_test() 152 { 152 { 153 RET=0 153 RET=0 154 154 155 $IP nexthop add id 1 via 192.0.2.2 dev 155 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 156 $IP nexthop add id 2 via 192.0.2.3 dev 156 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 157 157 158 $IP nexthop add id 10 group 1/2 158 $IP nexthop add id 10 group 1/2 159 nexthop_check "id 10" "id 10 group 1/2 159 nexthop_check "id 10" "id 10 group 1/2 trap" 160 check_err $? "Unexpected nexthop group 160 check_err $? "Unexpected nexthop group entry" 161 161 162 nexthop_resource_check 4 162 nexthop_resource_check 4 163 check_err $? "Wrong nexthop occupancy" 163 check_err $? "Wrong nexthop occupancy" 164 164 165 $IP nexthop del id 10 165 $IP nexthop del id 10 166 nexthop_resource_check 2 166 nexthop_resource_check 2 167 check_err $? "Wrong nexthop occupancy 167 check_err $? "Wrong nexthop occupancy after delete" 168 168 169 $IP nexthop add id 10 group 1,20/2,39 169 $IP nexthop add id 10 group 1,20/2,39 170 nexthop_check "id 10" "id 10 group 1,2 170 nexthop_check "id 10" "id 10 group 1,20/2,39 trap" 171 check_err $? "Unexpected weighted next 171 check_err $? "Unexpected weighted nexthop group entry" 172 172 173 nexthop_resource_check 61 173 nexthop_resource_check 61 174 check_err $? "Wrong weighted nexthop o 174 check_err $? "Wrong weighted nexthop occupancy" 175 175 176 $IP nexthop del id 10 176 $IP nexthop del id 10 177 nexthop_resource_check 2 177 nexthop_resource_check 2 178 check_err $? "Wrong nexthop occupancy 178 check_err $? "Wrong nexthop occupancy after delete" 179 179 180 log_test "Nexthop group add and delete 180 log_test "Nexthop group add and delete" 181 181 182 $IP nexthop flush &> /dev/null 182 $IP nexthop flush &> /dev/null 183 } 183 } 184 184 185 nexthop_group_add_err_test() 185 nexthop_group_add_err_test() 186 { 186 { 187 RET=0 187 RET=0 188 188 189 nexthop_resource_set 2 189 nexthop_resource_set 2 190 190 191 $IP nexthop add id 1 via 192.0.2.2 dev 191 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 192 $IP nexthop add id 2 via 192.0.2.3 dev 192 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 193 193 194 $IP nexthop add id 10 group 1/2 &> /de 194 $IP nexthop add id 10 group 1/2 &> /dev/null 195 check_fail $? "Nexthop group addition 195 check_fail $? "Nexthop group addition succeeded when should fail" 196 196 197 nexthop_resource_check 2 197 nexthop_resource_check 2 198 check_err $? "Wrong nexthop occupancy" 198 check_err $? "Wrong nexthop occupancy" 199 199 200 log_test "Nexthop group add failure" 200 log_test "Nexthop group add failure" 201 201 202 $IP nexthop flush &> /dev/null 202 $IP nexthop flush &> /dev/null 203 nexthop_resource_set 9999 203 nexthop_resource_set 9999 204 } 204 } 205 205 206 nexthop_res_group_add_test() 206 nexthop_res_group_add_test() 207 { 207 { 208 RET=0 208 RET=0 209 209 210 $IP nexthop add id 1 via 192.0.2.2 dev 210 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 211 $IP nexthop add id 2 via 192.0.2.3 dev 211 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 212 212 213 $IP nexthop add id 10 group 1/2 type r 213 $IP nexthop add id 10 group 1/2 type resilient buckets 4 214 nexthop_check "id 10" "id 10 group 1/2 214 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 215 check_err $? "Unexpected nexthop group 215 check_err $? "Unexpected nexthop group entry" 216 216 217 nexthop_bucket_nhid_count_check 10 1 2 217 nexthop_bucket_nhid_count_check 10 1 2 218 check_err $? "Wrong nexthop buckets co 218 check_err $? "Wrong nexthop buckets count" 219 nexthop_bucket_nhid_count_check 10 2 2 219 nexthop_bucket_nhid_count_check 10 2 2 220 check_err $? "Wrong nexthop buckets co 220 check_err $? "Wrong nexthop buckets count" 221 221 222 nexthop_resource_check 6 222 nexthop_resource_check 6 223 check_err $? "Wrong nexthop occupancy" 223 check_err $? "Wrong nexthop occupancy" 224 224 225 $IP nexthop del id 10 225 $IP nexthop del id 10 226 nexthop_resource_check 2 226 nexthop_resource_check 2 227 check_err $? "Wrong nexthop occupancy 227 check_err $? "Wrong nexthop occupancy after delete" 228 228 229 $IP nexthop add id 10 group 1,3/2,2 ty 229 $IP nexthop add id 10 group 1,3/2,2 type resilient buckets 5 230 nexthop_check "id 10" "id 10 group 1,3 230 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" 231 check_err $? "Unexpected weighted next 231 check_err $? "Unexpected weighted nexthop group entry" 232 232 233 nexthop_bucket_nhid_count_check 10 1 3 233 nexthop_bucket_nhid_count_check 10 1 3 234 check_err $? "Wrong nexthop buckets co 234 check_err $? "Wrong nexthop buckets count" 235 nexthop_bucket_nhid_count_check 10 2 2 235 nexthop_bucket_nhid_count_check 10 2 2 236 check_err $? "Wrong nexthop buckets co 236 check_err $? "Wrong nexthop buckets count" 237 237 238 nexthop_resource_check 7 238 nexthop_resource_check 7 239 check_err $? "Wrong weighted nexthop o 239 check_err $? "Wrong weighted nexthop occupancy" 240 240 241 $IP nexthop del id 10 241 $IP nexthop del id 10 242 nexthop_resource_check 2 242 nexthop_resource_check 2 243 check_err $? "Wrong nexthop occupancy 243 check_err $? "Wrong nexthop occupancy after delete" 244 244 245 log_test "Resilient nexthop group add 245 log_test "Resilient nexthop group add and delete" 246 246 247 $IP nexthop flush &> /dev/null 247 $IP nexthop flush &> /dev/null 248 } 248 } 249 249 250 nexthop_res_group_add_err_test() 250 nexthop_res_group_add_err_test() 251 { 251 { 252 RET=0 252 RET=0 253 253 254 nexthop_resource_set 2 254 nexthop_resource_set 2 255 255 256 $IP nexthop add id 1 via 192.0.2.2 dev 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 257 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 258 258 259 $IP nexthop add id 10 group 1/2 type r 259 $IP nexthop add id 10 group 1/2 type resilient buckets 4 &> /dev/null 260 check_fail $? "Nexthop group addition 260 check_fail $? "Nexthop group addition succeeded when should fail" 261 261 262 nexthop_resource_check 2 262 nexthop_resource_check 2 263 check_err $? "Wrong nexthop occupancy" 263 check_err $? "Wrong nexthop occupancy" 264 264 265 log_test "Resilient nexthop group add 265 log_test "Resilient nexthop group add failure" 266 266 267 $IP nexthop flush &> /dev/null 267 $IP nexthop flush &> /dev/null 268 nexthop_resource_set 9999 268 nexthop_resource_set 9999 269 } 269 } 270 270 271 nexthop_group_replace_test() 271 nexthop_group_replace_test() 272 { 272 { 273 RET=0 273 RET=0 274 274 275 $IP nexthop add id 1 via 192.0.2.2 dev 275 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 276 $IP nexthop add id 2 via 192.0.2.3 dev 276 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 277 $IP nexthop add id 3 via 192.0.2.4 dev 277 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 278 $IP nexthop add id 10 group 1/2 278 $IP nexthop add id 10 group 1/2 279 279 280 $IP nexthop replace id 10 group 1/2/3 280 $IP nexthop replace id 10 group 1/2/3 281 nexthop_check "id 10" "id 10 group 1/2 281 nexthop_check "id 10" "id 10 group 1/2/3 trap" 282 check_err $? "Unexpected nexthop group 282 check_err $? "Unexpected nexthop group entry" 283 283 284 nexthop_resource_check 6 284 nexthop_resource_check 6 285 check_err $? "Wrong nexthop occupancy" 285 check_err $? "Wrong nexthop occupancy" 286 286 287 log_test "Nexthop group replace" 287 log_test "Nexthop group replace" 288 288 289 $IP nexthop flush &> /dev/null 289 $IP nexthop flush &> /dev/null 290 } 290 } 291 291 292 nexthop_group_replace_err_test() 292 nexthop_group_replace_err_test() 293 { 293 { 294 RET=0 294 RET=0 295 295 296 nexthop_resource_set 5 296 nexthop_resource_set 5 297 297 298 $IP nexthop add id 1 via 192.0.2.2 dev 298 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 299 $IP nexthop add id 2 via 192.0.2.3 dev 299 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 300 $IP nexthop add id 3 via 192.0.2.4 dev 300 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 301 $IP nexthop add id 10 group 1/2 301 $IP nexthop add id 10 group 1/2 302 302 303 $IP nexthop replace id 10 group 1/2/3 303 $IP nexthop replace id 10 group 1/2/3 &> /dev/null 304 check_fail $? "Nexthop group replaceme 304 check_fail $? "Nexthop group replacement succeeded when should fail" 305 305 306 nexthop_check "id 10" "id 10 group 1/2 306 nexthop_check "id 10" "id 10 group 1/2 trap" 307 check_err $? "Unexpected nexthop group 307 check_err $? "Unexpected nexthop group entry after failure" 308 308 309 nexthop_resource_check 5 309 nexthop_resource_check 5 310 check_err $? "Wrong nexthop occupancy 310 check_err $? "Wrong nexthop occupancy after failure" 311 311 312 log_test "Nexthop group replace failur 312 log_test "Nexthop group replace failure" 313 313 314 $IP nexthop flush &> /dev/null 314 $IP nexthop flush &> /dev/null 315 nexthop_resource_set 9999 315 nexthop_resource_set 9999 316 } 316 } 317 317 318 nexthop_res_group_replace_test() 318 nexthop_res_group_replace_test() 319 { 319 { 320 RET=0 320 RET=0 321 321 322 $IP nexthop add id 1 via 192.0.2.2 dev 322 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 323 $IP nexthop add id 2 via 192.0.2.3 dev 323 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 324 $IP nexthop add id 3 via 192.0.2.4 dev 324 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 325 $IP nexthop add id 10 group 1/2 type r 325 $IP nexthop add id 10 group 1/2 type resilient buckets 6 326 326 327 $IP nexthop replace id 10 group 1/2/3 327 $IP nexthop replace id 10 group 1/2/3 type resilient 328 nexthop_check "id 10" "id 10 group 1/2 328 nexthop_check "id 10" "id 10 group 1/2/3 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 329 check_err $? "Unexpected nexthop group 329 check_err $? "Unexpected nexthop group entry" 330 330 331 nexthop_bucket_nhid_count_check 10 1 2 331 nexthop_bucket_nhid_count_check 10 1 2 332 check_err $? "Wrong nexthop buckets co 332 check_err $? "Wrong nexthop buckets count" 333 nexthop_bucket_nhid_count_check 10 2 2 333 nexthop_bucket_nhid_count_check 10 2 2 334 check_err $? "Wrong nexthop buckets co 334 check_err $? "Wrong nexthop buckets count" 335 nexthop_bucket_nhid_count_check 10 3 2 335 nexthop_bucket_nhid_count_check 10 3 2 336 check_err $? "Wrong nexthop buckets co 336 check_err $? "Wrong nexthop buckets count" 337 337 338 nexthop_resource_check 9 338 nexthop_resource_check 9 339 check_err $? "Wrong nexthop occupancy" 339 check_err $? "Wrong nexthop occupancy" 340 340 341 log_test "Resilient nexthop group repl 341 log_test "Resilient nexthop group replace" 342 342 343 $IP nexthop flush &> /dev/null 343 $IP nexthop flush &> /dev/null 344 } 344 } 345 345 346 nexthop_res_group_replace_err_test() 346 nexthop_res_group_replace_err_test() 347 { 347 { 348 RET=0 348 RET=0 349 349 350 $IP nexthop add id 1 via 192.0.2.2 dev 350 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 351 $IP nexthop add id 2 via 192.0.2.3 dev 351 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 352 $IP nexthop add id 3 via 192.0.2.4 dev 352 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 353 $IP nexthop add id 10 group 1/2 type r 353 $IP nexthop add id 10 group 1/2 type resilient buckets 6 354 354 355 ip netns exec testns1 \ 355 ip netns exec testns1 \ 356 echo 1 > $DEBUGFS_NET_DIR/fib/ 356 echo 1 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace 357 $IP nexthop replace id 10 group 1/2/3 357 $IP nexthop replace id 10 group 1/2/3 type resilient &> /dev/null 358 check_fail $? "Nexthop group replaceme 358 check_fail $? "Nexthop group replacement succeeded when should fail" 359 359 360 nexthop_check "id 10" "id 10 group 1/2 360 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 361 check_err $? "Unexpected nexthop group 361 check_err $? "Unexpected nexthop group entry after failure" 362 362 363 nexthop_bucket_nhid_count_check 10 1 3 363 nexthop_bucket_nhid_count_check 10 1 3 364 check_err $? "Wrong nexthop buckets co 364 check_err $? "Wrong nexthop buckets count" 365 nexthop_bucket_nhid_count_check 10 2 3 365 nexthop_bucket_nhid_count_check 10 2 3 366 check_err $? "Wrong nexthop buckets co 366 check_err $? "Wrong nexthop buckets count" 367 367 368 nexthop_resource_check 9 368 nexthop_resource_check 9 369 check_err $? "Wrong nexthop occupancy 369 check_err $? "Wrong nexthop occupancy after failure" 370 370 371 log_test "Resilient nexthop group repl 371 log_test "Resilient nexthop group replace failure" 372 372 373 $IP nexthop flush &> /dev/null 373 $IP nexthop flush &> /dev/null 374 ip netns exec testns1 \ 374 ip netns exec testns1 \ 375 echo 0 > $DEBUGFS_NET_DIR/fib/ 375 echo 0 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace 376 } 376 } 377 377 378 nexthop_res_mark_buckets_busy() 378 nexthop_res_mark_buckets_busy() 379 { 379 { 380 local group_id=$1; shift 380 local group_id=$1; shift 381 local nhid=$1; shift 381 local nhid=$1; shift 382 local count=$1; shift 382 local count=$1; shift 383 local index 383 local index 384 384 385 for index in $($IP -j nexthop bucket s 385 for index in $($IP -j nexthop bucket show id $group_id nhid $nhid | 386 jq '.[].bucket.index' | 386 jq '.[].bucket.index' | head -n ${count:--0}) 387 do 387 do 388 echo $group_id $index \ 388 echo $group_id $index \ 389 > $DEBUGFS_NET_DIR/fib 389 > $DEBUGFS_NET_DIR/fib/nexthop_bucket_activity 390 done 390 done 391 } 391 } 392 392 393 nexthop_res_num_nhid_buckets() 393 nexthop_res_num_nhid_buckets() 394 { 394 { 395 local group_id=$1; shift 395 local group_id=$1; shift 396 local nhid=$1; shift 396 local nhid=$1; shift 397 397 398 $IP -j nexthop bucket show id $group_i 398 $IP -j nexthop bucket show id $group_id nhid $nhid | jq length 399 } 399 } 400 400 401 nexthop_res_group_idle_timer_test() 401 nexthop_res_group_idle_timer_test() 402 { 402 { 403 $IP nexthop add id 1 via 192.0.2.2 dev 403 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 404 $IP nexthop add id 2 via 192.0.2.3 dev 404 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 405 405 406 RET=0 406 RET=0 407 407 408 $IP nexthop add id 10 group 1/2 type r 408 $IP nexthop add id 10 group 1/2 type resilient buckets 8 idle_timer 4 409 nexthop_res_mark_buckets_busy 10 1 409 nexthop_res_mark_buckets_busy 10 1 410 $IP nexthop replace id 10 group 1/2,3 410 $IP nexthop replace id 10 group 1/2,3 type resilient 411 411 412 nexthop_bucket_nhid_count_check 10 1 412 nexthop_bucket_nhid_count_check 10 1 4 2 4 413 check_err $? "Group expected to be unb 413 check_err $? "Group expected to be unbalanced" 414 414 415 sleep 6 415 sleep 6 416 416 417 nexthop_bucket_nhid_count_check 10 1 417 nexthop_bucket_nhid_count_check 10 1 2 2 6 418 check_err $? "Group expected to be bal 418 check_err $? "Group expected to be balanced" 419 419 420 log_test "Bucket migration after idle 420 log_test "Bucket migration after idle timer" 421 421 422 $IP nexthop flush &> /dev/null 422 $IP nexthop flush &> /dev/null 423 } 423 } 424 424 425 nexthop_res_group_idle_timer_del_test() 425 nexthop_res_group_idle_timer_del_test() 426 { 426 { 427 $IP nexthop add id 1 via 192.0.2.2 dev 427 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 428 $IP nexthop add id 2 via 192.0.2.3 dev 428 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 429 $IP nexthop add id 3 via 192.0.2.3 dev 429 $IP nexthop add id 3 via 192.0.2.3 dev dummy1 430 430 431 RET=0 431 RET=0 432 432 433 $IP nexthop add id 10 group 1,50/2,50/ 433 $IP nexthop add id 10 group 1,50/2,50/3,1 \ 434 type resilient buckets 8 idle_time 434 type resilient buckets 8 idle_timer 6 435 nexthop_res_mark_buckets_busy 10 1 435 nexthop_res_mark_buckets_busy 10 1 436 $IP nexthop replace id 10 group 1,50/2 436 $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient 437 437 438 nexthop_bucket_nhid_count_check 10 1 438 nexthop_bucket_nhid_count_check 10 1 4 2 4 3 0 439 check_err $? "Group expected to be unb 439 check_err $? "Group expected to be unbalanced" 440 440 441 sleep 4 441 sleep 4 442 442 443 # Deletion prompts group replacement. 443 # Deletion prompts group replacement. Check that the bucket timers 444 # are kept. 444 # are kept. 445 $IP nexthop delete id 3 445 $IP nexthop delete id 3 446 446 447 nexthop_bucket_nhid_count_check 10 1 447 nexthop_bucket_nhid_count_check 10 1 4 2 4 448 check_err $? "Group expected to still 448 check_err $? "Group expected to still be unbalanced" 449 449 450 sleep 4 450 sleep 4 451 451 452 nexthop_bucket_nhid_count_check 10 1 452 nexthop_bucket_nhid_count_check 10 1 2 2 6 453 check_err $? "Group expected to be bal 453 check_err $? "Group expected to be balanced" 454 454 455 log_test "Bucket migration after idle 455 log_test "Bucket migration after idle timer (with delete)" 456 456 457 $IP nexthop flush &> /dev/null 457 $IP nexthop flush &> /dev/null 458 } 458 } 459 459 460 __nexthop_res_group_increase_timer_test() 460 __nexthop_res_group_increase_timer_test() 461 { 461 { 462 local timer=$1; shift 462 local timer=$1; shift 463 463 464 $IP nexthop add id 1 via 192.0.2.2 dev 464 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 465 $IP nexthop add id 2 via 192.0.2.3 dev 465 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 466 466 467 RET=0 467 RET=0 468 468 469 $IP nexthop add id 10 group 1/2 type r 469 $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 4 470 nexthop_res_mark_buckets_busy 10 1 470 nexthop_res_mark_buckets_busy 10 1 471 $IP nexthop replace id 10 group 1/2,3 471 $IP nexthop replace id 10 group 1/2,3 type resilient 472 472 473 nexthop_bucket_nhid_count_check 10 2 6 473 nexthop_bucket_nhid_count_check 10 2 6 474 check_fail $? "Group expected to be un 474 check_fail $? "Group expected to be unbalanced" 475 475 476 sleep 2 476 sleep 2 477 $IP nexthop replace id 10 group 1/2,3 477 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8 478 sleep 4 478 sleep 4 479 479 480 # 6 seconds, past the original timer. 480 # 6 seconds, past the original timer. 481 nexthop_bucket_nhid_count_check 10 2 6 481 nexthop_bucket_nhid_count_check 10 2 6 482 check_fail $? "Group still expected to 482 check_fail $? "Group still expected to be unbalanced" 483 483 484 sleep 4 484 sleep 4 485 485 486 # 10 seconds, past the new timer. 486 # 10 seconds, past the new timer. 487 nexthop_bucket_nhid_count_check 10 2 6 487 nexthop_bucket_nhid_count_check 10 2 6 488 check_err $? "Group expected to be bal 488 check_err $? "Group expected to be balanced" 489 489 490 log_test "Bucket migration after $time 490 log_test "Bucket migration after $timer increase" 491 491 492 $IP nexthop flush &> /dev/null 492 $IP nexthop flush &> /dev/null 493 } 493 } 494 494 495 __nexthop_res_group_decrease_timer_test() 495 __nexthop_res_group_decrease_timer_test() 496 { 496 { 497 local timer=$1; shift 497 local timer=$1; shift 498 498 499 $IP nexthop add id 1 via 192.0.2.2 dev 499 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 500 $IP nexthop add id 2 via 192.0.2.3 dev 500 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 501 501 502 RET=0 502 RET=0 503 503 504 $IP nexthop add id 10 group 1/2 type r 504 $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 8 505 nexthop_res_mark_buckets_busy 10 1 505 nexthop_res_mark_buckets_busy 10 1 506 $IP nexthop replace id 10 group 1/2,3 506 $IP nexthop replace id 10 group 1/2,3 type resilient 507 507 508 nexthop_bucket_nhid_count_check 10 2 6 508 nexthop_bucket_nhid_count_check 10 2 6 509 check_fail $? "Group expected to be un 509 check_fail $? "Group expected to be unbalanced" 510 510 511 sleep 2 511 sleep 2 512 $IP nexthop replace id 10 group 1/2,3 512 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 4 513 sleep 4 513 sleep 4 514 514 515 # 6 seconds, past the new timer, befor 515 # 6 seconds, past the new timer, before the old timer. 516 nexthop_bucket_nhid_count_check 10 2 6 516 nexthop_bucket_nhid_count_check 10 2 6 517 check_err $? "Group expected to be bal 517 check_err $? "Group expected to be balanced" 518 518 519 log_test "Bucket migration after $time 519 log_test "Bucket migration after $timer decrease" 520 520 521 $IP nexthop flush &> /dev/null 521 $IP nexthop flush &> /dev/null 522 } 522 } 523 523 524 __nexthop_res_group_increase_timer_del_test() 524 __nexthop_res_group_increase_timer_del_test() 525 { 525 { 526 local timer=$1; shift 526 local timer=$1; shift 527 527 528 $IP nexthop add id 1 via 192.0.2.2 dev 528 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 529 $IP nexthop add id 2 via 192.0.2.3 dev 529 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 530 $IP nexthop add id 3 via 192.0.2.3 dev 530 $IP nexthop add id 3 via 192.0.2.3 dev dummy1 531 531 532 RET=0 532 RET=0 533 533 534 $IP nexthop add id 10 group 1,100/2,10 534 $IP nexthop add id 10 group 1,100/2,100/3,1 \ 535 type resilient buckets 8 $timer 4 535 type resilient buckets 8 $timer 4 536 nexthop_res_mark_buckets_busy 10 1 536 nexthop_res_mark_buckets_busy 10 1 537 $IP nexthop replace id 10 group 1,100/ 537 $IP nexthop replace id 10 group 1,100/2,300/3,1 type resilient 538 538 539 nexthop_bucket_nhid_count_check 10 2 6 539 nexthop_bucket_nhid_count_check 10 2 6 540 check_fail $? "Group expected to be un 540 check_fail $? "Group expected to be unbalanced" 541 541 542 sleep 2 542 sleep 2 543 $IP nexthop replace id 10 group 1/2,3 543 $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8 544 sleep 4 544 sleep 4 545 545 546 # 6 seconds, past the original timer. 546 # 6 seconds, past the original timer. 547 nexthop_bucket_nhid_count_check 10 2 6 547 nexthop_bucket_nhid_count_check 10 2 6 548 check_fail $? "Group still expected to 548 check_fail $? "Group still expected to be unbalanced" 549 549 550 sleep 4 550 sleep 4 551 551 552 # 10 seconds, past the new timer. 552 # 10 seconds, past the new timer. 553 nexthop_bucket_nhid_count_check 10 2 6 553 nexthop_bucket_nhid_count_check 10 2 6 554 check_err $? "Group expected to be bal 554 check_err $? "Group expected to be balanced" 555 555 556 log_test "Bucket migration after $time 556 log_test "Bucket migration after $timer increase" 557 557 558 $IP nexthop flush &> /dev/null 558 $IP nexthop flush &> /dev/null 559 } 559 } 560 560 561 nexthop_res_group_increase_idle_timer_test() 561 nexthop_res_group_increase_idle_timer_test() 562 { 562 { 563 __nexthop_res_group_increase_timer_tes 563 __nexthop_res_group_increase_timer_test idle_timer 564 } 564 } 565 565 566 nexthop_res_group_decrease_idle_timer_test() 566 nexthop_res_group_decrease_idle_timer_test() 567 { 567 { 568 __nexthop_res_group_decrease_timer_tes 568 __nexthop_res_group_decrease_timer_test idle_timer 569 } 569 } 570 570 571 nexthop_res_group_unbalanced_timer_test() 571 nexthop_res_group_unbalanced_timer_test() 572 { 572 { 573 local i 573 local i 574 574 575 $IP nexthop add id 1 via 192.0.2.2 dev 575 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 576 $IP nexthop add id 2 via 192.0.2.3 dev 576 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 577 577 578 RET=0 578 RET=0 579 579 580 $IP nexthop add id 10 group 1/2 type r 580 $IP nexthop add id 10 group 1/2 type resilient \ 581 buckets 8 idle_timer 6 unbalanced_ 581 buckets 8 idle_timer 6 unbalanced_timer 10 582 nexthop_res_mark_buckets_busy 10 1 582 nexthop_res_mark_buckets_busy 10 1 583 $IP nexthop replace id 10 group 1/2,3 583 $IP nexthop replace id 10 group 1/2,3 type resilient 584 584 585 for i in 1 2; do 585 for i in 1 2; do 586 sleep 4 586 sleep 4 587 nexthop_bucket_nhid_count_chec 587 nexthop_bucket_nhid_count_check 10 1 4 2 4 588 check_err $? "$i: Group expect 588 check_err $? "$i: Group expected to be unbalanced" 589 nexthop_res_mark_buckets_busy 589 nexthop_res_mark_buckets_busy 10 1 590 done 590 done 591 591 592 # 3 x sleep 4 > unbalanced timer 10 592 # 3 x sleep 4 > unbalanced timer 10 593 sleep 4 593 sleep 4 594 nexthop_bucket_nhid_count_check 10 1 594 nexthop_bucket_nhid_count_check 10 1 2 2 6 595 check_err $? "Group expected to be bal 595 check_err $? "Group expected to be balanced" 596 596 597 log_test "Bucket migration after unbal 597 log_test "Bucket migration after unbalanced timer" 598 598 599 $IP nexthop flush &> /dev/null 599 $IP nexthop flush &> /dev/null 600 } 600 } 601 601 602 nexthop_res_group_unbalanced_timer_del_test() 602 nexthop_res_group_unbalanced_timer_del_test() 603 { 603 { 604 local i 604 local i 605 605 606 $IP nexthop add id 1 via 192.0.2.2 dev 606 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 607 $IP nexthop add id 2 via 192.0.2.3 dev 607 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 608 $IP nexthop add id 3 via 192.0.2.3 dev 608 $IP nexthop add id 3 via 192.0.2.3 dev dummy1 609 609 610 RET=0 610 RET=0 611 611 612 $IP nexthop add id 10 group 1,50/2,50/ 612 $IP nexthop add id 10 group 1,50/2,50/3,1 type resilient \ 613 buckets 8 idle_timer 6 unbalanced_ 613 buckets 8 idle_timer 6 unbalanced_timer 10 614 nexthop_res_mark_buckets_busy 10 1 614 nexthop_res_mark_buckets_busy 10 1 615 $IP nexthop replace id 10 group 1,50/2 615 $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient 616 616 617 # Check that NH delete does not reset 617 # Check that NH delete does not reset unbalanced time. 618 sleep 4 618 sleep 4 619 $IP nexthop delete id 3 619 $IP nexthop delete id 3 620 nexthop_bucket_nhid_count_check 10 1 620 nexthop_bucket_nhid_count_check 10 1 4 2 4 621 check_err $? "1: Group expected to be 621 check_err $? "1: Group expected to be unbalanced" 622 nexthop_res_mark_buckets_busy 10 1 622 nexthop_res_mark_buckets_busy 10 1 623 623 624 sleep 4 624 sleep 4 625 nexthop_bucket_nhid_count_check 10 1 625 nexthop_bucket_nhid_count_check 10 1 4 2 4 626 check_err $? "2: Group expected to be 626 check_err $? "2: Group expected to be unbalanced" 627 nexthop_res_mark_buckets_busy 10 1 627 nexthop_res_mark_buckets_busy 10 1 628 628 629 # 3 x sleep 4 > unbalanced timer 10 629 # 3 x sleep 4 > unbalanced timer 10 630 sleep 4 630 sleep 4 631 nexthop_bucket_nhid_count_check 10 1 631 nexthop_bucket_nhid_count_check 10 1 2 2 6 632 check_err $? "Group expected to be bal 632 check_err $? "Group expected to be balanced" 633 633 634 log_test "Bucket migration after unbal 634 log_test "Bucket migration after unbalanced timer (with delete)" 635 635 636 $IP nexthop flush &> /dev/null 636 $IP nexthop flush &> /dev/null 637 } 637 } 638 638 639 nexthop_res_group_no_unbalanced_timer_test() 639 nexthop_res_group_no_unbalanced_timer_test() 640 { 640 { 641 local i 641 local i 642 642 643 $IP nexthop add id 1 via 192.0.2.2 dev 643 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 644 $IP nexthop add id 2 via 192.0.2.3 dev 644 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 645 645 646 RET=0 646 RET=0 647 647 648 $IP nexthop add id 10 group 1/2 type r 648 $IP nexthop add id 10 group 1/2 type resilient buckets 8 649 nexthop_res_mark_buckets_busy 10 1 649 nexthop_res_mark_buckets_busy 10 1 650 $IP nexthop replace id 10 group 1/2,3 650 $IP nexthop replace id 10 group 1/2,3 type resilient 651 651 652 for i in $(seq 3); do 652 for i in $(seq 3); do 653 sleep 60 653 sleep 60 654 nexthop_bucket_nhid_count_chec 654 nexthop_bucket_nhid_count_check 10 2 6 655 check_fail $? "$i: Group expec 655 check_fail $? "$i: Group expected to be unbalanced" 656 nexthop_res_mark_buckets_busy 656 nexthop_res_mark_buckets_busy 10 1 657 done 657 done 658 658 659 log_test "Buckets never force-migrated 659 log_test "Buckets never force-migrated without unbalanced timer" 660 660 661 $IP nexthop flush &> /dev/null 661 $IP nexthop flush &> /dev/null 662 } 662 } 663 663 664 nexthop_res_group_short_unbalanced_timer_test( 664 nexthop_res_group_short_unbalanced_timer_test() 665 { 665 { 666 $IP nexthop add id 1 via 192.0.2.2 dev 666 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 667 $IP nexthop add id 2 via 192.0.2.3 dev 667 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 668 668 669 RET=0 669 RET=0 670 670 671 $IP nexthop add id 10 group 1/2 type r 671 $IP nexthop add id 10 group 1/2 type resilient \ 672 buckets 8 idle_timer 120 unbalance 672 buckets 8 idle_timer 120 unbalanced_timer 4 673 nexthop_res_mark_buckets_busy 10 1 673 nexthop_res_mark_buckets_busy 10 1 674 $IP nexthop replace id 10 group 1/2,3 674 $IP nexthop replace id 10 group 1/2,3 type resilient 675 675 676 nexthop_bucket_nhid_count_check 10 2 6 676 nexthop_bucket_nhid_count_check 10 2 6 677 check_fail $? "Group expected to be un 677 check_fail $? "Group expected to be unbalanced" 678 678 679 sleep 5 679 sleep 5 680 680 681 nexthop_bucket_nhid_count_check 10 2 6 681 nexthop_bucket_nhid_count_check 10 2 6 682 check_err $? "Group expected to be bal 682 check_err $? "Group expected to be balanced" 683 683 684 log_test "Bucket migration after unbal 684 log_test "Bucket migration after unbalanced < idle timer" 685 685 686 $IP nexthop flush &> /dev/null 686 $IP nexthop flush &> /dev/null 687 } 687 } 688 688 689 nexthop_res_group_increase_unbalanced_timer_te 689 nexthop_res_group_increase_unbalanced_timer_test() 690 { 690 { 691 __nexthop_res_group_increase_timer_tes 691 __nexthop_res_group_increase_timer_test unbalanced_timer 692 } 692 } 693 693 694 nexthop_res_group_decrease_unbalanced_timer_te 694 nexthop_res_group_decrease_unbalanced_timer_test() 695 { 695 { 696 __nexthop_res_group_decrease_timer_tes 696 __nexthop_res_group_decrease_timer_test unbalanced_timer 697 } 697 } 698 698 699 nexthop_res_group_force_migrate_busy_test() 699 nexthop_res_group_force_migrate_busy_test() 700 { 700 { 701 $IP nexthop add id 1 via 192.0.2.2 dev 701 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 702 $IP nexthop add id 2 via 192.0.2.3 dev 702 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 703 703 704 RET=0 704 RET=0 705 705 706 $IP nexthop add id 10 group 1/2 type r 706 $IP nexthop add id 10 group 1/2 type resilient \ 707 buckets 8 idle_timer 120 707 buckets 8 idle_timer 120 708 nexthop_res_mark_buckets_busy 10 1 708 nexthop_res_mark_buckets_busy 10 1 709 $IP nexthop replace id 10 group 1/2,3 709 $IP nexthop replace id 10 group 1/2,3 type resilient 710 710 711 nexthop_bucket_nhid_count_check 10 2 6 711 nexthop_bucket_nhid_count_check 10 2 6 712 check_fail $? "Group expected to be un 712 check_fail $? "Group expected to be unbalanced" 713 713 714 $IP nexthop replace id 10 group 2 type 714 $IP nexthop replace id 10 group 2 type resilient 715 nexthop_bucket_nhid_count_check 10 2 8 715 nexthop_bucket_nhid_count_check 10 2 8 716 check_err $? "All buckets expected to 716 check_err $? "All buckets expected to have migrated" 717 717 718 log_test "Busy buckets force-migrated 718 log_test "Busy buckets force-migrated when NH removed" 719 719 720 $IP nexthop flush &> /dev/null 720 $IP nexthop flush &> /dev/null 721 } 721 } 722 722 723 nexthop_single_replace_test() 723 nexthop_single_replace_test() 724 { 724 { 725 RET=0 725 RET=0 726 726 727 $IP nexthop add id 1 via 192.0.2.2 dev 727 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 728 728 729 $IP nexthop replace id 1 via 192.0.2.3 729 $IP nexthop replace id 1 via 192.0.2.3 dev dummy1 730 nexthop_check "id 1" "id 1 via 192.0.2 730 nexthop_check "id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap" 731 check_err $? "Unexpected nexthop entry 731 check_err $? "Unexpected nexthop entry" 732 732 733 nexthop_resource_check 1 733 nexthop_resource_check 1 734 check_err $? "Wrong nexthop occupancy" 734 check_err $? "Wrong nexthop occupancy" 735 735 736 log_test "Single nexthop replace" 736 log_test "Single nexthop replace" 737 737 738 $IP nexthop flush &> /dev/null 738 $IP nexthop flush &> /dev/null 739 } 739 } 740 740 741 nexthop_single_replace_err_test() 741 nexthop_single_replace_err_test() 742 { 742 { 743 RET=0 743 RET=0 744 744 745 # This is supposed to cause the replac 745 # This is supposed to cause the replace to fail because the new nexthop 746 # is programmed before deleting the re 746 # is programmed before deleting the replaced one. 747 nexthop_resource_set 1 747 nexthop_resource_set 1 748 748 749 $IP nexthop add id 1 via 192.0.2.2 dev 749 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 750 750 751 $IP nexthop replace id 1 via 192.0.2.3 751 $IP nexthop replace id 1 via 192.0.2.3 dev dummy1 &> /dev/null 752 check_fail $? "Nexthop replace succeed 752 check_fail $? "Nexthop replace succeeded when should fail" 753 753 754 nexthop_check "id 1" "id 1 via 192.0.2 754 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap" 755 check_err $? "Unexpected nexthop entry 755 check_err $? "Unexpected nexthop entry after failure" 756 756 757 nexthop_resource_check 1 757 nexthop_resource_check 1 758 check_err $? "Wrong nexthop occupancy 758 check_err $? "Wrong nexthop occupancy after failure" 759 759 760 log_test "Single nexthop replace failu 760 log_test "Single nexthop replace failure" 761 761 762 $IP nexthop flush &> /dev/null 762 $IP nexthop flush &> /dev/null 763 nexthop_resource_set 9999 763 nexthop_resource_set 9999 764 } 764 } 765 765 766 nexthop_single_in_group_replace_test() 766 nexthop_single_in_group_replace_test() 767 { 767 { 768 RET=0 768 RET=0 769 769 770 $IP nexthop add id 1 via 192.0.2.2 dev 770 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 771 $IP nexthop add id 2 via 192.0.2.3 dev 771 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 772 $IP nexthop add id 10 group 1/2 772 $IP nexthop add id 10 group 1/2 773 773 774 $IP nexthop replace id 1 via 192.0.2.4 774 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 775 check_err $? "Failed to replace nextho 775 check_err $? "Failed to replace nexthop when should not" 776 776 777 nexthop_check "id 10" "id 10 group 1/2 777 nexthop_check "id 10" "id 10 group 1/2 trap" 778 check_err $? "Unexpected nexthop group 778 check_err $? "Unexpected nexthop group entry" 779 779 780 nexthop_resource_check 4 780 nexthop_resource_check 4 781 check_err $? "Wrong nexthop occupancy" 781 check_err $? "Wrong nexthop occupancy" 782 782 783 log_test "Single nexthop replace while 783 log_test "Single nexthop replace while in group" 784 784 785 $IP nexthop flush &> /dev/null 785 $IP nexthop flush &> /dev/null 786 } 786 } 787 787 788 nexthop_single_in_group_replace_err_test() 788 nexthop_single_in_group_replace_err_test() 789 { 789 { 790 RET=0 790 RET=0 791 791 792 nexthop_resource_set 5 792 nexthop_resource_set 5 793 793 794 $IP nexthop add id 1 via 192.0.2.2 dev 794 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 795 $IP nexthop add id 2 via 192.0.2.3 dev 795 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 796 $IP nexthop add id 10 group 1/2 796 $IP nexthop add id 10 group 1/2 797 797 798 $IP nexthop replace id 1 via 192.0.2.4 798 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null 799 check_fail $? "Nexthop replacement suc 799 check_fail $? "Nexthop replacement succeeded when should fail" 800 800 801 nexthop_check "id 1" "id 1 via 192.0.2 801 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap" 802 check_err $? "Unexpected nexthop entry 802 check_err $? "Unexpected nexthop entry after failure" 803 803 804 nexthop_check "id 10" "id 10 group 1/2 804 nexthop_check "id 10" "id 10 group 1/2 trap" 805 check_err $? "Unexpected nexthop group 805 check_err $? "Unexpected nexthop group entry after failure" 806 806 807 nexthop_resource_check 4 807 nexthop_resource_check 4 808 check_err $? "Wrong nexthop occupancy" 808 check_err $? "Wrong nexthop occupancy" 809 809 810 log_test "Single nexthop replace while 810 log_test "Single nexthop replace while in group failure" 811 811 812 $IP nexthop flush &> /dev/null 812 $IP nexthop flush &> /dev/null 813 nexthop_resource_set 9999 813 nexthop_resource_set 9999 814 } 814 } 815 815 816 nexthop_single_in_res_group_replace_test() 816 nexthop_single_in_res_group_replace_test() 817 { 817 { 818 RET=0 818 RET=0 819 819 820 $IP nexthop add id 1 via 192.0.2.2 dev 820 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 821 $IP nexthop add id 2 via 192.0.2.3 dev 821 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 822 $IP nexthop add id 10 group 1/2 type r 822 $IP nexthop add id 10 group 1/2 type resilient buckets 4 823 823 824 $IP nexthop replace id 1 via 192.0.2.4 824 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 825 check_err $? "Failed to replace nextho 825 check_err $? "Failed to replace nexthop when should not" 826 826 827 nexthop_check "id 10" "id 10 group 1/2 827 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 828 check_err $? "Unexpected nexthop group 828 check_err $? "Unexpected nexthop group entry" 829 829 830 nexthop_bucket_nhid_count_check 10 1 830 nexthop_bucket_nhid_count_check 10 1 2 2 2 831 check_err $? "Wrong nexthop buckets co 831 check_err $? "Wrong nexthop buckets count" 832 832 833 nexthop_resource_check 6 833 nexthop_resource_check 6 834 check_err $? "Wrong nexthop occupancy" 834 check_err $? "Wrong nexthop occupancy" 835 835 836 log_test "Single nexthop replace while 836 log_test "Single nexthop replace while in resilient group" 837 837 838 $IP nexthop flush &> /dev/null 838 $IP nexthop flush &> /dev/null 839 } 839 } 840 840 841 nexthop_single_in_res_group_replace_err_test() 841 nexthop_single_in_res_group_replace_err_test() 842 { 842 { 843 RET=0 843 RET=0 844 844 845 $IP nexthop add id 1 via 192.0.2.2 dev 845 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 846 $IP nexthop add id 2 via 192.0.2.3 dev 846 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 847 $IP nexthop add id 10 group 1/2 type r 847 $IP nexthop add id 10 group 1/2 type resilient buckets 4 848 848 849 ip netns exec testns1 \ 849 ip netns exec testns1 \ 850 echo 1 > $DEBUGFS_NET_DIR/fib/ 850 echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace 851 $IP nexthop replace id 1 via 192.0.2.4 851 $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null 852 check_fail $? "Nexthop replacement suc 852 check_fail $? "Nexthop replacement succeeded when should fail" 853 853 854 nexthop_check "id 1" "id 1 via 192.0.2 854 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap" 855 check_err $? "Unexpected nexthop entry 855 check_err $? "Unexpected nexthop entry after failure" 856 856 857 nexthop_check "id 10" "id 10 group 1/2 857 nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 858 check_err $? "Unexpected nexthop group 858 check_err $? "Unexpected nexthop group entry after failure" 859 859 860 nexthop_bucket_nhid_count_check 10 1 860 nexthop_bucket_nhid_count_check 10 1 2 2 2 861 check_err $? "Wrong nexthop buckets co 861 check_err $? "Wrong nexthop buckets count" 862 862 863 nexthop_resource_check 6 863 nexthop_resource_check 6 864 check_err $? "Wrong nexthop occupancy" 864 check_err $? "Wrong nexthop occupancy" 865 865 866 log_test "Single nexthop replace while 866 log_test "Single nexthop replace while in resilient group failure" 867 867 868 $IP nexthop flush &> /dev/null 868 $IP nexthop flush &> /dev/null 869 ip netns exec testns1 \ 869 ip netns exec testns1 \ 870 echo 0 > $DEBUGFS_NET_DIR/fib/ 870 echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace 871 } 871 } 872 872 873 nexthop_single_in_group_delete_test() 873 nexthop_single_in_group_delete_test() 874 { 874 { 875 RET=0 875 RET=0 876 876 877 $IP nexthop add id 1 via 192.0.2.2 dev 877 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 878 $IP nexthop add id 2 via 192.0.2.3 dev 878 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 879 $IP nexthop add id 10 group 1/2 879 $IP nexthop add id 10 group 1/2 880 880 881 $IP nexthop del id 1 881 $IP nexthop del id 1 882 nexthop_check "id 10" "id 10 group 2 t 882 nexthop_check "id 10" "id 10 group 2 trap" 883 check_err $? "Unexpected nexthop group 883 check_err $? "Unexpected nexthop group entry" 884 884 885 nexthop_resource_check 2 885 nexthop_resource_check 2 886 check_err $? "Wrong nexthop occupancy" 886 check_err $? "Wrong nexthop occupancy" 887 887 888 log_test "Single nexthop delete while 888 log_test "Single nexthop delete while in group" 889 889 890 $IP nexthop flush &> /dev/null 890 $IP nexthop flush &> /dev/null 891 } 891 } 892 892 893 nexthop_single_in_group_delete_err_test() 893 nexthop_single_in_group_delete_err_test() 894 { 894 { 895 RET=0 895 RET=0 896 896 897 # First, nexthop 1 will be deleted, wh 897 # First, nexthop 1 will be deleted, which will reduce the occupancy to 898 # 5. Afterwards, a replace notificatio 898 # 5. Afterwards, a replace notification will be sent for nexthop group 899 # 10 with only two nexthops. Since the 899 # 10 with only two nexthops. Since the new group is allocated before 900 # the old is deleted, the replacement 900 # the old is deleted, the replacement will fail as it will result in an 901 # occupancy of 7. 901 # occupancy of 7. 902 nexthop_resource_set 6 902 nexthop_resource_set 6 903 903 904 $IP nexthop add id 1 via 192.0.2.2 dev 904 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 905 $IP nexthop add id 2 via 192.0.2.3 dev 905 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 906 $IP nexthop add id 3 via 192.0.2.4 dev 906 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 907 $IP nexthop add id 10 group 1/2/3 907 $IP nexthop add id 10 group 1/2/3 908 908 909 $IP nexthop del id 1 909 $IP nexthop del id 1 910 910 911 nexthop_resource_check 5 911 nexthop_resource_check 5 912 check_err $? "Wrong nexthop occupancy" 912 check_err $? "Wrong nexthop occupancy" 913 913 914 log_test "Single nexthop delete while 914 log_test "Single nexthop delete while in group failure" 915 915 916 $IP nexthop flush &> /dev/null 916 $IP nexthop flush &> /dev/null 917 nexthop_resource_set 9999 917 nexthop_resource_set 9999 918 } 918 } 919 919 920 nexthop_single_in_res_group_delete_test() 920 nexthop_single_in_res_group_delete_test() 921 { 921 { 922 RET=0 922 RET=0 923 923 924 $IP nexthop add id 1 via 192.0.2.2 dev 924 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 925 $IP nexthop add id 2 via 192.0.2.3 dev 925 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 926 $IP nexthop add id 10 group 1/2 type r 926 $IP nexthop add id 10 group 1/2 type resilient buckets 4 927 927 928 $IP nexthop del id 1 928 $IP nexthop del id 1 929 nexthop_check "id 10" "id 10 group 2 t 929 nexthop_check "id 10" "id 10 group 2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap" 930 check_err $? "Unexpected nexthop group 930 check_err $? "Unexpected nexthop group entry" 931 931 932 nexthop_bucket_nhid_count_check 10 2 4 932 nexthop_bucket_nhid_count_check 10 2 4 933 check_err $? "Wrong nexthop buckets co 933 check_err $? "Wrong nexthop buckets count" 934 934 935 nexthop_resource_check 5 935 nexthop_resource_check 5 936 check_err $? "Wrong nexthop occupancy" 936 check_err $? "Wrong nexthop occupancy" 937 937 938 log_test "Single nexthop delete while 938 log_test "Single nexthop delete while in resilient group" 939 939 940 $IP nexthop flush &> /dev/null 940 $IP nexthop flush &> /dev/null 941 } 941 } 942 942 943 nexthop_single_in_res_group_delete_err_test() 943 nexthop_single_in_res_group_delete_err_test() 944 { 944 { 945 RET=0 945 RET=0 946 946 947 $IP nexthop add id 1 via 192.0.2.2 dev 947 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 948 $IP nexthop add id 2 via 192.0.2.3 dev 948 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 949 $IP nexthop add id 3 via 192.0.2.4 dev 949 $IP nexthop add id 3 via 192.0.2.4 dev dummy1 950 $IP nexthop add id 10 group 1/2/3 type 950 $IP nexthop add id 10 group 1/2/3 type resilient buckets 6 951 951 952 ip netns exec testns1 \ 952 ip netns exec testns1 \ 953 echo 1 > $DEBUGFS_NET_DIR/fib/ 953 echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace 954 $IP nexthop del id 1 954 $IP nexthop del id 1 955 955 956 # We failed to replace the two nexthop 956 # We failed to replace the two nexthop buckets that were originally 957 # assigned to nhid 1. 957 # assigned to nhid 1. 958 nexthop_bucket_nhid_count_check 10 2 958 nexthop_bucket_nhid_count_check 10 2 2 3 2 959 check_err $? "Wrong nexthop buckets co 959 check_err $? "Wrong nexthop buckets count" 960 960 961 nexthop_resource_check 8 961 nexthop_resource_check 8 962 check_err $? "Wrong nexthop occupancy" 962 check_err $? "Wrong nexthop occupancy" 963 963 964 log_test "Single nexthop delete while 964 log_test "Single nexthop delete while in resilient group failure" 965 965 966 $IP nexthop flush &> /dev/null 966 $IP nexthop flush &> /dev/null 967 ip netns exec testns1 \ 967 ip netns exec testns1 \ 968 echo 0 > $DEBUGFS_NET_DIR/fib/ 968 echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace 969 } 969 } 970 970 971 nexthop_replay_test() 971 nexthop_replay_test() 972 { 972 { 973 RET=0 973 RET=0 974 974 975 $IP nexthop add id 1 via 192.0.2.2 dev 975 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 976 $IP nexthop add id 2 via 192.0.2.3 dev 976 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 977 $IP nexthop add id 10 group 1/2 977 $IP nexthop add id 10 group 1/2 978 978 979 $DEVLINK dev reload $DEVLINK_DEV 979 $DEVLINK dev reload $DEVLINK_DEV 980 check_err $? "Failed to reload when sh 980 check_err $? "Failed to reload when should not" 981 981 982 nexthop_check "id 1" "id 1 via 192.0.2 982 nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap" 983 check_err $? "Unexpected nexthop entry 983 check_err $? "Unexpected nexthop entry after reload" 984 984 985 nexthop_check "id 2" "id 2 via 192.0.2 985 nexthop_check "id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap" 986 check_err $? "Unexpected nexthop entry 986 check_err $? "Unexpected nexthop entry after reload" 987 987 988 nexthop_check "id 10" "id 10 group 1/2 988 nexthop_check "id 10" "id 10 group 1/2 trap" 989 check_err $? "Unexpected nexthop group 989 check_err $? "Unexpected nexthop group entry after reload" 990 990 991 nexthop_resource_check 4 991 nexthop_resource_check 4 992 check_err $? "Wrong nexthop occupancy" 992 check_err $? "Wrong nexthop occupancy" 993 993 994 log_test "Nexthop replay" 994 log_test "Nexthop replay" 995 995 996 $IP nexthop flush &> /dev/null 996 $IP nexthop flush &> /dev/null 997 } 997 } 998 998 999 nexthop_replay_err_test() 999 nexthop_replay_err_test() 1000 { 1000 { 1001 RET=0 1001 RET=0 1002 1002 1003 $IP nexthop add id 1 via 192.0.2.2 de 1003 $IP nexthop add id 1 via 192.0.2.2 dev dummy1 1004 $IP nexthop add id 2 via 192.0.2.3 de 1004 $IP nexthop add id 2 via 192.0.2.3 dev dummy1 1005 $IP nexthop add id 10 group 1/2 1005 $IP nexthop add id 10 group 1/2 1006 1006 1007 # Reduce size of nexthop resource so 1007 # Reduce size of nexthop resource so that reload will fail. 1008 $DEVLINK resource set $DEVLINK_DEV pa 1008 $DEVLINK resource set $DEVLINK_DEV path nexthops size 3 1009 $DEVLINK dev reload $DEVLINK_DEV &> / 1009 $DEVLINK dev reload $DEVLINK_DEV &> /dev/null 1010 check_fail $? "Reload succeeded when 1010 check_fail $? "Reload succeeded when should fail" 1011 1011 1012 $DEVLINK resource set $DEVLINK_DEV pa 1012 $DEVLINK resource set $DEVLINK_DEV path nexthops size 9999 1013 $DEVLINK dev reload $DEVLINK_DEV 1013 $DEVLINK dev reload $DEVLINK_DEV 1014 check_err $? "Failed to reload when s 1014 check_err $? "Failed to reload when should not" 1015 1015 1016 log_test "Nexthop replay failure" 1016 log_test "Nexthop replay failure" 1017 1017 1018 $IP nexthop flush &> /dev/null 1018 $IP nexthop flush &> /dev/null 1019 } 1019 } 1020 1020 1021 setup_prepare() 1021 setup_prepare() 1022 { 1022 { 1023 local netdev 1023 local netdev 1024 1024 1025 modprobe netdevsim &> /dev/null 1025 modprobe netdevsim &> /dev/null 1026 1026 1027 echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH 1027 echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device 1028 while [ ! -d $SYSFS_NET_DIR ] ; do :; 1028 while [ ! -d $SYSFS_NET_DIR ] ; do :; done 1029 1029 1030 set -e 1030 set -e 1031 1031 1032 ip netns add testns1 1032 ip netns add testns1 1033 devlink dev reload $DEVLINK_DEV netns 1033 devlink dev reload $DEVLINK_DEV netns testns1 1034 1034 1035 IP="ip -netns testns1" 1035 IP="ip -netns testns1" 1036 DEVLINK="devlink -N testns1" 1036 DEVLINK="devlink -N testns1" 1037 1037 1038 $IP link add name dummy1 up type dumm 1038 $IP link add name dummy1 up type dummy 1039 $IP address add 192.0.2.1/24 dev dumm 1039 $IP address add 192.0.2.1/24 dev dummy1 1040 1040 1041 set +e 1041 set +e 1042 } 1042 } 1043 1043 1044 cleanup() 1044 cleanup() 1045 { 1045 { 1046 pre_cleanup 1046 pre_cleanup 1047 ip netns del testns1 1047 ip netns del testns1 1048 echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/ 1048 echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device 1049 modprobe -r netdevsim &> /dev/null 1049 modprobe -r netdevsim &> /dev/null 1050 } 1050 } 1051 1051 1052 trap cleanup EXIT 1052 trap cleanup EXIT 1053 1053 1054 setup_prepare 1054 setup_prepare 1055 1055 1056 tests_run 1056 tests_run 1057 1057 1058 exit $EXIT_STATUS 1058 exit $EXIT_STATUS
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.