Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 
0003 TC_POLICE_NUM_NETIFS=2
0004 
0005 tc_police_h1_create()
0006 {
0007         simple_if_init $h1
0008 }
0009 
0010 tc_police_h1_destroy()
0011 {
0012         simple_if_fini $h1
0013 }
0014 
0015 tc_police_switch_create()
0016 {
0017         simple_if_init $swp1
0018         tc qdisc add dev $swp1 clsact
0019 }
0020 
0021 tc_police_switch_destroy()
0022 {
0023         tc qdisc del dev $swp1 clsact
0024         simple_if_fini $swp1
0025 }
0026 
0027 tc_police_addr()
0028 {
0029        local num=$1; shift
0030 
0031        printf "2001:db8:1::%x" $num
0032 }
0033 
0034 tc_police_rules_create()
0035 {
0036         local count=$1; shift
0037         local should_fail=$1; shift
0038 
0039         TC_POLICE_BATCH_FILE="$(mktemp)"
0040 
0041         for ((i = 0; i < count; ++i)); do
0042                 cat >> $TC_POLICE_BATCH_FILE <<-EOF
0043                         filter add dev $swp1 ingress \
0044                                 prot ipv6 \
0045                                 pref 1000 \
0046                                 flower skip_sw dst_ip $(tc_police_addr $i) \
0047                                 action police rate 10mbit burst 100k \
0048                                 conform-exceed drop/ok
0049                 EOF
0050         done
0051 
0052         tc -b $TC_POLICE_BATCH_FILE
0053         check_err_fail $should_fail $? "Rule insertion"
0054 }
0055 
0056 __tc_police_test()
0057 {
0058         local count=$1; shift
0059         local should_fail=$1; shift
0060 
0061         tc_police_rules_create $count $should_fail
0062 
0063         offload_count=$(tc -j filter show dev $swp1 ingress |
0064                         jq "[.[] | select(.options.in_hw == true)] | length")
0065         ((offload_count == count))
0066         check_err_fail $should_fail $? "tc police offload count"
0067 }
0068 
0069 tc_police_test()
0070 {
0071         local count=$1; shift
0072         local should_fail=$1; shift
0073 
0074         if ! tc_offload_check $TC_POLICE_NUM_NETIFS; then
0075                 check_err 1 "Could not test offloaded functionality"
0076                 return
0077         fi
0078 
0079         __tc_police_test $count $should_fail
0080 }
0081 
0082 tc_police_setup_prepare()
0083 {
0084         h1=${NETIFS[p1]}
0085         swp1=${NETIFS[p2]}
0086 
0087         vrf_prepare
0088 
0089         tc_police_h1_create
0090         tc_police_switch_create
0091 }
0092 
0093 tc_police_cleanup()
0094 {
0095         pre_cleanup
0096 
0097         tc_police_switch_destroy
0098         tc_police_h1_destroy
0099 
0100         vrf_cleanup
0101 }