WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / tc_action_hw_stats.sh
blob20ed98fe5a60b42c7855379bc1ba594c13227c31
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 lib_dir=$(dirname $0)/../../../net/forwarding
6 ALL_TESTS="
7 default_hw_stats_test
8 immediate_hw_stats_test
9 delayed_hw_stats_test
10 disabled_hw_stats_test
12 NUM_NETIFS=2
14 source $lib_dir/tc_common.sh
15 source $lib_dir/lib.sh
16 source $lib_dir/devlink_lib.sh
18 h1_create()
20 simple_if_init $h1 192.0.2.1/24
23 h1_destroy()
25 simple_if_fini $h1 192.0.2.1/24
28 switch_create()
30 simple_if_init $swp1 192.0.2.2/24
31 tc qdisc add dev $swp1 clsact
34 switch_destroy()
36 tc qdisc del dev $swp1 clsact
37 simple_if_fini $swp1 192.0.2.2/24
40 hw_stats_test()
42 RET=0
44 local name=$1
45 local action_hw_stats=$2
46 local occ_delta=$3
47 local expected_packet_count=$4
49 local orig_occ=$(devlink_resource_get "counters" "flow" | jq '.["occ"]')
51 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
52 skip_sw dst_ip 192.0.2.2 action drop $action_hw_stats
53 check_err $? "Failed to add rule with $name hw_stats"
55 local new_occ=$(devlink_resource_get "counters" "flow" | jq '.["occ"]')
56 local expected_occ=$((orig_occ + occ_delta))
57 [ "$new_occ" == "$expected_occ" ]
58 check_err $? "Expected occupancy of $expected_occ, got $new_occ"
60 $MZ $h1 -c 1 -p 64 -a $h1mac -b $swp1mac -A 192.0.2.1 -B 192.0.2.2 \
61 -t ip -q
63 tc_check_packets "dev $swp1 ingress" 101 $expected_packet_count
64 check_err $? "Did not match incoming packet"
66 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
68 log_test "$name hw_stats"
71 default_hw_stats_test()
73 hw_stats_test "default" "" 2 1
76 immediate_hw_stats_test()
78 hw_stats_test "immediate" "hw_stats immediate" 2 1
81 delayed_hw_stats_test()
83 RET=0
85 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
86 skip_sw dst_ip 192.0.2.2 action drop hw_stats delayed
87 check_fail $? "Unexpected success in adding rule with delayed hw_stats"
89 log_test "delayed hw_stats"
92 disabled_hw_stats_test()
94 hw_stats_test "disabled" "hw_stats disabled" 0 0
97 setup_prepare()
99 h1=${NETIFS[p1]}
100 swp1=${NETIFS[p2]}
102 h1mac=$(mac_get $h1)
103 swp1mac=$(mac_get $swp1)
105 vrf_prepare
107 h1_create
108 switch_create
111 cleanup()
113 pre_cleanup
115 switch_destroy
116 h1_destroy
118 vrf_cleanup
121 check_tc_action_hw_stats_support
123 trap cleanup EXIT
125 setup_prepare
126 setup_wait
128 tests_run
130 exit $EXIT_STATUS