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

Russell Bryant rbryant at redhat.com
Wed Apr 8 19:19:41 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 |  4 ++-
 ovn/ovn-nbctl.c     | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml
index 7cdef00..d61367c 100644
--- a/ovn/ovn-nbctl.8.xml
+++ b/ovn/ovn-nbctl.8.xml
@@ -17,9 +17,11 @@
     <p><code>lswitch-get-external-id</code> <var>lswitch</var> [<var>key</var>]</p>
 
     <h1>Logical Port Commands</h1>
-    <p><code>lport-add</code> <var>name</var> <var>lswitch</var></p>
+    <p><code>lport-add</code> <var>name</var> <var>lswitch</var> [<var>parent_name</var>] [<var>tag</var>]</p>
     <p><code>lport-del</code> <var>lport</var></p>
     <p><code>lport-list</code> <var>lswitch</var></p>
+    <p><code>lport-get-parent</code> <var>lport</var></p>
+    <p><code>lport-get-tag</code> <var>lport</var></p>
     <p><code>lport-set-external-id</code> <var>lport</var> <var>key</var> [<var>value</var>]</p>
     <p><code>lport-get-external-id</code> <var>lport</var> [<var>key</var>]</p>
     <p><code>lport-set-macs</code> <var>lport</var> [<var>mac</var>] [<var>mac</var>] [...]</p>
diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c
index 3178105..6cb3c14 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>
 
@@ -56,9 +57,12 @@ Logical Switch Commands:\n\
                             List one or all external:ids set on a switch\n\
 \n\
 Logical Port Commands:\n\
-  lport-add <name> <lswitch> Create a logical port on a logical switch\n\
+  lport-add <name> <lswitch> [parent_name] [tag]\n\
+                            Create a logical port on a logical switch\n\
   lport-del <lport>         Delete a logical port (by name or UUID)\n\
   lport-list <lswitch>      List ports on a logical switch\n\
+  lport-get-parent          Get the parent port name if set\n\
+  lport-get-tag             Get the tag if set\n\
   lport-set-external-id <lport> <key> [value]\n\
                             Set or delete an external:id on a logical port\n\
   lport-get-external-id <lport> [key]\n\
@@ -252,15 +256,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[2]);
     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[1]);
     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
@@ -318,6 +344,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;
@@ -520,9 +578,9 @@ static const struct ovs_cmdl_command all_commands[] = {
     },
     {
         .name = "lport-add",
-        .usage = "<name> <lswitch>",
+        .usage = "<name> <lswitch> [parent_name] [tag]",
         .min_args = 2,
-        .max_args = 2,
+        .max_args = 4,
         .handler = do_lport_add,
     },
     {
@@ -540,6 +598,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