From: Russell Bryant Date: Mon, 20 Apr 2015 16:56:06 +0000 (-0400) Subject: ovn-nbctl: Updates for container integration. X-Git-Tag: v2.5.0~1124 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=bf5fa52a6c14f282b5c8969bc98c786d4dc7223d;p=cascardo%2Fovs.git ovn-nbctl: Updates for container integration. 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 Signed-off-by: Justin Pettit --- diff --git a/ovn/ovn-nbctl.8.xml b/ovn/ovn-nbctl.8.xml index eb3de7e50..477db7a7d 100644 --- a/ovn/ovn-nbctl.8.xml +++ b/ovn/ovn-nbctl.8.xml @@ -65,6 +65,16 @@ lport. +
lport-add lswitch lport parent tag
+
+ Creates on lswitch a logical port named lport + that is a child of parent that is identied with + tag. 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. +
+
lport-del lport
Deletes lport. @@ -76,6 +86,18 @@ standard output, one per line.
+
lport-get-parent lport
+
+ If set, get the parent port of lport. If not set, print + nothing. +
+ +
lport-get-tag lport
+
+ If set, get the tag for lport traffic. If not set, print + nothing. +
+
lport-set-external-id lport key [value]

Sets or clears an ``external ID'' value on lport. diff --git a/ovn/ovn-nbctl.c b/ovn/ovn-nbctl.c index b00d7b1d1..02dc0ad85 100644 --- a/ovn/ovn-nbctl.c +++ b/ovn/ovn-nbctl.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -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]",