]>
Commit | Line | Data |
---|---|---|
eeecce05 BP |
1 | #! /bin/sh |
2 | # | |
fa183acc | 3 | # Copyright (c) 2013, 2015, 2016 Nicira, Inc. |
eeecce05 BP |
4 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | # you may not use this file except in compliance with the License. | |
7 | # You may obtain a copy of the License at: | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, software | |
12 | # distributed under the License is distributed on an "AS IS" BASIS, | |
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | # See the License for the specific language governing permissions and | |
15 | # limitations under the License. | |
16 | ||
17 | set -e | |
18 | ||
8da7cd8c | 19 | run() { |
eeecce05 BP |
20 | (cd "$sandbox" && "$@") || exit 1 |
21 | } | |
22 | ||
8da7cd8c | 23 | run_xterm() { |
4cf272aa AZ |
24 | title=$1; |
25 | shift | |
26 | run xterm -T "$title" -e "$@" & | |
8da7cd8c AZ |
27 | } |
28 | ||
29 | rungdb() { | |
30 | under_gdb=$1 | |
60ceeb6c | 31 | gdb_run=$2 |
8da7cd8c | 32 | shift |
60ceeb6c AZ |
33 | shift |
34 | ||
8da7cd8c AZ |
35 | # Remove the --detach and to put the process under gdb control. |
36 | # Also remove --vconsole:off to allow error message to show up | |
37 | # on the console. | |
38 | # Use "DISPLAY" variable to determine out if X is supported | |
39 | if $under_gdb && [ "$DISPLAY" ]; then | |
40 | args=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g` | |
30a67866 | 41 | xterm_title=$1 |
60ceeb6c AZ |
42 | |
43 | gdb_cmd="" | |
44 | if $gdb_run; then | |
45 | gdb_cmd="-ex run" | |
46 | fi | |
47 | ||
48 | run_xterm $xterm_title gdb $gdb_cmd --args $args | |
8da7cd8c AZ |
49 | else |
50 | run $@ | |
51 | fi | |
52 | } | |
53 | ||
4b814d41 AZ |
54 | gdb_vswitchd=false |
55 | gdb_ovsdb=false | |
60ceeb6c AZ |
56 | gdb_vswitchd_ex=false |
57 | gdb_ovsdb_ex=false | |
91ae2065 | 58 | gdb_ovn_northd=false |
2c6bcfa2 | 59 | gdb_ovn_northd_ex=false |
717c7fc5 | 60 | gdb_ovn_controller=false |
2c6bcfa2 | 61 | gdb_ovn_controller_ex=false |
36561090 RB |
62 | gdb_ovn_controller_vtep=false |
63 | gdb_ovn_controller_vtep_ex=false | |
eeecce05 BP |
64 | builddir= |
65 | srcdir= | |
66 | schema= | |
67 | installed=false | |
68 | built=false | |
ff358c71 | 69 | ovn=false |
1369720c JP |
70 | ovnsb_schema= |
71 | ovnnb_schema= | |
8da7cd8c | 72 | |
eeecce05 BP |
73 | for option; do |
74 | # This option-parsing mechanism borrowed from a Autoconf-generated | |
75 | # configure script under the following license: | |
76 | ||
77 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, | |
78 | # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc. | |
79 | # This configure script is free software; the Free Software Foundation | |
80 | # gives unlimited permission to copy, distribute and modify it. | |
81 | ||
82 | # If the previous option needs an argument, assign it. | |
83 | if test -n "$prev"; then | |
84 | eval $prev=\$option | |
85 | prev= | |
86 | continue | |
87 | fi | |
88 | case $option in | |
89 | *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;; | |
90 | *) optarg=yes ;; | |
91 | esac | |
92 | ||
93 | case $dashdash$option in | |
94 | --) | |
95 | dashdash=yes ;; | |
96 | -h|--help) | |
97 | cat <<EOF | |
98 | ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment | |
99 | usage: $0 [OPTION...] | |
100 | ||
101 | If you run ovs-sandbox from an OVS build directory, it uses the OVS that | |
102 | you built. Otherwise, if you have an installed Open vSwitch, it uses | |
103 | the installed version. | |
104 | ||
105 | These options force ovs-sandbox to use a particular OVS build: | |
106 | -b, --builddir=DIR specify Open vSwitch build directory | |
107 | -s, --srcdir=DIR specify Open vSwitch source directory | |
108 | These options force ovs-sandbox to use an installed Open vSwitch: | |
109 | -i, --installed use installed Open vSwitch | |
8da7cd8c | 110 | -g, --gdb-vswitchd run ovs-vswitchd under gdb |
4b814d41 | 111 | -d, --gdb-ovsdb run ovsdb-server under gdb |
91ae2065 | 112 | --gdb-ovn-northd run ovn-northd under gdb |
717c7fc5 | 113 | --gdb-ovn-controller run ovn-controller under gdb |
36561090 | 114 | --gdb-ovn-controller-vtep run ovn-controller-vtep under gdb |
2c6bcfa2 RB |
115 | -R, --gdb-run automatically start running the daemon in gdb |
116 | for any daemon set to run under gdb | |
eeecce05 | 117 | -S, --schema=FILE use FILE as vswitch.ovsschema |
ff358c71 | 118 | -o, --ovn enable OVN |
eeecce05 BP |
119 | |
120 | Other options: | |
121 | -h, --help Print this usage message. | |
122 | EOF | |
123 | exit 0 | |
124 | ;; | |
125 | ||
126 | --b*=*) | |
127 | builddir=$optarg | |
128 | built=: | |
129 | ;; | |
130 | -b|--b*) | |
131 | prev=builddir | |
132 | built=: | |
133 | ;; | |
134 | --sr*=*) | |
135 | srcdir=$optarg | |
136 | built=false | |
137 | ;; | |
138 | -s|--sr*) | |
139 | prev=srcdir | |
140 | built=false | |
141 | ;; | |
142 | -i|--installed) | |
143 | installed=: | |
144 | ;; | |
145 | --sc*=*) | |
146 | schema=$optarg | |
147 | installed=: | |
148 | ;; | |
149 | -S|--sc*) | |
150 | prev=schema | |
151 | installed=: | |
152 | ;; | |
8da7cd8c AZ |
153 | -g|--gdb-v*) |
154 | gdb_vswitchd=true | |
60ceeb6c AZ |
155 | gdb_vswitchd_ex=false |
156 | ;; | |
157 | -e|--gdb-ex-v*) | |
158 | gdb_vswitchd=true | |
159 | gdb_vswitchd_ex=true | |
8da7cd8c | 160 | ;; |
30a67866 | 161 | -d|--gdb-ovsdb) |
4b814d41 | 162 | gdb_ovsdb=true |
60ceeb6c AZ |
163 | gdb_ovsdb_ex=false |
164 | ;; | |
165 | -r|--gdb-ex-o*) | |
166 | gdb_ovsdb=true | |
167 | gdb_ovsdb_ex=true | |
4b814d41 | 168 | ;; |
91ae2065 RB |
169 | --gdb-ovn-northd) |
170 | gdb_ovn_northd=true | |
30a67866 | 171 | ;; |
717c7fc5 JP |
172 | --gdb-ovn-controller) |
173 | gdb_ovn_controller=true | |
174 | ;; | |
36561090 RB |
175 | --gdb-ovn-controller-vtep) |
176 | gdb_ovn_controller_vtep=true | |
177 | ;; | |
ff358c71 RB |
178 | -o|--ovn) |
179 | ovn=true | |
180 | ;; | |
2c6bcfa2 RB |
181 | -R|--gdb-run) |
182 | gdb_vswitchd_ex=true | |
183 | gdb_ovsdb_ex=true | |
184 | gdb_ovn_northd_ex=true | |
185 | gdb_ovn_controller_ex=true | |
36561090 | 186 | gdb_ovn_controller_vtep_ex=true |
2c6bcfa2 | 187 | ;; |
eeecce05 BP |
188 | -*) |
189 | echo "unrecognized option $option (use --help for help)" >&2 | |
190 | exit 1 | |
191 | ;; | |
192 | *) | |
193 | echo "$option: non-option arguments not supported (use --help for help)" >&2 | |
194 | exit 1 | |
195 | ;; | |
196 | esac | |
197 | shift | |
198 | done | |
199 | ||
200 | if $installed && $built; then | |
201 | echo "sorry, conflicting options (use --help for help)" >&2 | |
202 | exit 1 | |
203 | elif $installed || $built; then | |
204 | : | |
205 | elif test -e vswitchd/ovs-vswitchd; then | |
206 | built=: | |
207 | builddir=. | |
208 | elif (ovs-vswitchd --version) >/dev/null 2>&1; then | |
209 | installed=: | |
210 | else | |
211 | echo "can't find an OVS build or install (use --help for help)" >&2 | |
212 | exit 1 | |
213 | fi | |
214 | ||
215 | if $built; then | |
216 | if test ! -e "$builddir"/vswitchd/ovs-vswitchd; then | |
217 | echo "$builddir does not appear to be an OVS build directory" >&2 | |
218 | exit 1 | |
219 | fi | |
220 | builddir=`cd $builddir && pwd` | |
221 | ||
222 | # Find srcdir. | |
223 | case $srcdir in | |
224 | '') | |
225 | srcdir=$builddir | |
9feb1017 | 226 | if test ! -e "$srcdir"/WHY-OVS.md; then |
eeecce05 BP |
227 | srcdir=`cd $builddir/.. && pwd` |
228 | fi | |
229 | ;; | |
230 | /*) ;; | |
231 | *) srcdir=`pwd`/$srcdir ;; | |
232 | esac | |
233 | schema=$srcdir/vswitchd/vswitch.ovsschema | |
234 | if test ! -e "$schema"; then | |
235 | echo >&2 'source directory not found, please use --srcdir' | |
236 | exit 1 | |
237 | fi | |
ff358c71 | 238 | if $ovn; then |
1369720c JP |
239 | ovnsb_schema=$srcdir/ovn/ovn-sb.ovsschema |
240 | if test ! -e "$ovnsb_schema"; then | |
ff358c71 RB |
241 | echo >&2 'source directory not found, please use --srcdir' |
242 | exit 1 | |
243 | fi | |
1369720c JP |
244 | ovnnb_schema=$srcdir/ovn/ovn-nb.ovsschema |
245 | if test ! -e "$ovnnb_schema"; then | |
ff358c71 RB |
246 | echo >&2 'source directory not found, please use --srcdir' |
247 | exit 1 | |
248 | fi | |
36561090 RB |
249 | vtep_schema=$srcdir/vtep/vtep.ovsschema |
250 | if test ! -e "$vtep_schema"; then | |
251 | echo >&2 'source directory not found, please use --srcdir' | |
252 | exit 1 | |
253 | fi | |
ff358c71 | 254 | fi |
eeecce05 BP |
255 | |
256 | # Put built tools early in $PATH. | |
257 | if test ! -e $builddir/vswitchd/ovs-vswitchd; then | |
258 | echo >&2 'build not found, please change set $builddir or change directory' | |
259 | exit 1 | |
260 | fi | |
8013510c | 261 | PATH=$builddir/ovsdb:$builddir/vswitchd:$builddir/utilities:$builddir/vtep:$PATH |
ff358c71 | 262 | if $ovn; then |
72eaa2ba | 263 | PATH=$builddir/ovn/controller:$builddir/ovn/controller-vtep:$builddir/ovn/northd:$builddir/ovn/utilities:$PATH |
ff358c71 | 264 | fi |
eeecce05 BP |
265 | export PATH |
266 | else | |
267 | case $schema in | |
268 | '') | |
269 | for schema in \ | |
270 | /usr/local/share/openvswitch/vswitch.ovsschema \ | |
271 | /usr/share/openvswitch/vswitch.ovsschema \ | |
272 | none; do | |
273 | if test -r $schema; then | |
274 | break | |
275 | fi | |
276 | done | |
277 | ;; | |
278 | /*) ;; | |
279 | *) schema=`pwd`/$schema ;; | |
280 | esac | |
281 | if test ! -r "$schema"; then | |
282 | echo "can't find vswitch.ovsschema, please specify --schema" >&2 | |
283 | exit 1 | |
284 | fi | |
ff358c71 RB |
285 | if $ovn; then |
286 | echo "running with ovn is only supported from the build dir." >&2 | |
287 | exit 1 | |
288 | fi | |
eeecce05 BP |
289 | fi |
290 | ||
291 | # Create sandbox. | |
292 | rm -rf sandbox | |
293 | mkdir sandbox | |
294 | sandbox=`cd sandbox && pwd` | |
295 | ||
296 | # Set up environment for OVS programs to sandbox themselves. | |
297 | OVS_RUNDIR=$sandbox; export OVS_RUNDIR | |
298 | OVS_LOGDIR=$sandbox; export OVS_LOGDIR | |
299 | OVS_DBDIR=$sandbox; export OVS_DBDIR | |
300 | OVS_SYSCONFDIR=$sandbox; export OVS_SYSCONFDIR | |
301 | ||
302 | if $built; then | |
303 | # Easy access to OVS manpages. | |
211d89b2 | 304 | (cd "$builddir" && ${MAKE-make} install-man mandir="$sandbox"/man) |
eeecce05 BP |
305 | MANPATH=$sandbox/man:; export MANPATH |
306 | fi | |
307 | ||
308 | # Ensure cleanup. | |
309 | trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15 | |
310 | ||
311 | # Create database and start ovsdb-server. | |
312 | touch "$sandbox"/.conf.db.~lock~ | |
431ad535 | 313 | run ovsdb-tool create conf.db "$schema" |
ff358c71 RB |
314 | ovsdb_server_args= |
315 | if $ovn; then | |
1369720c | 316 | touch "$sandbox"/.ovnsb.db.~lock~ |
ff358c71 | 317 | touch "$sandbox"/.ovnnb.db.~lock~ |
1369720c JP |
318 | run ovsdb-tool create ovnsb.db "$ovnsb_schema" |
319 | run ovsdb-tool create ovnnb.db "$ovnnb_schema" | |
36561090 | 320 | run ovsdb-tool create vtep.db "$vtep_schema" |
60bdd011 RM |
321 | ovsdb_server_args="vtep.db conf.db" |
322 | ovsdb_sb_server_args="ovnsb.db" | |
323 | ovsdb_nb_server_args="ovnnb.db" | |
ff358c71 | 324 | fi |
60ceeb6c | 325 | rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file \ |
ff358c71 | 326 | --remote=punix:"$sandbox"/db.sock $ovsdb_server_args |
60bdd011 RM |
327 | if $ovn; then |
328 | rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir \ | |
329 | --pidfile="$sandbox"/ovnnb_db.pid -vconsole:off \ | |
330 | --log-file="$sandbox"/ovnnb_db.log \ | |
331 | --remote=punix:"$sandbox"/ovnnb_db.sock $ovsdb_nb_server_args | |
332 | rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir \ | |
333 | --pidfile="$sandbox"/ovnsb_db.pid -vconsole:off \ | |
334 | --log-file="$sandbox"/ovnsb_db.log \ | |
335 | --remote=punix:"$sandbox"/ovnsb_db.sock $ovsdb_sb_server_args | |
336 | fi | |
eeecce05 | 337 | |
e43a07ba AZ |
338 | #Add a small delay to allow ovsdb-server to launch. |
339 | sleep 0.1 | |
340 | ||
341 | #Wait for ovsdb-server to finish launching. | |
342 | if test ! -e "$sandbox"/db.sock; then | |
343 | echo -n "Waiting for ovsdb-server to start..." | |
344 | while test ! -e "$sandbox"/db.sock; do | |
345 | sleep 1; | |
346 | done | |
347 | echo " Done" | |
348 | fi | |
349 | ||
6b2771c3 BP |
350 | # Initialize database. |
351 | run ovs-vsctl --no-wait -- init | |
352 | ||
eeecce05 | 353 | # Start ovs-vswitchd. |
60ceeb6c | 354 | rungdb $gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \ |
eeecce05 BP |
355 | --enable-dummy=override -vvconn -vnetdev_dummy |
356 | ||
30a67866 | 357 | if $ovn; then |
717c7fc5 | 358 | ovs-vsctl set open . external-ids:system-id=56b18105-5706-46ef-80c4-ff20979ab068 |
9e6ec60a | 359 | ovs-vsctl set open . external-ids:hostname=sandbox |
60bdd011 | 360 | ovs-vsctl set open . external-ids:ovn-remote=unix:"$sandbox"/ovnsb_db.sock |
b705f9ea | 361 | ovs-vsctl set open . external-ids:ovn-encap-type=geneve |
717c7fc5 | 362 | ovs-vsctl set open . external-ids:ovn-encap-ip=127.0.0.1 |
717c7fc5 | 363 | |
fa183acc BP |
364 | ovn-nbctl init |
365 | ovn-sbctl init | |
366 | ||
60bdd011 RM |
367 | rungdb $gdb_ovn_northd $gdb_ovn_northd_ex ovn-northd --detach \ |
368 | --no-chdir --pidfile -vconsole:off --log-file \ | |
369 | --ovnsb-db=unix:"$sandbox"/ovnsb_db.sock \ | |
370 | --ovnnb-db=unix:"$sandbox"/ovnnb_db.sock | |
371 | rungdb $gdb_ovn_controller $gdb_ovn_controller_ex ovn-controller \ | |
372 | --detach --no-chdir --pidfile -vconsole:off --log-file | |
373 | rungdb $gdb_ovn_controller_vtep $gdb_ovn_controller_vtep_ex \ | |
374 | ovn-controller-vtep --detach --no-chdir --pidfile -vconsole:off \ | |
375 | --log-file --ovnsb-db=unix:"$sandbox"/ovnsb_db.sock | |
30a67866 RB |
376 | fi |
377 | ||
eeecce05 BP |
378 | cat <<EOF |
379 | ||
380 | ||
381 | ||
382 | ---------------------------------------------------------------------- | |
383 | You are running in a dummy Open vSwitch environment. You can use | |
384 | ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the | |
79b4e6dc | 385 | dummy switch. |
eeecce05 | 386 | |
79b4e6dc RB |
387 | EOF |
388 | if $ovn; then cat << EOF | |
389 | This environment also has the OVN daemons and databases enabled. | |
390 | You can use ovn-nbctl and ovn-sbctl to interact with the OVN databases. | |
391 | ||
392 | EOF | |
393 | fi | |
394 | cat <<EOF | |
eeecce05 BP |
395 | Log files, pidfiles, and the configuration database are in the |
396 | "sandbox" subdirectory. | |
397 | ||
398 | Exit the shell to kill the running daemons. | |
399 | EOF | |
400 | ||
401 | status=0; $SHELL || status=$? | |
402 | ||
403 | cat <<EOF | |
404 | ---------------------------------------------------------------------- | |
405 | ||
406 | ||
407 | ||
408 | EOF | |
409 | ||
410 | exit $status |