WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / tc_police_occ.sh
blob448b75c1545a0465c783362cc47055985c13a73f
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test that policers shared by different tc filters are correctly reference
5 # counted by observing policers' occupancy via devlink-resource.
7 lib_dir=$(dirname $0)/../../../net/forwarding
9 ALL_TESTS="
10 tc_police_occ_test
12 NUM_NETIFS=2
13 source $lib_dir/lib.sh
14 source $lib_dir/devlink_lib.sh
16 h1_create()
18 simple_if_init $h1
21 h1_destroy()
23 simple_if_fini $h1
26 switch_create()
28 simple_if_init $swp1
29 tc qdisc add dev $swp1 clsact
32 switch_destroy()
34 tc qdisc del dev $swp1 clsact
35 simple_if_fini $swp1
38 setup_prepare()
40 h1=${NETIFS[p1]}
41 swp1=${NETIFS[p2]}
43 vrf_prepare
45 h1_create
46 switch_create
49 cleanup()
51 pre_cleanup
53 switch_destroy
54 h1_destroy
56 vrf_cleanup
59 tc_police_occ_get()
61 devlink_resource_occ_get global_policers single_rate_policers
64 tc_police_occ_test()
66 RET=0
68 local occ=$(tc_police_occ_get)
70 tc filter add dev $swp1 ingress pref 1 handle 101 proto ip \
71 flower skip_sw \
72 action police rate 100mbit burst 100k conform-exceed drop/ok
73 (( occ + 1 == $(tc_police_occ_get) ))
74 check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
76 tc filter del dev $swp1 ingress pref 1 handle 101 flower
77 (( occ == $(tc_police_occ_get) ))
78 check_err $? "Got occupancy $(tc_police_occ_get), expected $occ"
80 tc filter add dev $swp1 ingress pref 1 handle 101 proto ip \
81 flower skip_sw \
82 action police rate 100mbit burst 100k conform-exceed drop/ok \
83 index 10
84 tc filter add dev $swp1 ingress pref 2 handle 102 proto ip \
85 flower skip_sw action police index 10
87 (( occ + 1 == $(tc_police_occ_get) ))
88 check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
90 tc filter del dev $swp1 ingress pref 2 handle 102 flower
91 (( occ + 1 == $(tc_police_occ_get) ))
92 check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
94 tc filter del dev $swp1 ingress pref 1 handle 101 flower
95 (( occ == $(tc_police_occ_get) ))
96 check_err $? "Got occupancy $(tc_police_occ_get), expected $occ"
98 log_test "tc police occupancy"
101 trap cleanup EXIT
103 setup_prepare
104 setup_wait
106 tests_run
108 exit $EXIT_STATUS