Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / drivers / net / hw / hw_stats_l3.sh
blob67fafefc80bea6c828ed3d6846fd41852f7cac10
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # +--------------------+ +----------------------+
5 # | H1 | | H2 |
6 # | | | |
7 # | $h1.200 + | | + $h2.200 |
8 # | 192.0.2.1/28 | | | | 192.0.2.18/28 |
9 # | 2001:db8:1::1/64 | | | | 2001:db8:2::1/64 |
10 # | | | | | |
11 # | $h1 + | | + $h2 |
12 # | | | | | |
13 # +------------------|-+ +-|--------------------+
14 # | |
15 # +------------------|-------------------------|--------------------+
16 # | SW | | |
17 # | | | |
18 # | $rp1 + + $rp2 |
19 # | | | |
20 # | $rp1.200 + + $rp2.200 |
21 # | 192.0.2.2/28 192.0.2.17/28 |
22 # | 2001:db8:1::2/64 2001:db8:2::2/64 |
23 # | |
24 # +-----------------------------------------------------------------+
26 ALL_TESTS="
27 ping_ipv4
28 ping_ipv6
29 test_stats_rx_ipv4
30 test_stats_tx_ipv4
31 test_stats_rx_ipv6
32 test_stats_tx_ipv6
33 respin_enablement
34 test_stats_rx_ipv4
35 test_stats_tx_ipv4
36 test_stats_rx_ipv6
37 test_stats_tx_ipv6
38 reapply_config
39 ping_ipv4
40 ping_ipv6
41 test_stats_rx_ipv4
42 test_stats_tx_ipv4
43 test_stats_rx_ipv6
44 test_stats_tx_ipv6
45 test_stats_report_rx
46 test_stats_report_tx
47 test_destroy_enabled
48 test_double_enable
50 NUM_NETIFS=4
51 lib_dir=$(dirname "$0")
52 source "$lib_dir"/../../../net/forwarding/lib.sh
53 source "$lib_dir"/../../../net/forwarding/tc_common.sh
55 h1_create()
57 simple_if_init $h1
58 vlan_create $h1 200 v$h1 192.0.2.1/28 2001:db8:1::1/64
59 ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2
60 ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
63 h1_destroy()
65 ip -6 route del 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
66 ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2
67 vlan_destroy $h1 200
68 simple_if_fini $h1
71 h2_create()
73 simple_if_init $h2
74 vlan_create $h2 200 v$h2 192.0.2.18/28 2001:db8:2::1/64
75 ip route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17
76 ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2
79 h2_destroy()
81 ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2
82 ip route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17
83 vlan_destroy $h2 200
84 simple_if_fini $h2
87 router_rp1_200_create()
89 ip link add name $rp1.200 link $rp1 type vlan id 200
90 ip link set dev $rp1.200 addrgenmode eui64
91 ip link set dev $rp1.200 up
92 ip address add dev $rp1.200 192.0.2.2/28
93 ip address add dev $rp1.200 2001:db8:1::2/64
94 ip stats set dev $rp1.200 l3_stats on
97 router_rp1_200_destroy()
99 ip stats set dev $rp1.200 l3_stats off
100 ip address del dev $rp1.200 2001:db8:1::2/64
101 ip address del dev $rp1.200 192.0.2.2/28
102 ip link del dev $rp1.200
105 router_create()
107 ip link set dev $rp1 up
108 router_rp1_200_create
110 ip link set dev $rp2 up
111 vlan_create $rp2 200 "" 192.0.2.17/28 2001:db8:2::2/64
114 router_destroy()
116 vlan_destroy $rp2 200
117 ip link set dev $rp2 down
119 router_rp1_200_destroy
120 ip link set dev $rp1 down
123 setup_prepare()
125 h1=${NETIFS[p1]}
126 rp1=${NETIFS[p2]}
128 rp2=${NETIFS[p3]}
129 h2=${NETIFS[p4]}
131 rp1mac=$(mac_get $rp1)
132 rp2mac=$(mac_get $rp2)
134 vrf_prepare
136 h1_create
137 h2_create
139 router_create
141 forwarding_enable
144 cleanup()
146 pre_cleanup
148 forwarding_restore
150 router_destroy
152 h2_destroy
153 h1_destroy
155 vrf_cleanup
158 ping_ipv4()
160 ping_test $h1.200 192.0.2.18 " IPv4"
163 ping_ipv6()
165 ping_test $h1.200 2001:db8:2::1 " IPv6"
168 send_packets_rx_ipv4()
170 # Send 21 packets instead of 20, because the first one might trap and go
171 # through the SW datapath, which might not bump the HW counter.
172 $MZ $h1.200 -c 21 -d 20msec -p 100 \
173 -a own -b $rp1mac -A 192.0.2.1 -B 192.0.2.18 \
174 -q -t udp sp=54321,dp=12345
177 send_packets_rx_ipv6()
179 $MZ $h1.200 -6 -c 21 -d 20msec -p 100 \
180 -a own -b $rp1mac -A 2001:db8:1::1 -B 2001:db8:2::1 \
181 -q -t udp sp=54321,dp=12345
184 send_packets_tx_ipv4()
186 $MZ $h2.200 -c 21 -d 20msec -p 100 \
187 -a own -b $rp2mac -A 192.0.2.18 -B 192.0.2.1 \
188 -q -t udp sp=54321,dp=12345
191 send_packets_tx_ipv6()
193 $MZ $h2.200 -6 -c 21 -d 20msec -p 100 \
194 -a own -b $rp2mac -A 2001:db8:2::1 -B 2001:db8:1::1 \
195 -q -t udp sp=54321,dp=12345
198 ___test_stats()
200 local dir=$1; shift
201 local prot=$1; shift
203 local a
204 local b
206 a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)
207 send_packets_${dir}_${prot}
208 "$@"
209 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
210 hw_stats_get l3_stats $rp1.200 ${dir} packets)
211 check_err $? "Traffic not reflected in the counter: $a -> $b"
214 __test_stats()
216 local dir=$1; shift
217 local prot=$1; shift
219 RET=0
220 ___test_stats "$dir" "$prot"
221 log_test "Test $dir packets: $prot"
224 test_stats_rx_ipv4()
226 __test_stats rx ipv4
229 test_stats_tx_ipv4()
231 __test_stats tx ipv4
234 test_stats_rx_ipv6()
236 __test_stats rx ipv6
239 test_stats_tx_ipv6()
241 __test_stats tx ipv6
244 # Make sure everything works well even after stats have been disabled and
245 # reenabled on the same device without touching the L3 configuration.
246 respin_enablement()
248 log_info "Turning stats off and on again"
249 ip stats set dev $rp1.200 l3_stats off
250 ip stats set dev $rp1.200 l3_stats on
253 # For the initial run, l3_stats is enabled on a completely set up netdevice. Now
254 # do it the other way around: enabling the L3 stats on an L2 netdevice, and only
255 # then apply the L3 configuration.
256 reapply_config()
258 log_info "Reapplying configuration"
260 router_rp1_200_destroy
262 ip link add name $rp1.200 link $rp1 type vlan id 200
263 ip link set dev $rp1.200 addrgenmode none
264 ip stats set dev $rp1.200 l3_stats on
265 ip link set dev $rp1.200 addrgenmode eui64
266 ip link set dev $rp1.200 up
267 ip address add dev $rp1.200 192.0.2.2/28
268 ip address add dev $rp1.200 2001:db8:1::2/64
271 __test_stats_report()
273 local dir=$1; shift
274 local prot=$1; shift
276 local a
277 local b
279 RET=0
281 a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)
282 send_packets_${dir}_${prot}
283 ip address flush dev $rp1.200
284 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
285 hw_stats_get l3_stats $rp1.200 ${dir} packets)
286 check_err $? "Traffic not reflected in the counter: $a -> $b"
287 log_test "Test ${dir} packets: stats pushed on loss of L3"
289 ip stats set dev $rp1.200 l3_stats off
290 ip link del dev $rp1.200
291 router_rp1_200_create
294 test_stats_report_rx()
296 __test_stats_report rx ipv4
299 test_stats_report_tx()
301 __test_stats_report tx ipv4
304 test_destroy_enabled()
306 RET=0
308 ip link del dev $rp1.200
309 router_rp1_200_create
311 log_test "Destroy l3_stats-enabled netdev"
314 test_double_enable()
316 RET=0
317 ___test_stats rx ipv4 \
318 ip stats set dev $rp1.200 l3_stats on
319 log_test "Test stat retention across a spurious enablement"
322 trap cleanup EXIT
324 setup_prepare
325 setup_wait
327 used=$(ip -j stats show dev $rp1.200 group offload subgroup hw_stats_info |
328 jq '.[].info.l3_stats.used')
329 [[ $used = true ]]
330 check_err $? "hw_stats_info.used=$used"
331 log_test "l3_stats offloaded"
332 tests_run
334 exit $EXIT_STATUS