-
Notifications
You must be signed in to change notification settings - Fork 1
/
topo
executable file
·117 lines (92 loc) · 3.02 KB
/
topo
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
#!/bin/bash
DOCKER_IMAGE=scion_host:latest
SWITCH=l2_switch_grpc
export SCION_ROOT=${HOME}/scion
export SCION_APPS=${HOME}/scion-apps
. helper.bash
##############
## Commands ##
##############
cmd_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() {
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/diamond.yaml
popd
rm -f $SCION_ROOT/gen/links_established
# Rewrite BR interface IPs
set_link_underlay 1-ff00:0:1 10.1.1.2:50000 1-ff00:0:2 10.1.1.3:50000 # link 1
set_link_underlay 1-ff00:0:1 10.1.2.2:50000 1-ff00:0:3 10.1.2.4:50000 # link 2
set_link_underlay 1-ff00:0:2 10.1.3.3:50000 1-ff00:0:4 10.1.3.5:50000 # link 3
set_link_underlay 1-ff00:0:3 10.1.4.4:50000 1-ff00:0:4 10.1.4.5:50000 # link 4
# For convenience: Set scion daemon address to default value
set_scion_daemon_address ASff00_0_1 127.0.0.1:30255
set_scion_daemon_address ASff00_0_2 127.0.0.1:30255
set_scion_daemon_address ASff00_0_3 127.0.0.1:30255
set_scion_daemon_address ASff00_0_4 127.0.0.1:30255
# Run topology using docker-compose
rm -f $SCION_ROOT/logs/*
docker-compose up -d
# Create links to simple_switch
mount_netns host1
mount_netns host2
create_veth_global_ns link1_sw0 link1_h1 host1 10.1.1.2/24
create_veth_global_ns link1_sw1 link1_h2 host2 10.1.1.3/24
force_chksum_update host1 link1_h1
force_chksum_update host2 link1_h2
# Run simple_switch
sudo simple_switch_grpc --device-id 0 -i 0@link1_sw0 -i 1@link1_sw1 \
--log-level info --log-file log/switch --log-flush --no-p4 -- \
--grpc-server-addr localhost:9559 > /dev/null &
# Run controller
local SW_BUILD_DIR=../simple_switch/${SWITCH}/build
$SW_BUILD_DIR/controller/ctrl $SW_BUILD_DIR/p4info.txt $SW_BUILD_DIR/${SWITCH}.json \
localhost:9559 0 1 > log/controller &
# 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 down
# Delete links to simple_switch
delete_veth link1_sw0
delete_veth link1_sw1
umount_netns host1
umount_netns host2
}
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