summaryrefslogtreecommitdiff
path: root/lib/learn.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2018-01-05 16:59:13 -0800
committerBen Pfaff <blp@ovn.org>2018-02-01 10:08:32 -0800
commit4bc938ccb3124282c873084a7d11cd8bc37e27a7 (patch)
tree1e890e37284ea4a4f4618d073e064b2a194d244a /lib/learn.c
parenta203f653b1a6a2544603be00966b8d4731d91b69 (diff)
downloadopenvswitch-4bc938ccb3124282c873084a7d11cd8bc37e27a7.tar.gz
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has supported table names for ages, but it has never used or displayed them outside of commands dedicated to table manipulation. This commit adds support for table names in ovs-ofctl. When a table has a name, it displays that name in flows and actions, so that, for example, the following: table=1, arp, actions=resubmit(,2) might become: table=ingress_acl, arp, actions=resubmit(,mac_learning) given appropriately named tables. For backward compatibility, only interactive ovs-ofctl commands by default display table names; to display them in scripts, use the new --names option. This feature was inspired by a talk that Kei Nohguchi presented at Open vSwitch 2017 Fall Conference. CC: Kei Nohguchi <kei@nohguchi.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Diffstat (limited to 'lib/learn.c')
-rw-r--r--lib/learn.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/learn.c b/lib/learn.c
index 9e321371c..5164082f8 100644
--- a/lib/learn.c
+++ b/lib/learn.c
@@ -381,6 +381,7 @@ learn_parse_spec(const char *orig, char *name, char *value,
* error. The caller is responsible for freeing the returned string. */
static char * OVS_WARN_UNUSED_RESULT
learn_parse__(char *orig, char *arg, const struct ofputil_port_map *port_map,
+ const struct ofputil_table_map *table_map,
struct ofpbuf *ofpacts)
{
struct ofpact_learn *learn;
@@ -396,8 +397,10 @@ learn_parse__(char *orig, char *arg, const struct ofputil_port_map *port_map,
match_init_catchall(&match);
while (ofputil_parse_key_value(&arg, &name, &value)) {
if (!strcmp(name, "table")) {
- learn->table_id = atoi(value);
- if (learn->table_id == 255) {
+ if (!ofputil_table_from_string(value, table_map,
+ &learn->table_id)) {
+ return xasprintf("unknown table \"%s\"", value);
+ } else if (learn->table_id == 255) {
return xasprintf("%s: table id 255 not valid for `learn' "
"action", orig);
}
@@ -465,10 +468,11 @@ learn_parse__(char *orig, char *arg, const struct ofputil_port_map *port_map,
* Modifies 'arg'. */
char * OVS_WARN_UNUSED_RESULT
learn_parse(char *arg, const struct ofputil_port_map *port_map,
+ const struct ofputil_table_map *table_map,
struct ofpbuf *ofpacts)
{
char *orig = xstrdup(arg);
- char *error = learn_parse__(orig, arg, port_map, ofpacts);
+ char *error = learn_parse__(orig, arg, port_map, table_map, ofpacts);
free(orig);
return error;
}
@@ -477,16 +481,18 @@ learn_parse(char *arg, const struct ofputil_port_map *port_map,
* describes. */
void
learn_format(const struct ofpact_learn *learn,
- const struct ofputil_port_map *port_map, struct ds *s)
+ const struct ofputil_port_map *port_map,
+ const struct ofputil_table_map *table_map,
+ struct ds *s)
{
const struct ofpact_learn_spec *spec;
struct match match;
match_init_catchall(&match);
- ds_put_format(s, "%slearn(%s%stable=%s%"PRIu8,
- colors.learn, colors.end, colors.special, colors.end,
- learn->table_id);
+ ds_put_format(s, "%slearn(%s%stable=%s",
+ colors.learn, colors.end, colors.special, colors.end);
+ ofputil_format_table(learn->table_id, table_map, s);
if (learn->idle_timeout != OFP_FLOW_PERMANENT) {
ds_put_format(s, ",%sidle_timeout=%s%"PRIu16,
colors.param, colors.end, learn->idle_timeout);