forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scion.sh
executable file
·184 lines (162 loc) · 4.48 KB
/
scion.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
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
#!/usr/bin/env bash
export PYTHONPATH=.
EXTRA_NOSE_ARGS="--with-xunit --xunit-file=logs/nosetests.xml"
# BEGIN subcommand functions
cmd_topology() {
local zkclean
if type -p supervisorctl &>/dev/null; then
echo "Shutting down supervisord: $(supervisor/supervisor.sh shutdown)"
fi
mkdir -p logs traces
[ -e gen ] && rm -r gen
if [ "$1" = "zkclean" ]; then
shift
zkclean="y"
fi
echo "Create topology, configuration, and execution files."
topology/generator.py "$@" || exit 1
if [ -n "$zkclean" ]; then
echo "Deleting all Zookeeper state"
rm -rf /run/shm/scion-zk
tools/zkcleanslate --zk 127.0.0.1:2181
fi
}
cmd_run() {
if [ "$1" != "nobuild" ]; then
echo "Compiling..."
cmd_build || exit 1
fi
echo "Running the network..."
if [ -e gen/zk_datalog_dirs.sh ]; then
bash gen/zk_datalog_dirs.sh || exit 1
fi
supervisor/supervisor.sh start all
}
cmd_stop() {
echo "Terminating this run of the SCION infrastructure"
supervisor/supervisor.sh stop all
}
cmd_status() {
supervisor/supervisor.sh status | grep -v RUNNING
# If all tasks are running, then return 0. Else return 1.
[ $? -eq 1 ]
return
}
cmd_test(){
set -e
case "$1" in
py) shift; py_test "$@";;
go) shift; go_test "$@";;
*) py_test; go_test;;
esac
}
py_test() {
nosetests3 ${EXTRA_NOSE_ARGS} "$@"
}
go_test() {
# `make -C go` breaks if there are symlinks in $PWD
( cd go && make -s test )
}
cmd_coverage(){
set -e
case "$1" in
py) shift; py_cover "$@";;
go) shift; go_cover "$@";;
*) py_cover;
echo "============================================="
go_cover;;
esac
}
py_cover() {
nosetests3 ${EXTRA_NOSE_ARGS} --with-cov --cov-report html "$@"
echo
echo "Python coverage report here: file://$PWD/htmlcov/index.html"
}
go_cover() {
( cd go && make -s coverage )
}
cmd_lint() {
set -o pipefail
local ret=0
for i in . sub/web; do
[ -d "$i" ] || continue
echo "Linting $i"
echo "============================================="
( cd "$i" && flake8 --config flake8.ini . ) | sort -t: -k1,1 -k2n,2 -k3n,3 || ((ret++))
done
return $ret
}
cmd_golint() {
( cd go && make -s lint )
}
cmd_version() {
cat <<-_EOF
============================================
= SCION =
= https://github.com/netsec-ethz/scion =
============================================
_EOF
}
cmd_build() {
if [ "$1" == "bypass" ]; then
USER_OPTS=-DBYPASS_ROUTERS make -s all install
else
make -s all install
fi
}
cmd_clean() {
make -s clean
}
cmd_sciond() {
[ -n "$1" ] || { echo "ISD-AS argument required"; exit 1; }
# Convert the ISD-AS argument into an array, where the first element is the
# ISD, and the second is the AS.
IFS=- read -a ia <<< $1
ISD=${ia[0]:?No ISD provided}
AS=${ia[1]:?No AS provided}
ADDR=${2:-127.${ISD}.${AS}.254}
GENDIR=gen/ISD${ISD}/AS${AS}/endhost
[ -d "$GENDIR" ] || { echo "Topology directory for $ISD-$AS doesn't exist: $GENDIR"; exit 1; }
APIADDR="/run/shm/sciond/${ISD}-${AS}.sock"
PYTHONPATH=. bin/sciond --addr $ADDR --api-addr $APIADDR sd${ISD}-${AS} $GENDIR &
echo "Sciond running for $ISD-$AS (pid $!)"
wait
exit $?
}
cmd_help() {
cmd_version
echo
cat <<-_EOF
Usage:
$PROGRAM topology [zkclean]
Create topology, configuration, and execution files. With the
'zkclean' option, also reset all local Zookeeper state. Another
other arguments or options are passed to topology/generator.py
$PROGRAM run
Run network.
$PROGRAM sciond ISD AS [ADDR]
Start sciond with provided ISD and AS parameters. A third optional
parameter is the address to bind when not running on localhost.
$PROGRAM stop
Terminate this run of the SCION infrastructure.
$PROGRAM status
Show all non-running tasks.
$PROGRAM test
Run all unit tests.
$PROGRAM coverage
Create a html report with unit test code coverage.
$PROGRAM help
Show this text.
$PROGRAM version
Show version information.
_EOF
}
# END subcommand functions
PROGRAM="${0##*/}"
COMMAND="$1"
shift
case "$COMMAND" in
coverage|help|lint|golint|run|stop|status|test|topology|version|build|clean|sciond)
"cmd_$COMMAND" "$@" ;;
*) cmd_help; exit 1 ;;
esac