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.
19 sim_builddir
='@abs_builddir@'; export sim_builddir
20 sim_srcdir
='@abs_top_srcdir@'; export sim_srcdir
28 $0, for starting sandboxed dummy Open vSwitch environments
29 usage: $0 [OPTION...] [SCRIPT...]
32 -i, --interactive Prompt for interactive input (default if no SCRIPTs)
33 -h, --help Print this usage message.
43 echo "unrecognized option $option (use --help for help)" >&2
49 *) option
=`pwd`/$option ;;
51 scripts
="$scripts $option"
57 if test -z "$scripts"; then
61 # Check that we've got proper builddir and srcdir.
62 if test ! -e "$sim_builddir"/vswitchd
/ovs-vswitchd
; then
63 echo "$sim_builddir/vswitchd/ovs-vswitchd does not exist (need to run \"make\"?)" >&2
66 if test ! -e "$sim_srcdir"/README.rst
; then
67 echo "$sim_srcdir/README.rst does not exist" >&2
71 # Put built tools early in $PATH.
72 PATH
=$sim_builddir/ovsdb
:$sim_builddir/vswitchd
:$sim_builddir/utilities
:$PATH
73 PATH
=$sim_builddir/ovn
/controller
:$sim_builddir/ovn
/northd
:$sim_builddir/ovn
/utilities
:$PATH
79 sim_base
=`pwd`; export sim_base
82 for signal
in 0 1 2 3 13 14 15; do
85 cd '$sim_base' && (kill \`cat */*.pid\`) >/dev/null 2>&1
87 kill -$signal $$" $signal
90 export -f trap_signals
95 OVS_RUNDIR
=$sim_base/$1; export OVS_RUNDIR
96 OVS_LOGDIR
=$sim_base/$1; export OVS_LOGDIR
97 OVS_DBDIR
=$sim_base/$1; export OVS_DBDIR
98 OVS_SYSCONFDIR
=$sim_base/$1; export OVS_SYSCONFDIR
101 export -f sim_setvars
103 ovs-vsctl
() { command ovs-vsctl
-vsyslog:off
"$@"; }; export -f ovs-vsctl
104 ovs-nbctl
() { command ovs-nbctl
-vsyslog:off
"$@"; }; export -f ovs-nbctl
105 ovs-sbctl
() { command ovs-sbctl
-vsyslog:off
"$@"; }; export -f ovs-sbctl
106 vtep-ctl
() { command vtep-ctl
-vsyslog:off
"$@"; }; export -f vtep-ctl
111 echo >&2 "$FUNCNAME: missing arguments (use --help for help)"
115 if test "$1" != --help; then
119 $FUNCNAME: set the default sandbox for Open vSwitch commands
120 usage: $FUNCNAME SANDBOX [COMMAND ARG...]
121 where SANDBOX is the name of the desired sandbox.
123 With COMMAND arguments, this command sets the default target for that
124 single command, which it runs directly. Otherwise, it sets the default
125 target for all following commands.
130 (sim_setvars
$1; shift; "$@")
137 if test "$1" == --help; then
139 $FUNCNAME: create a new sandboxed Open vSwitch instance
140 usage: $FUNCNAME SANDBOX
142 where SANDBOX is the name of the new sandbox, which will be created in
143 a directory named $sim_base/SANDBOX.
144 Afterward, use "as SANDBOX" to execute OVS commands in the sandbox's
149 if test $# != 1; then
150 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
155 if test $# != 1; then
156 echo >&2 "$FUNCNAME: sandbox name must be a single word"
160 if test -e "$sim_base/$1"; then
161 echo >&2 "$1 already exists"
166 mkdir
"$sim_base"/$1 ||
return 1
168 daemon_opts
="--detach --no-chdir --pidfile -vconsole:off -vsyslog:off --log-file"
170 # Create database and start ovsdb-server.
171 touch $sim_base/$1/.conf.db.~lock~
172 as
$1 ovsdb-tool create
$sim_base/$1/conf.db
"$sim_srcdir/vswitchd/vswitch.ovsschema"
173 as
$1 ovsdb-server
--remote=punix
:"$sim_base"/$1/db.sock
$daemon_opts
175 # Initialize database.
176 as
$1 ovs-vsctl
--no-wait -- init
178 # Start ovs-vswitchd.
179 as
$1 ovs-vswitchd
--enable-dummy=system
-vvconn -vnetdev_dummy $daemon_opts
184 if test "$1" == --help; then
186 $FUNCNAME: create a new interconnection network
187 usage: $FUNCNAME NETWORK
189 where NETWORK is the name of the new network. Interconnection networks
190 are used with net_attach and ovn_attach.
194 if test $# != 1; then
195 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
199 as main ovs-vsctl add-br
"$1"
204 if test "$1" == --help; then
206 $FUNCNAME: attach the default sandbox to an interconnection network
207 usage: $FUNCNAME NETWORK BRIDGE
209 Adds a port to BRIDGE within the default sandbox that connects BRIDGE
210 to the interconnection network NETWORK. (Use "as" to set the default
215 if test $# != 2; then
216 echo >&2 "$FUNCNAME: wrong number of arguments (use --help for help)"
219 if test $sandbox = main
; then
220 echo >&2 "$FUNCNAME: can only attach interconnection networks to sandboxes other than main"
224 local net
=$1 bridge
=$2
226 port
=${sandbox}_
$bridge
228 -- add-port
$net "$port" \
229 -- set Interface
"$port" options
:pstream
="punix:$sim_base/main/$port.sock" options
:rxq_pcap
="$sim_base/main/$port-rx.pcap" options
:tx_pcap
="$sim_base/main/$port-tx.pcap" options
:header
=extended
232 -- set Interface
$bridge options
:tx_pcap
="$sim_base/$sandbox/$bridge-tx.pcap" options
:rxq_pcap
="$sim_base/$sandbox/$bridge-rx.pcap" \
233 -- add-port
$bridge ${bridge}_
$net \
234 -- set Interface
${bridge}_$net options:stream="unix:$sim_base/main/$port.sock" options:rxq_pcap="$sim_base/$sandbox/${bridge}_$net-rx.pcap" options:tx_pcap="$sim_base/$sandbox/${bridge}_
$net-tx.pcap
" options:header=extended
239 local db=$1 model=$2 servers=$3 schema=$4
240 local DB=$(echo $db | tr a-z A-Z)
241 local schema_name=$(ovsdb-tool schema-name $schema)
244 standalone | backup) ;;
247 [1-9] | [1-9][0-9]) ;;
248 *) echo "${db}db servers must be between
1 and
99" >&2
254 echo "unknown
${db}db model
\"$model\"" >&2
259 ovn_start_ovsdb_server() {
261 as ${db}$i ovsdb-server --detach --no-chdir --pidfile=$db.pid \
262 -vsyslog:off -vconsole:off --log-file="$sim_base"/$db$i/$db.log \
263 --remote=db:$schema_name,${DB}_Global,connections \
264 --private-key=db:$schema_name,SSL,private_key \
265 --certificate=db:$schema_name,SSL,certificate \
266 --ca-cert=db:$schema_name,SSL,ca_cert \
267 --ssl-protocols=db:$schema_name,SSL,ssl_protocols \
268 --ssl-ciphers=db:$schema_name,SSL,ssl_ciphers \
269 --unixctl=${db} --remote=punix:$db.ovsdb \
270 "$sim_base"/$db$i/$db.db "$@
"
275 mkdir "$sim_base"/${db}$i
276 touch "$sim_base"/${db}$i/.$db.db.~lock~
283 ovsdb-tool create "$sim_base"/${db}1/$db.db "$schema"
284 ovn_start_ovsdb_server 1
289 ovsdb-tool create "$sim_base"/$db$i/$db.db "$schema"
291 ovn_start_ovsdb_server 1
292 ovn_start_ovsdb_server 2 --sync-from=unix:"$sim_base"/${db}1/$db.ovsdb
294 The backup server of OVN $DB can be accessed by:
295 * ovn-${db}ctl --db=unix:$sim_base/${db}2/$db.ovsdb
296 * ovs-appctl -t $sim_base/${db}2/${db}
297 The backup database file is $sim_base/${db}2/$db.db
302 for i in $(seq $servers); do
305 ovsdb-tool create-cluster "$sim_base"/$db$i/$db.db "$schema" unix:"$sim_base"/$db$i/db.raft
307 ovsdb-tool join-cluster "$sim_base"/$db$i/$db.db $schema_name unix:"$sim_base"/$db$i/db.raft unix:"$sim_base"/${db}1/db.raft
309 ovn_start_ovsdb_server $i
311 for i in $(seq $servers); do
312 ovsdb-client wait unix:"$sim_base"/${db}$i/$db.ovsdb $schema_name connected
317 remote=unix:"$sim_base"/${db}1/$db.ovsdb
318 for i in `seq 2 $n_remotes`; do
319 remote=$remote,unix:"$sim_base"/${db}$i/$db.ovsdb
321 eval OVN_${DB}_DB=\$remote
322 eval export OVN_${DB}_DB
324 export -f ovn_start_db
327 local nbdb_model=standalone
329 local sbdb_model=standalone
333 # This option-parsing mechanism borrowed from a Autoconf-generated
334 # configure script under the following license:
336 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
337 # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
338 # This configure script is free software; the Free Software Foundation
339 # gives unlimited permission to copy, distribute and modify it.
341 # If the previous option needs an argument, assign it.
342 if test -n "$prev"; then
348 *=*) optarg=`expr "X
$option" : '[^=]*=\(.*\)'` ;;
352 case $dashdash$option in
357 $FUNCNAME: start OVN central databases and daemons
358 usage: $FUNCNAME [OPTION...]
360 This creates and initializes the central OVN databases (northbound and
361 southbound), starts their ovsdb-server daemons, and starts the ovn-northd
365 --nbdb-model=standalone|backup|clustered northbound database model
366 --nbdb-servers=N number of servers in nbdb cluster (default: 3)
367 --sbdb-model=standalone|backup|clustered southbound database model
368 --sbdb-servers=N number of servers in sbdb cluster (default: 3)
369 -h, --help Print this usage message.
403 echo "unrecognized option
$option (use
--help for help)" >&2
407 echo "$option: non-option arguments not supported
(use
--help for help)" >&2
414 if test -d ovn-sb || test -d ovn-nb; then
415 echo >&2 "OVN already started
"
419 ovn_start_db nb "$nbdb_model" "$nbdb_servers" "$sim_srcdir"/ovn/ovn-nb.ovsschema
420 ovn_start_db sb "$sbdb_model" "$sbdb_servers" "$sim_srcdir"/ovn/ovn-sb.ovsschema
425 mkdir "$sim_base"/northd
426 as northd ovn-northd --ovnnb-db="$OVN_NB_DB" --ovnsb-db="$OVN_SB_DB" \
432 if test "$1" == --help; then
434 $FUNCNAME: attach default sandbox to an interconnection network for OVN
435 usage: $FUNCNAME NETWORK BRIDGE IP [MASKLEN]
437 This starts by doing everything that net_attach does. Then it configures the
438 specified IP and MASKLEN (e.g. 192.168.0.1 and 24) on BRIDGE and starts
439 and configures ovn-controller.
441 MASKLEN defaults to 24 if it is not specified.
445 if test $# != 3 && test $# != 4; then
446 echo >&2 "$FUNCNAME: wrong number of arguments
(use
--help for help)"
450 local net=$1 bridge=$2 ip=$3 masklen=${4-24}
451 net_attach $net $bridge || return $?
453 ovs-appctl netdev-dummy/ip4addr $bridge $ip/$masklen >/dev/null
454 ovs-appctl ovs/route/add $ip/$masklen $bridge > /dev/null
456 -- set Open_vSwitch . external-ids:system-id=$sandbox \
457 -- set Open_vSwitch . external-ids:ovn-remote=$OVN_SB_DB \
458 -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
459 -- set Open_vSwitch . external-ids:ovn-encap-ip=$ip\
461 -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
462 ovn-controller --detach --no-chdir --pidfile -vconsole:off -vsyslog:off --log-file
466 # Easy access to OVS manpages.
468 mandir=`cd $sim_base/man && pwd`
469 (cd "$sim_builddir" && ${MAKE-make} install-man install-man-rst mandir=$mandir EXTRA_RST_MANPAGES=ovs-sim.1.rst >/dev/null)
470 MANPATH=$mandir:; export MANPATH
475 if [ -f /etc/bashrc ]; then
478 if [ -f ~/.bashrc ]; then
487 for script in $scripts; do
491 $interactive || exit 0
494 ______________________________________________________________________
496 | You are running in a nested shell environment meant for Open vSwitch
497 | and OVN testing in simulation. The OVS manpages are available via
498 | "man
". Please see ovs-sim(1) for more information.
500 | Exit the shell to kill the running daemons and leave the simulation
506 status=0; bash --rcfile <(echo "$rc") || status=$?
508 if $interactive; then
510 |______________________________________________________________________