From patchwork Thu Oct 10 10:45:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Flaviof X-Patchwork-Id: 1174398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=flaviof.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46pnms4HK9z9sPL for ; Thu, 10 Oct 2019 21:45:48 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 5B02EEB4; Thu, 10 Oct 2019 10:45:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 94BBEEA1 for ; Thu, 10 Oct 2019 10:45:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-yw1-f50.google.com (mail-yw1-f50.google.com [209.85.161.50]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5BEDA709 for ; Thu, 10 Oct 2019 10:45:39 +0000 (UTC) Received: by mail-yw1-f50.google.com with SMTP id w140so1988245ywd.0 for ; Thu, 10 Oct 2019 03:45:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :senderwebaddress:content-transfer-encoding; bh=2X6ujxiVNfElCh3jCMPL0dvHj42oD55cDbZYI5EDMWY=; b=UF/cpwGzFx6SAt8HKne7fpIJ6ScDV18v+ZKADxe4soQkYrlJiE7cKqN5KTXfyJKuEs +weYkK8gPATPrrP5GsmQmbcfiOWEo+8jZbZ93f57FDOj8Y/yFafhNHtYNM9iYsS4hN4n 4X99j6Yz+RQcJD4+9lV9XGISE+/nMHVWrGTZl+xg+LNAVQTcZIvA0biiZfacOBsDrfyQ BVnSQ7tP4M+mbuZsvXsas/qOmz+hnb7oeZOpB/o+AVKwXe+aDOniGooLG7M2ESs/Vwq0 o+un52Td0VsqXchOuySUXr8Jj70w40Sq1vr3dbfBa9IZigj+E4DywrSHKBea+PUQ13ab tu1w== X-Gm-Message-State: APjAAAV4nCm/vQ+fVHSetzbw6Cz+nRzyPjVeteUrwV6mHh5eJnZESQNF U5z7f8TzA2l+jB9YlDCnvoiZiq/yu+g= X-Google-Smtp-Source: APXvYqxcd8ojL4rtXzZABX2m6AugwsyCp92UMn/QH6jTwa/Y33KUnWJXufbFaIjPiNF9dQqXfnGP6g== X-Received: by 2002:a81:9e06:: with SMTP id m6mr6330159ywj.393.1570704337550; Thu, 10 Oct 2019 03:45:37 -0700 (PDT) Received: from localhost.localdomain (pool-173-76-169-118.bstnma.fios.verizon.net. [173.76.169.118]) by smtp.gmail.com with ESMTPSA id u69sm1423125ywu.93.2019.10.10.03.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 03:45:35 -0700 (PDT) From: Flavio Fernandes To: dev@openvswitch.org Date: Thu, 10 Oct 2019 06:45:32 -0400 Message-Id: <20191010104532.19406-1-flavio@flaviof.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 SenderWebAddress: http://flaviof.com/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH ovn v2] Utilities: add ovn-sim X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Adding a wrapper to ovs-sim called ovn-sim, which re-introduces the primitives for OVN in the simulator that were lost as part of the ovn-org/ovn split. Also resurrected the man page used to document ovn-sim usage. Lastly, there were some leftover ovs-sim references that were not proper. This patch renames these to ovn-sim. All in all, this change is nothing but porting over the OVN sections of ovs-sim from OVS version 2.12 (pre-split). Reported-by: Flavio Fernandes Reported-at: https://github.com/ovn-org/ovn/issues/21 (Fixes #21) Signed-off-by: Flavio Fernandes --- v1 -> v2: * Fix real issues found by 0-day Robot --- Documentation/automake.mk | 2 +- Documentation/conf.py | 4 +- Documentation/ref/index.rst | 2 +- Documentation/ref/ovn-sim.1.rst | 126 +++++++++++++ Documentation/ref/ovs-sim.1.rst | 244 ------------------------- Makefile.am | 1 + utilities/.gitignore | 1 + utilities/automake.mk | 6 +- utilities/ovn-sim.in | 308 ++++++++++++++++++++++++++++++++ 9 files changed, 445 insertions(+), 249 deletions(-) create mode 100644 Documentation/ref/ovn-sim.1.rst delete mode 100644 Documentation/ref/ovs-sim.1.rst create mode 100755 utilities/ovn-sim.in diff --git a/Documentation/automake.mk b/Documentation/automake.mk index 5968d6941..bf2166349 100644 --- a/Documentation/automake.mk +++ b/Documentation/automake.mk @@ -106,7 +106,7 @@ RST_MANPAGES = \ # rST formatted manpages that we don't want to install because they # document stuff that only works with a build tree, not with an # installed OVS. -RST_MANPAGES_NOINST = ovs-sim.1.rst +RST_MANPAGES_NOINST = ovn-sim.1.rst # The GNU standards say that these variables should control # installation directories for manpages in each section. Automake diff --git a/Documentation/conf.py b/Documentation/conf.py index 6bf528bde..2c85dcf4d 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -114,8 +114,8 @@ html_static_path = ['_static'] # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). _man_pages = [ - ('ovs-sim.1', - u'Open vSwitch simulator environment'), + ('ovn-sim.1', + u'Open Virtual Network simulator environment'), ('ovsdb-server.7', u'Open vSwitch Database Server Protocol'), ('ovsdb.5', diff --git a/Documentation/ref/index.rst b/Documentation/ref/index.rst index 530d639d6..7ff9edd09 100644 --- a/Documentation/ref/index.rst +++ b/Documentation/ref/index.rst @@ -39,7 +39,7 @@ time: .. toctree:: :maxdepth: 3 - ovs-sim.1 + ovn-sim.1 ovsdb-server.7 ovsdb.5 ovsdb.7 diff --git a/Documentation/ref/ovn-sim.1.rst b/Documentation/ref/ovn-sim.1.rst new file mode 100644 index 000000000..35abd39b1 --- /dev/null +++ b/Documentation/ref/ovn-sim.1.rst @@ -0,0 +1,126 @@ +======= +ovn-sim +======= + +Synopsis +======== + +``ovn-sim`` [*option*]... [*script*]... + +Description +=========== + +``ovn-sim`` is a wrapper script that adds ovn related commands on +top of ``ovs-sim``. + +``ovs-sim`` provides a convenient environment for running one or more Open +vSwitch instances and related software in a sandboxed simulation environment. + +To use ``ovn-sim``, first build Open vSwitch, then invoke it directly from the +build directory, e.g.:: + + git clone https://github.com/openvswitch/ovs.git + cd ovs + ./boot.sh && ./configure && make + cd .. + git clone https://github.com/ovn-org/ovn.git + cd ovn + ./boot.sh && ./configure --with-ovs-source=${PWD}/../ovs + make + utilities/ovn-sim + +See documentation on ``ovs-sim`` for info on simulator, including the +parameters you can use. + +OVN Commands +------------ + +These commands interact with OVN, the Open Virtual Network. + +``ovn_start`` [*options*] + Creates and initializes the central OVN databases (both + ``ovn-sb(5)`` and ``ovn-nb(5)``) and starts an instance of + ``ovsdb-server`` for each one. Also starts an instance of + ``ovn-northd``. + + The following options are available: + + ``--nbdb-model`` *model* + Uses the given database model for the northbound database. + The *model* may be ``standalone`` (the default), ``backup``, + or ``clustered``. + + ``--nbdb-servers`` *n* + For a clustered northbound database, the number of servers in + the cluster. The default is 3. + + ``--sbdb-model`` *model* + Uses the given database model for the southbound database. + The *model* may be ``standalone`` (the default), ``backup``, + or ``clustered``. + + ``--sbdb-servers`` *n* + For a clustered southbound database, the number of servers in + the cluster. The default is 3. + +``ovn_attach`` *network* *bridge* *ip* [*masklen*] + First, this command attaches bridge to interconnection network + network, just like ``net_attach`` *network* *bridge*. Second, it + configures (simulated) IP address *ip* (with network mask length + *masklen*, which defaults to 24) on *bridge*. Finally, it + configures the Open vSwitch database to work with OVN and starts + ``ovn-controller``. + +Examples +======== + +Simulating hypervisors, starting ovn controller (via ovn_attach) and +adding a logical port on each one of them:: + + ovn_start + ovn-nbctl ls-add lsw0 + net_add n1 + for i in 0 1; do + sim_add hv$i + as hv$i + ovs-vsctl add-br br-phys + ovn_attach n1 br-phys 192.168.0.`expr $i + 1` + ovs-vsctl add-port br-int vif$i -- \ + set Interface vif$i external-ids:iface-id=lp$i + ovn-nbctl lsp-add lsw0 lp$i + ovn-nbctl lsp-set-addresses lp$i f0:00:00:00:00:0$i + done + +Here’s a primitive OVN "scale test" (adjust the scale by changing +``n`` in the first line):: + + n=200; export n + ovn_start --sbdb-model=clustered + net_add n1 + ovn-nbctl ls-add br0 + for i in `seq $n`; do + (sim_add hv$i + as hv$i + ovs-vsctl add-br br-phys + y=$(expr $i / 256) + x=$(expr $i % 256) + ovn_attach n1 br-phys 192.168.$y.$x + ovs-vsctl add-port br-int vif$i -- \ + set Interface vif$i external-ids:iface-id=lp$i) & + case $i in + *50|*00) echo $i; wait ;; + esac + done + wait + for i in `seq $n`; do + yy=$(printf %02x $(expr $i / 256)) + xx=$(printf %02x $(expr $i % 256)) + ovn-nbctl lsp-add br0 lp$i + ovn-nbctl lsp-set-addresses lp$i f0:00:00:00:$yy:$xx + done + +When the scale test has finished initializing, you can watch the +logical ports come up with a command like this:: + + watch 'for i in `seq $n`; do \ + if test `ovn-nbctl lsp-get-up lp$i` != up; then echo $i; fi; done' diff --git a/Documentation/ref/ovs-sim.1.rst b/Documentation/ref/ovs-sim.1.rst deleted file mode 100644 index 4382598e1..000000000 --- a/Documentation/ref/ovs-sim.1.rst +++ /dev/null @@ -1,244 +0,0 @@ -======= -ovs-sim -======= - -Synopsis -======== - -``ovs-sim`` [*option*]... [*script*]... - -Description -=========== - -``ovs-sim`` provides a convenient environment for running one or more Open -vSwitch instances and related software in a sandboxed simulation environment. - -To use ``ovs-sim``, first build Open vSwitch, then invoke it directly from the -build directory, e.g.:: - - git clone https://github.com/openvswitch/ovs.git - cd ovs - ./configure - make - utilities/ovs-sim - -When invoked in the most ordinary way as shown above, ovs-sim does the -following: - -1. Creates a directory ``sandbox`` as a subdirectory of the current - directory (first destroying such a directory if it already exists) - and makes it the current directory. - -2. Installs all of the Open vSwitch manpages into a ``man`` - subdirectory of sandbox and adjusts the ``MANPATH`` environment - variable so that ``man`` and other manpage viewers can find them. - -3. Creates a simulated Open vSwitch named ``main`` and sets it up as the - default target for OVS commands, as if the following ``ovs-sim`` - commands had been run:: - - sim_add main - as main - - See `Commands`_, below, for an explanation. - -4. Runs any scripts specified on the command line (see `Options`_, - below). The scripts can use arbitrary Bash syntax, plus the - additional commands described under `Commands`_, below. - -5. If no scripts were specified, or if ``-i`` or ``--interactive`` was - specified, invokes an interactive Bash subshell. The user can use - arbitrary Bash commands, plus the additional commands described under - `Commands`_, below. - -``ovs-sim`` and the sandbox environment that it creates does not require -superuser or other special privileges. Generally, it should not be run with -such privileges. - -Options -======= - -.. program: ovs-sim - -*script* - Runs *script*, which should be a Bash script, within a subshell - after initializing. If multiple script arguments are given, then - they are run in the order given. If any script exits with a - nonzero exit code, then ``ovs-sim`` exits immediately with the - same exit code. - -``-i`` or ``--interactive`` - By default, if any script is specified, ``ovs-sim`` exits as soon as the - scripts finish executing. With this option, or if no scripts are specified, - ``ovs-sim`` instead starts an interactive Bash session. - -Commands -======== - -Scripts and interactive usage may use the following commands -implemented by ``ovs-sim``. They are implemented as Bash shell functions -exported to subshells. - -Basic Commands --------------- - -These are the basic commands for working with sandboxed Open vSwitch -instances. - -``sim_add`` *sandbox* - Starts a new simulated Open vSwitch instance named *sandbox*. - Files related to the instance, such as logs, databases, sockets, - and pidfiles, are created in a subdirectory also named - *sandbox*. Afterward, the ``as`` command (see below) can be used - to run Open vSwitch utilities in the context of the new sandbox. - - The new sandbox starts out without any bridges. Use ``ovs-vsctl`` - in the context of the new sandbox to create a bridge, e.g.:: - - sim_add hv0 # Create sandbox hv0. - as hv0 # Set hv0 as default sandbox. - ovs-vsctl add-br br0 # Add bridge br0 inside hv0. - - The Open vSwitch instances that ``sim_add`` creates enable - ``dummy`` devices. This means that bridges and interfaces can be - created with type ``dummy`` to indicate that they should be - totally simulated, without any reference to system entities. In - fact, ``ovs-sim`` also configures Open vSwitch so that the default - system type of bridges and interfaces are replaced by dummy - devices. Other types of devices, however, retain their usual - functions, which means that, e.g., vxlan tunnels still act as - tunnels (refer to the documentation). - -``as`` *sandbox* - Sets sandbox as the default simulation target for Open vSwitch - commands (e.g. ``ovs-vsctl``, ``ovs-ofctl``, ``ovs-appctl``). - - This command updates the beginning of the shell prompt to indicate - the new default target. - -``as`` *sandbox* *command* *arg*... - Runs the given command with *sandbox* as the simulation target, - e.g. ``as hv0 ovs-vsctl add-br br0`` runs ``ovs-vsctl add-br - br0`` within sandbox ``hv0``. The default target is unchanged. - -Interconnection Network Commands --------------------------------- - -When multiple sandboxed Open vSwitch instances exist, one will -inevitably want to connect them together. These commands allow for -that. Conceptually, an interconnection network is a switch that -``ovs-sim`` makes it easy to plug into other switches in other -sandboxed Open vSwitch instances. Interconnection networks are -implemented as bridges in the ``main`` switch that ``ovs-sim`` creates -by default, so to use interconnection networks please avoid working -with ``main`` directly. - -``net_add`` *network* - Creates a new interconnection network named *network*. - -``net_attach`` *network* *bridge* - Adds a new port to *bridge* in the default sandbox (as set with - ``as``) and plugs it into interconnection network *network*, which - must already have been created by a previous invocation of - ``net_add``. The default sandbox must not be ``main``. - -OVN Commands ------------- - -These commands interact with OVN, the Open Virtual Network. - -``ovn_start`` [*options*] - Creates and initializes the central OVN databases (both - ``ovn-sb(5)`` and ``ovn-nb(5)``) and starts an instance of - ``ovsdb-server`` for each one. Also starts an instance of - ``ovn-northd``. - - The following options are available: - - ``--nbdb-model`` *model* - Uses the given database model for the northbound database. - The *model* may be ``standalone`` (the default), ``backup``, - or ``clustered``. - - ``--nbdb-servers`` *n* - For a clustered northbound database, the number of servers in - the cluster. The default is 3. - - ``--sbdb-model`` *model* - Uses the given database model for the southbound database. - The *model* may be ``standalone`` (the default), ``backup``, - or ``clustered``. - - ``--sbdb-servers`` *n* - For a clustered southbound database, the number of servers in - the cluster. The default is 3. - -``ovn_attach`` *network* *bridge* *ip* [*masklen*] - First, this command attaches bridge to interconnection network - network, just like ``net_attach`` *network* *bridge*. Second, it - configures (simulated) IP address *ip* (with network mask length - *masklen*, which defaults to 24) on *bridge*. Finally, it - configures the Open vSwitch database to work with OVN and starts - ``ovn-controller``. - -Examples -======== - -The following creates a pair of Open vSwitch instances ``hv0`` and -``hv1``, adds a port named ``vif0`` or ``vif1``, respectively, to each -one, and then connects the two through an interconnection network -``n1``:: - - net_add n1 - for i in 0 1; do - sim_add hv$i - as hv$i ovs-vsctl add-br br0 -- add-port br0 vif$i - as hv$i net_attach n1 br0 - done - -Here’s an extended version that also starts OVN:: - - ovn_start - ovn-nbctl ls-add lsw0 - net_add n1 - for i in 0 1; do - sim_add hv$i - as hv$i - ovs-vsctl add-br br-phys - ovn_attach n1 br-phys 192.168.0.`expr $i + 1` - ovs-vsctl add-port br-int vif$i -- set Interface vif$i external-ids:iface-id=lp$i - ovn-nbctl lsp-add lsw0 lp$i - ovn-nbctl lsp-set-addresses lp$i f0:00:00:00:00:0$i - done - -Here’s a primitive OVN "scale test" (adjust the scale by changing -``n`` in the first line:: - - n=200; export n - ovn_start --sbdb-model=clustered - net_add n1 - ovn-nbctl ls-add br0 - for i in `seq $n`; do - (sim_add hv$i - as hv$i - ovs-vsctl add-br br-phys - y=$(expr $i / 256) - x=$(expr $i % 256) - ovn_attach n1 br-phys 192.168.$y.$x - ovs-vsctl add-port br-int vif$i -- set Interface vif$i external-ids:iface-id=lp$i) & - case $i in - *50|*00) echo $i; wait ;; - esac - done - wait - for i in `seq $n`; do - yy=$(printf %02x $(expr $i / 256)) - xx=$(printf $02x $(expr $i % 256)) - ovn-nbctl lsp-add br0 lp$i - ovn-nbctl lsp-set-addresses lp$i f0:00:00:00:$yy:$xx - done - -When the scale test has finished initializing, you can watch the -logical ports come up with a command like this:: - - watch 'for i in `seq $n`; do if test `ovn-nbctl lsp-get-up lp$i` != up; then echo $i; fi; done' diff --git a/Makefile.am b/Makefile.am index 33c18c5d8..88ede2d82 100644 --- a/Makefile.am +++ b/Makefile.am @@ -173,6 +173,7 @@ SUFFIXES += .in -e 's,[@]DBDIR[@],$(DBDIR),g' \ -e 's,[@]PYTHON[@],$(PYTHON),g' \ -e 's,[@]OVN_RUNDIR[@],$(OVN_RUNDIR),g' \ + -e 's,[@]OVSBUILDDIR[@],$(OVSBUILDDIR),g' \ -e 's,[@]VERSION[@],$(VERSION),g' \ -e 's,[@]localstatedir[@],$(localstatedir),g' \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ diff --git a/utilities/.gitignore b/utilities/.gitignore index faaa85ee9..ab063fa04 100644 --- a/utilities/.gitignore +++ b/utilities/.gitignore @@ -12,3 +12,4 @@ /ovn-docker-overlay-driver /ovn-docker-underlay-driver /ovn-lib +/ovn-sim diff --git a/utilities/automake.mk b/utilities/automake.mk index 197cc7011..bf9388192 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -52,7 +52,11 @@ CLEANFILES += \ utilities/ovn-detrace.1 \ utilities/ovn-detrace \ utilities/ovn-appctl.8 \ - utilities/ovn-appctl + utilities/ovn-appctl \ + utilities/ovn-sim + +EXTRA_DIST += utilities/ovn-sim.in +noinst_SCRIPTS += utilities/ovn-sim utilities/ovn-lib: $(top_builddir)/config.status diff --git a/utilities/ovn-sim.in b/utilities/ovn-sim.in new file mode 100755 index 000000000..a05e4cd8a --- /dev/null +++ b/utilities/ovn-sim.in @@ -0,0 +1,308 @@ +#! /usr/bin/env bash +# +# Copyright (c) 2019 Nicira, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +ovn_sim_builddir='@abs_builddir@'; export ovn_sim_builddir +ovn_sim_srcdir='@abs_top_srcdir@'; export ovn_sim_srcdir +ovs_sim_builddir='@OVSBUILDDIR@' + +# Check that we've got proper builddir and srcdir. +if test ! -e "$ovs_sim_builddir"/utilities/ovs-sim; then + echo "$ovs_sim_builddir/utilities/ovs-sim does not exist ($0 requires ovs-sim)" >&2 + exit 1 +fi +if test ! -e "$ovn_sim_builddir"/northd/ovn-northd; then + echo "$ovn_sim_builddir/northd/ovn-northd does not exist (need to run \"make\"?)" >&2 + exit 1 +fi +if test ! -e "$ovn_sim_srcdir"/README.rst; then + echo "$ovn_sim_srcdir/README.rst does not exist" >&2 + exit 1 +fi + +# Put built tools early in $PATH. +PATH=$ovn_sim_builddir/controller:$ovn_sim_builddir/northd:$ovn_sim_builddir/utilities:$PATH +export PATH + +ovn-nbctl () { command ovn-nbctl -vsyslog:off "$@"; }; export -f ovn-nbctl +ovn-sbctl () { command ovn-sbctl -vsyslog:off "$@"; }; export -f ovn-sbctl + +ovn_start_db() { + local db=$1 model=$2 servers=$3 schema=$4 + local DB=$(echo $db | tr a-z A-Z) + local schema_name=$(ovsdb-tool schema-name $schema) + + case $model in + standalone | backup) ;; + clustered) + case $servers in + [1-9] | [1-9][0-9]) ;; + *) echo "${db}db servers must be between 1 and 99" >&2 + exit 1 + ;; + esac + ;; + *) + echo "unknown ${db}db model \"$model\"" >&2 + exit 1 + ;; + esac + + ovn_start_ovsdb_server() { + local i=$1; shift + as ${db}$i ovsdb-server --detach --no-chdir --pidfile=$db.pid \ + -vsyslog:off -vconsole:off --log-file="$sim_base"/$db$i/$db.log \ + --remote=db:$schema_name,${DB}_Global,connections \ + --private-key=db:$schema_name,SSL,private_key \ + --certificate=db:$schema_name,SSL,certificate \ + --ca-cert=db:$schema_name,SSL,ca_cert \ + --ssl-protocols=db:$schema_name,SSL,ssl_protocols \ + --ssl-ciphers=db:$schema_name,SSL,ssl_ciphers \ + --unixctl=${db} --remote=punix:$db.ovsdb \ + "$sim_base"/$db$i/$db.db "$@" + } + + ovn_prep_db() { + local i=$1 + mkdir "$sim_base"/${db}$i + touch "$sim_base"/${db}$i/.$db.db.~lock~ + } + + local n_remotes=1 + case $model in + standalone) + ovn_prep_db 1 + ovsdb-tool create "$sim_base"/${db}1/$db.db "$schema" + ovn_start_ovsdb_server 1 + ;; + backup) + for i in 1 2; do + ovn_prep_db $i + ovsdb-tool create "$sim_base"/$db$i/$db.db "$schema" + done + ovn_start_ovsdb_server 1 + ovn_start_ovsdb_server 2 --sync-from=unix:"$sim_base"/${db}1/$db.ovsdb + cat <&2 + return 1 + ;; + *) + echo "$option: non-option arguments not supported (use --help for help)" >&2 + return 1 + ;; + esac + shift + done + + if test -d ovn-sb || test -d ovn-nb; then + echo >&2 "OVN already started" + return 1 + fi + + ovn_sim_setvars $sandbox + + # Build ovn man pages as part of ovn_start + ovn_man_pages + + ovn_start_db nb "$nbdb_model" "$nbdb_servers" "$ovn_sim_srcdir"/ovn-nb.ovsschema + ovn_start_db sb "$sbdb_model" "$sbdb_servers" "$ovn_sim_srcdir"/ovn-sb.ovsschema + + ovn-nbctl init + ovn-sbctl init + + mkdir "$sim_base"/northd + as northd ovn-northd --detach --no-chdir --pidfile=ovn-northd.pid -vconsole:off \ + --log-file=ovn-northd.log -vsyslog:off \ + --ovnnb-db="$OVN_NB_DB" --ovnsb-db="$OVN_SB_DB" +} +export -f ovn_start + +ovn_attach() { + if test "$1" == --help; then + cat <&2 "$FUNCNAME: wrong number of arguments (use --help for help)" + return 1 + fi + + local net=$1 bridge=$2 ip=$3 masklen=${4-24} + net_attach $net $bridge || return $? + + ovn_sim_setvars $sandbox + + ovs-appctl netdev-dummy/ip4addr $bridge $ip/$masklen >/dev/null + ovs-appctl ovs/route/add $ip/$masklen $bridge > /dev/null + ovs-vsctl \ + -- set Open_vSwitch . external-ids:system-id=$sandbox \ + -- set Open_vSwitch . external-ids:ovn-remote=$OVN_SB_DB \ + -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \ + -- set Open_vSwitch . external-ids:ovn-encap-ip=$ip\ + -- add-br br-int \ + -- set bridge br-int fail-mode=secure other-config:disable-in-band=true + ovn-controller --detach --no-chdir -vsyslog:off -vconsole:off \ + --log-file=ovn-controller.${sandbox}.log \ + --pidfile=ovn-controller.${sandbox}.pid +} +export -f ovn_attach + +ovn_sim_setvars() { + OVN_RUNDIR=$sim_base/$1; export OVN_RUNDIR + OVN_LOGDIR=$sim_base/$1; export OVN_LOGDIR + OVN_DBDIR=$sim_base/$1; export OVN_DBDIR + OVN_SYSCONFDIR=$sim_base/$1; export OVN_SYSCONFDIR +} +export -f ovn_sim_setvars + +ovn_as() { + if test -n "$1"; then + ovn_sim_setvars $1 + fi + as $@ +} +export -f ovn_as + +ovn_man_pages() { + # Easy access to OVN manpages. + mkdir -p $sim_base/man + mandir=`cd $sim_base/man && pwd` + (cd "$ovn_sim_builddir" && ${MAKE-make} install-man install-man-rst mandir=$mandir EXTRA_RST_MANPAGES=ovn-sim.1.rst >/dev/null) + # Note: MANPATH expected to be already exported by ovs-sim + #MANPATH=$mandir:; export MANPATH +} +export -f ovn_man_pages + +source ${ovs_sim_builddir}/utilities/ovs-sim