ovn-nbctl: Updates for container integration.
authorRussell Bryant <rbryant@redhat.com>
Mon, 20 Apr 2015 16:56:06 +0000 (12:56 -0400)
committerJustin Pettit <jpettit@nicira.com>
Mon, 20 Apr 2015 17:27:06 +0000 (10:27 -0700)
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@redhat.com>
Signed-off-by: Justin Pettit <jpettit@nicira.com>
ovn/ovn-nbctl.8.xml
ovn/ovn-nbctl.c

index eb3de7e..477db7a 100644 (file)
         <var>lport</var>.
       </dd>
 
+      <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 logical port named <var>lport</var>
+        that is a child of <var>parent</var> that is identied with
+        <var>tag</var>.  This is useful in cases such as virtualized
+        container environments where Open vSwitch does not have a direct
+        connection to the container's port and it must be shared with
+        the virtual machine's port.
+      </dd>
+
       <dt><code>lport-del</code> <var>lport</var></dt>
       <dd>
         Deletes <var>lport</var>.
         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>.
index b00d7b1..02dc0ad 100644 (file)
@@ -15,6 +15,7 @@
 #include <config.h>
 
 #include <getopt.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -58,8 +59,13 @@ Logical switch commands:\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 with PARENT\n\
+                            on TAG\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 of LPORT if set\n\
+  lport-get-tag LPORT       get the LPORT'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 +257,35 @@ 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;
 
     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 '%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
@@ -316,6 +342,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)
 {
@@ -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,
     },
     {
@@ -536,6 +594,20 @@ static const struct ovs_cmdl_command all_commands[] = {
         .max_args = 1,
         .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]",