[ovs-dev] [RFC PATCH v1 1/6] Vlan Support in ovn, add network type in northbound schema

Ankur Sharma ankur.sharma at nutanix.com
Wed Feb 20 22:34:52 UTC 2019


Background:
[1] https://mail.openvswitch.org/pipermail/ovs-dev/2018-October/353066.html
[2] https://docs.google.com/document/d/1uoQH478wM1OZ16HrxzbOUvk5LvFnfNEWbkPT6Zmm9OU/edit?usp=sharing

This Series:
Layer 2, Layer 3 E-W and Layer 3 N-S (NO NAT) changes for vlan
backed distributed logical router.

This Patch:
a. Add 1 more column to the Logical_Switch table in north bound
   schema, to indicate if a logical switch is of type "vlan" or "overlay".
   We will support NULL value in this table as well, to keep it backward
   compatible. NULL value will be treated as "overlay" type by northd.

b. Column name:
   i. network_type: Represents whether network is vlan backed or
   overlay.

c. Update ovn-nbctl ls-add clis to take network type as optional
   input.
   ovn-nbctl ls-add [SWITCH] [TYPE]

d. Add a new ovn-nbctl command to set network type of a logical
   switch.
   ovn-nbctl ls-set-network-type SWITCH vlan|overlay

Signed-off-by: Ankur Sharma <ankur.sharma at nutanix.com>
---
 ovn/ovn-nb.ovsschema      |  8 ++++++--
 ovn/ovn-nb.xml            |  9 +++++++++
 ovn/utilities/ovn-nbctl.c | 45 +++++++++++++++++++++++++++++++++++++-------
 tests/ovn-nbctl.at        | 48 +++++++++++++++++++++++++++++++++++------------
 4 files changed, 89 insertions(+), 21 deletions(-)

