Skip to content

Commit

Permalink
ovn-nbctl: Update logical switch port commands.
Browse files Browse the repository at this point in the history
A few minor changes related to logical switch port commands:

    - Use "lsp" instead of "lport" to be more consistent with later
      changes.
    - Use commands where possible in ovn unit tests.
    - Update references from "lport" to "lsp" (code) or "port" (user).

Signed-off-by: Justin Pettit <[email protected]>
Acked-by: Ryan Moats <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
justinpettit committed Jun 11, 2016
1 parent 80f408f commit 31ed119
Show file tree
Hide file tree
Showing 19 changed files with 413 additions and 410 deletions.
2 changes: 1 addition & 1 deletion INSTALL.Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Docker currently does not have a CLI command to list all your logical ports.
But you can look at them in the OVN database, by running:

```
ovn-nbctl --db=tcp:$CENTRAL_IP:6640 lport-list $NID
ovn-nbctl --db=tcp:$CENTRAL_IP:6640 lsp-list $NID
```

* You can also create a logical port and attach it to a running container.
Expand Down
15 changes: 8 additions & 7 deletions ovn/utilities/ovn-docker-overlay-driver
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def create_endpoint():
mac_address_output = ""

try:
ovn_nbctl("lport-add", nid, eid)
ovn_nbctl("lsp-add", nid, eid)
except Exception as e:
error = "create_endpoint: lport-add (%s)" % (str(e))
error = "create_endpoint: lsp-add (%s)" % (str(e))
return jsonify({'Err': error})

if not mac_address_input:
Expand All @@ -243,10 +243,10 @@ def create_endpoint():
mac_address = mac_address_input

