Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Test that policers shared by different tc filters are correctly reference
0005 # counted by observing policers' occupancy via devlink-resource.
0006 
0007 lib_dir=$(dirname $0)/../../../net/forwarding
0008 
0009 ALL_TESTS="
0010         tc_police_occ_test
0011 "
0012 NUM_NETIFS=2
0013 source $lib_dir/lib.sh
0014 source $lib_dir/devlink_lib.sh
0015 
0016 h1_create()
0017 {
0018         simple_if_init $h1
0019 }
0020 
0021 h1_destroy()
0022 {
0023         simple_if_fini $h1
0024 }
0025 
0026 switch_create()
0027 {
0028         simple_if_init $swp1
0029         tc qdisc add dev $swp1 clsact
0030 }
0031 
0032 switch_destroy()
0033 {
0034         tc qdisc del dev $swp1 clsact
0035         simple_if_fini $swp1
0036 }
0037 
0038 setup_prepare()
0039 {
0040         h1=${NETIFS[p1]}
0041         swp1=${NETIFS[p2]}
0042 
0043         vrf_prepare
0044 
0045         h1_create
0046         switch_create
0047 }
0048 
0049 cleanup()
0050 {
0051         pre_cleanup
0052 
0053         switch_destroy
0054         h1_destroy
0055 
0056         vrf_cleanup
0057 }
0058 
0059 tc_police_occ_get()
0060 {
0061         devlink_resource_occ_get global_policers single_rate_policers
0062 }
0063 
0064 tc_police_occ_test()
0065 {
0066         RET=0
0067 
0068         local occ=$(tc_police_occ_get)
0069 
0070         tc filter add dev $swp1 ingress pref 1 handle 101 proto ip \
0071                 flower skip_sw \
0072                 action police rate 100mbit burst 100k conform-exceed drop/ok
0073         (( occ + 1 == $(tc_police_occ_get) ))
0074         check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
0075 
0076         tc filter del dev $swp1 ingress pref 1 handle 101 flower
0077         (( occ == $(tc_police_occ_get) ))
0078         check_err $? "Got occupancy $(tc_police_occ_get), expected $occ"
0079 
0080         tc filter add dev $swp1 ingress pref 1 handle 101 proto ip \
0081                 flower skip_sw \
0082                 action police rate 100mbit burst 100k conform-exceed drop/ok \
0083                 index 10
0084         tc filter add dev $swp1 ingress pref 2 handle 102 proto ip \
0085                 flower skip_sw action police index 10
0086 
0087         (( occ + 1 == $(tc_police_occ_get) ))
0088         check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
0089 
0090         tc filter del dev $swp1 ingress pref 2 handle 102 flower
0091         (( occ + 1 == $(tc_police_occ_get) ))
0092         check_err $? "Got occupancy $(tc_police_occ_get), expected $((occ + 1))"
0093 
0094         tc filter del dev $swp1 ingress pref 1 handle 101 flower
0095         (( occ == $(tc_police_occ_get) ))
0096         check_err $? "Got occupancy $(tc_police_occ_get), expected $occ"
0097 
0098         log_test "tc police occupancy"
0099 }
0100 
0101 trap cleanup EXIT
0102 
0103 setup_prepare
0104 setup_wait
0105 
0106 tests_run
0107 
0108 exit $EXIT_STATUS