From patchwork Thu May 23 20:07:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 1104400 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=ovn.org 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 4590vG6rhFz9s00 for ; Fri, 24 May 2019 06:08:58 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CAEB4FAE; Thu, 23 May 2019 20:08:18 +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 72497F8C for ; Thu, 23 May 2019 20:08:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E6F756C5 for ; Thu, 23 May 2019 20:08:13 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (unknown [66.170.99.1]) (Authenticated sender: jpettit@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 97419100006 for ; Thu, 23 May 2019 20:08:10 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Thu, 23 May 2019 13:07:35 -0700 Message-Id: <20190523200737.87615-1-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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 1/3] ovn.at: Clean up northd-backup in "ovn -- ipam" test. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- tests/ovn.at | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ovn.at b/tests/ovn.at index 6499df3d3e2a..298f647d37bf 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -6408,6 +6408,9 @@ OVS_APP_EXIT_AND_WAIT([ovsdb-server]) as northd OVS_APP_EXIT_AND_WAIT([ovn-northd]) +as northd-backup +OVS_APP_EXIT_AND_WAIT([ovn-northd]) + AT_CLEANUP AT_SETUP([ovn -- ipam connectivity]) From patchwork Thu May 23 20:07:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 1104399 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=ovn.org 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 4590tX5w7Pz9s3l for ; Fri, 24 May 2019 06:08:19 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1D45CFA4; Thu, 23 May 2019 20:08:17 +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 3EFC7F8C for ; Thu, 23 May 2019 20:08:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 72FEF829 for ; Thu, 23 May 2019 20:08:14 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (unknown [66.170.99.1]) (Authenticated sender: jpettit@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 886B0100002 for ; Thu, 23 May 2019 20:08:12 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Thu, 23 May 2019 13:07:36 -0700 Message-Id: <20190523200737.87615-2-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523200737.87615-1-jpettit@ovn.org> References: <20190523200737.87615-1-jpettit@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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 2/3] ovn.at: Use ovn cleanup macros. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Justin Pettit --- tests/ovn.at | 92 +++------------------------------------------------- 1 file changed, 5 insertions(+), 87 deletions(-) diff --git a/tests/ovn.at b/tests/ovn.at index 298f647d37bf..9c71dc9ffdcf 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -3857,24 +3857,7 @@ echo "${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${d OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) - -as hv1 -OVS_APP_EXIT_AND_WAIT([ovn-controller]) -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-sb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-nb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as northd -OVS_APP_EXIT_AND_WAIT([ovn-northd]) - -as main -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) +OVN_CLEANUP([hv1]) AT_CLEANUP @@ -4808,23 +4791,7 @@ OVS_WAIT_UNTIL([test 8 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) # vif1-tx.pcap should have received the DHCPv4 request packet OVN_CHECK_PACKETS([hv1/vif1-tx.pcap], [1.expected]) -as hv1 -OVS_APP_EXIT_AND_WAIT([ovn-controller]) -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-sb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-nb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as northd -OVS_APP_EXIT_AND_WAIT([ovn-northd]) - -as main -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) +OVN_CLEANUP([hv1]) AT_CLEANUP @@ -5096,23 +5063,7 @@ trim_zeros > 5.packets cat 5.expected | cut -c 1-120,125- > expout AT_CHECK([cat 5.packets | cut -c 1-120,125- ], [0], [expout]) -as hv1 -OVS_APP_EXIT_AND_WAIT([ovn-controller]) -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-sb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-nb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as northd -OVS_APP_EXIT_AND_WAIT([ovn-northd]) - -as main -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) +OVN_CLEANUP([hv1]) AT_CLEANUP @@ -8039,25 +7990,7 @@ expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}00351 echo $expected > expected OVN_CHECK_PACKETS([hv3/vif1-tx.pcap], [expected]) -for sim in hv1 hv2 hv3; do - as $sim - OVS_APP_EXIT_AND_WAIT([ovn-controller]) - OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) - OVS_APP_EXIT_AND_WAIT([ovsdb-server]) -done - -as ovn-sb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-nb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as northd -OVS_APP_EXIT_AND_WAIT([ovn-northd]) - -as main -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) +OVN_CLEANUP([hv1],[hv2],[hv3]) AT_CLEANUP @@ -8471,23 +8404,8 @@ reset_pcap_file hv1-vif2 hv1/vif2 rm -f 1.expected rm -f 2.expected -as hv1 - OVS_APP_EXIT_AND_WAIT([ovn-controller]) -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-sb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as ovn-nb -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - -as northd -OVS_APP_EXIT_AND_WAIT([ovn-northd]) +OVN_CLEANUP([hv1]) -as main -OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) -OVS_APP_EXIT_AND_WAIT([ovsdb-server]) AT_CLEANUP AT_SETUP([ovn -- 4 HV, 1 LS, 1 LR, packet test with HA distributed router gateway port]) From patchwork Thu May 23 20:07:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 1104401 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=ovn.org 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 4590vs17G2z9s00 for ; Fri, 24 May 2019 06:09:29 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8A8DBFB6; Thu, 23 May 2019 20:08:19 +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 DEC53F8C for ; Thu, 23 May 2019 20:08:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 62FFA829 for ; Thu, 23 May 2019 20:08:15 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (unknown [66.170.99.1]) (Authenticated sender: jpettit@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 77A3210000F for ; Thu, 23 May 2019 20:08:13 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Thu, 23 May 2019 13:07:37 -0700 Message-Id: <20190523200737.87615-3-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523200737.87615-1-jpettit@ovn.org> References: <20190523200737.87615-1-jpettit@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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 3/3] ovn-macros: Break the OVN macros into their own file. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Justin Pettit --- tests/automake.mk | 3 +- tests/ofproto-macros.at | 177 --------------------------------------- tests/ovn-macros.at | 180 ++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 4 files changed, 183 insertions(+), 178 deletions(-) create mode 100644 tests/ovn-macros.at diff --git a/tests/automake.mk b/tests/automake.mk index ea16532dd2a0..bc906fb79b46 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -21,7 +21,8 @@ EXTRA_DIST += \ COMMON_MACROS_AT = \ tests/ovsdb-macros.at \ tests/ovs-macros.at \ - tests/ofproto-macros.at + tests/ofproto-macros.at \ + tests/ovn-macros.at TESTSUITE_AT = \ tests/testsuite.at \ diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index 2f33feabc954..3763fed329e9 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -113,183 +113,6 @@ as() { fi } -# OVN_CLEANUP_VSWITCH(sim) -# -# Gracefully terminate vswitch daemons in the -# specified sandbox. -m4_define([OVN_CLEANUP_VSWITCH],[ - as $1 - OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) - OVS_APP_EXIT_AND_WAIT([ovsdb-server]) -]) - -# OVN_CLEANUP_SBOX(sbox) -# -# Gracefully terminate OVN daemons in the specified -# sandbox instance. The sandbox name "vtep" is treated -# as a special case, and is assumed to have ovn-controller-vtep -# and ovs-vtep daemons running instead of ovn-controller. -m4_define([OVN_CLEANUP_SBOX],[ - as $1 - if test "$1" = "vtep"; then - OVS_APP_EXIT_AND_WAIT([ovn-controller-vtep]) - OVS_APP_EXIT_AND_WAIT([ovs-vtep]) - else - OVS_APP_EXIT_AND_WAIT([ovn-controller]) - fi - OVN_CLEANUP_VSWITCH([$1]) -]) - -# OVN_CLEANUP(sim [, sim ...]) -# -# Gracefully terminate all OVN daemons, including those in the -# specified sandbox instances. -m4_define([OVN_CLEANUP],[ - m4_foreach([sbox], [$@], [ - OVN_CLEANUP_SBOX([sbox]) - ]) - as ovn-sb - OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - - as ovn-nb - OVS_APP_EXIT_AND_WAIT([ovsdb-server]) - - as northd - OVS_APP_EXIT_AND_WAIT([ovn-northd]) - - as northd-backup - OVS_APP_EXIT_AND_WAIT([ovn-northd]) - - OVN_CLEANUP_VSWITCH([main]) -]) - -# ovn_init_db DATABASE -# -# Creates and initializes the given DATABASE (one of "ovn-sb" or "ovn-nb"), -# starts its ovsdb-server instance, and sets the appropriate environment -# variable (OVN_SB_DB or OVN_NB_DB) so that ovn-sbctl or ovn-nbctl uses the -# database by default. -# -# Usually invoked from ovn_start. -ovn_init_db () { - echo "creating $1 database" - local d=$ovs_base/$1 - mkdir "$d" || return 1 - : > "$d"/.$1.db.~lock~ - as $1 ovsdb-tool create "$d"/$1.db "$abs_top_srcdir"/ovn/$1.ovsschema - as $1 start_daemon ovsdb-server --remote=punix:"$d"/$1.sock "$d"/$1.db - local var=`echo $1_db | tr a-z- A-Z_` - AS_VAR_SET([$var], [unix:$ovs_base/$1/$1.sock]); export $var -} - -# ovn_start -# -# Creates and initializes ovn-sb and ovn-nb databases and starts their -# ovsdb-server instance, sets appropriate environment variables so that -# ovn-sbctl and ovn-nbctl use them by default, and starts ovn-northd running -# against them. -ovn_start () { - ovn_init_db ovn-sb; ovn-sbctl init - ovn_init_db ovn-nb; ovn-nbctl init - - echo "starting ovn-northd" - mkdir "$ovs_base"/northd - as northd start_daemon ovn-northd \ - --ovnnb-db=unix:"$ovs_base"/ovn-nb/ovn-nb.sock \ - --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock - - echo "starting backup ovn-northd" - mkdir "$ovs_base"/northd-backup - as northd-backup start_daemon ovn-northd \ - --ovnnb-db=unix:"$ovs_base"/ovn-nb/ovn-nb.sock \ - --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock -} - -# Interconnection networks. -# -# 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 for which these functions make it easy -# to plug into other switches in other sandboxed Open vSwitch instances. -# Interconnection networks are implemented as bridges in a switch named "main", -# so to use interconnection networks please avoid working with that switch -# directly. - -# net_add NETWORK -# -# Creates a new interconnection network named NETWORK. -net_add () { - test -d "$ovs_base"/main || sim_add main || return 1 - as main ovs-vsctl add-br "$1" -} - -# net_attach NETWORK BRIDGE -# -# Adds a new port to BRIDGE in the default sandbox (as set with as()) and plugs -# it into the NETWORK interconnection network. NETWORK must already have been -# created by a previous invocation of net_add. The default sandbox must not be -# "main". -net_attach () { - local net=$1 bridge=$2 - - local port=${sandbox}_$bridge - as main ovs-vsctl \ - -- add-port $net $port \ - -- set Interface $port options:pstream="punix:$ovs_base/main/$port.sock" options:rxq_pcap="$ovs_base/main/$port-rx.pcap" options:tx_pcap="$ovs_base/main/$port-tx.pcap" \ - || return 1 - - ovs-vsctl \ - -- set Interface $bridge options:tx_pcap="$ovs_base/$sandbox/$bridge-tx.pcap" options:rxq_pcap="$ovs_base/$sandbox/$bridge-rx.pcap" \ - -- add-port $bridge ${bridge}_$net \ - -- set Interface ${bridge}_$net options:stream="unix:$ovs_base/main/$port.sock" options:rxq_pcap="$ovs_base/$sandbox/${bridge}_$net-rx.pcap" options:tx_pcap="$ovs_base/$sandbox/${bridge}_$net-tx.pcap" \ - || return 1 -} - -# 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. -ovn_attach() { - local net=$1 bridge=$2 ip=$3 masklen=${4-24} - net_attach $net $bridge || return 1 - - mac=`ovs-vsctl get Interface $bridge mac_in_use | sed s/\"//g` - arp_table="$arp_table $sandbox,$bridge,$ip,$mac" - ovs-appctl netdev-dummy/ip4addr $bridge $ip/$masklen >/dev/null || return 1 - ovs-appctl ovs/route/add $ip/$masklen $bridge >/dev/null || return 1 - ovs-vsctl \ - -- set Open_vSwitch . external-ids:system-id=$sandbox \ - -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \ - -- set Open_vSwitch . external-ids:ovn-encap-type=geneve,vxlan \ - -- 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 \ - || return 1 - start_daemon ovn-controller || return 1 -} - -# OVN_POPULATE_ARP -# -# This pre-populates the ARP tables of all of the OVN instances that have been -# started with ovn_attach(). That means that packets sent from one hypervisor -# to another never get dropped or delayed by ARP resolution, which makes -# testing easier. -ovn_populate_arp__() { - for e1 in $arp_table; do - set `echo $e1 | sed 's/,/ /g'`; sb1=$1 br1=$2 ip=$3 mac=$4 - for e2 in $arp_table; do - set `echo $e2 | sed 's/,/ /g'`; sb2=$1 br2=$2 - if test $sb1,$br1 != $sb2,$br2; then - as $sb2 ovs-appctl tnl/neigh/set $br2 $ip $mac || return 1 - fi - done - done -} -m4_define([OVN_POPULATE_ARP], [AT_CHECK(ovn_populate_arp__, [0], [ignore])]) - # Strips 'xid=0x1234' from ovs-ofctl output. strip_xids () { sed 's/ (xid=0x[[0-9a-fA-F]]*)//' diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at new file mode 100644 index 000000000000..7dba42c99892 --- /dev/null +++ b/tests/ovn-macros.at @@ -0,0 +1,180 @@ +# OVN_CLEANUP_VSWITCH(sim) +# +# Gracefully terminate vswitch daemons in the +# specified sandbox. +m4_define([OVN_CLEANUP_VSWITCH],[ + as $1 + OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) + OVS_APP_EXIT_AND_WAIT([ovsdb-server]) +]) + +# OVN_CLEANUP_SBOX(sbox) +# +# Gracefully terminate OVN daemons in the specified +# sandbox instance. The sandbox name "vtep" is treated +# as a special case, and is assumed to have ovn-controller-vtep +# and ovs-vtep daemons running instead of ovn-controller. +m4_define([OVN_CLEANUP_SBOX],[ + as $1 + if test "$1" = "vtep"; then + OVS_APP_EXIT_AND_WAIT([ovn-controller-vtep]) + OVS_APP_EXIT_AND_WAIT([ovs-vtep]) + else + OVS_APP_EXIT_AND_WAIT([ovn-controller]) + fi + OVN_CLEANUP_VSWITCH([$1]) +]) + +# OVN_CLEANUP(sim [, sim ...]) +# +# Gracefully terminate all OVN daemons, including those in the +# specified sandbox instances. +m4_define([OVN_CLEANUP],[ + m4_foreach([sbox], [$@], [ + OVN_CLEANUP_SBOX([sbox]) + ]) + as ovn-sb + OVS_APP_EXIT_AND_WAIT([ovsdb-server]) + + as ovn-nb + OVS_APP_EXIT_AND_WAIT([ovsdb-server]) + + as northd + OVS_APP_EXIT_AND_WAIT([ovn-northd]) + + as northd-backup + OVS_APP_EXIT_AND_WAIT([ovn-northd]) + + OVN_CLEANUP_VSWITCH([main]) +]) + +m4_divert_push([PREPARE_TESTS]) + +# ovn_init_db DATABASE +# +# Creates and initializes the given DATABASE (one of "ovn-sb" or "ovn-nb"), +# starts its ovsdb-server instance, and sets the appropriate environment +# variable (OVN_SB_DB or OVN_NB_DB) so that ovn-sbctl or ovn-nbctl uses the +# database by default. +# +# Usually invoked from ovn_start. +ovn_init_db () { + echo "creating $1 database" + local d=$ovs_base/$1 + mkdir "$d" || return 1 + : > "$d"/.$1.db.~lock~ + as $1 ovsdb-tool create "$d"/$1.db "$abs_top_srcdir"/ovn/$1.ovsschema + as $1 start_daemon ovsdb-server --remote=punix:"$d"/$1.sock "$d"/$1.db + local var=`echo $1_db | tr a-z- A-Z_` + AS_VAR_SET([$var], [unix:$ovs_base/$1/$1.sock]); export $var +} + +# ovn_start +# +# Creates and initializes ovn-sb and ovn-nb databases and starts their +# ovsdb-server instance, sets appropriate environment variables so that +# ovn-sbctl and ovn-nbctl use them by default, and starts ovn-northd running +# against them. +ovn_start () { + ovn_init_db ovn-sb; ovn-sbctl init + ovn_init_db ovn-nb; ovn-nbctl init + + echo "starting ovn-northd" + mkdir "$ovs_base"/northd + as northd start_daemon ovn-northd -v \ + --ovnnb-db=unix:"$ovs_base"/ovn-nb/ovn-nb.sock \ + --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock + + echo "starting backup ovn-northd" + mkdir "$ovs_base"/northd-backup + as northd-backup start_daemon ovn-northd -v \ + --ovnnb-db=unix:"$ovs_base"/ovn-nb/ovn-nb.sock \ + --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock +} + +# Interconnection networks. +# +# 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 for which these functions make it easy +# to plug into other switches in other sandboxed Open vSwitch instances. +# Interconnection networks are implemented as bridges in a switch named "main", +# so to use interconnection networks please avoid working with that switch +# directly. + +# net_add NETWORK +# +# Creates a new interconnection network named NETWORK. +net_add () { + test -d "$ovs_base"/main || sim_add main || return 1 + as main ovs-vsctl add-br "$1" +} + +# net_attach NETWORK BRIDGE +# +# Adds a new port to BRIDGE in the default sandbox (as set with as()) and plugs +# it into the NETWORK interconnection network. NETWORK must already have been +# created by a previous invocation of net_add. The default sandbox must not be +# "main". +net_attach () { + local net=$1 bridge=$2 + + local port=${sandbox}_$bridge + as main ovs-vsctl \ + -- add-port $net $port \ + -- set Interface $port options:pstream="punix:$ovs_base/main/$port.sock" options:rxq_pcap="$ovs_base/main/$port-rx.pcap" options:tx_pcap="$ovs_base/main/$port-tx.pcap" \ + || return 1 + + ovs-vsctl \ + -- set Interface $bridge options:tx_pcap="$ovs_base/$sandbox/$bridge-tx.pcap" options:rxq_pcap="$ovs_base/$sandbox/$bridge-rx.pcap" \ + -- add-port $bridge ${bridge}_$net \ + -- set Interface ${bridge}_$net options:stream="unix:$ovs_base/main/$port.sock" options:rxq_pcap="$ovs_base/$sandbox/${bridge}_$net-rx.pcap" options:tx_pcap="$ovs_base/$sandbox/${bridge}_$net-tx.pcap" \ + || return 1 +} + +# 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. +ovn_attach() { + local net=$1 bridge=$2 ip=$3 masklen=${4-24} + net_attach $net $bridge || return 1 + + mac=`ovs-vsctl get Interface $bridge mac_in_use | sed s/\"//g` + arp_table="$arp_table $sandbox,$bridge,$ip,$mac" + ovs-appctl netdev-dummy/ip4addr $bridge $ip/$masklen >/dev/null || return 1 + ovs-appctl ovs/route/add $ip/$masklen $bridge >/dev/null || return 1 + ovs-vsctl \ + -- set Open_vSwitch . external-ids:system-id=$sandbox \ + -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \ + -- set Open_vSwitch . external-ids:ovn-encap-type=geneve,vxlan \ + -- 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 \ + || return 1 + start_daemon ovn-controller || return 1 +} + +# OVN_POPULATE_ARP +# +# This pre-populates the ARP tables of all of the OVN instances that have been +# started with ovn_attach(). That means that packets sent from one hypervisor +# to another never get dropped or delayed by ARP resolution, which makes +# testing easier. +ovn_populate_arp__() { + for e1 in $arp_table; do + set `echo $e1 | sed 's/,/ /g'`; sb1=$1 br1=$2 ip=$3 mac=$4 + for e2 in $arp_table; do + set `echo $e2 | sed 's/,/ /g'`; sb2=$1 br2=$2 + if test $sb1,$br1 != $sb2,$br2; then + as $sb2 ovs-appctl tnl/neigh/set $br2 $ip $mac || return 1 + fi + done + done +} +m4_divert_pop([PREPARE_TESTS]) + +m4_define([OVN_POPULATE_ARP], [AT_CHECK(ovn_populate_arp__, [0], [ignore])]) diff --git a/tests/testsuite.at b/tests/testsuite.at index b840dbfa7048..60997ea3a764 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -19,6 +19,7 @@ m4_ifdef([AT_COLOR_TESTS], [AT_COLOR_TESTS]) m4_include([tests/ovs-macros.at]) m4_include([tests/ovsdb-macros.at]) m4_include([tests/ofproto-macros.at]) +m4_include([tests/ovn-macros.at]) m4_include([tests/completion.at]) m4_include([tests/checkpatch.at])