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.
21 (cd "$sandbox" && "$@") ||
exit 1
27 run xterm
-T "$title" -e "$@" &
36 # Remove the --detach and to put the process under gdb control.
37 # Also remove --vconsole:off to allow error message to show up
39 # Use "DISPLAY" variable to determine out if X is supported
40 if $under_gdb && [ "$DISPLAY" ]; then
41 args
=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g`
49 run_xterm
$xterm_title gdb
$gdb_cmd --args $args
60 gdb_ovn_northd_ex
=false
61 gdb_ovn_controller
=false
62 gdb_ovn_controller_ex
=false
63 gdb_ovn_controller_vtep
=false
64 gdb_ovn_controller_vtep_ex
=false
83 # This option-parsing mechanism borrowed from a Autoconf-generated
84 # configure script under the following license:
86 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
87 # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
88 # This configure script is free software; the Free Software Foundation
89 # gives unlimited permission to copy, distribute and modify it.
91 # If the previous option needs an argument, assign it.
92 if test -n "$prev"; then
98 *=*) optarg
=`expr "X$option" : '[^=]*=\(.*\)'` ;;
102 case $dashdash$option in
107 ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment
108 usage: $0 [OPTION...]
110 If you run ovs-sandbox from an OVS build directory, it uses the OVS that
111 you built. Otherwise, if you have an installed Open vSwitch, it uses
112 the installed version.
114 These options force ovs-sandbox to use a particular OVS build:
115 -b, --builddir=DIR specify Open vSwitch build directory
116 -s, --srcdir=DIR specify Open vSwitch source directory
117 These options force ovs-sandbox to use an installed Open vSwitch:
118 -i, --installed use installed Open vSwitch
121 -g, --gdb-vswitchd run ovs-vswitchd under gdb
122 -d, --gdb-ovsdb run ovsdb-server under gdb
123 --gdb-ovn-northd run ovn-northd under gdb
124 --gdb-ovn-controller run ovn-controller under gdb
125 --gdb-ovn-controller-vtep run ovn-controller-vtep under gdb
126 --dummy=ARG pass --enable-dummy=ARG to vswitchd (default: override)
127 -R, --gdb-run automatically start running the daemon in gdb
128 for any daemon set to run under gdb
129 -S, --schema=FILE use FILE as vswitch.ovsschema
133 --no-ovn-rbac disable role-based access control for OVN
134 --n-northds=NUMBER run NUMBER copies of northd (default: 1)
135 --nbdb-model=standalone|backup|clustered northbound database model
136 --nbdb-servers=N number of servers in nbdb cluster (default: 3)
137 --sbdb-model=standalone|backup|clustered southbound database model
138 --sbdb-servers=N number of servers in sbdb cluster (default: 3)
141 -h, --help Print this usage message.
181 gdb_vswitchd_ex
=false
198 --gdb-ovn-controller)
199 gdb_ovn_controller
=true
201 --gdb-ovn-controller-vtep)
202 gdb_ovn_controller_vtep
=true
217 n_controllers
=$optarg
253 gdb_ovn_northd_ex
=true
254 gdb_ovn_controller_ex
=true
255 gdb_ovn_controller_vtep_ex
=true
258 echo "unrecognized option $option (use --help for help)" >&2
262 echo "$option: non-option arguments not supported (use --help for help)" >&2
269 if $installed && $built; then
270 echo "sorry, conflicting options (use --help for help)" >&2
272 elif $installed ||
$built; then
274 elif test -e vswitchd
/ovs-vswitchd
; then
277 elif (ovs-vswitchd
--version) >/dev
/null
2>&1; then
280 echo "can't find an OVS build or install (use --help for help)" >&2
285 if test ! -e "$builddir"/vswitchd
/ovs-vswitchd
; then
286 echo "$builddir does not appear to be an OVS build directory" >&2
289 builddir
=`cd $builddir && pwd`
295 if test ! -e "$srcdir"/README.rst
; then
296 srcdir
=`cd $builddir/.. && pwd`
300 *) srcdir
=`pwd`/$srcdir ;;
302 schema
=$srcdir/vswitchd
/vswitch.ovsschema
303 if test ! -e "$schema"; then
304 echo >&2 'source directory not found, please use --srcdir'
308 ovnsb_schema
=$srcdir/ovn
/ovn-sb.ovsschema
309 if test ! -e "$ovnsb_schema"; then
310 echo >&2 'source directory not found, please use --srcdir'
313 ovnnb_schema
=$srcdir/ovn
/ovn-nb.ovsschema
314 if test ! -e "$ovnnb_schema"; then
315 echo >&2 'source directory not found, please use --srcdir'
318 vtep_schema
=$srcdir/vtep
/vtep.ovsschema
319 if test ! -e "$vtep_schema"; then
320 echo >&2 'source directory not found, please use --srcdir'
325 # Put built tools early in $PATH.
326 if test ! -e $builddir/vswitchd
/ovs-vswitchd
; then
327 echo >&2 'build not found, please change set $builddir or change directory'
330 PATH
=$builddir/ovsdb
:$builddir/vswitchd
:$builddir/utilities
:$builddir/vtep
:$PATH
332 PATH
=$builddir/ovn
/controller
:$builddir/ovn
/controller-vtep
:$builddir/ovn
/northd
:$builddir/ovn
/utilities
:$PATH
339 /usr
/local
/share
/openvswitch
/vswitch.ovsschema \
340 /usr
/share
/openvswitch
/vswitch.ovsschema \
342 if test -r $schema; then
348 *) schema
=`pwd`/$schema ;;
350 if test ! -r "$schema"; then
351 echo "can't find vswitch.ovsschema, please specify --schema" >&2
355 echo "running with ovn is only supported from the build dir." >&2
363 sandbox
=`cd sandbox && pwd`
365 # Set up environment for OVS programs to sandbox themselves.
366 OVS_RUNDIR
=$sandbox; export OVS_RUNDIR
367 OVS_LOGDIR
=$sandbox; export OVS_LOGDIR
368 OVS_DBDIR
=$sandbox; export OVS_DBDIR
369 OVS_SYSCONFDIR
=$sandbox; export OVS_SYSCONFDIR
372 # Easy access to OVS manpages.
373 (cd "$builddir" && ${MAKE-make} install-man install-man-rst mandir
="$sandbox"/man
)
374 MANPATH
=$sandbox/man
:; export MANPATH
378 trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
380 # Create database and start ovsdb-server.
381 touch "$sandbox"/.conf.db.~lock~
382 run ovsdb-tool create conf.db
"$schema"
385 touch "$sandbox"/.ovnnb.db.~lock~
386 run ovsdb-tool create ovnnb.db
"$ovnnb_schema"
387 run ovsdb-tool create vtep.db
"$vtep_schema"
388 ovsdb_server_args
="vtep.db conf.db"
389 ovsdb_nb_server_args
="ovnnb.db"
391 if [ "$HAVE_OPENSSL" = yes ]; then
392 OVS_PKI
="run ovs-pki --dir=$sandbox/pki --log=$sandbox/ovs-pki.log"
393 $OVS_PKI -B 1024 init
394 $OVS_PKI -B 1024 req
+sign ovnsb switch
395 $OVS_PKI -B 1024 req
+sign ovnnb switch
396 for i
in $
(seq $n_controllers); do
397 $OVS_PKI -B 1024 -u req
+sign chassis-
$i switch
401 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir --pidfile -vconsole:off
--log-file -vsyslog:off \
402 --remote=punix
:"$sandbox"/db.sock \
403 --remote=db
:Open_vSwitch
,Open_vSwitch
,manager_options \
407 local db
=$1 model
=$2 servers
=$3 schema
=$4
408 local DB
=$
(echo $db |
tr a-z A-Z
)
409 local schema_name
=$
(ovsdb-tool schema-name
$schema)
412 standalone | backup
) ;;
415 [1-9] |
[1-9][0-9]) ;;
416 *) echo "${db}db servers must be between 1 and 99" >&2
422 echo "unknown ${db}db model \"$model\"" >&2
427 ovn_start_ovsdb_server
() {
429 rungdb
$gdb_ovsdb $gdb_ovsdb_ex ovsdb-server
--detach --no-chdir \
430 --pidfile=$db$i.pid
-vconsole:off
--log-file=$db$i.log \
432 --remote=db
:$schema_name,${DB}_Global
,connections \
433 --private-key=db
:$schema_name,SSL
,private_key \
434 --certificate=db
:$schema_name,SSL
,certificate \
435 --ca-cert=db
:$schema_name,SSL
,ca_cert \
436 --ssl-protocols=db
:$schema_name,SSL
,ssl_protocols \
437 --ssl-ciphers=db
:$schema_name,SSL
,ssl_ciphers \
438 --unixctl=${db}$i --remote=punix
:$db$i.ovsdb
${db}$i.db
"$@"
443 run ovsdb-tool create
${db}1.db
"$schema"
444 ovn_start_ovsdb_server
1
445 remote
=unix
:${db}1.ovsdb
449 run ovsdb-tool create
$db$i.db
"$schema"
451 ovn_start_ovsdb_server
1
452 ovn_start_ovsdb_server
2 --sync-from=unix
:${db}1.ovsdb
453 remote
=unix
:${db}1.ovsdb
454 backup_note
="$backup_note
455 The backup server of OVN $DB can be accessed by:
456 * ovn-${db}ctl --db=unix:`pwd`/sandbox/${db}2.ovsdb
457 * ovs-appctl -t `pwd`/sandbox/${db}2
458 The backup database file is sandbox/${db}2.db
462 for i
in $
(seq $servers); do
464 run ovsdb-tool create-cluster
${db}1.db
"$schema" unix
:${db}1.raft
;
466 run ovsdb-tool join-cluster
$db$i.db
$schema_name unix
:$db$i.raft unix
:${db}1.raft
468 ovn_start_ovsdb_server
$i
470 remote
=unix
:${db}1.ovsdb
471 for i
in `seq 2 $n`; do
472 remote
=$remote,unix
:$db$i.ovsdb
474 for i
in $
(seq $servers); do
475 run ovsdb-client
wait unix
:$db$i.ovsdb
$schema_name connected
479 eval OVN_
${DB}_DB
=\
$remote
480 eval export OVN_
${DB}_DB
484 ovn_start_db nb
"$nbdb_model" "$nbdb_servers" "$ovnnb_schema"
485 ovn_start_db sb
"$sbdb_model" "$sbdb_servers" "$ovnsb_schema"
488 #Add a small delay to allow ovsdb-server to launch.
491 #Wait for ovsdb-server to finish launching.
492 if test ! -e "$sandbox"/db.sock
; then
493 printf "Waiting for ovsdb-server to start..."
494 while test ! -e "$sandbox"/db.sock
; do
500 # Initialize database.
501 run ovs-vsctl
--no-wait -- init
503 # Start ovs-vswitchd.
504 rungdb
$gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd
--detach --no-chdir --pidfile -vconsole:off
--log-file -vsyslog:off \
505 --enable-dummy=$dummy -vvconn -vnetdev_dummy
511 ovs-vsctl
set open . external-ids
:system-id
=chassis-1
512 ovs-vsctl
set open . external-ids
:hostname
=sandbox
513 ovs-vsctl
set open . external-ids
:ovn-encap-type
=geneve
514 ovs-vsctl
set open . external-ids
:ovn-encap-ip
=127.0.0.1
516 if [ "$HAVE_OPENSSL" = yes ]; then
517 ovn-nbctl set-ssl
$sandbox/ovnnb-privkey.pem
$sandbox/ovnnb-cert.pem
$sandbox/pki
/switchca
/cacert.pem
518 ovn-nbctl set-connection pssl
:6641
519 ovn-sbctl set-ssl
$sandbox/ovnsb-privkey.pem
$sandbox/ovnsb-cert.pem
$sandbox/pki
/switchca
/cacert.pem
521 ovn-sbctl set-connection role
=ovn-controller pssl
:6642
523 ovn-sbctl set-connection pssl
:6642
525 ovs-vsctl
set open . external-ids
:ovn-remote
=ssl
:127.0.0.1:6642
526 OVN_CTRLR_PKI
="-p $sandbox/chassis-1-privkey.pem -c $sandbox/chassis-1-cert.pem -C $sandbox/pki/switchca/cacert.pem"
528 ovs-vsctl
set open . external-ids
:ovn-remote
=$OVN_SB_DB
531 for i
in $
(seq $n_northds); do
532 rungdb
$gdb_ovn_northd $gdb_ovn_northd_ex ovn-northd
--detach \
533 --no-chdir --pidfile=ovn-northd
$i.pid
-vconsole:off \
534 --log-file=ovn-northd
$i.log
-vsyslog:off \
535 --ovnsb-db="$OVN_SB_DB" --ovnnb-db="$OVN_NB_DB"
537 for i
in $
(seq $n_controllers); do
538 rungdb
$gdb_ovn_controller $gdb_ovn_controller_ex ovn-controller \
539 $OVN_CTRLR_PKI --detach --no-chdir -vsyslog:off \
540 --pidfile=ovn-controller
$i.pid
-vconsole:off
--log-file
542 rungdb
$gdb_ovn_controller_vtep $gdb_ovn_controller_vtep_ex \
543 ovn-controller-vtep
--detach --no-chdir --pidfile -vconsole:off \
544 $OVN_CTRLR_PKI --log-file -vsyslog:off \
545 --ovnsb-db=unix
:"$sandbox"/ovnsb_db.sock
552 ----------------------------------------------------------------------
553 You are running in a dummy Open vSwitch environment. You can use
554 ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the
558 if $ovn; then cat << EOF
559 This environment also has the OVN daemons and databases enabled.
560 You can use ovn-nbctl and ovn-sbctl to interact with the OVN databases.
565 Log files, pidfiles, and the configuration database are in the
566 "sandbox" subdirectory.
568 Exit the shell to kill the running daemons.
571 status
=0; $SHELL || status
=$?
574 ----------------------------------------------------------------------