From patchwork Thu Oct 15 08:54:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 530562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id C4F351402B6 for ; Thu, 15 Oct 2015 19:55:13 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C8F7B109B5; Thu, 15 Oct 2015 01:55:09 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 975F710936 for ; Thu, 15 Oct 2015 01:55:07 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id 1C41461806E for ; Thu, 15 Oct 2015 02:55:07 -0600 (MDT) X-ASG-Debug-ID: 1444899306-03dd7b78c390c70001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar3.cudamail.com with ESMTP id DrUscHDWK5vTXWK6 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 15 Oct 2015 02:55:06 -0600 (MDT) X-Barracuda-Envelope-From: jpettit@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mail-pa0-f46.google.com) (209.85.220.46) by mx3-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 15 Oct 2015 08:55:06 -0000 Received-SPF: unknown (mx3-pf1.cudamail.com: Multiple SPF records returned) X-Barracuda-Apparent-Source-IP: 209.85.220.46 X-Barracuda-RBL-IP: 209.85.220.46 Received: by payp3 with SMTP id p3so33962336pay.1 for ; Thu, 15 Oct 2015 01:55:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=i4zcmymyJTPCzOAkyk9FCBfQ7B4Dr5FhSBw15tEN/Fk=; b=aRgP5NEYCC/HOSbO98mfpmzzLxtYBEuYvK0vPGG1aB9TDCPzqXi4ZkJjKwB6oJciSJ VFz73SqixkqXFF3wiPmF2vgGjfgLIgIKTvkh6LSgzQD55f5fe0u0ksgfRRk1y8N/ZndV kmtG3ObbzG0Jv7FJk6Kv3gr35IstU8jcmddo2r0XygRF1Iy9wesVaa8DWkSv6amWhsL3 bVIebz3Hif+z8JPqAvi/IwykLU/Nh2vawUM2Y1pTK6VtxXEEQ6fTkNuEMP2bcHzSyDQu cDnenp0EvVmSI6wDMAUMm48hnh1Yfx4TSmXHoCykmY157CXqZiQFjpg/QyV6gP+DpgfM wl1A== X-Gm-Message-State: ALoCoQm1GS8IQOnrRFt+vqcVKOCSebCqWHrG2ZKQC07QMB8Dan8QK49gOl5mnB+7ejyvtbqh4qbm X-Received: by 10.66.121.225 with SMTP id ln1mr8948847pab.86.1444899305920; Thu, 15 Oct 2015 01:55:05 -0700 (PDT) Received: from localhost.localdomain (c-67-161-8-206.hsd1.ca.comcast.net. [67.161.8.206]) by smtp.gmail.com with ESMTPSA id ci2sm14015113pbc.66.2015.10.15.01.55.05 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Oct 2015 01:55:05 -0700 (PDT) X-CudaMail-Envelope-Sender: jpettit@nicira.com From: Justin Pettit To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V1-1014002618 X-CudaMail-DTE: 101515 X-CudaMail-Originating-IP: 209.85.220.46 Date: Thu, 15 Oct 2015 01:54:57 -0700 X-ASG-Orig-Subj: [##CM-V1-1014002618##][PATCH 2/5] ovn-sbctl: Add multiple encaps with "chassis-add". Message-Id: <1444899300-37713-2-git-send-email-jpettit@nicira.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1444899300-37713-1-git-send-email-jpettit@nicira.com> References: <1444899300-37713-1-git-send-email-jpettit@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1444899306 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 2/5] ovn-sbctl: Add multiple encaps with "chassis-add". X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- ovn/utilities/ovn-sbctl.8.in | 9 ++++--- ovn/utilities/ovn-sbctl.c | 44 ++++++++++++++++++++++++++++++----------- tests/ovn-sbctl.at | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/ovn/utilities/ovn-sbctl.8.in b/ovn/utilities/ovn-sbctl.8.in index 2f783e9..e4e4431 100644 --- a/ovn/utilities/ovn-sbctl.8.in +++ b/ovn/utilities/ovn-sbctl.8.in @@ -114,10 +114,11 @@ Prints a brief overview of the database contents. .SS "Chassis Commands" These commands manipulate \fBOVN_Southbound\fR chassis. . -.IP "[\fB\-\-may\-exist\fR] \fBchassis\-add \fIchassis\fR \fIencap-type\fR \fIencap-ip\fR" -Creates a new chassis named \fIchassis\fR. The chassis will have -one encap entry with \fIencap-type\fR as tunnel type and \fIencap-ip\fR -as destination ip. +.IP "[\fB\-\-may\-exist\fR] \fBchassis\-add \fIchassis\fR \fIencap\-type\fR \fIencap-ip\fR" +Creates a new chassis named \fIchassis\fR. \fIencap\-type\fR is a +comma-separated list of tunnel types. The chassis will have +one encap entry for each specified tunnel type with \fIencap-ip\fR +as the destination IP for each. .IP Without \fB\-\-may\-exist\fR, attempting to create a chassis that exists is an error. With \fB\-\-may\-exist\fR, this command does diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index 29aaf47..7861fe7 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -308,9 +308,9 @@ General commands:\n\ \n\ Chassis commands:\n\ chassis-add CHASSIS ENCAP-TYPE ENCAP-IP create a new chassis named\n\ - CHASSIS with one encapsulation\n\ - entry of ENCAP-TYPE and ENCAP-IP\n\ - chassis-del CHASSIS delete CHASSIS and all of its encaps,\n\ + CHASSIS with ENCAP-TYPE tunnels\n\ + and ENCAP-IP\n\ + chassis-del CHASSIS delete CHASSIS and all of its encaps\n\ and gateway_ports\n\ \n\ Port binding commands:\n\ @@ -526,13 +526,11 @@ static void cmd_chassis_add(struct ctl_context *ctx) { struct sbctl_context *sbctl_ctx = sbctl_context_cast(ctx); - struct sbrec_chassis *ch; - struct sbrec_encap *encap; bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; - const char *ch_name, *encap_type, *encap_ip; + const char *ch_name, *encap_types, *encap_ip; ch_name = ctx->argv[1]; - encap_type = ctx->argv[2]; + encap_types = ctx->argv[2]; encap_ip = ctx->argv[3]; sbctl_context_populate_cache(ctx); @@ -546,12 +544,34 @@ cmd_chassis_add(struct ctl_context *ctx) } check_conflicts(sbctl_ctx, ch_name, xasprintf("cannot create a chassis named %s", ch_name)); - ch = sbrec_chassis_insert(ctx->txn); + + char *tokstr = xstrdup(encap_types); + char *token, *save_ptr = NULL; + struct sset encap_set = SSET_INITIALIZER(&encap_set); + for (token = strtok_r(tokstr, ",", &save_ptr); token != NULL; + token = strtok_r(NULL, ",", &save_ptr)) { + sset_add(&encap_set, token); + } + free(tokstr); + + size_t n_encaps = sset_count(&encap_set); + struct sbrec_encap **encaps = xmalloc(n_encaps * sizeof *encaps); + const char *encap_type; + int i = 0; + SSET_FOR_EACH (encap_type, &encap_set){ + encaps[i] = sbrec_encap_insert(ctx->txn); + + sbrec_encap_set_type(encaps[i], encap_type); + sbrec_encap_set_ip(encaps[i], encap_ip); + i++; + } + sset_destroy(&encap_set); + + struct sbrec_chassis *ch = sbrec_chassis_insert(ctx->txn); sbrec_chassis_set_name(ch, ch_name); - encap = sbrec_encap_insert(ctx->txn); - sbrec_encap_set_type(encap, encap_type); - sbrec_encap_set_ip(encap, encap_ip); - sbrec_chassis_set_encaps(ch, &encap, 1); + sbrec_chassis_set_encaps(ch, encaps, n_encaps); + free(encaps); + sbctl_context_invalidate_cache(ctx); } diff --git a/tests/ovn-sbctl.at b/tests/ovn-sbctl.at index 674e1e8..d02e00f 100644 --- a/tests/ovn-sbctl.at +++ b/tests/ovn-sbctl.at @@ -29,7 +29,40 @@ m4_define([OVN_SBCTL_TEST_STOP], AT_CHECK([ovs-appctl -t ovn-northd exit]) AT_CHECK([ovs-appctl -t ovsdb-server exit])]) -# ovn-sbctl test. +dnl --------------------------------------------------------------------- + +AT_SETUP([ovn-sbctl - chassis commands]) +OVN_SBCTL_TEST_START +ovn_init_db ovn-sb + +AT_CHECK([ovn-sbctl chassis-add ch0 geneve 1.2.3.4]) +AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort], + [0], [dnl +1.2.3.4,geneve +]) + +AT_CHECK([ovn-sbctl chassis-add ch1 stt,geneve,vxlan 1.2.3.5]) +AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort], + [0], [dnl +1.2.3.4,geneve +1.2.3.5,geneve +1.2.3.5,stt +1.2.3.5,vxlan +]) + +AT_CHECK([ovn-sbctl chassis-del ch0]) +AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort], + [0], [dnl +1.2.3.5,geneve +1.2.3.5,stt +1.2.3.5,vxlan +]) + +OVN_SBCTL_TEST_STOP +AT_CLEANUP + +dnl --------------------------------------------------------------------- + AT_SETUP([ovn-sbctl - test]) OVN_SBCTL_TEST_START