]>
git.proxmox.com Git - ovs.git/blob - utilities/ovs-sim.in
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
78 sim_base
=`pwd`; export sim_base
81 for signal
in 0 1 2 3 13 14 15; do
84 cd '$sim_base' && (kill \`cat */*.pid\`) >/dev/null 2>&1
86 kill -$signal $$" $signal
89 export -f trap_signals
94 OVS_RUNDIR
=$sim_base/$1; export OVS_RUNDIR
95 OVS_LOGDIR
=$sim_base/$1; export OVS_LOGDIR
96 OVS_DBDIR
=$sim_base/$1; export OVS_DBDIR
97 OVS_SYSCONFDIR
=$sim_base/$1; export OVS_SYSCONFDIR
100 export -f sim_setvars
102 ovs-vsctl
() { command ovs-vsctl
-vsyslog:off
"$@"; }; export -f ovs-vsctl
103 vtep-ctl
() { command vtep-ctl
-vsyslog:off
"$@"; }; export -f vtep-ctl
108 echo >&2 "$FUNCNAME: missing arguments (use --help for help)"
112 if test "$1" != --help; then
116 $FUNCNAME: set the default sandbox for Open vSwitch commands
117 usage: $FUNCNAME SANDBOX [COMMAND ARG...]
118 where SANDBOX is the name of the desired sandbox.
120 With COMMAND arguments, this command sets the default target for that
121 single command, which it runs directly. Otherwise, it sets the default
122 target for all following commands.
127 (sim_setvars
$1; shift; "$@")
134 if test "$1" == --help; then
136 $FUNCNAME: create a new sandboxed Open vSwitch instance
137 usage: $FUNCNAME SANDBOX
139 where SANDBOX is the name of the new sandbox, which will be created in
140 a directory named $sim_base/SANDBOX.
141 Afterward, use "as SANDBOX" to execute OVS commands in the sandbox's
146 if test $# != 1; then
147 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
152 if test $# != 1; then
153 echo >&2 "$FUNCNAME: sandbox name must be a single word"
157 if test -e "$sim_base/$1"; then
158 echo >&2 "$1 already exists"
163 mkdir
"$sim_base"/$1 ||
return 1
165 daemon_opts
="--detach --no-chdir --pidfile -vconsole:off -vsyslog:off --log-file"
167 # Create database and start ovsdb-server.
168 touch $sim_base/$1/.conf.db.~lock~
169 as
$1 ovsdb-tool create
$sim_base/$1/conf.db
"$sim_srcdir/vswitchd/vswitch.ovsschema"
170 as
$1 ovsdb-server
--remote=punix
:"$sim_base"/$1/db.sock
$daemon_opts
172 # Initialize database.
173 as
$1 ovs-vsctl
--no-wait -- init
175 # Start ovs-vswitchd.
176 as
$1 ovs-vswitchd
--enable-dummy=system
-vvconn -vnetdev_dummy $daemon_opts
181 if test "$1" == --help; then
183 $FUNCNAME: create a new interconnection network
184 usage: $FUNCNAME NETWORK
186 where NETWORK is the name of the new network. Interconnection networks
187 are used with net_attach.
191 if test $# != 1; then
192 echo >&2 "$FUNCNAME: missing argument (use --help for help)"
196 as main ovs-vsctl add-br
"$1"
201 if test "$1" == --help; then
203 $FUNCNAME: attach the default sandbox to an interconnection network
204 usage: $FUNCNAME NETWORK BRIDGE
206 Adds a port to BRIDGE within the default sandbox that connects BRIDGE
207 to the interconnection network NETWORK. (Use "as" to set the default
212 if test $# != 2; then
213 echo >&2 "$FUNCNAME: wrong number of arguments (use --help for help)"
216 if test $sandbox = main
; then
217 echo >&2 "$FUNCNAME: can only attach interconnection networks to sandboxes other than main"
221 local net
=$1 bridge
=$2
223 port
=${sandbox}_
$bridge
225 -- add-port
$net "$port" \
226 -- 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
229 -- set Interface
$bridge options
:tx_pcap
="$sim_base/$sandbox/$bridge-tx.pcap" options
:rxq_pcap
="$sim_base/$sandbox/$bridge-rx.pcap" \
230 -- add-port
$bridge ${bridge}_
$net \
231 -- 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
235 # Easy access to OVS manpages.
237 mandir=`cd $sim_base/man && pwd`
238 (cd "$sim_builddir" && ${MAKE-make} install-man install-man-rst mandir=$mandir EXTRA_RST_MANPAGES=ovs-sim.1.rst >/dev/null)
239 MANPATH=$mandir:; export MANPATH
244 if [ -f /etc/bashrc ]; then
247 if [ -f ~/.bashrc ]; then
256 for script in $scripts; do
260 $interactive || exit 0
263 ______________________________________________________________________
265 | You are running in a nested shell environment meant for Open vSwitch
266 | testing in simulation. The OVS manpages are available via "man
".
267 | Please see ovs-sim(1) for more information.
269 | Exit the shell to kill the running daemons and leave the simulation
275 status=0; bash --rcfile <(echo "$rc") || status=$?
277 if $interactive; then
279 |______________________________________________________________________