-
Notifications
You must be signed in to change notification settings - Fork 0
/
trafficsimulator.sh
executable file
·116 lines (81 loc) · 2.17 KB
/
trafficsimulator.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
#! /bin/bash
set -e
source VERSION
default () {
if ! [ "$(eval "echo \"\$$1\"")" ]; then
eval "export $1='$2'"
fi
}
default ARG_name trafficsimulator
default ARG_control ./control
default ARG_outdir .
default ARG_client client.sh
default ARG_server server.sh
default ARG_flows 5
default ARG_ratelimit 10M
default ARG_netem "rate 100kbit"
default ARG_time 300s
argparse() {
export ARGS=()
for _ARG in "$@"; do
if [ "${_ARG##--*}" == "" ]; then
_ARG="${_ARG#--}"
if [ "${_ARG%%*=*}" == "" ]; then
_ARGNAME="$(echo ${_ARG%=*} | tr - _)"
eval "export ARG_${_ARGNAME}"='"${_ARG#*=}"'
else
eval "export ARG_${_ARG}"='True'
fi
else
ARGS+=($_ARG)
fi
done
}
argparse "$@"
if [ "$ARG_help" ]; then
cat <<EOF
Usage:
trafficsimulator.sh OPTIONS
--client=${ARG_client}
--server=${ARG_server}
--flows=${ARG_flows}
--ratelimit=${ARG_ratelimit}
--netem="${ARG_netem}"
--time=${ARG_time}
--control=${ARG_control}
--outdir=${ARG_outdir}
--repository=${ARG_repository}
--name=${ARG_name}
Any OPTIONS can also be given as environment variables with their
names prefixed with ARG_, e.g.
export ARG_ratelimit=${ARG_ratelimit}
EOF
exit 1
fi
echo "Settings:"
export | grep ARG_
echo
mkdir -p "${ARG_control}"/{client,server}
cp $ARG_client "${ARG_control}/client/script2"
cp $ARG_server "${ARG_control}/server/script2"
cat > "${ARG_control}/client/script" <<EOF
#! /bin/bash
set -x
$(export | grep ARG_)
/control/script2
EOF
cat > "${ARG_control}/server/script" <<EOF
#! /bin/bash
set -x
$(export | grep ARG_)
/control/script2
EOF
chmod ugo+rx "${ARG_control}"/*/script*
if [ "$(docker image ls -q "${ARG_repository}traffic-simulator:${VERSION}")" == "" ]; then
docker build --tag "${ARG_repository}traffic-simulator:${VERSION}" host
fi
docker-compose -p "${ARG_name}" -f trafficsimulator-compose.yml up --abort-on-container-exit
mkdir -p "${ARG_outdir}"
ls "${ARG_control}"/client/dumpfile* "${ARG_control}"/client/interfaces
mv "${ARG_control}"/client/interfaces "${ARG_outdir}"
mv "${ARG_control}"/client/dumpfile* "${ARG_outdir}"