WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / fib_offload_lib.sh
blob66496659bea70656faf10931a1ddae135d876313
1 # SPDX-License-Identifier: GPL-2.0
3 # Various helpers and tests to verify FIB offload.
5 __fib_trap_check()
7 local ns=$1; shift
8 local family=$1; shift
9 local route=$1; shift
10 local should_fail=$1; shift
11 local ret
13 ip -n $ns -j -p -$family route show $route \
14 | jq -e '.[]["flags"] | contains(["trap"])' &> /dev/null
15 ret=$?
16 if [[ $should_fail == "true" ]]; then
17 if [[ $ret -ne 0 ]]; then
18 return 0
19 else
20 return 1
24 return $ret
27 fib_trap_check()
29 local ns=$1; shift
30 local family=$1; shift
31 local route=$1; shift
32 local should_fail=$1; shift
34 busywait 5000 __fib_trap_check $ns $family "$route" $should_fail
37 fib4_trap_check()
39 local ns=$1; shift
40 local route=$1; shift
41 local should_fail=$1; shift
43 fib_trap_check $ns 4 "$route" $should_fail
46 fib6_trap_check()
48 local ns=$1; shift
49 local route=$1; shift
50 local should_fail=$1; shift
52 fib_trap_check $ns 6 "$route" $should_fail
55 fib_ipv4_identical_routes_test()
57 local ns=$1; shift
58 local i
60 RET=0
62 for i in $(seq 1 3); do
63 ip -n $ns link add name dummy$i type dummy
64 ip -n $ns link set dev dummy$i up
65 done
67 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 0 metric 1024
68 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 0 metric 1024" false
69 check_err $? "Route not in hardware when should"
71 ip -n $ns route append 192.0.2.0/24 dev dummy2 tos 0 metric 1024
72 fib4_trap_check $ns "192.0.2.0/24 dev dummy2 tos 0 metric 1024" true
73 check_err $? "Appended route in hardware when should not"
75 ip -n $ns route prepend 192.0.2.0/24 dev dummy3 tos 0 metric 1024
76 fib4_trap_check $ns "192.0.2.0/24 dev dummy3 tos 0 metric 1024" false
77 check_err $? "Prepended route not in hardware when should"
79 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 0 metric 1024" true
80 check_err $? "Route was not replaced in hardware by prepended one"
82 log_test "IPv4 identical routes"
84 for i in $(seq 1 3); do
85 ip -n $ns link del dev dummy$i
86 done
89 fib_ipv4_tos_test()
91 local ns=$1; shift
93 RET=0
95 ip -n $ns link add name dummy1 type dummy
96 ip -n $ns link set dev dummy1 up
98 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 0 metric 1024
99 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 0 metric 1024" false
100 check_err $? "Route not in hardware when should"
102 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 2 metric 1024
103 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 2 metric 1024" false
104 check_err $? "Highest TOS route not in hardware when should"
106 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 0 metric 1024" true
107 check_err $? "Lowest TOS route still in hardware when should not"
109 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 1 metric 1024
110 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 1 metric 1024" true
111 check_err $? "Middle TOS route in hardware when should not"
113 log_test "IPv4 routes with TOS"
115 ip -n $ns link del dev dummy1
118 fib_ipv4_metric_test()
120 local ns=$1; shift
122 RET=0
124 ip -n $ns link add name dummy1 type dummy
125 ip -n $ns link set dev dummy1 up
127 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1024
128 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1024" false
129 check_err $? "Route not in hardware when should"
131 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1022
132 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1022" false
133 check_err $? "Lowest metric route not in hardware when should"
135 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1024" true
136 check_err $? "Highest metric route still in hardware when should not"
138 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1023
139 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1023" true
140 check_err $? "Middle metric route in hardware when should not"
142 log_test "IPv4 routes with metric"
144 ip -n $ns link del dev dummy1
147 fib_ipv4_replace_test()
149 local ns=$1; shift
150 local i
152 RET=0
154 for i in $(seq 1 2); do
155 ip -n $ns link add name dummy$i type dummy
156 ip -n $ns link set dev dummy$i up
157 done
159 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1024
160 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1024" false
161 check_err $? "Route not in hardware when should"
163 ip -n $ns route replace 192.0.2.0/24 dev dummy2 metric 1024
164 fib4_trap_check $ns "192.0.2.0/24 dev dummy2 metric 1024" false
165 check_err $? "Replacement route not in hardware when should"
167 # Add a route with an higher metric and make sure that replacing it
168 # does not affect the lower metric one.
169 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1025
170 ip -n $ns route replace 192.0.2.0/24 dev dummy2 metric 1025
172 fib4_trap_check $ns "192.0.2.0/24 dev dummy2 metric 1024" false
173 check_err $? "Lowest metric route not in hardware when should"
174 fib4_trap_check $ns "192.0.2.0/24 dev dummy2 metric 1025" true
175 check_err $? "Highest metric route in hardware when should not"
177 log_test "IPv4 route replace"
179 for i in $(seq 1 2); do
180 ip -n $ns link del dev dummy$i
181 done
184 fib_ipv4_delete_test()
186 local ns=$1; shift
187 local metric
189 RET=0
191 ip -n $ns link add name dummy1 type dummy
192 ip -n $ns link set dev dummy1 up
194 # Insert multiple routes with the same prefix and length and varying
195 # metrics. Make sure that throughout delete operations the lowest
196 # metric route is the one in hardware.
197 for metric in $(seq 1024 1026); do
198 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric $metric
199 done
201 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1024" false
202 check_err $? "Route not in hardware when should"
204 ip -n $ns route del 192.0.2.0/24 dev dummy1 metric 1024
205 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1025" false
206 check_err $? "Lowest metric route not in hardware when should"
208 ip -n $ns route del 192.0.2.0/24 dev dummy1 metric 1026
209 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1025" false
210 check_err $? "Sole route not in hardware when should"
212 log_test "IPv4 route delete"
214 ip -n $ns link del dev dummy1
217 fib_ipv4_plen_test()
219 local ns=$1; shift
221 RET=0
223 ip -n $ns link add name dummy1 type dummy
224 ip -n $ns link set dev dummy1 up
226 # Add two routes with the same key and different prefix length and
227 # make sure both are in hardware. It can be verfied that both are
228 # sharing the same leaf by checking the /proc/net/fib_trie
229 ip -n $ns route add 192.0.2.0/24 dev dummy1
230 ip -n $ns route add 192.0.2.0/25 dev dummy1
232 fib4_trap_check $ns "192.0.2.0/24 dev dummy1" false
233 check_err $? "/24 not in hardware when should"
235 fib4_trap_check $ns "192.0.2.0/25 dev dummy1" false
236 check_err $? "/25 not in hardware when should"
238 log_test "IPv4 routes with different prefix length"
240 ip -n $ns link del dev dummy1
243 fib_ipv4_replay_metric_test()
245 local ns=$1; shift
246 local devlink_dev=$1; shift
248 RET=0
250 ip -n $ns link add name dummy1 type dummy
251 ip -n $ns link set dev dummy1 up
253 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1024
254 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric 1025
256 devlink -N $ns dev reload $devlink_dev
258 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1024" false
259 check_err $? "Lowest metric route not in hardware when should"
261 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 metric 1025" true
262 check_err $? "Highest metric route in hardware when should not"
264 log_test "IPv4 routes replay - metric"
266 ip -n $ns link del dev dummy1
269 fib_ipv4_replay_tos_test()
271 local ns=$1; shift
272 local devlink_dev=$1; shift
274 RET=0
276 ip -n $ns link add name dummy1 type dummy
277 ip -n $ns link set dev dummy1 up
279 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 0
280 ip -n $ns route add 192.0.2.0/24 dev dummy1 tos 1
282 devlink -N $ns dev reload $devlink_dev
284 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 1" false
285 check_err $? "Highest TOS route not in hardware when should"
287 fib4_trap_check $ns "192.0.2.0/24 dev dummy1 tos 0" true
288 check_err $? "Lowest TOS route in hardware when should not"
290 log_test "IPv4 routes replay - TOS"
292 ip -n $ns link del dev dummy1
295 fib_ipv4_replay_plen_test()
297 local ns=$1; shift
298 local devlink_dev=$1; shift
300 RET=0
302 ip -n $ns link add name dummy1 type dummy
303 ip -n $ns link set dev dummy1 up
305 ip -n $ns route add 192.0.2.0/24 dev dummy1
306 ip -n $ns route add 192.0.2.0/25 dev dummy1
308 devlink -N $ns dev reload $devlink_dev
310 fib4_trap_check $ns "192.0.2.0/24 dev dummy1" false
311 check_err $? "/24 not in hardware when should"
313 fib4_trap_check $ns "192.0.2.0/25 dev dummy1" false
314 check_err $? "/25 not in hardware when should"
316 log_test "IPv4 routes replay - prefix length"
318 ip -n $ns link del dev dummy1
321 fib_ipv4_flush_test()
323 local ns=$1; shift
324 local metric
326 RET=0
328 ip -n $ns link add name dummy1 type dummy
329 ip -n $ns link set dev dummy1 up
331 # Exercise the routes flushing code paths by inserting various
332 # prefix routes on a netdev and then deleting it.
333 for metric in $(seq 1 20); do
334 ip -n $ns route add 192.0.2.0/24 dev dummy1 metric $metric
335 done
337 ip -n $ns link del dev dummy1
339 log_test "IPv4 routes flushing"
342 fib_ipv6_add_test()
344 local ns=$1; shift
346 RET=0
348 for i in $(seq 1 2); do
349 ip -n $ns link add name dummy$i type dummy
350 ip -n $ns link set dev dummy$i up
351 done
353 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1024
354 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1024" false
355 check_err $? "Route not in hardware when should"
357 ip -n $ns route append 2001:db8:1::/64 dev dummy2 metric 1024
358 fib6_trap_check $ns "2001:db8:1::/64 dev dummy2 metric 1024" true
359 check_err $? "Route in hardware when should not"
361 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1024" false
362 check_err $? "Route not in hardware after appending route"
364 log_test "IPv6 single route add"
366 for i in $(seq 1 2); do
367 ip -n $ns link del dev dummy$i
368 done
371 fib_ipv6_metric_test()
373 local ns=$1; shift
375 RET=0
377 ip -n $ns link add name dummy1 type dummy
378 ip -n $ns link set dev dummy1 up
380 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1024
381 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1024" false
382 check_err $? "Route not in hardware when should"
384 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1022
385 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1022" false
386 check_err $? "Lowest metric route not in hardware when should"
388 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1024" true
389 check_err $? "Highest metric route still in hardware when should not"
391 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1023
392 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1023" true
393 check_err $? "Middle metric route in hardware when should not"
395 log_test "IPv6 routes with metric"
397 ip -n $ns link del dev dummy1
400 fib_ipv6_append_single_test()
402 local ns=$1; shift
404 # When an IPv6 multipath route is added without the 'nexthop' keyword,
405 # different code paths are taken compared to when the keyword is used.
406 # This test tries to verify the former.
407 RET=0
409 for i in $(seq 1 2); do
410 ip -n $ns link add name dummy$i type dummy
411 ip -n $ns link set dev dummy$i up
412 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
413 done
415 ip -n $ns route add 2001:db8:10::/64 via 2001:db8:1::2 metric 1024
416 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
417 check_err $? "Route not in hardware when should"
419 ip -n $ns route append 2001:db8:10::/64 via 2001:db8:2::2 metric 1024
420 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
421 check_err $? "Route not in hardware after appending"
423 ip -n $ns route add 2001:db8:10::/64 via 2001:db8:1::2 metric 1025
424 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
425 check_err $? "Route in hardware when should not"
427 ip -n $ns route append 2001:db8:10::/64 via 2001:db8:2::2 metric 1025
428 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
429 check_err $? "Route in hardware when should not after appending"
431 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
432 check_err $? "Lowest metric route not in hardware when should"
434 log_test "IPv6 append single route without 'nexthop' keyword"
436 for i in $(seq 1 2); do
437 ip -n $ns link del dev dummy$i
438 done
441 fib_ipv6_replace_single_test()
443 local ns=$1; shift
444 local i
446 RET=0
448 for i in $(seq 1 2); do
449 ip -n $ns link add name dummy$i type dummy
450 ip -n $ns link set dev dummy$i up
451 done
453 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1024
454 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1 metric 1024" false
455 check_err $? "Route not in hardware when should"
457 ip -n $ns route replace 2001:db8:1::/64 dev dummy2 metric 1024
458 fib6_trap_check $ns "2001:db8:1::/64 dev dummy2 metric 1024" false
459 check_err $? "Replacement route not in hardware when should"
461 # Add a route with an higher metric and make sure that replacing it
462 # does not affect the lower metric one.
463 ip -n $ns route add 2001:db8:1::/64 dev dummy1 metric 1025
464 ip -n $ns route replace 2001:db8:1::/64 dev dummy2 metric 1025
466 fib6_trap_check $ns "2001:db8:1::/64 dev dummy2 metric 1024" false
467 check_err $? "Lowest metric route not in hardware when should"
468 fib6_trap_check $ns "2001:db8:1::/64 dev dummy2 metric 1025" true
469 check_err $? "Highest metric route in hardware when should not"
471 log_test "IPv6 single route replace"
473 for i in $(seq 1 2); do
474 ip -n $ns link del dev dummy$i
475 done
478 fib_ipv6_metric_multipath_test()
480 local ns=$1; shift
482 RET=0
484 for i in $(seq 1 2); do
485 ip -n $ns link add name dummy$i type dummy
486 ip -n $ns link set dev dummy$i up
487 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
488 done
490 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
491 nexthop via 2001:db8:1::2 dev dummy1 \
492 nexthop via 2001:db8:2::2 dev dummy2
493 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
494 check_err $? "Route not in hardware when should"
496 ip -n $ns route add 2001:db8:10::/64 metric 1022 \
497 nexthop via 2001:db8:1::2 dev dummy1 \
498 nexthop via 2001:db8:2::2 dev dummy2
499 fib6_trap_check $ns "2001:db8:10::/64 metric 1022" false
500 check_err $? "Lowest metric route not in hardware when should"
502 ip -n $ns route add 2001:db8:10::/64 metric 1023 \
503 nexthop via 2001:db8:1::2 dev dummy1 \
504 nexthop via 2001:db8:2::2 dev dummy2
505 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" true
506 check_err $? "Highest metric route still in hardware when should not"
508 fib6_trap_check $ns "2001:db8:10::/64 metric 1023" true
509 check_err $? "Middle metric route in hardware when should not"
511 log_test "IPv6 multipath routes with metric"
513 for i in $(seq 1 2); do
514 ip -n $ns link del dev dummy$i
515 done
518 fib_ipv6_append_multipath_test()
520 local ns=$1; shift
522 RET=0
524 for i in $(seq 1 3); do
525 ip -n $ns link add name dummy$i type dummy
526 ip -n $ns link set dev dummy$i up
527 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
528 done
530 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
531 nexthop via 2001:db8:1::2 dev dummy1
532 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
533 check_err $? "Route not in hardware when should"
535 ip -n $ns route append 2001:db8:10::/64 metric 1024 \
536 nexthop via 2001:db8:2::2 dev dummy2 \
537 nexthop via 2001:db8:3::2 dev dummy3
538 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
539 check_err $? "Route not in hardware after appending"
541 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
542 nexthop via 2001:db8:1::2 dev dummy1
543 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
544 check_err $? "Route in hardware when should not"
546 ip -n $ns route append 2001:db8:10::/64 metric 1025 \
547 nexthop via 2001:db8:2::2 dev dummy2 \
548 nexthop via 2001:db8:3::2 dev dummy3
549 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
550 check_err $? "Route in hardware when should not after appending"
552 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
553 check_err $? "Lowest metric route not in hardware when should"
555 log_test "IPv6 append multipath route with 'nexthop' keyword"
557 for i in $(seq 1 3); do
558 ip -n $ns link del dev dummy$i
559 done
562 fib_ipv6_replace_multipath_test()
564 local ns=$1; shift
565 local i
567 RET=0
569 for i in $(seq 1 3); do
570 ip -n $ns link add name dummy$i type dummy
571 ip -n $ns link set dev dummy$i up
572 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
573 done
575 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
576 nexthop via 2001:db8:1::2 dev dummy1 \
577 nexthop via 2001:db8:2::2 dev dummy2
578 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
579 check_err $? "Route not in hardware when should"
581 ip -n $ns route replace 2001:db8:10::/64 metric 1024 \
582 nexthop via 2001:db8:1::2 dev dummy1 \
583 nexthop via 2001:db8:3::2 dev dummy3
584 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
585 check_err $? "Replacement route not in hardware when should"
587 # Add a route with an higher metric and make sure that replacing it
588 # does not affect the lower metric one.
589 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
590 nexthop via 2001:db8:1::2 dev dummy1 \
591 nexthop via 2001:db8:2::2 dev dummy2
592 ip -n $ns route replace 2001:db8:10::/64 metric 1025 \
593 nexthop via 2001:db8:1::2 dev dummy1 \
594 nexthop via 2001:db8:3::2 dev dummy3
596 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
597 check_err $? "Lowest metric route not in hardware when should"
598 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
599 check_err $? "Highest metric route in hardware when should not"
601 log_test "IPv6 multipath route replace"
603 for i in $(seq 1 3); do
604 ip -n $ns link del dev dummy$i
605 done
608 fib_ipv6_append_multipath_to_single_test()
610 local ns=$1; shift
612 # Test that when the first route in the leaf is not a multipath route
613 # and we try to append a multipath route with the same metric to it, it
614 # is not notified.
615 RET=0
617 for i in $(seq 1 2); do
618 ip -n $ns link add name dummy$i type dummy
619 ip -n $ns link set dev dummy$i up
620 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
621 done
623 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1024
624 fib6_trap_check $ns "2001:db8:10::/64 dev dummy1 metric 1024" false
625 check_err $? "Route not in hardware when should"
627 ip -n $ns route append 2001:db8:10::/64 metric 1024 \
628 nexthop via 2001:db8:2::2 dev dummy2
629 fib6_trap_check $ns "2001:db8:10::/64 dev dummy2 metric 1024" true
630 check_err $? "Route in hardware when should not"
632 fib6_trap_check $ns "2001:db8:10::/64 dev dummy1 metric 1024" false
633 check_err $? "Route not in hardware after append"
635 log_test "IPv6 append multipath route to non-multipath route"
637 for i in $(seq 1 2); do
638 ip -n $ns link del dev dummy$i
639 done
642 fib_ipv6_delete_single_test()
644 local ns=$1; shift
646 # Test various deletion scenarios, where only a single route is
647 # deleted from the FIB node.
648 for i in $(seq 1 2); do
649 ip -n $ns link add name dummy$i type dummy
650 ip -n $ns link set dev dummy$i up
651 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
652 done
654 # Test deletion of a single route when it is the only route in the FIB
655 # node.
656 RET=0
658 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1024
659 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1024
661 log_test "IPv6 delete sole single route"
663 # Test that deletion of last route does not affect the first one.
664 RET=0
666 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1024
667 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1025
668 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1025
670 fib6_trap_check $ns "2001:db8:10::/64 dev dummy1 metric 1024" false
671 check_err $? "Route not in hardware after deleting higher metric route"
673 log_test "IPv6 delete single route not in hardware"
675 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1024
677 # Test that first route is replaced by next single route in the FIB
678 # node.
679 RET=0
681 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1024
682 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1025
683 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1024
685 fib6_trap_check $ns "2001:db8:10::/64 dev dummy1 metric 1025" false
686 check_err $? "Route not in hardware after deleting lowest metric route"
688 log_test "IPv6 delete single route - replaced by single"
690 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1025
692 # Test that first route is replaced by next multipath route in the FIB
693 # node.
694 RET=0
696 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1024
697 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
698 nexthop via 2001:db8:1::2 dev dummy1 \
699 nexthop via 2001:db8:2::2 dev dummy2
700 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1024
702 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" false
703 check_err $? "Route not in hardware after deleting lowest metric route"
705 log_test "IPv6 delete single route - replaced by multipath"
707 ip -n $ns route del 2001:db8:10::/64 metric 1025
709 # Test deletion of a single nexthop from a multipath route.
710 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
711 nexthop via 2001:db8:1::2 dev dummy1 \
712 nexthop via 2001:db8:2::2 dev dummy2
713 ip -n $ns route del 2001:db8:10::/64 metric 1024 \
714 nexthop via 2001:db8:1::2 dev dummy1
716 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
717 check_err $? "Route not in hardware after deleting a single nexthop"
719 log_test "IPv6 delete single nexthop"
721 ip -n $ns route del 2001:db8:10::/64 metric 1024
723 for i in $(seq 1 2); do
724 ip -n $ns link del dev dummy$i
725 done
728 fib_ipv6_delete_multipath_test()
730 local ns=$1; shift
732 # Test various deletion scenarios, where an entire multipath route is
733 # deleted from the FIB node.
734 for i in $(seq 1 2); do
735 ip -n $ns link add name dummy$i type dummy
736 ip -n $ns link set dev dummy$i up
737 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
738 done
740 # Test deletion of a multipath route when it is the only route in the
741 # FIB node.
742 RET=0
744 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
745 nexthop via 2001:db8:1::2 dev dummy1 \
746 nexthop via 2001:db8:2::2 dev dummy2
747 ip -n $ns route del 2001:db8:10::/64 metric 1024
749 log_test "IPv6 delete sole multipath route"
751 # Test that deletion of last route does not affect the first one.
752 RET=0
754 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
755 nexthop via 2001:db8:1::2 dev dummy1 \
756 nexthop via 2001:db8:2::2 dev dummy2
757 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
758 nexthop via 2001:db8:1::2 dev dummy1 \
759 nexthop via 2001:db8:2::2 dev dummy2
760 ip -n $ns route del 2001:db8:10::/64 metric 1025
762 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
763 check_err $? "Route not in hardware after deleting higher metric route"
765 log_test "IPv6 delete multipath route not in hardware"
767 ip -n $ns route del 2001:db8:10::/64 metric 1024
769 # Test that first route is replaced by next single route in the FIB
770 # node.
771 RET=0
773 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
774 nexthop via 2001:db8:1::2 dev dummy1 \
775 nexthop via 2001:db8:2::2 dev dummy2
776 ip -n $ns route add 2001:db8:10::/64 dev dummy1 metric 1025
777 ip -n $ns route del 2001:db8:10::/64 metric 1024
779 fib6_trap_check $ns "2001:db8:10::/64 dev dummy1 metric 1025" false
780 check_err $? "Route not in hardware after deleting lowest metric route"
782 log_test "IPv6 delete multipath route - replaced by single"
784 ip -n $ns route del 2001:db8:10::/64 dev dummy1 metric 1025
786 # Test that first route is replaced by next multipath route in the FIB
787 # node.
788 RET=0
790 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
791 nexthop via 2001:db8:1::2 dev dummy1 \
792 nexthop via 2001:db8:2::2 dev dummy2
793 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
794 nexthop via 2001:db8:1::2 dev dummy1 \
795 nexthop via 2001:db8:2::2 dev dummy2
796 ip -n $ns route del 2001:db8:10::/64 metric 1024
798 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" false
799 check_err $? "Route not in hardware after deleting lowest metric route"
801 log_test "IPv6 delete multipath route - replaced by multipath"
803 ip -n $ns route del 2001:db8:10::/64 metric 1025
805 for i in $(seq 1 2); do
806 ip -n $ns link del dev dummy$i
807 done
810 fib_ipv6_replay_single_test()
812 local ns=$1; shift
813 local devlink_dev=$1; shift
815 RET=0
817 for i in $(seq 1 2); do
818 ip -n $ns link add name dummy$i type dummy
819 ip -n $ns link set dev dummy$i up
820 done
822 ip -n $ns route add 2001:db8:1::/64 dev dummy1
823 ip -n $ns route append 2001:db8:1::/64 dev dummy2
825 devlink -N $ns dev reload $devlink_dev
827 fib6_trap_check $ns "2001:db8:1::/64 dev dummy1" false
828 check_err $? "First route not in hardware when should"
830 fib6_trap_check $ns "2001:db8:1::/64 dev dummy2" true
831 check_err $? "Second route in hardware when should not"
833 log_test "IPv6 routes replay - single route"
835 for i in $(seq 1 2); do
836 ip -n $ns link del dev dummy$i
837 done
840 fib_ipv6_replay_multipath_test()
842 local ns=$1; shift
843 local devlink_dev=$1; shift
845 RET=0
847 for i in $(seq 1 2); do
848 ip -n $ns link add name dummy$i type dummy
849 ip -n $ns link set dev dummy$i up
850 ip -n $ns address add 2001:db8:$i::1/64 dev dummy$i
851 done
853 ip -n $ns route add 2001:db8:10::/64 metric 1024 \
854 nexthop via 2001:db8:1::2 dev dummy1 \
855 nexthop via 2001:db8:2::2 dev dummy2
856 ip -n $ns route add 2001:db8:10::/64 metric 1025 \
857 nexthop via 2001:db8:1::2 dev dummy1 \
858 nexthop via 2001:db8:2::2 dev dummy2
860 devlink -N $ns dev reload $devlink_dev
862 fib6_trap_check $ns "2001:db8:10::/64 metric 1024" false
863 check_err $? "First route not in hardware when should"
865 fib6_trap_check $ns "2001:db8:10::/64 metric 1025" true
866 check_err $? "Second route in hardware when should not"
868 log_test "IPv6 routes replay - multipath route"
870 for i in $(seq 1 2); do
871 ip -n $ns link del dev dummy$i
872 done