[ovs-dev] [PATCH ovn 1/2 v6] ovn-nbctl: Updates for container integration.

Russell Bryant rbryant at redhat.com
Fri Apr 17 20:17:21 UTC 2015


Add support for specifying a parent port name and tag when creating
logical ports.  Also add commands for getting the parent_name or tag
set on a logical port.  These are necessary for dealing with container
interfaces that sit behind normal interfaces.

Signed-off-by: Russell Bryant <rbryant at redhat.com>
---
 ovn/ovn-nbctl.8.xml | 18 +++++++++++--
 ovn/ovn-nbctl.c     | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml
index eb3de7e..f352efb 100644
--- a/ovn/ovn-nbctl.8.xml
+++ b/ovn/ovn-nbctl.8.xml
@@ -59,10 +59,12 @@
 
     <h1>Logical Port Commands</h1>
     <dl>
-      <dt><code>lport-add</code> <var>lswitch</var> <var>lport</var></dt>
+      <dt><code>lport-add</code> <var>lswitch</var> <var>lport</var> [<var>parent</var>] [<var>tag</var>]</dt>
       <dd>
         Creates on <var>lswitch</var> a new logical port named
-        <var>lport</var>.
+        <var>lport</var>.  If this port is a child port (for a
+        container running inside a VM), specify the parent port
+        and tag for identifying this port's traffic.
       </dd>
 
       <dt><code>lport-del</code> <var>lport</var></dt>
@@ -76,6 +78,18 @@
         standard output, one per line.
       </dd>
 
+      <dt><code>lport-get-parent</code> <var>lport</var></dt>
+      <dd>
+        If set, get the parent port of <var>lport</var>.  If not set, print
+        nothing.
+      </dd>
+
+      <dt><code>lport-get-tag</code> <var>lport</var></dt>
+      <dd>
+        If set, get the tag for <var>lport</var> traffic.  If not set, print
+        nothing.
+      </dd>
+
       <dt><code>lport-set-external-id</code> <var>lport</var> <var>key</var> [<var>value</var>]</dt>
       <dd>
         <p>Sets or clears an ``external ID'' value on <var>lport</var>.
diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c
index b00d7b1..d33df67 100644
--- a/ovn/ovn-nbctl.c
+++ b/ovn/ovn-nbctl.c
@@ -15,6 +15,7 @@
 #include <config.h>
 
 #include <getopt.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -57,9 +58,12 @@ Logical switch commands:\n\
                             list one or all external-ids on LSWITCH\n\
 \n\
 Logical port commands:\n\
-  lport-add LSWITCH LPORT   add logical port LPORT on LSWITCH\n\
+  lport-add LSWITCH LPORT [PARENT] [TAG]\n\
+                            add logical port LPORT on LSWITCH\n\
   lport-del LPORT           delete LPORT from its attached switch\n\
   lport-list LSWITCH        print the names of all logical ports on LSWITCH\n\
+  lport-get-parent LPORT    Get the parent port name if set\n\
+  lport-get-tag LPORT       Get the port's tag if set\n\
   lport-set-external-id LPORT KEY [VALUE]\n\
                             set or delete an external-id on LPORT\n\
   lport-get-external-id LPORT [KEY]\n\
@@ -251,15 +255,37 @@ do_lport_add(struct ovs_cmdl_context *ctx)
     struct nbctl_context *nb_ctx = ctx->pvt;
     struct nbrec_logical_port *lport;
     const struct nbrec_logical_switch *lswitch;
+    int64_t tag;
+
+    /* Validate all of the input */
 
     lswitch = lswitch_by_name_or_uuid(nb_ctx, ctx->argv[1]);
     if (!lswitch) {
         return;
     }
 
+    if (ctx->argc != 3 && ctx->argc != 5) {
+        /* If a parent_name is specififed, a tag must be specified as well. */
+        VLOG_WARN("Invalid arguments to lport-add.");
+        return;
+    }
+
+    if (ctx->argc == 5) {
+        /* Validate tag. */
+        if (!ovs_scan(ctx->argv[4], "%"SCNd64, &tag) || tag < 0 || tag > 4095) {
+            VLOG_WARN("Invalid tag for logical port '%s'", ctx->argv[4]);
+            return;
+        }
+    }
+
+    /* Finally, create the transaction. */
     lport = nbrec_logical_port_insert(nb_ctx->txn);
     nbrec_logical_port_set_name(lport, ctx->argv[2]);
     nbrec_logical_port_set_lswitch(lport, lswitch);
+    if (ctx->argc == 5) {
+        nbrec_logical_port_set_parent_name(lport, ctx->argv[3]);
+        nbrec_logical_port_set_tag(lport, &tag, 1);
+    }
 }
 
 static void
@@ -317,6 +343,38 @@ do_lport_list(struct ovs_cmdl_context *ctx)
 }
 
 static void
+do_lport_get_parent(struct ovs_cmdl_context *ctx)
+{
+    struct nbctl_context *nb_ctx = ctx->pvt;
+    const struct nbrec_logical_port *lport;
+
+    lport = lport_by_name_or_uuid(nb_ctx, ctx->argv[1]);
+    if (!lport) {
+        return;
+    }
+
+    if (lport->parent_name) {
+        printf("%s\n", lport->parent_name);
+    }
+}
+
+static void
+do_lport_get_tag(struct ovs_cmdl_context *ctx)
+{
+    struct nbctl_context *nb_ctx = ctx->pvt;
+    const struct nbrec_logical_port *lport;
+
+    lport = lport_by_name_or_uuid(nb_ctx, ctx->argv[1]);
+    if (!lport) {
+        return;
+    }
+
+    if (lport->n_tag > 0) {
+        printf("%"PRId64"\n", lport->tag[0]);
+    }
+}
+
+static void
 do_lport_set_external_id(struct ovs_cmdl_context *ctx)
 {
     struct nbctl_context *nb_ctx = ctx->pvt;
@@ -517,9 +575,9 @@ static const struct ovs_cmdl_command all_commands[] = {
     },
     {
         .name = "lport-add",
-        .usage = "LSWITCH LPORT",
+        .usage = "LSWITCH LPORT [PARENT] [TAG]",
         .min_args = 2,
-        .max_args = 2,
+        .max_args = 4,
         .handler = do_lport_add,
     },
     {
@@ -537,6 +595,20 @@ static const struct ovs_cmdl_command all_commands[] = {
         .handler = do_lport_list,
     },
     {
+        .name = "lport-get-parent",
+        .usage = "LPORT",
+        .min_args = 1,
+        .max_args = 1,
+        .handler = do_lport_get_parent,
+    },
+    {
+        .name = "lport-get-tag",
+        .usage = "LPORT",
+        .min_args = 1,
+        .max_args = 1,
+        .handler = do_lport_get_tag,
+    },
+    {
         .name = "lport-set-external-id",
         .usage = "LPORT KEY [VALUE]",
         .min_args = 2,
-- 
2.1.0




More information about the dev mailing list