try:
ovn_nbctl("lport-set-addresses", eid,
ovn_nbctl("lsp-set-addresses", eid,
mac_address + " " + ip_address)
except Exception as e:
error = "create_endpoint: lport-set-addresses (%s)" % (str(e))
error = "create_endpoint: lsp-set-addresses (%s)" % (str(e))
return jsonify({'Err': error})

# Only return a mac address if one did not come as request.
Expand Down Expand Up @@ -295,7 +295,8 @@ def show_endpoint():
if error:
jsonify({'Err': error})
except Exception as e:
error = "show_endpoint: get Logical_Switch_Port addresses. (%s)" % (str(e))
error = "show_endpoint: get Logical_Switch_Port addresses. (%s)" \
% (str(e))
return jsonify({'Err': error})

veth_outside = eid[0:15]
Expand All @@ -321,9 +322,9 @@ def delete_endpoint():
abort(400)

try:
ovn_nbctl("lport-del", eid)
ovn_nbctl("lsp-del", eid)
except Exception as e:
error = "delete_endpoint: lport-del %s" % (str(e))
error = "delete_endpoint: lsp-del %s" % (str(e))
return jsonify({'Err': error})

return jsonify({})
Expand Down
82 changes: 41 additions & 41 deletions ovn/utilities/ovn-nbctl.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,93 +94,93 @@
</dd>
</dl>

<h1>Logical Port Commands</h1>
<h1>Logical Switch Port Commands</h1>
<dl>
<dt>[<code>--may-exist</code>] <code>lport-add</code> <var>lswitch</var> <var>lport</var></dt>
<dt>[<code>--may-exist</code>] <code>lsp-add</code> <var>lswitch</var> <var>port</var></dt>
<dd>
<p>
Creates on <var>lswitch</var> a new logical port named
<var>lport</var>.
Creates on <var>lswitch</var> a new logical switch port named
<var>port</var>.
</p>

<p>
It is an error if a logical port named <var>lport</var> already
It is an error if a logical port named <var>port</var> already
exists, unless <code>--may-exist</code> is specified. Regardless of
<code>--may-exist</code>, it is an error if the existing port is in
some logical switch other than <var>lswitch</var> or if it has a
parent port.
</p>
</dd>

<dt>[<code>--may-exist</code>] <code>lport-add</code> <var>lswitch</var> <var>lport</var> <var>parent</var> <var>tag</var></dt>
<dt>[<code>--may-exist</code>] <code>lsp-add</code> <var>lswitch</var> <var>port</var> <var>parent</var> <var>tag</var></dt>
<dd>
<p>
Creates on <var>lswitch</var> a logical port named <var>lport</var>
that is a child of <var>parent</var> that is identifed with VLAN ID
<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.
Creates on <var>lswitch</var> a logical switch port named
<var>port</var> that is a child of <var>parent</var> that is
identifed with VLAN ID <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.
</p>

<p>
It is an error if a logical port named <var>lport</var> already
It is an error if a logical port named <var>port</var> already
exists, unless <code>--may-exist</code> is specified. Regardless of
<code>--may-exist</code>, it is an error if the existing port is not
in <var>lswitch</var> or if it does not have the specified
<var>parent</var> and <var>tag</var>.
</p>
</dd>

<dt>[<code>--if-exists</code>] <code>lport-del</code> <var>lport</var></dt>
<dt>[<code>--if-exists</code>] <code>lsp-del</code> <var>port</var></dt>
<dd>
Deletes <var>lport</var>. It is an error if <var>lport</var> does
Deletes <var>port</var>. It is an error if <var>port</var> does
not exist, unless <code>--if-exists</code> is specified.
</dd>

<dt><code>lport-list</code> <var>lswitch</var></dt>
<dt><code>lsp-list</code> <var>lswitch</var></dt>
<dd>
Lists all the logical ports within <var>lswitch</var> on
Lists all the logical switch ports within <var>lswitch</var> on
standard output, one per line.
</dd>

<dt><code>lport-get-parent</code> <var>lport</var></dt>
<dt><code>lsp-get-parent</code> <var>port</var></dt>
<dd>
If set, get the parent port of <var>lport</var>. If not set, print
If set, get the parent port of <var>port</var>. If not set, print
nothing.
</dd>

<dt><code>lport-get-tag</code> <var>lport</var></dt>
<dt><code>lsp-get-tag</code> <var>port</var></dt>
<dd>
If set, get the tag for <var>lport</var> traffic. If not set, print
If set, get the tag for <var>port</var> traffic. If not set, print
nothing.
</dd>

<dt><code>lport-set-addresses</code> <var>lport</var> [<var>address</var>]...</dt>
<dt><code>lsp-set-addresses</code> <var>port</var> [<var>address</var>]...</dt>
<dd>
Sets the addresses associated with <var>lport</var> to
Sets the addresses associated with <var>port</var> to
<var>address</var>. Each <var>address</var> should be either an
Ethernet address or an Ethernet address followed by an IP address
(separated by a space and quoted to form a single command-line
argument). The special form <code>unknown</code> is also valid.
Multiple Ethernet addresses or Ethernet+IP pairs may be set. If no
<var>address</var> argument is given, <var>lport</var> will have no
<var>address</var> argument is given, <var>port</var> will have no
addresses associated with it.
</dd>

<dt><code>lport-get-addresses</code> <var>lport</var></dt>
<dt><code>lsp-get-addresses</code> <var>port</var></dt>
<dd>
Lists all the addresses associated with <var>lport</var> on standard
Lists all the addresses associated with <var>port</var> on standard
output, one per line.
</dd>

<dt><code>lport-set-port-security</code> <var>lport</var> [<var>addrs</var>]...</dt>
<dt><code>lsp-set-port-security</code> <var>port</var> [<var>addrs</var>]...</dt>
<dd>
<p>
Sets the port security addresses associated with <var>lport</var> to
Sets the port security addresses associated with <var>port</var> to
<var>addrs</var>. Multiple sets of addresses may be set by using
multiple <var>addrs</var> arguments. If no <var>addrs</var> argument
is given, <var>lport</var> will not have port security enabled.
is given, <var>port</var> will not have port security enabled.
</p>

<p>
Expand All @@ -192,47 +192,47 @@
</p>
</dd>

<dt><code>lport-get-port-security</code> <var>lport</var></dt>
<dt><code>lsp-get-port-security</code> <var>port</var></dt>
<dd>
Lists all the port security addresses associated with <var>lport</var>
Lists all the port security addresses associated with <var>port</var>
on standard output, one per line.
</dd>

<dt><code>lport-get-up</code> <var>lport</var></dt>
<dt><code>lsp-get-up</code> <var>port</var></dt>
<dd>
Prints the state of <var>lport</var>, either <code>up</code> or
Prints the state of <var>port</var>, either <code>up</code> or
<code>down</code>.
</dd>

<dt><code>lport-set-enabled</code> <var>lport</var> <var>state</var></dt>
<dt><code>lsp-set-enabled</code> <var>port</var> <var>state</var></dt>
<dd>
Set the administrative state of <var>lport</var>, either <code>enabled</code>
Set the administrative state of <var>port</var>, either <code>enabled</code>
or <code>disabled</code>. When a port is disabled, no traffic is allowed into
or out of the port.
</dd>

<dt><code>lport-get-enabled</code> <var>lport</var></dt>
<dt><code>lsp-get-enabled</code> <var>port</var></dt>
<dd>
Prints the administrative state of <var>lport</var>, either <code>enabled</code>
Prints the administrative state of <var>port</var>, either <code>enabled</code>
or <code>disabled</code>.
</dd>

<dt><code>lport-set-type</code> <var>lport</var> <var>type</var></dt>
<dt><code>lsp-set-type</code> <var>port</var> <var>type</var></dt>
<dd>
Set the type for the logical port. No special types have been implemented yet.
</dd>

<dt><code>lport-get-type</code> <var>lport</var></dt>
<dt><code>lsp-get-type</code> <var>port</var></dt>
<dd>
Get the type for the logical port.
</dd>

<dt><code>lport-set-options</code> <var>lport</var> [<var>key=value</var>]...</dt>
<dt><code>lsp-set-options</code> <var>port</var> [<var>key=value</var>]...</dt>
<dd>
Set type-specific key-value options for the logical port.
</dd>

<dt><code>lport-get-options</code> <var>lport</var></dt>
<dt><code>lsp-get-options</code> <var>port</var></dt>
<dd>
Get the type-specific options for the logical port.
</dd>
Expand Down
96 changes: 46 additions & 50 deletions ovn/utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,31 +308,31 @@ ACL commands:\n\
acl-list LSWITCH print ACLs for LSWITCH\n\
\n\
Logical switch 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\
lsp-add LSWITCH PORT add logical port PORT on LSWITCH\n\
lsp-add LSWITCH PORT PARENT TAG\n\
add logical port PORT 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-addresses LPORT [ADDRESS]...\n\
set MAC or MAC+IP addresses for LPORT.\n\
lport-get-addresses LPORT get a list of MAC addresses on LPORT\n\
lport-set-port-security LPORT [ADDRS]...\n\
set port security addresses for LPORT.\n\
lport-get-port-security LPORT get LPORT's port security addresses\n\
lport-get-up LPORT get state of LPORT ('up' or 'down')\n\
lport-set-enabled LPORT STATE\n\
set administrative state LPORT\n\
lsp-del PORT delete PORT from its attached switch\n\
lsp-list LSWITCH print the names of all logical ports on LSWITCH\n\
lsp-get-parent PORT get the parent of PORT if set\n\
lsp-get-tag PORT get the PORT's tag if set\n\
lsp-set-addresses PORT [ADDRESS]...\n\
set MAC or MAC+IP addresses for PORT.\n\
lsp-get-addresses PORT get a list of MAC addresses on PORT\n\
lsp-set-port-security PORT [ADDRS]...\n\
set port security addresses for PORT.\n\
lsp-get-port-security PORT get PORT's port security addresses\n\
lsp-get-up PORT get state of PORT ('up' or 'down')\n\
lsp-set-enabled PORT STATE\n\
set administrative state PORT\n\
('enabled' or 'disabled')\n\
lport-get-enabled LPORT get administrative state LPORT\n\
lsp-get-enabled PORT get administrative state PORT\n\
('enabled' or 'disabled')\n\
lport-set-type LPORT TYPE Set the type for LPORT\n\
lport-get-type LPORT Get the type for LPORT\n\
lport-set-options LPORT KEY=VALUE [KEY=VALUE]...\n\
Set options related to the type of LPORT\n\
lport-get-options LPORT Get the type specific options for LPORT\n\
lsp-set-type PORT TYPE set the type for PORT\n\
lsp-get-type PORT get the type for PORT\n\
lsp-set-options PORT KEY=VALUE [KEY=VALUE]...\n\
set options related to the type of PORT\n\
lsp-get-options PORT get the type specific options for PORT\n\
\n\
Logical router commands:\n\
lr-add [ROUTER] create a logical router named ROUTER\n\
Expand Down Expand Up @@ -673,45 +673,45 @@ nbctl_lsp_add(struct ctl_context *ctx)
ctl_fatal("%s: invalid tag", ctx->argv[4]);
}
} else {
ctl_fatal("lport-add with parent must also specify a tag");
ctl_fatal("lsp-add with parent must also specify a tag");
}

