3 # Copyright (c) 2013, 2015 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
72 # This option-parsing mechanism borrowed from a Autoconf-generated
73 # configure script under the following license:
75 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
76 # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
77 # This configure script is free software; the Free Software Foundation
78 # gives unlimited permission to copy, distribute and modify it.
80 # If the previous option needs an argument, assign it.
81 if test -n "$prev"; then
87 *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
91 case $dashdash$option in
96 ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment
99 If you run ovs-sandbox from an OVS build directory, it uses the OVS that
100 you built. Otherwise, if you have an installed Open vSwitch, it uses
101 the installed version.
103 These options force ovs-sandbox to use a particular OVS build:
104 -b, --builddir=DIR specify Open vSwitch build directory
105 -s, --srcdir=DIR specify Open vSwitch source directory
106 These options force ovs-sandbox to use an installed Open vSwitch:
107 -i, --installed use installed Open vSwitch
108 -g, --gdb-vswitchd run ovs-vswitchd under gdb
109 -d, --gdb-ovsdb run ovsdb-server under gdb
110 --gdb-ovn-northd run ovn-northd under gdb
111 --gdb-ovn-controller run ovn-controller under gdb
112 -R, --gdb-run automatically start running the daemon in gdb
113 for any daemon set to run under gdb
114 -S, --schema=FILE use FILE as vswitch.ovsschema
118 -h, --help Print this usage message.
152 gdb_vswitchd_ex=false
169 --gdb-ovn-controller)
170 gdb_ovn_controller=true
178 gdb_ovn_northd_ex=true
179 gdb_ovn_controller_ex=true
182 echo "unrecognized option $option (use --help for help)" >&2
186 echo "$option: non-option arguments not supported (use --help for help)" >&2
193 if $installed && $built; then
194 echo "sorry, conflicting options (use --help for help)" >&2
196 elif $installed || $built; then
198 elif test -e vswitchd/ovs-vswitchd; then
201 elif (ovs-vswitchd --version) >/dev/null 2>&1; then
204 echo "can't find an OVS build or install (use --help for help)" >&2
209 if test ! -e "$builddir"/vswitchd/ovs-vswitchd; then
210 echo "$builddir does not appear to be an OVS build directory" >&2
213 builddir=`cd $builddir && pwd`
219 if test ! -e "$srcdir"/WHY-OVS.md; then
220 srcdir=`cd $builddir/.. && pwd`
224 *) srcdir=`pwd`/$srcdir ;;
226 schema=$srcdir/vswitchd/vswitch.ovsschema
227 if test ! -e "$schema"; then
228 echo >&2 'source directory not found, please use --srcdir'
232 ovnsb_schema=$srcdir/ovn/ovn-sb.ovsschema
233 if test ! -e "$ovnsb_schema"; then
234 echo >&2 'source directory not found, please use --srcdir'
237 ovnnb_schema=$srcdir/ovn/ovn-nb.ovsschema
238 if test ! -e "$ovnnb_schema"; then
239 echo >&2 'source directory not found, please use --srcdir'
244 # Put built tools early in $PATH.
245 if test ! -e $builddir/vswitchd/ovs-vswitchd; then
246 echo >&2 'build not found, please change set $builddir or change directory'
249 PATH=$builddir/ovsdb:$builddir/vswitchd:$builddir/utilities:$PATH
251 PATH=$builddir/ovn:$builddir/ovn/controller:$builddir/ovn/northd:$builddir/ovn/utilities:$PATH
258 /usr/local/share/openvswitch/vswitch.ovsschema \
259 /usr/share/openvswitch/vswitch.ovsschema \
261 if test -r $schema; then
267 *) schema=`pwd`/$schema ;;
269 if test ! -r "$schema"; then
270 echo "can't find vswitch.ovsschema, please specify --schema" >&2
274 echo "running with ovn is only supported from the build dir." >&2
282 sandbox=`cd sandbox && pwd`
284 # Set up environment for OVS programs to sandbox themselves.
285 OVS_RUNDIR=$sandbox; export OVS_RUNDIR
286 OVS_LOGDIR=$sandbox; export OVS_LOGDIR
287 OVS_DBDIR=$sandbox; export OVS_DBDIR
288 OVS_SYSCONFDIR=$sandbox; export OVS_SYSCONFDIR
291 # Easy access to OVS manpages.
292 (cd "$builddir" && ${MAKE} install-man mandir="$sandbox"/man)
293 MANPATH=$sandbox/man:; export MANPATH
297 trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
299 # Create database and start ovsdb-server.
300 touch "$sandbox"/.conf.db.~lock~
301 run ovsdb-tool create conf.db "$schema"
304 touch "$sandbox"/.ovnsb.db.~lock~
305 touch "$sandbox"/.ovnnb.db.~lock~
306 run ovsdb-tool create ovnsb.db "$ovnsb_schema"
307 run ovsdb-tool create ovnnb.db "$ovnnb_schema"
308 ovsdb_server_args="ovnsb.db ovnnb.db conf.db"
310 rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file \
311 --remote=punix:"$sandbox"/db.sock $ovsdb_server_args
313 #Add a small delay to allow ovsdb-server to launch.
316 #Wait for ovsdb-server to finish launching.
317 if test ! -e "$sandbox"/db.sock; then
318 echo -n "Waiting for ovsdb-server to start..."
319 while test ! -e "$sandbox"/db.sock; do
325 # Initialize database.
326 run ovs-vsctl --no-wait -- init
328 # Start ovs-vswitchd.
329 rungdb $gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \
330 --enable-dummy=override -vvconn -vnetdev_dummy
333 ovs-vsctl set open . external-ids:system-id=56b18105-5706-46ef-80c4-ff20979ab068
334 ovs-vsctl set open . external-ids:ovn-remote=unix:"$sandbox"/db.sock
335 ovs-vsctl set open . external-ids:ovn-encap-type=geneve
336 ovs-vsctl set open . external-ids:ovn-encap-ip=127.0.0.1
337 ovs-vsctl add-br br-int \
338 -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
340 rungdb $gdb_ovn_northd $gdb_ovn_northd_ex ovn-northd --detach --no-chdir --pidfile -vconsole:off --log-file
341 rungdb $gdb_ovn_controller $gdb_ovn_controller_ex ovn-controller --detach --no-chdir --pidfile -vconsole:off --log-file
348 ----------------------------------------------------------------------
349 You are running in a dummy Open vSwitch environment. You can use
350 ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the
353 Log files, pidfiles, and the configuration database are in the
354 "sandbox" subdirectory.
356 Exit the shell to kill the running daemons.
359 status=0; $SHELL || status=$?
362 ----------------------------------------------------------------------