2 # SPDX-License-Identifier: GPL-2.0
4 # Test unicast FIB offload indication.
6 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
11 ipv6_route_nexthop_group_share
15 source $lib_dir/lib.sh
16 source $lib_dir/devlink_lib.sh
20 simple_if_init
$tor1_p1 2001:db8
:1::2/128 2001:db8
:1::3/128
25 simple_if_fini
$tor1_p1 2001:db8
:1::2/128 2001:db8
:1::3/128
30 simple_if_init
$tor2_p1 2001:db8
:2::2/128 2001:db8
:2::3/128
35 simple_if_fini
$tor2_p1 2001:db8
:2::2/128 2001:db8
:2::3/128
40 ip link
set dev
$spine_p1 up
41 ip link
set dev
$spine_p2 up
43 __addr_add_del
$spine_p1 add
2001:db8
:1::1/64
44 __addr_add_del
$spine_p2 add
2001:db8
:2::1/64
49 __addr_add_del
$spine_p2 del
2001:db8
:2::1/64
50 __addr_add_del
$spine_p1 del
2001:db8
:1::1/64
52 ip link
set dev
$spine_p2 down
53 ip link
set dev
$spine_p1 down
59 local expected_num
=$1; shift
62 # Try to avoid races with route offload
65 num
=$
(ip
-6 route show match
${pfx} |
grep "offload" |
wc -l)
67 if [ $num -eq $expected_num ]; then
74 ipv6_route_add_prefix
()
78 # Add a prefix route and check that it is offloaded.
79 ip
-6 route add
2001:db8
:3::/64 dev
$spine_p1 metric
100
80 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 100" 1
81 check_err $?
"prefix route not offloaded"
83 # Append an identical prefix route with an higher metric and check that
84 # offload indication did not change.
85 ip
-6 route append
2001:db8
:3::/64 dev
$spine_p1 metric
200
86 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 100" 1
87 check_err $?
"lowest metric not offloaded after append"
88 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 200" 0
89 check_err $?
"highest metric offloaded when should not"
91 # Prepend an identical prefix route with lower metric and check that
92 # it is offloaded and the others are not.
93 ip
-6 route append
2001:db8
:3::/64 dev
$spine_p1 metric
10
94 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 10" 1
95 check_err $?
"lowest metric not offloaded after prepend"
96 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 100" 0
97 check_err $?
"mid metric offloaded when should not"
98 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p1 metric 200" 0
99 check_err $?
"highest metric offloaded when should not"
101 # Delete the routes and add the same route with a different nexthop
102 # device. Check that it is offloaded.
103 ip
-6 route flush
2001:db8
:3::/64 dev
$spine_p1
104 ip
-6 route add
2001:db8
:3::/64 dev
$spine_p2
105 ipv6_offload_check
"2001:db8:3::/64 dev $spine_p2" 1
107 log_test
"IPv6 prefix route add"
109 ip
-6 route flush
2001:db8
:3::/64
112 ipv6_route_add_mpath
()
116 # Add a multipath route and check that it is offloaded.
117 ip
-6 route add
2001:db8
:3::/64 metric
100 \
118 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
119 nexthop via
2001:db8
:2::2 dev
$spine_p2
120 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
121 check_err $?
"multipath route not offloaded when should"
123 # Append another nexthop and check that it is offloaded as well.
124 ip
-6 route append
2001:db8
:3::/64 metric
100 \
125 nexthop via
2001:db8
:1::3 dev
$spine_p1
126 ipv6_offload_check
"2001:db8:3::/64 metric 100" 3
127 check_err $?
"appended nexthop not offloaded when should"
129 # Mimic route replace by removing the route and adding it back with
131 ip
-6 route del
2001:db8
:3::/64
132 ip
-6 route add
2001:db8
:3::/64 metric
100 \
133 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
134 nexthop via
2001:db8
:2::2 dev
$spine_p2
135 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
136 check_err $?
"multipath route not offloaded after delete & add"
138 # Append a nexthop with an higher metric and check that the offload
139 # indication did not change.
140 ip
-6 route append
2001:db8
:3::/64 metric
200 \
141 nexthop via
2001:db8
:1::3 dev
$spine_p1
142 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
143 check_err $?
"lowest metric not offloaded after append"
144 ipv6_offload_check
"2001:db8:3::/64 metric 200" 0
145 check_err $?
"highest metric offloaded when should not"
147 # Prepend a nexthop with a lower metric and check that it is offloaded
148 # and the others are not.
149 ip
-6 route append
2001:db8
:3::/64 metric
10 \
150 nexthop via
2001:db8
:1::3 dev
$spine_p1
151 ipv6_offload_check
"2001:db8:3::/64 metric 10" 1
152 check_err $?
"lowest metric not offloaded after prepend"
153 ipv6_offload_check
"2001:db8:3::/64 metric 100" 0
154 check_err $?
"mid metric offloaded when should not"
155 ipv6_offload_check
"2001:db8:3::/64 metric 200" 0
156 check_err $?
"highest metric offloaded when should not"
158 log_test
"IPv6 multipath route add"
160 ip
-6 route flush
2001:db8
:3::/64
165 ipv6_route_add_prefix
173 # Replace prefix route with prefix route.
174 ip
-6 route add
2001:db8
:3::/64 metric
100 dev
$spine_p1
175 ipv6_offload_check
"2001:db8:3::/64 metric 100" 1
176 check_err $?
"prefix route not offloaded when should"
177 ip
-6 route replace
2001:db8
:3::/64 metric
100 dev
$spine_p2
178 ipv6_offload_check
"2001:db8:3::/64 metric 100" 1
179 check_err $?
"prefix route not offloaded after replace"
181 # Replace prefix route with multipath route.
182 ip
-6 route replace
2001:db8
:3::/64 metric
100 \
183 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
184 nexthop via
2001:db8
:2::2 dev
$spine_p2
185 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
186 check_err $?
"multipath route not offloaded after replace"
188 # Replace multipath route with prefix route. A prefix route cannot
189 # replace a multipath route, so it is appended.
190 ip
-6 route replace
2001:db8
:3::/64 metric
100 dev
$spine_p1
191 ipv6_offload_check
"2001:db8:3::/64 metric 100 dev $spine_p1" 0
192 check_err $?
"prefix route offloaded after 'replacing' multipath route"
193 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
194 check_err $?
"multipath route not offloaded after being 'replaced' by prefix route"
196 # Replace multipath route with multipath route.
197 ip
-6 route replace
2001:db8
:3::/64 metric
100 \
198 nexthop via
2001:db8
:1::3 dev
$spine_p1 \
199 nexthop via
2001:db8
:2::3 dev
$spine_p2
200 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
201 check_err $?
"multipath route not offloaded after replacing multipath route"
203 # Replace a non-existing multipath route with a multipath route and
204 # check that it is appended and not offloaded.
205 ip
-6 route replace
2001:db8
:3::/64 metric
200 \
206 nexthop via
2001:db8
:1::3 dev
$spine_p1 \
207 nexthop via
2001:db8
:2::3 dev
$spine_p2
208 ipv6_offload_check
"2001:db8:3::/64 metric 100" 2
209 check_err $?
"multipath route not offloaded after non-existing route was 'replaced'"
210 ipv6_offload_check
"2001:db8:3::/64 metric 200" 0
211 check_err $?
"multipath route offloaded after 'replacing' non-existing route"
213 log_test
"IPv6 route replace"
215 ip
-6 route flush
2001:db8
:3::/64
218 ipv6_route_nexthop_group_share
()
222 # The driver consolidates identical nexthop groups in order to reduce
223 # the resource usage in its adjacency table. Check that the deletion
224 # of one multipath route using the group does not affect the other.
225 ip
-6 route add
2001:db8
:3::/64 \
226 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
227 nexthop via
2001:db8
:2::2 dev
$spine_p2
228 ip
-6 route add
2001:db8
:4::/64 \
229 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
230 nexthop via
2001:db8
:2::2 dev
$spine_p2
231 ipv6_offload_check
"2001:db8:3::/64" 2
232 check_err $?
"multipath route not offloaded when should"
233 ipv6_offload_check
"2001:db8:4::/64" 2
234 check_err $?
"multipath route not offloaded when should"
235 ip
-6 route del
2001:db8
:3::/64
236 ipv6_offload_check
"2001:db8:4::/64" 2
237 check_err $?
"multipath route not offloaded after deletion of route sharing the nexthop group"
239 # Check that after unsharing a nexthop group the routes are still
240 # marked as offloaded.
241 ip
-6 route add
2001:db8
:3::/64 \
242 nexthop via
2001:db8
:1::2 dev
$spine_p1 \
243 nexthop via
2001:db8
:2::2 dev
$spine_p2
244 ip
-6 route del
2001:db8
:4::/64 \
245 nexthop via
2001:db8
:1::2 dev
$spine_p1
246 ipv6_offload_check
"2001:db8:4::/64" 1
247 check_err $?
"singlepath route not offloaded after unsharing the nexthop group"
248 ipv6_offload_check
"2001:db8:3::/64" 2
249 check_err $?
"multipath route not offloaded after unsharing the nexthop group"
251 log_test
"IPv6 nexthop group sharing"
253 ip
-6 route flush
2001:db8
:3::/64
254 ip
-6 route flush
2001:db8
:4::/64
259 local batch_dir
=$
(mktemp
-d)
260 local num_rts
=$
((40 * 1024))
271 # Prepare 40K /64 multipath routes with 16 nexthops each and check how
272 # long it takes to add them. A limit of 60 seconds is set. It is much
273 # higher than insertion should take and meant to flag a serious
275 total
=$
((nums_nhs
* num_rts
))
277 for i
in $
(seq 1 $num_nhs); do
278 ip
-6 address add
2001:db8
:1::10:$i/128 dev
$tor1_p1
279 nexthops
+=" nexthop via 2001:db8:1::10:$i dev $spine_p1"
282 for i
in $
(seq 1 $num_rts); do
283 echo "route add 2001:db8:8:$(printf "%x
" $i)::/64$nexthops" \
284 >> $batch_dir/add.
batch
285 echo "route del 2001:db8:8:$(printf "%x
" $i)::/64$nexthops" \
286 >> $batch_dir/del.
batch
291 ip
-batch $batch_dir/add.
batch
292 count
=$
(ip
-6 route show |
grep offload |
wc -l)
293 while [ $count -lt $total ]; do
295 count
=$
(ip
-6 route show |
grep offload |
wc -l)
300 diff=$
(echo "$end - $start" |
bc -l)
301 test "$(echo "$diff > 60" | bc -l)" -eq 0
302 check_err $?
"route insertion took too long"
303 log_info
"inserted $num_rts routes in $diff seconds"
305 log_test
"IPv6 routes insertion rate"
307 ip
-batch $batch_dir/del.
batch
308 for i
in $
(seq 1 $num_nhs); do
309 ip
-6 address del
2001:db8
:1::10:$i/128 dev
$tor1_p1
316 spine_p1
=${NETIFS[p1]}
317 tor1_p1
=${NETIFS[p2]}
319 spine_p2
=${NETIFS[p3]}
320 tor2_p1
=${NETIFS[p4]}