[ovs-dev] [PATCH 2/5] ovn-sbctl: Add multiple encaps with "chassis-add".

Justin Pettit jpettit at nicira.com
Thu Oct 15 08:54:57 UTC 2015


Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
 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
 
-- 
1.7.5.4




More information about the dev mailing list