2 # SPDX-License-Identifier: GPL-2.0
4 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
14 NETDEVSIM_PATH
=/sys
/bus
/netdevsim
/
19 source $lib_dir/lib.sh
33 echo netdevsim$
(DEV_ADDR
$1)
38 echo netdevsim
/$
(DEV
$1)
43 echo /sys
/bus
/netdevsim
/devices
/$
(DEV
$1)/net
/
48 echo /sys
/kernel
/debug
/netdevsim
/$
(DEV
$1)/
55 echo "$(DEV_ADDR $n) 1" > ${NETDEVSIM_PATH}/new_device
56 while [ ! -d $
(SYSFS_NET_DIR
$n) ] ; do :; done
64 devlink dev reload $
(DEVLINK_DEV
$n) netns
$ns
67 echo "Failed to reload $(DEV $n) into netns \"testns1\""
77 echo "$(DEV_ADDR $n)" > ${NETDEVSIM_PATH}/del_device
82 local action
=$1; shift
83 local instance
=$1; shift
84 local netdev
=$1; shift
87 local ifindex
=$
($IP -j link show dev
$netdev | jq
'.[].ifindex')
89 echo $ifindex > $
(DEBUGFS_DIR
$instance)/hwstats
/$type/$action
94 nsim_hwstats_toggle enable_ifindex
"$@"
97 nsim_hwstats_disable
()
99 nsim_hwstats_toggle disable_ifindex
"$@"
102 nsim_hwstats_fail_next_enable
()
104 nsim_hwstats_toggle fail_next_enable
"$@"
109 modprobe netdevsim
&> /dev
/null
116 if [ $?
-ne 0 ]; then
117 echo "Failed to add netns \"testns1\""
121 nsim_reload
1 testns1
122 nsim_reload
2 testns1
123 nsim_reload
3 testns1
127 $IP link add name dummy1
type dummy
128 $IP link
set dev dummy1 up
129 DUMMY_IFINDEX
=$
($IP -j link show dev dummy1 | jq
'.[].ifindex')
136 $IP link del name dummy1
141 modprobe
-r netdevsim
&> /dev
/null
144 netdev_hwstats_used
()
146 local netdev
=$1; shift
149 $IP -j stats show dev
"$netdev" group offload subgroup hw_stats_info |
150 jq
'.[].info.l3_stats.used'
155 local netdev
=$1; shift
158 [[ $
(netdev_hwstats_used
$netdev $type) == "true" ]]
161 netdev_check_unused
()
163 local netdev
=$1; shift
166 [[ $
(netdev_hwstats_used
$netdev $type) == "false" ]]
169 netdev_hwstats_request
()
171 local netdev
=$1; shift
174 $IP -j stats show dev
"$netdev" group offload subgroup hw_stats_info |
175 jq
".[].info.${type}_stats.request"
178 netdev_check_requested
()
180 local netdev
=$1; shift
183 [[ $
(netdev_hwstats_request
$netdev $type) == "true" ]]
186 netdev_check_unrequested
()
188 local netdev
=$1; shift
191 [[ $
(netdev_hwstats_request
$netdev $type) == "false" ]]
201 [[ -n $
(netdev_hwstats_used dummy1
$type) ]]
202 check_err $?
"$type stats not reported"
204 netdev_check_unused dummy1
$type
205 check_err $?
"$type stats reported as used before either device or netdevsim request"
207 nsim_hwstats_enable
$instance dummy1
$type
208 netdev_check_unused dummy1
$type
209 check_err $?
"$type stats reported as used before device request"
210 netdev_check_unrequested dummy1
$type
211 check_err $?
"$type stats reported as requested before device request"
213 $IP stats
set dev dummy1
${type}_stats on
214 netdev_check_used dummy1
$type
215 check_err $?
"$type stats reported as not used after both device and netdevsim request"
216 netdev_check_requested dummy1
$type
217 check_err $?
"$type stats reported as not requested after device request"
219 nsim_hwstats_disable
$instance dummy1
$type
220 netdev_check_unused dummy1
$type
221 check_err $?
"$type stats reported as used after netdevsim request withdrawn"
223 nsim_hwstats_enable
$instance dummy1
$type
224 netdev_check_used dummy1
$type
225 check_err $?
"$type stats reported as not used after netdevsim request reenabled"
227 $IP stats
set dev dummy1
${type}_stats off
228 netdev_check_unused dummy1
$type
229 check_err $?
"$type stats reported as used after device request withdrawn"
230 netdev_check_unrequested dummy1
$type
231 check_err $?
"$type stats reported as requested after device request withdrawn"
233 nsim_hwstats_disable
$instance dummy1
$type
234 netdev_check_unused dummy1
$type
235 check_err $?
"$type stats reported as used after both requests withdrawn"
237 log_test
"Reporting of $type stats usage"
247 local instance
=$1; shift
252 netdev_check_unused dummy1
$type
253 check_err $?
"$type stats reported as used before either device or netdevsim request"
255 nsim_hwstats_enable
$instance dummy1
$type
256 nsim_hwstats_fail_next_enable
$instance dummy1
$type
257 netdev_check_unused dummy1
$type
258 check_err $?
"$type stats reported as used before device request"
259 netdev_check_unrequested dummy1
$type
260 check_err $?
"$type stats reported as requested before device request"
262 $IP stats
set dev dummy1
${type}_stats on
2>/dev
/null
263 check_fail $?
"$type stats request not bounced as it should have been"
264 netdev_check_unused dummy1
$type
265 check_err $?
"$type stats reported as used after bounce"
266 netdev_check_unrequested dummy1
$type
267 check_err $?
"$type stats reported as requested after bounce"
269 $IP stats
set dev dummy1
${type}_stats on
270 check_err $?
"$type stats request failed when it shouldn't have"
271 netdev_check_used dummy1
$type
272 check_err $?
"$type stats reported as not used after both device and netdevsim request"
273 netdev_check_requested dummy1
$type
274 check_err $?
"$type stats reported as not requested after device request"
276 $IP stats
set dev dummy1
${type}_stats off
277 nsim_hwstats_disable
$instance dummy1
$type
279 log_test
"Injected failure of $type stats enablement (netdevsim #$instance)"
284 __fail_next_test
1 "$@"
285 __fail_next_test
2 "$@"
286 __fail_next_test
3 "$@"
296 local netdev
=$1; shift
298 local selector
=$1; shift
300 $IP -j stats show dev
$netdev group offload subgroup
${type}_stats |
301 jq
".[0].stats64.${selector}"
311 nsim_hwstats_enable
$instance dummy1
$type
312 $IP stats
set dev dummy1
${type}_stats on
313 netdev_check_used dummy1
$type
314 check_err $?
"$type stats reported as not used after both device and netdevsim request"
316 # Netdevsim counts 10pps on ingress. We should see maybe a couple
317 # packets, unless things take a reeealy long time.
318 local pkts
=$
(get_hwstat dummy1 l3 rx.packets
)
320 check_err $?
"$type stats show >= 10 packets after first enablement"
324 local pkts
=$
(get_hwstat dummy1 l3 rx.packets
)
326 check_err $?
"$type stats show < 20 packets after 2.5s passed"
328 $IP stats
set dev dummy1
${type}_stats off
332 $IP stats
set dev dummy1
${type}_stats on
333 local pkts
=$
(get_hwstat dummy1 l3 rx.packets
)
335 check_err $?
"$type stats show >= 10 packets after second enablement"
337 $IP stats
set dev dummy1
${type}_stats off
338 nsim_hwstats_fail_next_enable
$instance dummy1
$type
339 $IP stats
set dev dummy1
${type}_stats on
2>/dev
/null
340 check_fail $?
"$type stats request not bounced as it should have been"
344 $IP stats
set dev dummy1
${type}_stats on
345 local pkts
=$
(get_hwstat dummy1 l3 rx.packets
)
347 check_err $?
"$type stats show >= 10 packets after post-fail enablement"
349 $IP stats
set dev dummy1
${type}_stats off
351 log_test
"Counter values in $type stats"
365 nsim_hwstats_enable
1 dummy1 l3
366 nsim_hwstats_enable
2 dummy1 l3
367 nsim_hwstats_enable
3 dummy1 l3
369 # The three netdevsim instances are registered in order of their number
370 # one after another. It is reasonable to expect that whatever
371 # notifications take place hit no. 2 in between hitting nos. 1 and 3,
372 # whatever the actual order. This allows us to test that a fail caused
373 # by no. 2 does not leave the system in a partial state, and rolls
376 nsim_hwstats_fail_next_enable
2 dummy1 l3
377 $IP stats
set dev dummy1
${type}_stats on
2>/dev
/null
378 check_fail $?
"$type stats request not bounced as it should have been"
380 netdev_check_unused dummy1
$type
381 check_err $?
"$type stats reported as used after bounce"
382 netdev_check_unrequested dummy1
$type
383 check_err $?
"$type stats reported as requested after bounce"
387 $IP stats
set dev dummy1
${type}_stats on
388 check_err $?
"$type stats request not upheld as it should have been"
390 local pkts
=$
(get_hwstat dummy1 l3 rx.packets
)
392 check_err $?
"$type stats show $pkts packets after post-fail enablement"
394 $IP stats
set dev dummy1
${type}_stats off
396 nsim_hwstats_disable
3 dummy1 l3
397 nsim_hwstats_disable
2 dummy1 l3
398 nsim_hwstats_disable
1 dummy1 l3
400 log_test
"Failure in $type stats enablement rolled back"
410 hw_stats_monitor_test dummy1 l3 \
411 "nsim_hwstats_enable 1 dummy1 l3" \
412 "nsim_hwstats_disable 1 dummy1 l3" \