2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

Support accepting and displaying port names in OVS tools.

Until now, most ovs-ofctl commands have not accepted names for ports, only
numbers, and have not been able to display port names either.  It's a lot
easier for users if they can use and see meaningful names instead of
arbitrary numbers.  This commit adds that support.

For backward compatibility, only interactive ovs-ofctl commands by default
display port names; to display them in scripts, use the new --names
option.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Aaron Conole <aconole@redhat.com>
This commit is contained in:
Ben Pfaff
2017-05-31 16:06:12 -07:00
parent 52182c5f50
commit 50f96b10e1
45 changed files with 1383 additions and 617 deletions

View File

@@ -1156,9 +1156,12 @@ format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask)
}
/* Appends a string representation of 'match' to 's'. If 'priority' is
* different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
* different from OFP_DEFAULT_PRIORITY, includes it in 's'. If 'port_map' is
* nonnull, uses it to translate port numbers to names in output. */
void
match_format(const struct match *match, struct ds *s, int priority)
match_format(const struct match *match,
const struct ofputil_port_map *port_map,
struct ds *s, int priority)
{
const struct flow_wildcards *wc = &match->wc;
size_t start_len = s->length;
@@ -1200,7 +1203,7 @@ match_format(const struct match *match, struct ds *s, int priority)
if (wc->masks.actset_output) {
ds_put_format(s, "%sactset_output=%s", colors.param, colors.end);
ofputil_format_port(f->actset_output, s);
ofputil_format_port(f->actset_output, port_map, s);
ds_put_char(s, ',');
}
@@ -1313,7 +1316,7 @@ match_format(const struct match *match, struct ds *s, int priority)
if (wc->masks.in_port.ofp_port) {
ds_put_format(s, "%sin_port=%s", colors.param, colors.end);
ofputil_format_port(f->in_port.ofp_port, s);
ofputil_format_port(f->in_port.ofp_port, port_map, s);
ds_put_char(s, ',');
}
for (i = 0; i < FLOW_MAX_VLAN_HEADERS; i++) {
@@ -1482,20 +1485,23 @@ match_format(const struct match *match, struct ds *s, int priority)
}
/* Converts 'match' to a string and returns the string. If 'priority' is
* different from OFP_DEFAULT_PRIORITY, includes it in the string. The caller
* must free the string (with free()). */
* different from OFP_DEFAULT_PRIORITY, includes it in the string. If
* 'port_map' is nonnull, uses it to translate port numbers to names in
* output. The caller must free the string (with free()). */
char *
match_to_string(const struct match *match, int priority)
match_to_string(const struct match *match,
const struct ofputil_port_map *port_map, int priority)
{
struct ds s = DS_EMPTY_INITIALIZER;
match_format(match, &s, priority);
match_format(match, port_map, &s, priority);
return ds_steal_cstr(&s);
}
void
match_print(const struct match *match)
match_print(const struct match *match,
const struct ofputil_port_map *port_map)
{
char *s = match_to_string(match, OFP_DEFAULT_PRIORITY);
char *s = match_to_string(match, port_map, OFP_DEFAULT_PRIORITY);
puts(s);
free(s);
}
@@ -1586,27 +1592,32 @@ minimatch_matches_flow(const struct minimatch *match,
}
/* Appends a string representation of 'match' to 's'. If 'priority' is
* different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
* different from OFP_DEFAULT_PRIORITY, includes it in 's'. If 'port_map' is
* nonnull, uses it to translate port numbers to names in output. */
void
minimatch_format(const struct minimatch *match,
const struct tun_table *tun_table,struct ds *s, int priority)
const struct tun_table *tun_table,
const struct ofputil_port_map *port_map,
struct ds *s, int priority)
{
struct match megamatch;
minimatch_expand(match, &megamatch);
megamatch.flow.tunnel.metadata.tab = tun_table;
match_format(&megamatch, s, priority);
match_format(&megamatch, port_map, s, priority);
}
/* Converts 'match' to a string and returns the string. If 'priority' is
* different from OFP_DEFAULT_PRIORITY, includes it in the string. The caller
* must free the string (with free()). */
* must free the string (with free()). If 'port_map' is nonnull, uses it to
* translate port numbers to names in output. */
char *
minimatch_to_string(const struct minimatch *match, int priority)
minimatch_to_string(const struct minimatch *match,
const struct ofputil_port_map *port_map, int priority)
{
struct match megamatch;
minimatch_expand(match, &megamatch);
return match_to_string(&megamatch, priority);
return match_to_string(&megamatch, port_map, priority);
}