<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>.
#include <config.h>
#include <getopt.h>
+#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
\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\
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
}
}
+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)
{
},
{
.name = "lport-add",
- .usage = "LSWITCH LPORT",
+ .usage = "LSWITCH LPORT [PARENT] [TAG]",
.min_args = 2,
- .max_args = 2,
+ .max_args = 4,
.handler = do_lport_add,
},
{
.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]",