const char *lsp_name = ctx->argv[2];
const struct nbrec_logical_switch_port *lsp;
lsp = lsp_by_name_or_uuid(ctx, lsp_name, false);
if (lsp) {
if (!may_exist) {
ctl_fatal("%s: an lport with this name already exists",
ctl_fatal("%s: a port with this name already exists",
lsp_name);
}

const struct nbrec_logical_switch *lsw;
lsw = lsp_to_lswitch(ctx->idl, lsp);
if (lsw != lswitch) {
char uuid_s[UUID_LEN + 1];
ctl_fatal("%s: lport already exists but in lswitch %s", lsp_name,
ctl_fatal("%s: port already exists but in lswitch %s", lsp_name,
lswitch_get_name(lsw, uuid_s, sizeof uuid_s));
}

if (parent_name) {
if (!lsp->parent_name) {
ctl_fatal("%s: lport already exists but has no parent",
ctl_fatal("%s: port already exists but has no parent",
lsp_name);
} else if (strcmp(parent_name, lsp->parent_name)) {
ctl_fatal("%s: lport already exists with different parent %s",
ctl_fatal("%s: port already exists with different parent %s",
lsp_name, lsp->parent_name);
}

if (!lsp->n_tag) {
ctl_fatal("%s: lport already exists but has no tag",
ctl_fatal("%s: port already exists but has no tag",
lsp_name);
} else if (lsp->tag[0] != tag) {
ctl_fatal("%s: lport already exists with different "
ctl_fatal("%s: port already exists with different "
"tag %"PRId64, lsp_name, lsp->tag[0]);
}
} else {
if (lsp->parent_name) {
ctl_fatal("%s: lport already exists but has parent %s",
ctl_fatal("%s: port already exists but has parent %s",
lsp_name, lsp->parent_name);
}
}
Expand Down Expand Up @@ -2084,36 +2084,32 @@ static const struct ctl_command_syntax nbctl_commands[] = {
{ "acl-list", 1, 1, "LSWITCH", NULL, nbctl_acl_list, NULL, "", RO },

/* logical switch port commands. */
{ "lport-add", 2, 4, "LSWITCH LPORT [PARENT] [TAG]", NULL, nbctl_lsp_add,
{ "lsp-add", 2, 4, "LSWITCH PORT [PARENT] [TAG]", NULL, nbctl_lsp_add,
NULL, "--may-exist", RW },
{ "lport-del", 1, 1, "LPORT", NULL, nbctl_lsp_del, NULL, "--if-exists",
RW },
{ "lport-list", 1, 1, "LSWITCH", NULL, nbctl_lsp_list, NULL, "", RO },
{ "lport-get-parent", 1, 1, "LPORT", NULL, nbctl_lsp_get_parent, NULL,
{ "lsp-del", 1, 1, "PORT", NULL, nbctl_lsp_del, NULL, "--if-exists", RW },
{ "lsp-list", 1, 1, "LSWITCH", NULL, nbctl_lsp_list, NULL, "", RO },
{ "lsp-get-parent", 1, 1, "PORT", NULL, nbctl_lsp_get_parent, NULL,
"", RO },
{ "lport-get-tag", 1, 1, "LPORT", NULL, nbctl_lsp_get_tag, NULL, "",
RO },
{ "lport-set-addresses", 1, INT_MAX, "LPORT [ADDRESS]...", NULL,
{ "lsp-get-tag", 1, 1, "PORT", NULL, nbctl_lsp_get_tag, NULL, "", RO },
{ "lsp-set-addresses", 1, INT_MAX, "PORT [ADDRESS]...", NULL,
nbctl_lsp_set_addresses, NULL, "", RW },
{ "lport-get-addresses", 1, 1, "LPORT", NULL,
nbctl_lsp_get_addresses, NULL,
{ "lsp-get-addresses", 1, 1, "PORT", NULL, nbctl_lsp_get_addresses, NULL,
"", RO },
{ "lport-set-port-security", 0, INT_MAX, "LPORT [ADDRS]...", NULL,
{ "lsp-set-port-security", 0, INT_MAX, "PORT [ADDRS]...", NULL,
nbctl_lsp_set_port_security, NULL, "", RW },
{ "lport-get-port-security", 1, 1, "LPORT", NULL,
{ "lsp-get-port-security", 1, 1, "PORT", NULL,
nbctl_lsp_get_port_security, NULL, "", RO },
{ "lport-get-up", 1, 1, "LPORT", NULL, nbctl_lsp_get_up, NULL, "", RO },
{ "lport-set-enabled", 2, 2, "LPORT STATE", NULL, nbctl_lsp_set_enabled,
{ "lsp-get-up", 1, 1, "PORT", NULL, nbctl_lsp_get_up, NULL, "", RO },
{ "lsp-set-enabled", 2, 2, "PORT STATE", NULL, nbctl_lsp_set_enabled,
NULL, "", RW },
{ "lport-get-enabled", 1, 1, "LPORT", NULL, nbctl_lsp_get_enabled, NULL,
{ "lsp-get-enabled", 1, 1, "PORT", NULL, nbctl_lsp_get_enabled, NULL,
"", RO },
{ "lport-set-type", 2, 2, "LPORT TYPE", NULL, nbctl_lsp_set_type, NULL,
{ "lsp-set-type", 2, 2, "PORT TYPE", NULL, nbctl_lsp_set_type, NULL,
"", RW },
{ "lport-get-type", 1, 1, "LPORT", NULL, nbctl_lsp_get_type, NULL, "",
RO },
{ "lport-set-options", 1, INT_MAX, "LPORT KEY=VALUE [KEY=VALUE]...", NULL,
{ "lsp-get-type", 1, 1, "PORT", NULL, nbctl_lsp_get_type, NULL, "", RO },
{ "lsp-set-options", 1, INT_MAX, "PORT KEY=VALUE [KEY=VALUE]...", NULL,
nbctl_lsp_set_options, NULL, "", RW },
{ "lport-get-options", 1, 1, "LPORT", NULL, nbctl_lsp_get_options, NULL,
{ "lsp-get-options", 1, 1, "PORT", NULL, nbctl_lsp_get_options, NULL,
"", RO },

/* logical router commands. */
Expand Down
Loading

0 comments on commit 31ed119

Please sign in to comment.