3 # Copyright (c) 2013, 2015, 2016 Nicira, Inc.
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:
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 (cd "$sandbox" && "$@") ||
exit 1
26 run xterm
-T "$title" -e "$@" &
35 # Remove the --detach and to put the process under gdb control.
36 # Also remove --vconsole:off to allow error message to show up
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`
48 run_xterm
$xterm_title gdb
$gdb_cmd --args $args
59 gdb_ovn_northd_ex
=false
60 gdb_ovn_controller
=false
61 gdb_ovn_controller_ex
=false
62 gdb_ovn_controller_vtep
=false
63 gdb_ovn_controller_vtep_ex
=false
75 # This option-parsing mechanism borrowed from a Autoconf-generated
76 # configure script under the following license:
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.
83 # If the previous option needs an argument, assign it.
84 if test -n "$prev"; then
90 *=*) optarg
=`expr "X$option" : '[^=]*=\(.*\)'` ;;
94 case $dashdash$option in
99 ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment
100 usage: $0 [OPTION...]
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.
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
111 -g, --gdb-vswitchd run ovs-vswitchd under gdb
112 -d, --gdb-ovsdb run ovsdb-server under gdb
113 --gdb-ovn-northd run ovn-northd under gdb
114 --gdb-ovn-controller run ovn-controller under gdb
115 --gdb-ovn-controller-vtep run ovn-controller-vtep under gdb
116 --dummy=ARG pass --enable-dummy=ARG to vswitchd (default: override)
117 -R, --gdb-run automatically start running the daemon in gdb
118 for any daemon set to run under gdb
119 -S, --schema=FILE use FILE as vswitch.ovsschema
123 -h, --help Print this usage message.
163 gdb_vswitchd_ex
=false
180 --gdb-ovn-controller)
181 gdb_ovn_controller
=true
183 --gdb-ovn-controller-vtep)
184 gdb_ovn_controller_vtep
=true
192 gdb_ovn_northd_ex
=true
193 gdb_ovn_controller_ex
=true
194 gdb_ovn_controller_vtep_ex
=true
197 echo "unrecognized option $option (use --help for help)" >&2
201 echo "$option: non-option arguments not supported (use --help for help)" >&2
208 if $installed && $built; then
209 echo "sorry, conflicting options (use --help for help)" >&2
211 elif $installed ||
$built; then
213 elif test -e vswitchd
/ovs-vswitchd
; then
216 elif (ovs-vswitchd
--version) >/dev
/null
2>&1; then
219 echo "can't find an OVS build or install (use --help for help)" >&2
224 if test ! -e "$builddir"/vswitchd
/ovs-vswitchd
; then
225 echo "$builddir does not appear to be an OVS build directory" >&2
228 builddir
=`cd $builddir && pwd`
234 if test ! -e "$srcdir"/README.rst
; then
235 srcdir
=`cd $builddir/.. && pwd`
239 *) srcdir
=`pwd`/$srcdir ;;
241 schema
=$srcdir/vswitchd
/vswitch.ovsschema
242 if test ! -e "$schema"; then
243 echo >&2 'source directory not found, please use --srcdir'
247 ovnsb_schema
=$srcdir/ovn
/ovn-sb.ovsschema
248 if test ! -e "$ovnsb_schema"; then
249 echo >&2 'source directory not found, please use --srcdir'
252 ovnnb_schema
=$srcdir/ovn
/ovn-nb.ovsschema
253 if test ! -e "$ovnnb_schema"; then
254 echo >&2 'source directory not found, please use --srcdir'
257 vtep_schema
=$srcdir/vtep
/vtep.ovsschema
258 if test ! -e "$vtep_schema"; then
259 echo >&2 'source directory not found, please use --srcdir'
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'
269 PATH
=$builddir/ovsdb
:$builddir/vswitchd
:$builddir/utilities
:$builddir/vtep
:$PATH
271 PATH
=$builddir/ovn
/controller
:$builddir/ovn
/controller-vtep
:$builddir/ovn
/northd
:$builddir/ovn
/utilities
:$PATH
278 /usr
/local
/share
/openvswitch
/vswitch.ovsschema \
279 /usr
/share
/openvswitch
/vswitch.ovsschema \
281 if test -r $schema; then
287 *) schema
=`pwd`/$schema ;;
289 if test ! -r "$schema"; then
290 echo "can't find vswitch.ovsschema, please specify --schema" >&2
294 echo "running with ovn is only supported from the build dir." >&2
302 sandbox
=`cd sandbox && pwd`
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
311 # Easy access to OVS manpages.
312 (cd "$builddir" && ${MAKE-make} install-man mandir
="$sandbox"/man
)
313 MANPATH
=$sandbox/man
:; export MANPATH
317 trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
319 # Create database and start ovsdb-server.
320 touch "$sandbox"/.conf.db.~lock~
321 run ovsdb-tool create conf.db
"$schema"
324 touch "$sandbox"/.ovnsb.db.~lock~
325 touch "$sandbox"/.ovnnb.db.~lock~
326 run ovsdb-tool create ovnsb.db
"$ovnsb_schema"
327 run ovsdb-tool create ovnsb2.db
"$ovnsb_schema"
328 run ovsdb-tool create ovnnb.db
"$ovnnb_schema"
329 run ovsdb-tool create vtep.db
"$vtep_schema"
330 ovsdb_server_args
="vtep.db conf.db"
331 ovsdb_sb_server_args
="ovnsb.db"
332 ovsdb_sb_backup_server_args
="ovnsb2.db"
333 ovsdb_nb_server_args
="ovnnb.db"
335 if [ "$HAVE_OPENSSL" = yes ]; then
336 OVS_PKI
="run ovs-pki --dir=$sandbox/pki --log=$sandbox/ovs-pki.log"
337 $OVS_PKI -B 1024 init
338 $OVS_PKI -B 1024 req
+sign ovnsb switch
339 $OVS_PKI -B 1024 req
+sign ovnnb switch
340 $OVS_PKI -B 1024 req
+sign ovn-controller switch
343 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir --pidfile -vconsole:off
--log-file \
344 --remote=punix
:"$sandbox"/db.sock
$ovsdb_server_args
346 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir \
347 --pidfile="$sandbox"/ovnnb_db.pid
-vconsole:off \
348 --log-file="$sandbox"/ovnnb_db.log \
349 --remote=db
:OVN_Northbound
,NB_Global
,connections \
350 --private-key=db
:OVN_Northbound
,SSL
,private_key \
351 --certificate=db
:OVN_Northbound
,SSL
,certificate \
352 --ca-cert=db
:OVN_Northbound
,SSL
,ca_cert \
353 --ssl-protocols=db
:OVN_Northbound
,SSL
,ssl_protocols \
354 --ssl-ciphers=db
:OVN_Northbound
,SSL
,ssl_ciphers \
355 --remote=punix
:"$sandbox"/ovnnb_db.sock
$ovsdb_nb_server_args
356 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir \
357 --pidfile="$sandbox"/ovnsb_db.pid
-vconsole:off \
358 --log-file="$sandbox"/ovnsb_db.log \
359 --remote=db
:OVN_Southbound
,SB_Global
,connections \
360 --private-key=db
:OVN_Southbound
,SSL
,private_key \
361 --certificate=db
:OVN_Southbound
,SSL
,certificate \
362 --ca-cert=db
:OVN_Southbound
,SSL
,ca_cert \
363 --ssl-protocols=db
:OVN_Southbound
,SSL
,ssl_protocols \
364 --ssl-ciphers=db
:OVN_Southbound
,SSL
,ssl_ciphers \
365 --remote=punix
:"$sandbox"/ovnsb_db.sock
$ovsdb_sb_server_args
366 # Start SB back up server
367 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir \
368 --pidfile="$sandbox"/ovnsb_db2.pid
-vconsole:off \
369 --log-file="$sandbox"/ovnsb_db2.log \
370 --remote=db
:OVN_Southbound
,SB_Global
,connections \
371 --private-key=db
:OVN_Southbound
,SSL
,private_key \
372 --certificate=db
:OVN_Southbound
,SSL
,certificate \
373 --ca-cert=db
:OVN_Southbound
,SSL
,ca_cert \
374 --remote=punix
:"$sandbox"/ovnsb_db2.sock \
375 --unixctl="$sandbox"/sb_backup_unixctl \
376 --sync-from=unix
:"$sandbox"/ovnsb_db.sock
$ovsdb_sb_backup_server_args
379 #Add a small delay to allow ovsdb-server to launch.
382 #Wait for ovsdb-server to finish launching.
383 if test ! -e "$sandbox"/db.sock
; then
384 echo -n "Waiting for ovsdb-server to start..."
385 while test ! -e "$sandbox"/db.sock
; do
391 # Initialize database.
392 run ovs-vsctl
--no-wait -- init
394 # Start ovs-vswitchd.
395 rungdb
$gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd
--detach --no-chdir --pidfile -vconsole:off
--log-file \
396 --enable-dummy=$dummy -vvconn -vnetdev_dummy
402 ovs-vsctl
set open . external-ids
:system-id
=56b18105-5706-46ef-80c4-ff20979ab068
403 ovs-vsctl
set open . external-ids
:hostname
=sandbox
404 ovs-vsctl
set open . external-ids
:ovn-encap-type
=geneve
405 ovs-vsctl
set open . external-ids
:ovn-encap-ip
=127.0.0.1
407 if [ "$HAVE_OPENSSL" = yes ]; then
408 ovn-nbctl set-ssl
$sandbox/ovnnb-privkey.pem
$sandbox/ovnnb-cert.pem
$sandbox/pki
/switchca
/cacert.pem
409 ovn-nbctl set-connection pssl
:6641
410 ovn-sbctl set-ssl
$sandbox/ovnsb-privkey.pem
$sandbox/ovnsb-cert.pem
$sandbox/pki
/switchca
/cacert.pem
411 ovn-sbctl set-connection pssl
:6642
412 ovs-vsctl
set open . external-ids
:ovn-remote
=ssl
:127.0.0.1:6642
413 OVN_CTRLR_PKI
="-p $sandbox/ovn-controller-privkey.pem -c $sandbox/ovn-controller-cert.pem -C $sandbox/pki/switchca/cacert.pem"
415 ovs-vsctl
set open . external-ids
:ovn-remote
=unix
:"$sandbox"/ovnsb_db.sock
418 rungdb
$gdb_ovn_northd $gdb_ovn_northd_ex ovn-northd
--detach \
419 --no-chdir --pidfile -vconsole:off
--log-file \
420 --ovnsb-db=unix
:"$sandbox"/ovnsb_db.sock \
421 --ovnnb-db=unix
:"$sandbox"/ovnnb_db.sock
422 rungdb
$gdb_ovn_controller $gdb_ovn_controller_ex ovn-controller \
423 $OVN_CTRLR_PKI --detach --no-chdir --pidfile -vconsole:off
--log-file
424 rungdb
$gdb_ovn_controller_vtep $gdb_ovn_controller_vtep_ex \
425 ovn-controller-vtep
--detach --no-chdir --pidfile -vconsole:off \
426 $OVN_CTRLR_PKI --log-file --ovnsb-db=unix
:"$sandbox"/ovnsb_db.sock
433 ----------------------------------------------------------------------
434 You are running in a dummy Open vSwitch environment. You can use
435 ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the
439 if $ovn; then cat << EOF
440 This environment also has the OVN daemons and databases enabled.
441 You can use ovn-nbctl and ovn-sbctl to interact with the OVN databases.
443 The backup server of OVN SB can be accessed by:
444 * ovn-sbctl --db=unix:`pwd`/sandbox/ovnsb_db2.sock
445 * ovs-appctl -t `pwd`/sandbox/sb_backup_unixctl
446 The backup database file is "sandbox"/ovnsb2.db
452 Log files, pidfiles, and the configuration database are in the
453 "sandbox" subdirectory.
455 Exit the shell to kill the running daemons.
458 status
=0; $SHELL || status
=$?
461 ----------------------------------------------------------------------