-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo
executable file
·231 lines (200 loc) · 7.58 KB
/
demo
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
DOCKER_IMAGE=scion_host:latest
COMPOSE_ARGS="-f docker-compose-demo.yaml -p int-demo"
export SCION_ROOT=${HOME}/scion
export SCION_APPS=${HOME}/scion-apps
USABLE_SWITCHES=(int_switch l2_switch_grpc)
. helper.bash
##############
## Commands ##
##############
cmd_build() {
# Get used switch from argument
handle_arguments 'build' $@
# Build switch dataplane and controller
make -C ../simple_switch/${SWITCH}
# Build docker image
docker build --build-arg SCION_UID=$(id -u $LOGNAME) --build-arg SCION_GID=$(id -g $LOGNAME) \
-t ${DOCKER_IMAGE} ./scion_host
}
cmd_run() {
# Get used switch from argument
handle_arguments 'run' $@
if [[ "$(docker images -q ${DOCKER_IMAGE} 2> /dev/null)" == "" ]]; then
cmd_build
fi
set -e
sudo -v
mkdir -p log
# Create local topology
local SCRIPT_DIR=$PWD
pushd $SCION_ROOT
./scion.sh bazel_remote
./scion.sh topology -c $SCRIPT_DIR/topologies/star.yaml
popd
rm -f $SCION_ROOT/gen/links_established
# Rewrite AS ff00:0:1 internal network IPs
set_control_addr 1-ff00:0:1 10.2.1.2:31000
set_br_internal_addr 1-ff00:0:1 br1-ff00_0_1-1 10.2.1.2:31002
set_br_internal_addr 1-ff00:0:1 br1-ff00_0_1-2 10.2.1.3:31004
set_br_internal_addr 1-ff00:0:1 br1-ff00_0_1-3 10.2.1.4:31006
set_br_internal_addr 1-ff00:0:1 br1-ff00_0_1-4 10.2.1.5:31008
# Rewrite BR interface IPs
set_link_underlay 1-ff00:0:1 10.1.0.1:50000 1-ff00:0:2 10.1.0.2:50000
set_link_underlay 1-ff00:0:1 10.1.1.1:50000 1-ff00:0:3 10.1.1.2:50000
set_link_underlay 1-ff00:0:1 10.1.2.1:50000 1-ff00:0:4 10.1.2.2:50000
set_link_underlay 1-ff00:0:1 10.1.3.1:50000 1-ff00:0:5 10.1.3.2:50000
set_link_underlay 1-ff00:0:1 10.1.4.1:50000 1-ff00:0:6 10.1.4.2:50000
set_link_underlay 1-ff00:0:1 10.1.5.1:50000 1-ff00:0:7 10.1.5.2:50000
# For convenience: Set scion daemon address to default value
for i in {1..7}
do
set_scion_daemon_address ASff00_0_$i 127.0.0.1:30255
done
# Split ASff00:0:1 into four program groups
ed ${SCION_ROOT}/gen/supervisord.conf << EOF
/^\[group:as1-ff00_0_1]/
.,+1d
i
[group:as1-ff00_0_1_BR1]
programs = br1-ff00_0_1-1,cs1-ff00_0_1-1,sd1-ff00_0_1
[group:as1-ff00_0_1_BR2]
programs = br1-ff00_0_1-2,sd1-ff00_0_1
[group:as1-ff00_0_1_BR3]
programs = br1-ff00_0_1-3,sd1-ff00_0_1
[group:as1-ff00_0_1_BR4]
programs = br1-ff00_0_1-4,sd1-ff00_0_1
.
w
q
EOF
# Run topology using docker-compose
rm -f $SCION_ROOT/logs/*
docker-compose $COMPOSE_ARGS up -d
# Create links to simple_switch
for i in {1..4}
do
mount_netns as1br$i
done
for i in {2..7}
do
mount_netns as$i
done
# Switch 1
create_veth_global_ns veth0 veth1 as1br1 10.1.0.1/24
create_veth_global_ns veth2 veth3 as2 10.1.0.2/24
force_chksum_update as1br1 veth1
force_chksum_update as2 veth3
# Switch 2
create_veth_global_ns veth4 veth5 as1br2 10.1.1.1/24
create_veth_global_ns veth6 veth7 as3 10.1.1.2/24
force_chksum_update as1br2 veth5
force_chksum_update as3 veth7
# Switch 3
create_veth_global_ns veth8 veth9 as1br2 10.1.2.1/24
create_veth_global_ns veth10 veth11 as4 10.1.2.2/24
force_chksum_update as1br2 veth9
force_chksum_update as4 veth11
# Switch 4
create_veth_global_ns veth12 veth13 as1br3 10.1.3.1/24
create_veth_global_ns veth14 veth15 as5 10.1.3.2/24
force_chksum_update as1br3 veth13
force_chksum_update as5 veth15
# Switch 5
create_veth_global_ns veth16 veth17 as1br4 10.1.4.1/24
create_veth_global_ns veth18 veth19 as6 10.1.4.2/24
force_chksum_update as1br4 veth17
force_chksum_update as6 veth19
# Switch 6
create_veth_global_ns veth20 veth21 as1br4 10.1.5.1/24
create_veth_global_ns veth22 veth23 as7 10.1.5.2/24
force_chksum_update as1br4 veth21
force_chksum_update as7 veth23
# Switches
local SW_BUILD_DIR=../simple_switch/${SWITCH}/build
# Switch 1
local grpc_port=9559
local thrift_port=9190
sudo simple_switch_grpc --device-id 0 -i 0@veth0 -i 1@veth2 --thrift-port $thrift_port \
--log-level info --log-file log/switch1 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:2 1 int_table1.txt 127.0.0.1:9093 > log/controller1 &
# Switch 2
local grpc_port=9560
local thrift_port=9191
sudo simple_switch_grpc --device-id 0 -i 0@veth4 -i 1@veth6 --thrift-port $thrift_port \
--log-level info --log-file log/switch2 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:3 1 int_table2.txt 127.0.0.1:9093 > log/controller2 &
# Switch 3
local grpc_port=9561
local thrift_port=9192
sudo simple_switch_grpc --device-id 0 -i 0@veth8 -i 1@veth10 --thrift-port $thrift_port \
--log-level info --log-file log/switch3 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:4 1 int_table3.txt 127.0.0.1:9093 > log/controller3 &
# Switch 4
local grpc_port=9562
local thrift_port=9193
sudo simple_switch_grpc --device-id 0 -i 0@veth12 -i 1@veth14 --thrift-port $thrift_port \
--log-level info --log-file log/switch4 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:5 1 int_table4.txt 127.0.0.1:9093 > log/controller4 &
# Switch 5
local grpc_port=9563
local thrift_port=9194
sudo simple_switch_grpc --device-id 0 -i 0@veth16 -i 1@veth18 --thrift-port $thrift_port \
--log-level info --log-file log/switch5 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:6 1 int_table5.txt 127.0.0.1:9093 > log/controller5 &
# Switch 6
local grpc_port=9564
local thrift_port=9195
sudo simple_switch_grpc --device-id 0 -i 0@veth20 -i 1@veth22 --thrift-port $thrift_port \
--log-level info --log-file log/switch6 --log-flush --no-p4 -- \
--cpu-port 128 --grpc-server-addr localhost:$grpc_port > /dev/null &
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:$grpc_port 0 1 1-ff00:0:7 1 int_table6.txt 127.0.0.1:9093 > log/controller6 &
# Signal containers to start SCION
echo '1' > $SCION_ROOT/gen/links_established
}
cmd_stop() {
# Stop simple_switch and controller
sudo pkill --full '^simple_switch_grpc'
# Delete Docker containers and networks
docker-compose $COMPOSE_ARGS down
# Delete links to simple_switch
for i in {1..4}
do
umount_netns as1br$i
done
for i in {2..7}
do
umount_netns as$i
done
}
cmd_logs() {
docker-compose logs
}
cmd_enter() {
docker exec -it $1 bash -l
}
cmd_clean() {
rm -rf ./log
rm -rf $SCION_ROOT/gen* $SCION_ROOT/logs $SCION_ROOT/traces
}
#################
## Entry point ##
#################
COMMAND=$1
shift
case "$COMMAND" in
build|run|stop|logs|enter|clean|help)
"cmd_$COMMAND" "$@" ;;
*) echo "Command no recognized."; exit 1 ;;
esac