0001
0002
0003 RIF_COUNTER_NUM_NETIFS=2
0004
0005 rif_counter_addr4()
0006 {
0007 local i=$1; shift
0008 local p=$1; shift
0009
0010 printf 192.0.%d.%d $((i / 64)) $(((4 * i % 256) + p))
0011 }
0012
0013 rif_counter_addr4pfx()
0014 {
0015 rif_counter_addr4 $@
0016 printf /30
0017 }
0018
0019 rif_counter_h1_create()
0020 {
0021 simple_if_init $h1
0022 }
0023
0024 rif_counter_h1_destroy()
0025 {
0026 simple_if_fini $h1
0027 }
0028
0029 rif_counter_h2_create()
0030 {
0031 simple_if_init $h2
0032 }
0033
0034 rif_counter_h2_destroy()
0035 {
0036 simple_if_fini $h2
0037 }
0038
0039 rif_counter_setup_prepare()
0040 {
0041 h1=${NETIFS[p1]}
0042 h2=${NETIFS[p2]}
0043
0044 vrf_prepare
0045
0046 rif_counter_h1_create
0047 rif_counter_h2_create
0048 }
0049
0050 rif_counter_cleanup()
0051 {
0052 local count=$1; shift
0053
0054 pre_cleanup
0055
0056 for ((i = 1; i <= count; i++)); do
0057 vlan_destroy $h2 $i
0058 done
0059
0060 rif_counter_h2_destroy
0061 rif_counter_h1_destroy
0062
0063 vrf_cleanup
0064
0065 if [[ -v RIF_COUNTER_BATCH_FILE ]]; then
0066 rm -f $RIF_COUNTER_BATCH_FILE
0067 fi
0068 }
0069
0070
0071 rif_counter_test()
0072 {
0073 local count=$1; shift
0074 local should_fail=$1; shift
0075
0076 RIF_COUNTER_BATCH_FILE="$(mktemp)"
0077
0078 for ((i = 1; i <= count; i++)); do
0079 vlan_create $h2 $i v$h2 $(rif_counter_addr4pfx $i 2)
0080 done
0081 for ((i = 1; i <= count; i++)); do
0082 cat >> $RIF_COUNTER_BATCH_FILE <<-EOF
0083 stats set dev $h2.$i l3_stats on
0084 EOF
0085 done
0086
0087 ip -b $RIF_COUNTER_BATCH_FILE
0088 check_err_fail $should_fail $? "RIF counter enablement"
0089 }
0090
0091 rif_counter_traffic_test()
0092 {
0093 local count=$1; shift
0094 local i;
0095
0096 for ((i = count; i > 0; i /= 2)); do
0097 $MZ $h1 -Q $i -c 1 -d 20msec -p 100 -a own -b $(mac_get $h2) \
0098 -A $(rif_counter_addr4 $i 1) \
0099 -B $(rif_counter_addr4 $i 2) \
0100 -q -t udp sp=54321,dp=12345
0101 done
0102 for ((i = count; i > 0; i /= 2)); do
0103 busywait "$TC_HIT_TIMEOUT" until_counter_is "== 1" \
0104 hw_stats_get l3_stats $h2.$i rx packets > /dev/null
0105 check_err $? "Traffic not seen at RIF $h2.$i"
0106 done
0107 }