-
Notifications
You must be signed in to change notification settings - Fork 1
/
start
executable file
·129 lines (101 loc) · 2.75 KB
/
start
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
122
123
124
125
126
127
128
129
#!/bin/bash
# Author : Doeraene Anthony
ask_confirmation(){
msg=$1
yes=$2
no=$3
echo "$msg [Y/N]"
read resp
# convert to lower case
resp=${resp,,}
if [ "$resp" == "y" ]; then
$yes
else
$no
fi
}
is_red_hat(){
test -f /etc/redhat-release
}
is_fedora(){
test -n "$(cat /etc/os-release | grep fedora)"
}
disable_firewall(){
echo "Disabling firewall..."
sudo systemctl stop firewalld
}
abort(){
echo "Aborting"
exit 1
}
init_device_dirs(){
name=$1
# create the directories for devices
mkdir lab/$name
mkdir lab/$name/home
# copy the certs needed to run the server
cp -r certs lab/$name/home
# copy the data files
cp -r data lab/$name/home
# copy the init script file
cp lab/scripts/init lab/$name/home/init
# copy the server and client files
cp -r src lab/$name/home
# copy the public key used for ssh
cp ssh_keys/ssh_keys.pub lab/$name/home
}
init_router(){
name=$1
mkdir lab/$name
# copy the public key used by main
cp ssh_keys/ssh_keys.pub lab/$name
# copy the impairement script
cp lab/scripts/impair_itf lab/$name
}
start_server(){
name=$1
ip=$2
# start a quic + iperf server
sudo kathara exec $name -- "sh -c \"cd /home && /venv/bin/python src/server.py --host ${ip} -v 1\"" &
sudo kathara exec $name -- "sh -c \"iperf -s\"" &
}
init_main(){
mkdir lab/main
# copy the private key to main
cp ssh_keys/ssh_keys lab/main
# copy the connect script
cp lab/scripts/connect lab/main
# copy the scenarios
cp -r scenarios lab/main
}
# start docker
# https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux
case "$(uname -s)" in
Linux*) echo "starting docker for Linux"; sudo systemctl start docker;;
Darwin*) echo "starting docker for Mac"; sudo docker-machine start default;;
esac
# remove previously started lab
# ./clean
# comment the following line if not on Red-Hat based distribution
if is_red_hat || is_fedora ; then
echo "Fedora/Red-hat system detected"
ask_confirmation "This lab requires to stop the firewall on fedora/red-hat in order to work. Disable it ?" \
'disable_firewall' \
'abort'
fi
# create the dirs for each device
init_device_dirs client1
init_device_dirs client2
init_device_dirs server1
init_device_dirs server2
# init the files for the routes
init_router router1
init_router router2
# init the files for the main hub
init_main
# start the lab
cd lab && \
sudo kathara lstart --noterminals &&
sudo chmod 777 shared # on Mac, we have to explicitly set the permissions of the shared folder
start_server server1 "10.0.1.1" > server1.logs
start_server server2 "10.0.1.2" > server2.logs