diff --git a/ovn/ovn-nb.ovsschema b/ovn/ovn-nb.ovsschema
index 10a5964..270781e 100644
--- a/ovn/ovn-nb.ovsschema
+++ b/ovn/ovn-nb.ovsschema
@@ -1,7 +1,7 @@
 {
     "name": "OVN_Northbound",
-    "version": "5.14.1",
-    "cksum": "3758097843 20509",
+    "version": "5.15.0",
+    "cksum": "3140342094 20772",
     "tables": {
         "NB_Global": {
             "columns": {
@@ -29,6 +29,10 @@
         "Logical_Switch": {
             "columns": {
                 "name": {"type": "string"},
+                "network_type": {"type": {"key": {"type": "string",
+                                                  "enum": ["set", ["overlay", "vlan"]]},
+                                          "min": 0,
+                                          "max": 1}},
                 "ports": {"type": {"key": {"type": "uuid",
                                            "refTable": "Logical_Switch_Port",
                                            "refType": "strong"},
diff --git a/ovn/ovn-nb.xml b/ovn/ovn-nb.xml
index 1839650..442ccfc 100644
--- a/ovn/ovn-nb.xml
+++ b/ovn/ovn-nb.xml
@@ -158,6 +158,15 @@
       </p>
     </column>
 
+    <column name="network_type">
+      <p>
+        Whether logical switch is VLAN backed or Overlay.
+      </p>
+
+      <p>
+        Default is overlay.
+      </p>
+    </column>
     <column name="load_balancer">
       Load balance a virtual ip address to a set of logical port endpoint
       ip addresses.
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 2fa0b33..3241d80 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -549,7 +549,7 @@ General commands:\n\
   show ROUTER               print overview of database contents for ROUTER\n\
 \n\
 Logical switch commands:\n\
-  ls-add [SWITCH]           create a logical switch named SWITCH\n\
+  ls-add [SWITCH] [TYPE]    create a logical switch named SWITCH of TYPE vlan or overlay\n\
   ls-del SWITCH             delete SWITCH and all its ports\n\
   ls-list                   print the names of all logical switches\n\
 \n\
@@ -971,8 +971,9 @@ print_lr(const struct nbrec_logical_router *lr, struct ds *s)
 static void
 print_ls(const struct nbrec_logical_switch *ls, struct ds *s)
 {
-    ds_put_format(s, "switch "UUID_FMT" (%s)",
-                  UUID_ARGS(&ls->header_.uuid), ls->name);
+    ds_put_format(s, "switch "UUID_FMT" (%s) (type: %s)",
+                  UUID_ARGS(&ls->header_.uuid), ls->name,
+                  strlen(ls->network_type) ? ls->network_type : "overlay");
     print_alias(&ls->external_ids, "neutron:network_name", s);
     ds_put_char(s, '\n');
 
@@ -1074,7 +1075,8 @@ nbctl_show(struct ctl_context *ctx)
 static void
 nbctl_ls_add(struct ctl_context *ctx)
 {
-    const char *ls_name = ctx->argc == 2 ? ctx->argv[1] : NULL;
+    const char *ls_name = ctx->argc >= 2 ? ctx->argv[1] : NULL;
+    const char *nw_type = ctx->argc == 3 ? ctx->argv[2] : "overlay";
 
     bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
     bool add_duplicate = shash_find(&ctx->options, "--add-duplicate") != NULL;
@@ -1111,6 +1113,31 @@ nbctl_ls_add(struct ctl_context *ctx)
     if (ls_name) {
         nbrec_logical_switch_set_name(ls, ls_name);
     }
+
+    nbrec_logical_switch_set_network_type(ls, nw_type);
+}
+
+static void
+nbctl_ls_set_network_type(struct ctl_context *ctx)
+{
+   const char *ls_name = ctx->argv[1];
+   const char *ls_type = ctx->argv[2];
+   const struct nbrec_logical_switch *ls = NULL;
+
+   char *error = ls_by_name_or_uuid(ctx, ls_name, true, &ls);
+
+   if (!ls || error) {
+      ctx->error = error;
+      return;
+   }
+
+   if (strcmp(ls_type, "vlan") && strcmp(ls_type, "overlay")) {
+      ctl_error(ctx, "Invalid type: \"%s\", supported types are \"vlan\" "
+                "and \"overlay\"", ls_type);
+      return;
+   }
+
+   nbrec_logical_switch_set_network_type(ls, ls_type);
 }
 
 static void
@@ -1140,8 +1167,10 @@ nbctl_ls_list(struct ctl_context *ctx)
 
     smap_init(&switches);
     NBREC_LOGICAL_SWITCH_FOR_EACH(ls, ctx->idl) {
-        smap_add_format(&switches, ls->name, UUID_FMT " (%s)",
-                        UUID_ARGS(&ls->header_.uuid), ls->name);
+        smap_add_format(&switches, ls->name, UUID_FMT " (%s) (type: %s)",
+                        UUID_ARGS(&ls->header_.uuid), ls->name,
+                        strlen(ls->network_type) ? ls->network_type :
+                        "overlay");
     }
     const struct smap_node **nodes = smap_sort(&switches);
     for (size_t i = 0; i < smap_count(&switches); i++) {
@@ -5047,10 +5076,12 @@ static const struct ctl_command_syntax nbctl_commands[] = {
     { "show", 0, 1, "[SWITCH]", NULL, nbctl_show, NULL, "", RO },
 
     /* logical switch commands. */
-    { "ls-add", 0, 1, "[SWITCH]", NULL, nbctl_ls_add, NULL,
+    { "ls-add", 0, 2, "[SWITCH] [TYPE]", NULL, nbctl_ls_add, NULL,
       "--may-exist,--add-duplicate", RW },
     { "ls-del", 1, 1, "SWITCH", NULL, nbctl_ls_del, NULL, "--if-exists", RW },
     { "ls-list", 0, 0, "", NULL, nbctl_ls_list, NULL, "", RO },
+    { "ls-set-network-type", 2, 2, "SWITCH TYPE", NULL,
+      nbctl_ls_set_network_type, NULL, "", RW },
 
     /* acl commands. */
     { "acl-add", 5, 6, "{SWITCH | PORTGROUP} DIRECTION PRIORITY MATCH ACTION",
diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
index 7a5903c..2cb420d 100644
--- a/tests/ovn-nbctl.at
+++ b/tests/ovn-nbctl.at
@@ -56,31 +56,39 @@ m4_define([OVN_NBCTL_TEST],
 OVN_NBCTL_TEST([ovn_nbctl_basic_switch], [basic switch commands], [
 AT_CHECK([ovn-nbctl ls-add ls0])
 AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
 ])
 
 AT_CHECK([ovn-nbctl ls-add ls1])
 AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
-<1> (ls1)
+<0> (ls0) (type: overlay)
+<1> (ls1) (type: overlay)
 ])
 
+AT_CHECK([ovn-nbctl ls-add ls2 vlan])
+AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
+<0> (ls0) (type: overlay)
+<1> (ls1) (type: overlay)
+<2> (ls2) (type: vlan)
+])
+
+AT_CHECK([ovn-nbctl ls-del ls2])
 AT_CHECK([ovn-nbctl ls-del ls0])
 AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls1)
+<0> (ls1) (type: overlay)
 ])
 
 AT_CHECK([ovn-nbctl show ls0])
 AT_CHECK([ovn-nbctl ls-add ls0])
 AT_CHECK([ovn-nbctl show ls0 | uuidfilt], [0],
-  [switch <0> (ls0)
+  [switch <0> (ls0) (type: overlay)
 ])
 AT_CHECK([ovn-nbctl ls-add ls0], [1], [],
   [ovn-nbctl: ls0: a switch with this name already exists
 ])
 AT_CHECK([ovn-nbctl --may-exist ls-add ls0])
 AT_CHECK([ovn-nbctl show ls0 | uuidfilt], [0],
-  [switch <0> (ls0)
+  [switch <0> (ls0) (type: overlay)
 ])
 AT_CHECK([ovn-nbctl --add-duplicate ls-add ls0])
 AT_CHECK([ovn-nbctl --may-exist --add-duplicate ls-add ls0], [1], [],
@@ -102,7 +110,23 @@ AT_CHECK([ovn-nbctl --add-duplicate ls-add], [1], [],
 ])
 AT_CHECK([ovn-nbctl --may-exist ls-add], [1], [],
   [ovn-nbctl: --may-exist requires specifying a name
-])])
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 vlan])
+AT_CHECK([ovn-nbctl show ls1 | uuidfilt], [0],
+  [switch <0> (ls1) (type: vlan)
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 overlay])
+AT_CHECK([ovn-nbctl show ls1 | uuidfilt], [0],
+  [switch <0> (ls1) (type: overlay)
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 temp], [1], [],
+  [ovn-nbctl: Invalid type: "temp", supported types are "vlan" and "overlay"
+])
+
+])
 
 dnl ---------------------------------------------------------------------
 
@@ -1419,7 +1443,7 @@ dnl ---------------------------------------------------------------------
 OVN_NBCTL_TEST([ovn_nbctl_dry_run_mode], [dry run mode], [
 dnl Check that dry run has no permanent effect.
 AT_CHECK([ovn-nbctl --dry-run ls-add ls0 -- ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
 ])
 AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
 ])
@@ -1427,7 +1451,7 @@ AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
 dnl Check that dry-run mode is not sticky.
 AT_CHECK([ovn-nbctl ls-add ls0])
 AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
 ])])
 
 dnl ---------------------------------------------------------------------
@@ -1437,13 +1461,13 @@ AT_CHECK([ovn-nbctl ls-add ls0 -- ls-add ls1])
 
 dnl Expect one line for one command.
 AT_CHECK([ovn-nbctl --oneline ls-list | uuidfilt], [0], [dnl
-<0> (ls0)\n<1> (ls1)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
 ])
 
 dnl Expect lines for two commands.
 AT_CHECK([ovn-nbctl --oneline ls-list -- ls-list | uuidfilt], [0], [dnl
-<0> (ls0)\n<1> (ls1)
-<0> (ls0)\n<1> (ls1)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
 ])])
 
 dnl ---------------------------------------------------------------------
-- 
1.8.3.1



More information about the dev mailing list