nexthop.sh 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # This test is for checking the nexthop offload API. It makes use of netdevsim
  5. # which registers a listener to the nexthop notification chain.
  6. lib_dir=$(dirname $0)/../../../net/forwarding
  7. ALL_TESTS="
  8. nexthop_single_add_test
  9. nexthop_single_add_err_test
  10. nexthop_group_add_test
  11. nexthop_group_add_err_test
  12. nexthop_res_group_add_test
  13. nexthop_res_group_add_err_test
  14. nexthop_group_replace_test
  15. nexthop_group_replace_err_test
  16. nexthop_res_group_replace_test
  17. nexthop_res_group_replace_err_test
  18. nexthop_res_group_idle_timer_test
  19. nexthop_res_group_idle_timer_del_test
  20. nexthop_res_group_increase_idle_timer_test
  21. nexthop_res_group_decrease_idle_timer_test
  22. nexthop_res_group_unbalanced_timer_test
  23. nexthop_res_group_unbalanced_timer_del_test
  24. nexthop_res_group_no_unbalanced_timer_test
  25. nexthop_res_group_short_unbalanced_timer_test
  26. nexthop_res_group_increase_unbalanced_timer_test
  27. nexthop_res_group_decrease_unbalanced_timer_test
  28. nexthop_res_group_force_migrate_busy_test
  29. nexthop_single_replace_test
  30. nexthop_single_replace_err_test
  31. nexthop_single_in_group_replace_test
  32. nexthop_single_in_group_replace_err_test
  33. nexthop_single_in_res_group_replace_test
  34. nexthop_single_in_res_group_replace_err_test
  35. nexthop_single_in_group_delete_test
  36. nexthop_single_in_group_delete_err_test
  37. nexthop_single_in_res_group_delete_test
  38. nexthop_single_in_res_group_delete_err_test
  39. nexthop_replay_test
  40. nexthop_replay_err_test
  41. "
  42. NETDEVSIM_PATH=/sys/bus/netdevsim/
  43. DEV_ADDR=1337
  44. DEV=netdevsim${DEV_ADDR}
  45. SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
  46. DEBUGFS_NET_DIR=/sys/kernel/debug/netdevsim/$DEV/
  47. NUM_NETIFS=0
  48. source $lib_dir/lib.sh
  49. DEVLINK_DEV=
  50. source $lib_dir/devlink_lib.sh
  51. DEVLINK_DEV=netdevsim/${DEV}
  52. nexthop_check()
  53. {
  54. local nharg="$1"; shift
  55. local expected="$1"; shift
  56. out=$($IP nexthop show ${nharg} | sed -e 's/ *$//')
  57. if [[ "$out" != "$expected" ]]; then
  58. return 1
  59. fi
  60. return 0
  61. }
  62. nexthop_bucket_nhid_count_check()
  63. {
  64. local group_id=$1; shift
  65. local expected
  66. local count
  67. local nhid
  68. local ret
  69. while (($# > 0)); do
  70. nhid=$1; shift
  71. expected=$1; shift
  72. count=$($IP nexthop bucket show id $group_id nhid $nhid |
  73. grep "trap" | wc -l)
  74. if ((expected != count)); then
  75. return 1
  76. fi
  77. done
  78. return 0
  79. }
  80. nexthop_resource_check()
  81. {
  82. local expected_occ=$1; shift
  83. occ=$($DEVLINK -jp resource show $DEVLINK_DEV \
  84. | jq '.[][][] | select(.name=="nexthops") | .["occ"]')
  85. if [ $expected_occ -ne $occ ]; then
  86. return 1
  87. fi
  88. return 0
  89. }
  90. nexthop_resource_set()
  91. {
  92. local size=$1; shift
  93. $DEVLINK resource set $DEVLINK_DEV path nexthops size $size
  94. $DEVLINK dev reload $DEVLINK_DEV
  95. }
  96. nexthop_single_add_test()
  97. {
  98. RET=0
  99. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  100. nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
  101. check_err $? "Unexpected nexthop entry"
  102. nexthop_resource_check 1
  103. check_err $? "Wrong nexthop occupancy"
  104. $IP nexthop del id 1
  105. nexthop_resource_check 0
  106. check_err $? "Wrong nexthop occupancy after delete"
  107. log_test "Single nexthop add and delete"
  108. }
  109. nexthop_single_add_err_test()
  110. {
  111. RET=0
  112. nexthop_resource_set 1
  113. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  114. $IP nexthop add id 2 via 192.0.2.3 dev dummy1 &> /dev/null
  115. check_fail $? "Nexthop addition succeeded when should fail"
  116. nexthop_resource_check 1
  117. check_err $? "Wrong nexthop occupancy"
  118. log_test "Single nexthop add failure"
  119. $IP nexthop flush &> /dev/null
  120. nexthop_resource_set 9999
  121. }
  122. nexthop_group_add_test()
  123. {
  124. RET=0
  125. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  126. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  127. $IP nexthop add id 10 group 1/2
  128. nexthop_check "id 10" "id 10 group 1/2 trap"
  129. check_err $? "Unexpected nexthop group entry"
  130. nexthop_resource_check 4
  131. check_err $? "Wrong nexthop occupancy"
  132. $IP nexthop del id 10
  133. nexthop_resource_check 2
  134. check_err $? "Wrong nexthop occupancy after delete"
  135. $IP nexthop add id 10 group 1,20/2,39
  136. nexthop_check "id 10" "id 10 group 1,20/2,39 trap"
  137. check_err $? "Unexpected weighted nexthop group entry"
  138. nexthop_resource_check 61
  139. check_err $? "Wrong weighted nexthop occupancy"
  140. $IP nexthop del id 10
  141. nexthop_resource_check 2
  142. check_err $? "Wrong nexthop occupancy after delete"
  143. log_test "Nexthop group add and delete"
  144. $IP nexthop flush &> /dev/null
  145. }
  146. nexthop_group_add_err_test()
  147. {
  148. RET=0
  149. nexthop_resource_set 2
  150. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  151. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  152. $IP nexthop add id 10 group 1/2 &> /dev/null
  153. check_fail $? "Nexthop group addition succeeded when should fail"
  154. nexthop_resource_check 2
  155. check_err $? "Wrong nexthop occupancy"
  156. log_test "Nexthop group add failure"
  157. $IP nexthop flush &> /dev/null
  158. nexthop_resource_set 9999
  159. }
  160. nexthop_res_group_add_test()
  161. {
  162. RET=0
  163. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  164. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  165. $IP nexthop add id 10 group 1/2 type resilient buckets 4
  166. nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  167. check_err $? "Unexpected nexthop group entry"
  168. nexthop_bucket_nhid_count_check 10 1 2
  169. check_err $? "Wrong nexthop buckets count"
  170. nexthop_bucket_nhid_count_check 10 2 2
  171. check_err $? "Wrong nexthop buckets count"
  172. nexthop_resource_check 6
  173. check_err $? "Wrong nexthop occupancy"
  174. $IP nexthop del id 10
  175. nexthop_resource_check 2
  176. check_err $? "Wrong nexthop occupancy after delete"
  177. $IP nexthop add id 10 group 1,3/2,2 type resilient buckets 5
  178. 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"
  179. check_err $? "Unexpected weighted nexthop group entry"
  180. nexthop_bucket_nhid_count_check 10 1 3
  181. check_err $? "Wrong nexthop buckets count"
  182. nexthop_bucket_nhid_count_check 10 2 2
  183. check_err $? "Wrong nexthop buckets count"
  184. nexthop_resource_check 7
  185. check_err $? "Wrong weighted nexthop occupancy"
  186. $IP nexthop del id 10
  187. nexthop_resource_check 2
  188. check_err $? "Wrong nexthop occupancy after delete"
  189. log_test "Resilient nexthop group add and delete"
  190. $IP nexthop flush &> /dev/null
  191. }
  192. nexthop_res_group_add_err_test()
  193. {
  194. RET=0
  195. nexthop_resource_set 2
  196. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  197. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  198. $IP nexthop add id 10 group 1/2 type resilient buckets 4 &> /dev/null
  199. check_fail $? "Nexthop group addition succeeded when should fail"
  200. nexthop_resource_check 2
  201. check_err $? "Wrong nexthop occupancy"
  202. log_test "Resilient nexthop group add failure"
  203. $IP nexthop flush &> /dev/null
  204. nexthop_resource_set 9999
  205. }
  206. nexthop_group_replace_test()
  207. {
  208. RET=0
  209. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  210. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  211. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  212. $IP nexthop add id 10 group 1/2
  213. $IP nexthop replace id 10 group 1/2/3
  214. nexthop_check "id 10" "id 10 group 1/2/3 trap"
  215. check_err $? "Unexpected nexthop group entry"
  216. nexthop_resource_check 6
  217. check_err $? "Wrong nexthop occupancy"
  218. log_test "Nexthop group replace"
  219. $IP nexthop flush &> /dev/null
  220. }
  221. nexthop_group_replace_err_test()
  222. {
  223. RET=0
  224. nexthop_resource_set 5
  225. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  226. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  227. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  228. $IP nexthop add id 10 group 1/2
  229. $IP nexthop replace id 10 group 1/2/3 &> /dev/null
  230. check_fail $? "Nexthop group replacement succeeded when should fail"
  231. nexthop_check "id 10" "id 10 group 1/2 trap"
  232. check_err $? "Unexpected nexthop group entry after failure"
  233. nexthop_resource_check 5
  234. check_err $? "Wrong nexthop occupancy after failure"
  235. log_test "Nexthop group replace failure"
  236. $IP nexthop flush &> /dev/null
  237. nexthop_resource_set 9999
  238. }
  239. nexthop_res_group_replace_test()
  240. {
  241. RET=0
  242. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  243. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  244. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  245. $IP nexthop add id 10 group 1/2 type resilient buckets 6
  246. $IP nexthop replace id 10 group 1/2/3 type resilient
  247. nexthop_check "id 10" "id 10 group 1/2/3 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  248. check_err $? "Unexpected nexthop group entry"
  249. nexthop_bucket_nhid_count_check 10 1 2
  250. check_err $? "Wrong nexthop buckets count"
  251. nexthop_bucket_nhid_count_check 10 2 2
  252. check_err $? "Wrong nexthop buckets count"
  253. nexthop_bucket_nhid_count_check 10 3 2
  254. check_err $? "Wrong nexthop buckets count"
  255. nexthop_resource_check 9
  256. check_err $? "Wrong nexthop occupancy"
  257. log_test "Resilient nexthop group replace"
  258. $IP nexthop flush &> /dev/null
  259. }
  260. nexthop_res_group_replace_err_test()
  261. {
  262. RET=0
  263. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  264. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  265. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  266. $IP nexthop add id 10 group 1/2 type resilient buckets 6
  267. ip netns exec testns1 \
  268. echo 1 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace
  269. $IP nexthop replace id 10 group 1/2/3 type resilient &> /dev/null
  270. check_fail $? "Nexthop group replacement succeeded when should fail"
  271. nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 6 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  272. check_err $? "Unexpected nexthop group entry after failure"
  273. nexthop_bucket_nhid_count_check 10 1 3
  274. check_err $? "Wrong nexthop buckets count"
  275. nexthop_bucket_nhid_count_check 10 2 3
  276. check_err $? "Wrong nexthop buckets count"
  277. nexthop_resource_check 9
  278. check_err $? "Wrong nexthop occupancy after failure"
  279. log_test "Resilient nexthop group replace failure"
  280. $IP nexthop flush &> /dev/null
  281. ip netns exec testns1 \
  282. echo 0 > $DEBUGFS_NET_DIR/fib/fail_res_nexthop_group_replace
  283. }
  284. nexthop_res_mark_buckets_busy()
  285. {
  286. local group_id=$1; shift
  287. local nhid=$1; shift
  288. local count=$1; shift
  289. local index
  290. for index in $($IP -j nexthop bucket show id $group_id nhid $nhid |
  291. jq '.[].bucket.index' | head -n ${count:--0})
  292. do
  293. echo $group_id $index \
  294. > $DEBUGFS_NET_DIR/fib/nexthop_bucket_activity
  295. done
  296. }
  297. nexthop_res_num_nhid_buckets()
  298. {
  299. local group_id=$1; shift
  300. local nhid=$1; shift
  301. $IP -j nexthop bucket show id $group_id nhid $nhid | jq length
  302. }
  303. nexthop_res_group_idle_timer_test()
  304. {
  305. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  306. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  307. RET=0
  308. $IP nexthop add id 10 group 1/2 type resilient buckets 8 idle_timer 4
  309. nexthop_res_mark_buckets_busy 10 1
  310. $IP nexthop replace id 10 group 1/2,3 type resilient
  311. nexthop_bucket_nhid_count_check 10 1 4 2 4
  312. check_err $? "Group expected to be unbalanced"
  313. sleep 6
  314. nexthop_bucket_nhid_count_check 10 1 2 2 6
  315. check_err $? "Group expected to be balanced"
  316. log_test "Bucket migration after idle timer"
  317. $IP nexthop flush &> /dev/null
  318. }
  319. nexthop_res_group_idle_timer_del_test()
  320. {
  321. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  322. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  323. $IP nexthop add id 3 via 192.0.2.3 dev dummy1
  324. RET=0
  325. $IP nexthop add id 10 group 1,50/2,50/3,1 \
  326. type resilient buckets 8 idle_timer 6
  327. nexthop_res_mark_buckets_busy 10 1
  328. $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient
  329. nexthop_bucket_nhid_count_check 10 1 4 2 4 3 0
  330. check_err $? "Group expected to be unbalanced"
  331. sleep 4
  332. # Deletion prompts group replacement. Check that the bucket timers
  333. # are kept.
  334. $IP nexthop delete id 3
  335. nexthop_bucket_nhid_count_check 10 1 4 2 4
  336. check_err $? "Group expected to still be unbalanced"
  337. sleep 4
  338. nexthop_bucket_nhid_count_check 10 1 2 2 6
  339. check_err $? "Group expected to be balanced"
  340. log_test "Bucket migration after idle timer (with delete)"
  341. $IP nexthop flush &> /dev/null
  342. }
  343. __nexthop_res_group_increase_timer_test()
  344. {
  345. local timer=$1; shift
  346. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  347. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  348. RET=0
  349. $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 4
  350. nexthop_res_mark_buckets_busy 10 1
  351. $IP nexthop replace id 10 group 1/2,3 type resilient
  352. nexthop_bucket_nhid_count_check 10 2 6
  353. check_fail $? "Group expected to be unbalanced"
  354. sleep 2
  355. $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8
  356. sleep 4
  357. # 6 seconds, past the original timer.
  358. nexthop_bucket_nhid_count_check 10 2 6
  359. check_fail $? "Group still expected to be unbalanced"
  360. sleep 4
  361. # 10 seconds, past the new timer.
  362. nexthop_bucket_nhid_count_check 10 2 6
  363. check_err $? "Group expected to be balanced"
  364. log_test "Bucket migration after $timer increase"
  365. $IP nexthop flush &> /dev/null
  366. }
  367. __nexthop_res_group_decrease_timer_test()
  368. {
  369. local timer=$1; shift
  370. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  371. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  372. RET=0
  373. $IP nexthop add id 10 group 1/2 type resilient buckets 8 $timer 8
  374. nexthop_res_mark_buckets_busy 10 1
  375. $IP nexthop replace id 10 group 1/2,3 type resilient
  376. nexthop_bucket_nhid_count_check 10 2 6
  377. check_fail $? "Group expected to be unbalanced"
  378. sleep 2
  379. $IP nexthop replace id 10 group 1/2,3 type resilient $timer 4
  380. sleep 4
  381. # 6 seconds, past the new timer, before the old timer.
  382. nexthop_bucket_nhid_count_check 10 2 6
  383. check_err $? "Group expected to be balanced"
  384. log_test "Bucket migration after $timer decrease"
  385. $IP nexthop flush &> /dev/null
  386. }
  387. __nexthop_res_group_increase_timer_del_test()
  388. {
  389. local timer=$1; shift
  390. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  391. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  392. $IP nexthop add id 3 via 192.0.2.3 dev dummy1
  393. RET=0
  394. $IP nexthop add id 10 group 1,100/2,100/3,1 \
  395. type resilient buckets 8 $timer 4
  396. nexthop_res_mark_buckets_busy 10 1
  397. $IP nexthop replace id 10 group 1,100/2,300/3,1 type resilient
  398. nexthop_bucket_nhid_count_check 10 2 6
  399. check_fail $? "Group expected to be unbalanced"
  400. sleep 2
  401. $IP nexthop replace id 10 group 1/2,3 type resilient $timer 8
  402. sleep 4
  403. # 6 seconds, past the original timer.
  404. nexthop_bucket_nhid_count_check 10 2 6
  405. check_fail $? "Group still expected to be unbalanced"
  406. sleep 4
  407. # 10 seconds, past the new timer.
  408. nexthop_bucket_nhid_count_check 10 2 6
  409. check_err $? "Group expected to be balanced"
  410. log_test "Bucket migration after $timer increase"
  411. $IP nexthop flush &> /dev/null
  412. }
  413. nexthop_res_group_increase_idle_timer_test()
  414. {
  415. __nexthop_res_group_increase_timer_test idle_timer
  416. }
  417. nexthop_res_group_decrease_idle_timer_test()
  418. {
  419. __nexthop_res_group_decrease_timer_test idle_timer
  420. }
  421. nexthop_res_group_unbalanced_timer_test()
  422. {
  423. local i
  424. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  425. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  426. RET=0
  427. $IP nexthop add id 10 group 1/2 type resilient \
  428. buckets 8 idle_timer 6 unbalanced_timer 10
  429. nexthop_res_mark_buckets_busy 10 1
  430. $IP nexthop replace id 10 group 1/2,3 type resilient
  431. for i in 1 2; do
  432. sleep 4
  433. nexthop_bucket_nhid_count_check 10 1 4 2 4
  434. check_err $? "$i: Group expected to be unbalanced"
  435. nexthop_res_mark_buckets_busy 10 1
  436. done
  437. # 3 x sleep 4 > unbalanced timer 10
  438. sleep 4
  439. nexthop_bucket_nhid_count_check 10 1 2 2 6
  440. check_err $? "Group expected to be balanced"
  441. log_test "Bucket migration after unbalanced timer"
  442. $IP nexthop flush &> /dev/null
  443. }
  444. nexthop_res_group_unbalanced_timer_del_test()
  445. {
  446. local i
  447. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  448. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  449. $IP nexthop add id 3 via 192.0.2.3 dev dummy1
  450. RET=0
  451. $IP nexthop add id 10 group 1,50/2,50/3,1 type resilient \
  452. buckets 8 idle_timer 6 unbalanced_timer 10
  453. nexthop_res_mark_buckets_busy 10 1
  454. $IP nexthop replace id 10 group 1,50/2,150/3,1 type resilient
  455. # Check that NH delete does not reset unbalanced time.
  456. sleep 4
  457. $IP nexthop delete id 3
  458. nexthop_bucket_nhid_count_check 10 1 4 2 4
  459. check_err $? "1: Group expected to be unbalanced"
  460. nexthop_res_mark_buckets_busy 10 1
  461. sleep 4
  462. nexthop_bucket_nhid_count_check 10 1 4 2 4
  463. check_err $? "2: Group expected to be unbalanced"
  464. nexthop_res_mark_buckets_busy 10 1
  465. # 3 x sleep 4 > unbalanced timer 10
  466. sleep 4
  467. nexthop_bucket_nhid_count_check 10 1 2 2 6
  468. check_err $? "Group expected to be balanced"
  469. log_test "Bucket migration after unbalanced timer (with delete)"
  470. $IP nexthop flush &> /dev/null
  471. }
  472. nexthop_res_group_no_unbalanced_timer_test()
  473. {
  474. local i
  475. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  476. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  477. RET=0
  478. $IP nexthop add id 10 group 1/2 type resilient buckets 8
  479. nexthop_res_mark_buckets_busy 10 1
  480. $IP nexthop replace id 10 group 1/2,3 type resilient
  481. for i in $(seq 3); do
  482. sleep 60
  483. nexthop_bucket_nhid_count_check 10 2 6
  484. check_fail $? "$i: Group expected to be unbalanced"
  485. nexthop_res_mark_buckets_busy 10 1
  486. done
  487. log_test "Buckets never force-migrated without unbalanced timer"
  488. $IP nexthop flush &> /dev/null
  489. }
  490. nexthop_res_group_short_unbalanced_timer_test()
  491. {
  492. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  493. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  494. RET=0
  495. $IP nexthop add id 10 group 1/2 type resilient \
  496. buckets 8 idle_timer 120 unbalanced_timer 4
  497. nexthop_res_mark_buckets_busy 10 1
  498. $IP nexthop replace id 10 group 1/2,3 type resilient
  499. nexthop_bucket_nhid_count_check 10 2 6
  500. check_fail $? "Group expected to be unbalanced"
  501. sleep 5
  502. nexthop_bucket_nhid_count_check 10 2 6
  503. check_err $? "Group expected to be balanced"
  504. log_test "Bucket migration after unbalanced < idle timer"
  505. $IP nexthop flush &> /dev/null
  506. }
  507. nexthop_res_group_increase_unbalanced_timer_test()
  508. {
  509. __nexthop_res_group_increase_timer_test unbalanced_timer
  510. }
  511. nexthop_res_group_decrease_unbalanced_timer_test()
  512. {
  513. __nexthop_res_group_decrease_timer_test unbalanced_timer
  514. }
  515. nexthop_res_group_force_migrate_busy_test()
  516. {
  517. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  518. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  519. RET=0
  520. $IP nexthop add id 10 group 1/2 type resilient \
  521. buckets 8 idle_timer 120
  522. nexthop_res_mark_buckets_busy 10 1
  523. $IP nexthop replace id 10 group 1/2,3 type resilient
  524. nexthop_bucket_nhid_count_check 10 2 6
  525. check_fail $? "Group expected to be unbalanced"
  526. $IP nexthop replace id 10 group 2 type resilient
  527. nexthop_bucket_nhid_count_check 10 2 8
  528. check_err $? "All buckets expected to have migrated"
  529. log_test "Busy buckets force-migrated when NH removed"
  530. $IP nexthop flush &> /dev/null
  531. }
  532. nexthop_single_replace_test()
  533. {
  534. RET=0
  535. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  536. $IP nexthop replace id 1 via 192.0.2.3 dev dummy1
  537. nexthop_check "id 1" "id 1 via 192.0.2.3 dev dummy1 scope link trap"
  538. check_err $? "Unexpected nexthop entry"
  539. nexthop_resource_check 1
  540. check_err $? "Wrong nexthop occupancy"
  541. log_test "Single nexthop replace"
  542. $IP nexthop flush &> /dev/null
  543. }
  544. nexthop_single_replace_err_test()
  545. {
  546. RET=0
  547. # This is supposed to cause the replace to fail because the new nexthop
  548. # is programmed before deleting the replaced one.
  549. nexthop_resource_set 1
  550. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  551. $IP nexthop replace id 1 via 192.0.2.3 dev dummy1 &> /dev/null
  552. check_fail $? "Nexthop replace succeeded when should fail"
  553. nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
  554. check_err $? "Unexpected nexthop entry after failure"
  555. nexthop_resource_check 1
  556. check_err $? "Wrong nexthop occupancy after failure"
  557. log_test "Single nexthop replace failure"
  558. $IP nexthop flush &> /dev/null
  559. nexthop_resource_set 9999
  560. }
  561. nexthop_single_in_group_replace_test()
  562. {
  563. RET=0
  564. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  565. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  566. $IP nexthop add id 10 group 1/2
  567. $IP nexthop replace id 1 via 192.0.2.4 dev dummy1
  568. check_err $? "Failed to replace nexthop when should not"
  569. nexthop_check "id 10" "id 10 group 1/2 trap"
  570. check_err $? "Unexpected nexthop group entry"
  571. nexthop_resource_check 4
  572. check_err $? "Wrong nexthop occupancy"
  573. log_test "Single nexthop replace while in group"
  574. $IP nexthop flush &> /dev/null
  575. }
  576. nexthop_single_in_group_replace_err_test()
  577. {
  578. RET=0
  579. nexthop_resource_set 5
  580. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  581. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  582. $IP nexthop add id 10 group 1/2
  583. $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null
  584. check_fail $? "Nexthop replacement succeeded when should fail"
  585. nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
  586. check_err $? "Unexpected nexthop entry after failure"
  587. nexthop_check "id 10" "id 10 group 1/2 trap"
  588. check_err $? "Unexpected nexthop group entry after failure"
  589. nexthop_resource_check 4
  590. check_err $? "Wrong nexthop occupancy"
  591. log_test "Single nexthop replace while in group failure"
  592. $IP nexthop flush &> /dev/null
  593. nexthop_resource_set 9999
  594. }
  595. nexthop_single_in_res_group_replace_test()
  596. {
  597. RET=0
  598. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  599. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  600. $IP nexthop add id 10 group 1/2 type resilient buckets 4
  601. $IP nexthop replace id 1 via 192.0.2.4 dev dummy1
  602. check_err $? "Failed to replace nexthop when should not"
  603. nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  604. check_err $? "Unexpected nexthop group entry"
  605. nexthop_bucket_nhid_count_check 10 1 2 2 2
  606. check_err $? "Wrong nexthop buckets count"
  607. nexthop_resource_check 6
  608. check_err $? "Wrong nexthop occupancy"
  609. log_test "Single nexthop replace while in resilient group"
  610. $IP nexthop flush &> /dev/null
  611. }
  612. nexthop_single_in_res_group_replace_err_test()
  613. {
  614. RET=0
  615. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  616. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  617. $IP nexthop add id 10 group 1/2 type resilient buckets 4
  618. ip netns exec testns1 \
  619. echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
  620. $IP nexthop replace id 1 via 192.0.2.4 dev dummy1 &> /dev/null
  621. check_fail $? "Nexthop replacement succeeded when should fail"
  622. nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
  623. check_err $? "Unexpected nexthop entry after failure"
  624. nexthop_check "id 10" "id 10 group 1/2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  625. check_err $? "Unexpected nexthop group entry after failure"
  626. nexthop_bucket_nhid_count_check 10 1 2 2 2
  627. check_err $? "Wrong nexthop buckets count"
  628. nexthop_resource_check 6
  629. check_err $? "Wrong nexthop occupancy"
  630. log_test "Single nexthop replace while in resilient group failure"
  631. $IP nexthop flush &> /dev/null
  632. ip netns exec testns1 \
  633. echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
  634. }
  635. nexthop_single_in_group_delete_test()
  636. {
  637. RET=0
  638. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  639. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  640. $IP nexthop add id 10 group 1/2
  641. $IP nexthop del id 1
  642. nexthop_check "id 10" "id 10 group 2 trap"
  643. check_err $? "Unexpected nexthop group entry"
  644. nexthop_resource_check 2
  645. check_err $? "Wrong nexthop occupancy"
  646. log_test "Single nexthop delete while in group"
  647. $IP nexthop flush &> /dev/null
  648. }
  649. nexthop_single_in_group_delete_err_test()
  650. {
  651. RET=0
  652. # First, nexthop 1 will be deleted, which will reduce the occupancy to
  653. # 5. Afterwards, a replace notification will be sent for nexthop group
  654. # 10 with only two nexthops. Since the new group is allocated before
  655. # the old is deleted, the replacement will fail as it will result in an
  656. # occupancy of 7.
  657. nexthop_resource_set 6
  658. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  659. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  660. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  661. $IP nexthop add id 10 group 1/2/3
  662. $IP nexthop del id 1
  663. nexthop_resource_check 5
  664. check_err $? "Wrong nexthop occupancy"
  665. log_test "Single nexthop delete while in group failure"
  666. $IP nexthop flush &> /dev/null
  667. nexthop_resource_set 9999
  668. }
  669. nexthop_single_in_res_group_delete_test()
  670. {
  671. RET=0
  672. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  673. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  674. $IP nexthop add id 10 group 1/2 type resilient buckets 4
  675. $IP nexthop del id 1
  676. nexthop_check "id 10" "id 10 group 2 type resilient buckets 4 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 trap"
  677. check_err $? "Unexpected nexthop group entry"
  678. nexthop_bucket_nhid_count_check 10 2 4
  679. check_err $? "Wrong nexthop buckets count"
  680. nexthop_resource_check 5
  681. check_err $? "Wrong nexthop occupancy"
  682. log_test "Single nexthop delete while in resilient group"
  683. $IP nexthop flush &> /dev/null
  684. }
  685. nexthop_single_in_res_group_delete_err_test()
  686. {
  687. RET=0
  688. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  689. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  690. $IP nexthop add id 3 via 192.0.2.4 dev dummy1
  691. $IP nexthop add id 10 group 1/2/3 type resilient buckets 6
  692. ip netns exec testns1 \
  693. echo 1 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
  694. $IP nexthop del id 1
  695. # We failed to replace the two nexthop buckets that were originally
  696. # assigned to nhid 1.
  697. nexthop_bucket_nhid_count_check 10 2 2 3 2
  698. check_err $? "Wrong nexthop buckets count"
  699. nexthop_resource_check 8
  700. check_err $? "Wrong nexthop occupancy"
  701. log_test "Single nexthop delete while in resilient group failure"
  702. $IP nexthop flush &> /dev/null
  703. ip netns exec testns1 \
  704. echo 0 > $DEBUGFS_NET_DIR/fib/fail_nexthop_bucket_replace
  705. }
  706. nexthop_replay_test()
  707. {
  708. RET=0
  709. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  710. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  711. $IP nexthop add id 10 group 1/2
  712. $DEVLINK dev reload $DEVLINK_DEV
  713. check_err $? "Failed to reload when should not"
  714. nexthop_check "id 1" "id 1 via 192.0.2.2 dev dummy1 scope link trap"
  715. check_err $? "Unexpected nexthop entry after reload"
  716. nexthop_check "id 2" "id 2 via 192.0.2.3 dev dummy1 scope link trap"
  717. check_err $? "Unexpected nexthop entry after reload"
  718. nexthop_check "id 10" "id 10 group 1/2 trap"
  719. check_err $? "Unexpected nexthop group entry after reload"
  720. nexthop_resource_check 4
  721. check_err $? "Wrong nexthop occupancy"
  722. log_test "Nexthop replay"
  723. $IP nexthop flush &> /dev/null
  724. }
  725. nexthop_replay_err_test()
  726. {
  727. RET=0
  728. $IP nexthop add id 1 via 192.0.2.2 dev dummy1
  729. $IP nexthop add id 2 via 192.0.2.3 dev dummy1
  730. $IP nexthop add id 10 group 1/2
  731. # Reduce size of nexthop resource so that reload will fail.
  732. $DEVLINK resource set $DEVLINK_DEV path nexthops size 3
  733. $DEVLINK dev reload $DEVLINK_DEV &> /dev/null
  734. check_fail $? "Reload succeeded when should fail"
  735. $DEVLINK resource set $DEVLINK_DEV path nexthops size 9999
  736. $DEVLINK dev reload $DEVLINK_DEV
  737. check_err $? "Failed to reload when should not"
  738. log_test "Nexthop replay failure"
  739. $IP nexthop flush &> /dev/null
  740. }
  741. setup_prepare()
  742. {
  743. local netdev
  744. modprobe netdevsim &> /dev/null
  745. echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
  746. while [ ! -d $SYSFS_NET_DIR ] ; do :; done
  747. set -e
  748. ip netns add testns1
  749. devlink dev reload $DEVLINK_DEV netns testns1
  750. IP="ip -netns testns1"
  751. DEVLINK="devlink -N testns1"
  752. $IP link add name dummy1 up type dummy
  753. $IP address add 192.0.2.1/24 dev dummy1
  754. set +e
  755. }
  756. cleanup()
  757. {
  758. pre_cleanup
  759. ip netns del testns1
  760. echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
  761. modprobe -r netdevsim &> /dev/null
  762. }
  763. trap cleanup EXIT
  764. setup_prepare
  765. tests_run
  766. exit $EXIT_STATUS