0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 TC_FLOWER_NUM_NETIFS=2
0011
0012 tc_flower_h1_create()
0013 {
0014 simple_if_init $h1
0015 tc qdisc add dev $h1 clsact
0016 }
0017
0018 tc_flower_h1_destroy()
0019 {
0020 tc qdisc del dev $h1 clsact
0021 simple_if_fini $h1
0022 }
0023
0024 tc_flower_h2_create()
0025 {
0026 simple_if_init $h2
0027 tc qdisc add dev $h2 clsact
0028 }
0029
0030 tc_flower_h2_destroy()
0031 {
0032 tc qdisc del dev $h2 clsact
0033 simple_if_fini $h2
0034 }
0035
0036 tc_flower_setup_prepare()
0037 {
0038 h1=${NETIFS[p1]}
0039 h2=${NETIFS[p2]}
0040
0041 vrf_prepare
0042
0043 tc_flower_h1_create
0044 tc_flower_h2_create
0045 }
0046
0047 tc_flower_cleanup()
0048 {
0049 pre_cleanup
0050
0051 tc_flower_h2_destroy
0052 tc_flower_h1_destroy
0053
0054 vrf_cleanup
0055
0056 if [[ -v TC_FLOWER_BATCH_FILE ]]; then
0057 rm -f $TC_FLOWER_BATCH_FILE
0058 fi
0059 }
0060
0061 tc_flower_addr()
0062 {
0063 local num=$1; shift
0064
0065 printf "2001:db8:1::%x" $num
0066 }
0067
0068 tc_flower_rules_create()
0069 {
0070 local count=$1; shift
0071 local should_fail=$1; shift
0072
0073 TC_FLOWER_BATCH_FILE="$(mktemp)"
0074
0075 for ((i = 0; i < count; ++i)); do
0076 cat >> $TC_FLOWER_BATCH_FILE <<-EOF
0077 filter add dev $h2 ingress \
0078 prot ipv6 \
0079 pref 1000 \
0080 handle 42$i \
0081 flower $tcflags dst_ip $(tc_flower_addr $i) \
0082 action drop
0083 EOF
0084 done
0085
0086 tc -b $TC_FLOWER_BATCH_FILE
0087 check_err_fail $should_fail $? "Rule insertion"
0088 }
0089
0090 __tc_flower_test()
0091 {
0092 local count=$1; shift
0093 local should_fail=$1; shift
0094 local last=$((count - 1))
0095
0096 tc_flower_rules_create $count $should_fail
0097
0098 offload_count=$(tc -j -s filter show dev $h2 ingress |
0099 jq -r '[ .[] | select(.kind == "flower") |
0100 .options | .in_hw ]' | jq .[] | wc -l)
0101 [[ $((offload_count - 1)) -eq $count ]]
0102 check_err_fail $should_fail $? "Attempt to offload $count rules (actual result $((offload_count - 1)))"
0103 }
0104
0105 tc_flower_test()
0106 {
0107 local count=$1; shift
0108 local should_fail=$1; shift
0109
0110
0111
0112 if ((count > 65536)); then
0113 check_err 1 "Invalid count of $count. At most 65536 rules supported"
0114 return
0115 fi
0116
0117 if ! tc_offload_check $TC_FLOWER_NUM_NETIFS; then
0118 check_err 1 "Could not test offloaded functionality"
0119 return
0120 fi
0121
0122 tcflags="skip_sw"
0123 __tc_flower_test $count $should_fail
0124 }
0125
0126 tc_flower_traffic_test()
0127 {
0128 local count=$1; shift
0129 local i;
0130
0131 for ((i = count - 1; i > 0; i /= 2)); do
0132 $MZ -6 $h1 -c 1 -d 20msec -p 100 -a own -b $(mac_get $h2) \
0133 -A $(tc_flower_addr 0) -B $(tc_flower_addr $i) \
0134 -q -t udp sp=54321,dp=12345
0135 done
0136 for ((i = count - 1; i > 0; i /= 2)); do
0137 tc_check_packets "dev $h2 ingress" 42$i 1
0138 check_err $? "Traffic not seen at rule #$i"
0139 done
0140 }