108 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3RIF_COUNTER_NUM_NETIFS=24 5rif_counter_addr4()6{7 local i=$1; shift8 local p=$1; shift9 10 printf 192.0.%d.%d $((i / 64)) $(((4 * i % 256) + p))11}12 13rif_counter_addr4pfx()14{15 rif_counter_addr4 $@16 printf /3017}18 19rif_counter_h1_create()20{21 simple_if_init $h122}23 24rif_counter_h1_destroy()25{26 simple_if_fini $h127}28 29rif_counter_h2_create()30{31 simple_if_init $h232}33 34rif_counter_h2_destroy()35{36 simple_if_fini $h237}38 39rif_counter_setup_prepare()40{41 h1=${NETIFS[p1]}42 h2=${NETIFS[p2]}43 44 vrf_prepare45 46 rif_counter_h1_create47 rif_counter_h2_create48}49 50rif_counter_cleanup()51{52 local count=$1; shift53 54 pre_cleanup55 56 for ((i = 1; i <= count; i++)); do57 vlan_destroy $h2 $i58 done59 60 rif_counter_h2_destroy61 rif_counter_h1_destroy62 63 vrf_cleanup64 65 if [[ -v RIF_COUNTER_BATCH_FILE ]]; then66 rm -f $RIF_COUNTER_BATCH_FILE67 fi68}69 70 71rif_counter_test()72{73 local count=$1; shift74 local should_fail=$1; shift75 76 RIF_COUNTER_BATCH_FILE="$(mktemp)"77 78 for ((i = 1; i <= count; i++)); do79 vlan_create $h2 $i v$h2 $(rif_counter_addr4pfx $i 2)80 done81 for ((i = 1; i <= count; i++)); do82 cat >> $RIF_COUNTER_BATCH_FILE <<-EOF83 stats set dev $h2.$i l3_stats on84 EOF85 done86 87 ip -b $RIF_COUNTER_BATCH_FILE88 check_err_fail $should_fail $? "RIF counter enablement"89}90 91rif_counter_traffic_test()92{93 local count=$1; shift94 local i;95 96 for ((i = count; i > 0; i /= 2)); do97 $MZ $h1 -Q $i -c 1 -d 20msec -p 100 -a own -b $(mac_get $h2) \98 -A $(rif_counter_addr4 $i 1) \99 -B $(rif_counter_addr4 $i 2) \100 -q -t udp sp=54321,dp=12345101 done102 for ((i = count; i > 0; i /= 2)); do103 busywait "$TC_HIT_TIMEOUT" until_counter_is "== 1" \104 hw_stats_get l3_stats $h2.$i rx packets > /dev/null105 check_err $? "Traffic not seen at RIF $h2.$i"106 done107}108