-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest-ct-meter-udp.sh
executable file
·112 lines (86 loc) · 2.97 KB
/
test-ct-meter-udp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
#
# Test CT and meter with udp traffic
# Bug SW #2707092, metering doesn't work before version xx.31.0354 xx.32.0114
# Bug SW #3232445, Multiple flow meters not working on old kernels
my_dir="$(dirname "$0")"
. $my_dir/common.sh
min_nic_cx6
require_module act_ct act_police
IP1="7.7.7.1"
IP2="7.7.7.2"
enable_switchdev
require_interfaces REP REP2
unbind_vfs
bind_vfs
reset_tc $REP
reset_tc $REP2
mac1=`cat /sys/class/net/$VF/address`
mac2=`cat /sys/class/net/$VF2/address`
test "$mac1" || fail "no mac1"
test "$mac2" || fail "no mac2"
RATE=100
BURST=65536
TMPFILE=/tmp/iperf3.log
function cleanup() {
ip netns del ns0 2> /dev/null
ip netns del ns1 2> /dev/null
reset_tc $REP
reset_tc $REP2
}
trap cleanup EXIT
function run() {
title "Test CT with police action by UDP traffic"
tc_test_verbose
config_vf ns0 $VF $REP $IP1
config_vf ns1 $VF2 $REP2 $IP2
echo "add arp rules"
tc_filter add dev $REP ingress protocol arp prio 1 flower $tc_verbose \
action mirred egress redirect dev $REP2
tc_filter add dev $REP2 ingress protocol arp prio 1 flower $tc_verbose \
action mirred egress redirect dev $REP
echo "add ct rules"
tc_filter add dev $REP ingress protocol ip prio 2 flower $tc_verbose \
dst_mac $mac2 ct_state -trk \
action ct \
action police rate ${RATE}mbit burst $BURST conform-exceed drop/pipe \
action goto chain 1
tc_filter add dev $REP ingress protocol ip chain 1 prio 2 flower $tc_verbose \
dst_mac $mac2 ct_state +trk+new \
action ct commit \
action mirred egress redirect dev $REP2
tc_filter add dev $REP ingress protocol ip chain 1 prio 2 flower $tc_verbose \
dst_mac $mac2 ct_state +trk+est \
action mirred egress redirect dev $REP2
# chain0,ct -> chain1,fwd
tc_filter add dev $REP2 ingress protocol ip prio 2 flower $tc_verbose \
dst_mac $mac1 \
action ct action goto chain 1
tc_filter add dev $REP2 ingress protocol ip prio 2 chain 1 flower $tc_verbose \
dst_mac $mac1 ct_state +trk+est \
action mirred egress redirect dev $REP
# add another meter with half rate, to verify Bug SW #3232445
tc_filter add dev $REP2 ingress protocol ipv6 prio 3 flower $tc_verbose \
action police rate $((RATE/2))mbit burst $BURST conform-exceed drop/pipe \
action mirred egress redirect dev $REP
fail_if_err
t=12
echo "run traffic for $t seconds"
ip netns exec ns1 timeout $((t+5)) iperf3 -s -1 -J > $TMPFILE &
sleep 2
ip netns exec ns0 timeout $((t+2)) iperf3 -t $t -O 3 -c $IP2 -u -b 1G &
sleep 2.5
pidof iperf3 &>/dev/null || err "iperf3 failed"
echo "sniff packets on $REP"
timeout $((t-4)) tcpdump -qnnei $REP -c 10 'udp' &
pid=$!
sleep $t
killall -9 iperf3 &>/dev/null
wait $! 2>/dev/null
title "verify traffic offloaded"
verify_no_traffic $pid
verify_iperf3_bw $TMPFILE $RATE
}
run
reset_tc $REP $REP2
test_done