-
Notifications
You must be signed in to change notification settings - Fork 13
/
common-ovs-ct.sh
121 lines (104 loc) · 3.01 KB
/
common-ovs-ct.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
113
114
115
116
117
118
119
120
121
function ping_remote() {
ip netns exec ns0 ping -q -c 1 -w 2 $REMOTE
if [ $? -ne 0 ]; then
err "ping failed"
return 1
fi
return 0
}
function initial_traffic() {
title "Initial traffic"
# this part is important when using multi-table CT.
# the initial traffic will cause ovs to create initial tc rules
# and also tuple rules. but since ovs adds the rules somewhat late
# conntrack will already mark the conn est. and tuple rules will be in hw.
# so we start second traffic which will be faster added to hw before
# conntrack and this will check the miss rule in our driver is ok
# (i.e. restoring reg_0 correctly)
ip netns exec ns0 iperf3 -s -D
on_remote timeout -k1 3 iperf3 -c $IP -t 2
killall -q iperf3
}
function start_traffic() {
title "Start traffic"
t=16
on_remote iperf3 -s -D
ip netns exec ns0 timeout -k1 $((t+2)) iperf3 -c $REMOTE -t $t -P3 &
pid2=$!
# verify pid
sleep 4
kill -0 $pid2 &>/dev/null
if [ $? -ne 0 ]; then
on_remote killall -9 -q iperf3
err "iperf failed"
return 1
fi
return 0
}
function verify_traffic() {
local have_traffic=$1
local no_traffic=$2
if [ "$have_traffic" == "" ] && [ "$no_traffic" == "" ]; then
err "Nothing to verify"
return
fi
local nic
declare -A tpids
local tcpdump_timeout=$((t-5))
for nic in $have_traffic; do
echo "start sniff on $nic"
if [ -e /sys/class/net/$nic ]; then
timeout $tcpdump_timeout tcpdump -qnnei $nic -c 30 tcp &
else
ip netns exec ns0 timeout $tcpdump_timeout tcpdump -qnnei $nic -c 30 tcp &
fi
tpids[$nic]=$!
done
for nic in $no_traffic; do
echo "start sniff on $nic"
timeout $tcpdump_timeout tcpdump -qnnei $nic -c 10 tcp &
tpids[$nic]=$!
done
sleep $t
for nic in $have_traffic; do
title "Verify traffic on $nic"
verify_have_traffic ${tpids[$nic]}
done
for nic in $no_traffic; do
title "Verify offload on $nic"
verify_no_traffic ${tpids[$nic]}
done
}
function kill_traffic() {
killall -q iperf3
on_remote killall -q iperf3
echo "wait for bgs"
wait &>/dev/null
}
function verify_ct_udp_have_traffic() {
local pid1=$1
local pid2=$2
title "Verify traffic"
verify_have_traffic $pid1
if [[ -n $pid2 ]]; then
verify_have_traffic $pid2
fi
# short-lived udp connections are not offloaded so wait a bit for offload.
sleep 3
}
function verify_ct_hw_counter() {
local sysfs_counter="/sys/kernel/debug/mlx5/$PCI/ct/offloaded"
local cnt=$1
local a
log "checking hw offload ct tuples count is at least $cnt"
if [ -f $sysfs_counter ]; then
a=`cat $sysfs_counter`
else
a=`cat /proc/net/nf_conntrack | grep HW_OFFLOAD | wc -l`
a=$((a*2))
fi
echo "offloaded ct tuples count: $a"
if [ $a -lt $cnt ]; then
err "low count, expected at least $cnt"
fi
}