-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiperf_exp.sh
97 lines (74 loc) · 3.45 KB
/
iperf_exp.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
if [ "$#" -ne 6 ]
then
echo "run like: iperf_exp.sh [MIN_CONST_VMS]1 [TOTAL_CONST_VMS]10 [TARGET_NODE_IP]10.10.1.1 [SOURCE_BRIDGE_PREFIX]192.168 [TARGET_BRIDGE_PREFIX]192.167 [OS]alpine"
exit 1
fi
MIN_CONST_VMS=$1
TOTAL_CONST_VMS=$2
TARGET_NODE="$3"
SOURCE_BRIDGE_PREFIX=$4
TARGET_BRIDGE_PREFIX=$5
OS=$6
# MAX_THROUGHPUT=5.71*1000*1000*1000 # 5.71 Gbps single vm to single vm scenario
S3_BUCKET="spec.ccfc.min"
TARGET="$(uname -m)"
kv="4.14"
REPO_NAME=$(basename `git rev-parse --show-toplevel`)
sudo ip route add ${TARGET_BRIDGE_PREFIX}.0.0/16 via $TARGET_NODE
ssh ag4786@${TARGET_NODE} sudo ip route add ${SOURCE_BRIDGE_PREFIX}.0.0/16 via 10.10.1.2
for (( CONST_VMS=${MIN_CONST_VMS}; CONST_VMS<=${TOTAL_CONST_VMS}; CONST_VMS++ ));
do
sleep 3
ssh ag4786@${TARGET_NODE} bash parallel_start_many ${CONST_VMS} ${TARGET_BRIDGE_PREFIX} ${OS}
sleep 5
ssh ag4786@${TARGET_NODE} "cd ${REPO_NAME}; bash enable_vm_networking ${CONST_VMS} ${TARGET_BRIDGE_PREFIX}"
wget -N -q "https://s3.amazonaws.com/$S3_BUCKET/img/alpine_demo/fsfiles/xenial.rootfs.ext4" -O rootfs.ext4
wget -N -q "https://s3.amazonaws.com/$S3_BUCKET/ci-artifacts/kernels/$TARGET/vmlinux-$kv.bin" -O "rootfs.vmlinux"
bash parallel_start_many ${CONST_VMS} ${SOURCE_BRIDGE_PREFIX} ${OS}
sleep 5
bash enable_vm_networking ${CONST_VMS} ${SOURCE_BRIDGE_PREFIX}
pids=()
for (( VM_INDEX=1; VM_INDEX<=$CONST_VMS; VM_INDEX++ ));
do
SRC_VM_IP="$(printf '%s.1.%s' ${SOURCE_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
DST_VM_IP="$(printf '%s.1.%s' ${TARGET_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
## add iperf3 package in the vm if it does not exist
ssh -i $HOME/$REPO_NAME/rootfs.id_rsa root@$SRC_VM_IP "apk info iperf3 >/dev/null 2>&1 || apk add iperf3"
ssh -i $HOME/$REPO_NAME/rootfs.id_rsa root@$DST_VM_IP "apk info iperf3 >/dev/null 2>&1 || apk add iperf3"
done
for (( VM_INDEX=1; VM_INDEX<=$CONST_VMS; VM_INDEX++ ));
do
DST_VM_IP="$(printf '%s.1.%s' ${TARGET_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
## start iperf3 server in the target vm
ssh -i $HOME/$REPO_NAME/rootfs.id_rsa root@$DST_VM_IP "iperf3 -s -D" # -D option to run iperf3 in daemon mode
done
SECONDS=0
for (( VM_INDEX=1; VM_INDEX<=$CONST_VMS; VM_INDEX++ ));
do
SRC_VM_IP="$(printf '%s.1.%s' ${SOURCE_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
DST_VM_IP="$(printf '%s.1.%s' ${TARGET_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
## start iperf3 client in the source vm
ssh -i $HOME/$REPO_NAME/rootfs.id_rsa root@$SRC_VM_IP "iperf3 -c $DST_VM_IP -t 300 -f g -i 0 > iperf_${VM_INDEX}" &
pids+=($!)
done
echo "It took $SECONDS seconds to start all clients. Waiting for clients to finish..."
for pid in ${pids[*]};
do
wait $pid
done
sleep 5
total=0
for (( VM_INDEX=1; VM_INDEX<=$CONST_VMS; VM_INDEX++ ));
do
SRC_VM_IP="$(printf '%s.1.%s' ${SOURCE_BRIDGE_PREFIX} $(((2 * VM_INDEX + 1) )))"
value=$(ssh -i rootfs.id_rsa root@$SRC_VM_IP "cat iperf_${VM_INDEX}" | grep receiver | awk '{print $7}')
total=$(echo "$total + $value" | bc)
done
average=$(bc <<< "scale=5; $total / $CONST_VMS")
echo $average > iperf_${CONST_VMS}
sudo bash $HOME/$REPO_NAME/server/cleanup.sh ${CONST_VMS}
rm rootfs.ext4
rm rootfs.vmlinux
ssh -tt ag4786@${TARGET_NODE} "sudo bash $HOME/$REPO_NAME/server/cleanup.sh ${CONST_VMS}"
sleep 5
done