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
106 echo >&2 "$FUNCNAME: missing arguments (use --help for help)"
110 if test "$1" != --help; then
114 $FUNCNAME: set the default sandbox for Open vSwitch commands
115 usage: $FUNCNAME SANDBOX [COMMAND ARG...]
116 where SANDBOX is the name of the desired sandbox.
118 With COMMAND arguments, this command sets the default target for that
119 single command, which it runs directly. Otherwise, it sets the default
120 target for all following commands.
125 (sim_setvars
$1; shift; "$@")
132 if test "$1" == --help; then
134 $FUNCNAME: create a new sandboxed Open vSwitch instance
135 usage: $FUNCNAME SANDBOX
137 where SANDBOX is the name of the new sandbox, which will be created in
138 a directory named $sim_base/SANDBOX.
139 Afterward, use "as SANDBOX" to execute OVS commands in the sandbox's
144 if test $# != 1; then
145 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
150 if test $# != 1; then
151 echo >&2 "$FUNCNAME: sandbox name must be a single word"
155 if test -e "$sim_base/$1"; then
156 echo >&2 "$1 already exists"
161 mkdir
"$sim_base"/$1 ||
return 1
163 daemon_opts
="--detach --no-chdir --pidfile -vconsole:off --log-file"
165 # Create database and start ovsdb-server.
166 touch $sim_base/$1/.conf.db.~lock~
167 as
$1 ovsdb-tool create
$sim_base/$1/conf.db
"$sim_srcdir/vswitchd/vswitch.ovsschema"
168 as
$1 ovsdb-server
$daemon_opts --remote=punix
:"$sim_base"/$1/db.sock
170 # Initialize database.
171 as
$1 ovs-vsctl
--no-wait -- init
173 # Start ovs-vswitchd.
174 as
$1 ovs-vswitchd
$daemon_opts --enable-dummy=system
-vvconn -vnetdev_dummy
179 if test "$1" == --help; then
181 $FUNCNAME: create a new interconnection network
182 usage: $FUNCNAME NETWORK
184 where NETWORK is the name of the new network. Interconnection networks
185 are used with net_attach and ovn_attach.
189 if test $# != 1; then
190 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
194 as main ovs-vsctl add-br
"$1"
199 if test "$1" == --help; then
201 $FUNCNAME: attach the default sandbox to an interconnection network
202 usage: $FUNCNAME NETWORK BRIDGE
204 Adds a port to BRIDGE within the default sandbox that connects BRIDGE
205 to the interconnection network NETWORK. (Use "as" to set the default
210 if test $# != 2; then
211 echo >&2 "$FUNCNAME: wrong number of arguments (use --help for help)"
214 if test $sandbox = main
; then
215 echo >&2 "$FUNCNAME: can only attach interconnection networks to sandboxes other than main"
219 local net
=$1 bridge
=$2
221 port
=${sandbox}_
$bridge
223 -- add-port
$net "$port" \
224 -- 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
227 -- set Interface
$bridge options
:tx_pcap
="$sim_base/$sandbox/$bridge-tx.pcap" options
:rxq_pcap
="$sim_base/$sandbox/$bridge-rx.pcap" \
228 -- add-port
$bridge ${bridge}_
$net \
229 -- 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
234 if test "$1" == --help; then
236 $FUNCNAME: start OVN central databases and daemons
239 This creates and initializes the central OVN databases (northbound and
240 southbound), starts their ovsdb-server daemons, and starts the ovn-northd
245 if test $# != 0; then
246 echo >&2 "$FUNCNAME: no arguments accepted
(use
--help for help)"
250 if test -d ovn-sb || test -d ovn-nb; then
251 echo >&2 "OVN already started
"
255 daemon_opts="--detach --no-chdir --pidfile -vconsole:off
--log-file"
256 for db in ovn-sb ovn-nb; do
257 mkdir "$sim_base"/$db
258 touch "$sim_base"/$db/.$db.db.~lock~
259 as $db ovsdb-tool create "$sim_base"/$db/$db.db "$sim_srcdir"/ovn/$db.ovsschema
260 as $db ovsdb-server $daemon_opts --remote=punix:"$sim_base"/$db/$db.sock "$sim_base"/$db/$db.db
263 OVN_NB_DB=unix:$sim_base/ovn-nb/ovn-nb.sock; export OVN_NB_DB
264 OVN_SB_DB=unix:$sim_base/ovn-sb/ovn-sb.sock; export OVN_SB_DB
269 mkdir "$sim_base"/northd
270 as northd ovn-northd $daemon_opts \
271 --ovnnb-db="$OVN_NB_DB" \
272 --ovnsb-db="$OVN_SB_DB"
277 if test "$1" == --help; then
279 $FUNCNAME: attach default sandbox to an interconnection network for OVN
280 usage: $FUNCNAME NETWORK BRIDGE IP [MASKLEN]
282 This starts by doing everything that net_attach does. Then it configures the
283 specified IP and MASKLEN (e.g. 192.168.0.1 and 24) on BRIDGE and starts
284 and configures ovn-controller.
286 MASKLEN defaults to 24 if it is not specified.
290 if test $# != 3 && test $# != 4; then
291 echo >&2 "$FUNCNAME: wrong number of arguments
(use
--help for help)"
295 local net=$1 bridge=$2 ip=$3 masklen=${4-24}
296 net_attach $net $bridge || return $?
298 ovs-appctl netdev-dummy/ip4addr $bridge $ip/$masklen >/dev/null
299 ovs-appctl ovs/route/add $ip/$masklen $bridge > /dev/null
301 -- set Open_vSwitch . external-ids:system-id=$sandbox \
302 -- set Open_vSwitch . external-ids:ovn-remote=unix:$sim_base/ovn-sb/ovn-sb.sock \
303 -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
304 -- set Open_vSwitch . external-ids:ovn-encap-ip=$ip\
306 -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
307 ovn-controller --detach --no-chdir --pidfile -vconsole:off --log-file
311 # Easy access to OVS manpages.
313 mandir=`cd $sim_base/man && pwd`
314 (cd "$sim_builddir" && ${MAKE-make} install-man mandir=$mandir >/dev/null)
315 MANPATH=$mandir:; export MANPATH
320 if [ -f /etc/bashrc ]; then
323 if [ -f ~/.bashrc ]; then
332 for script in $scripts; do
336 $interactive || exit 0
339 ______________________________________________________________________
341 | You are running in a nested shell environment meant for Open vSwitch
342 | and OVN testing in simulation. The OVS manpages are available via
343 | "man
". Please see ovs-sim(1) for more information.
345 | Exit the shell to kill the running daemons and leave the simulation
350 status=0; bash --rcfile <(echo "$rc") || status=$?
352 if $interactive; then
354 |______________________________________________________________________