141 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test for resource limit of offloaded flower rules. The test adds a given5# number of flower matches for different IPv6 addresses, then check the offload6# indication for all of the tc flower rules. This file contains functions to set7# up a testing topology and run the test, and is meant to be sourced from a test8# script that calls the testing routine with a given number of rules.9 10TC_FLOWER_NUM_NETIFS=211 12tc_flower_h1_create()13{14 simple_if_init $h115 tc qdisc add dev $h1 clsact16}17 18tc_flower_h1_destroy()19{20 tc qdisc del dev $h1 clsact21 simple_if_fini $h122}23 24tc_flower_h2_create()25{26 simple_if_init $h227 tc qdisc add dev $h2 clsact28}29 30tc_flower_h2_destroy()31{32 tc qdisc del dev $h2 clsact33 simple_if_fini $h234}35 36tc_flower_setup_prepare()37{38 h1=${NETIFS[p1]}39 h2=${NETIFS[p2]}40 41 vrf_prepare42 43 tc_flower_h1_create44 tc_flower_h2_create45}46 47tc_flower_cleanup()48{49 pre_cleanup50 51 tc_flower_h2_destroy52 tc_flower_h1_destroy53 54 vrf_cleanup55 56 if [[ -v TC_FLOWER_BATCH_FILE ]]; then57 rm -f $TC_FLOWER_BATCH_FILE58 fi59}60 61tc_flower_addr()62{63 local num=$1; shift64 65 printf "2001:db8:1::%x" $num66}67 68tc_flower_rules_create()69{70 local count=$1; shift71 local should_fail=$1; shift72 73 TC_FLOWER_BATCH_FILE="$(mktemp)"74 75 for ((i = 0; i < count; ++i)); do76 cat >> $TC_FLOWER_BATCH_FILE <<-EOF77 filter add dev $h2 ingress \78 prot ipv6 \79 pref 1000 \80 handle 42$i \81 flower $tcflags dst_ip $(tc_flower_addr $i) \82 action drop83 EOF84 done85 86 tc -b $TC_FLOWER_BATCH_FILE87 check_err_fail $should_fail $? "Rule insertion"88}89 90__tc_flower_test()91{92 local count=$1; shift93 local should_fail=$1; shift94 local last=$((count - 1))95 96 tc_flower_rules_create $count $should_fail97 98 offload_count=$(tc -j -s filter show dev $h2 ingress |99 jq -r '[ .[] | select(.kind == "flower") |100 .options | .in_hw ]' | jq .[] | wc -l)101 [[ $((offload_count - 1)) -eq $count ]]102 check_err_fail $should_fail $? "Attempt to offload $count rules (actual result $((offload_count - 1)))"103}104 105tc_flower_test()106{107 local count=$1; shift108 local should_fail=$1; shift109 110 # We use lower 16 bits of IPv6 address for match. Also there are only 16111 # bits of rule priority space.112 if ((count > 65536)); then113 check_err 1 "Invalid count of $count. At most 65536 rules supported"114 return115 fi116 117 if ! tc_offload_check $TC_FLOWER_NUM_NETIFS; then118 check_err 1 "Could not test offloaded functionality"119 return120 fi121 122 tcflags="skip_sw"123 __tc_flower_test $count $should_fail124}125 126tc_flower_traffic_test()127{128 local count=$1; shift129 local i;130 131 for ((i = count - 1; i > 0; i /= 2)); do132 $MZ -6 $h1 -c 1 -d 20msec -p 100 -a own -b $(mac_get $h2) \133 -A $(tc_flower_addr 0) -B $(tc_flower_addr $i) \134 -q -t udp sp=54321,dp=12345135 done136 for ((i = count - 1; i > 0; i /= 2)); do137 tc_check_packets "dev $h2 ingress" 42$i 1138 check_err $? "Traffic not seen at rule #$i"139 done140}141