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