2011-09-12 16:19:57 -07:00
|
|
|
/*
|
2016-03-03 10:20:46 -08:00
|
|
|
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
|
2011-09-12 16:19:57 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "learn.h"
|
|
|
|
|
|
|
|
#include "byte-order.h"
|
2016-03-02 15:56:20 +01:00
|
|
|
#include "colors.h"
|
2016-03-03 10:20:46 -08:00
|
|
|
#include "openvswitch/dynamic-string.h"
|
2016-04-04 21:32:06 -04:00
|
|
|
#include "openvswitch/match.h"
|
2016-04-04 21:32:07 -04:00
|
|
|
#include "openvswitch/meta-flow.h"
|
2011-09-12 16:19:57 -07:00
|
|
|
#include "nx-match.h"
|
2012-07-03 22:17:14 -07:00
|
|
|
#include "ofp-actions.h"
|
2016-04-04 21:32:09 -04:00
|
|
|
#include "openvswitch/ofp-util.h"
|
2016-03-25 14:10:24 -07:00
|
|
|
#include "openvswitch/ofpbuf.h"
|
2011-09-12 16:19:57 -07:00
|
|
|
#include "openflow/openflow.h"
|
2016-03-03 10:20:43 -08:00
|
|
|
#include "openvswitch/ofp-errors.h"
|
2011-09-12 16:19:57 -07:00
|
|
|
#include "unaligned.h"
|
|
|
|
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Checks that 'learn' is a valid action on 'flow'. Returns 0 if it is valid,
|
|
|
|
* otherwise an OFPERR_*. */
|
|
|
|
enum ofperr
|
|
|
|
learn_check(const struct ofpact_learn *learn, const struct flow *flow)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
const struct ofpact_learn_spec *spec;
|
2012-08-07 15:28:18 -07:00
|
|
|
struct match match;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_catchall(&match);
|
2012-07-03 22:17:14 -07:00
|
|
|
for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) {
|
|
|
|
enum ofperr error;
|
2012-04-11 17:08:13 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Check the source. */
|
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
|
|
|
error = mf_check_src(&spec->src, flow);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Check the destination. */
|
|
|
|
switch (spec->dst_type) {
|
2011-09-12 16:19:57 -07:00
|
|
|
case NX_LEARN_DST_MATCH:
|
2012-08-07 15:28:18 -07:00
|
|
|
error = mf_check_src(&spec->dst, &match.flow);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
mf_write_subfield(&spec->dst, &spec->src_imm, &match);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_LOAD:
|
2012-08-07 15:28:18 -07:00
|
|
|
error = mf_check_dst(&spec->dst, &match.flow);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
2012-04-11 17:08:13 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_OUTPUT:
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Nothing to do. */
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
return 0;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Composes 'fm' so that executing it will implement 'learn' given that the
|
|
|
|
* packet being processed has 'flow' as its flow.
|
|
|
|
*
|
|
|
|
* Uses 'ofpacts' to store the flow mod's actions. The caller must initialize
|
|
|
|
* 'ofpacts' and retains ownership of it. 'fm->ofpacts' will point into the
|
|
|
|
* 'ofpacts' buffer.
|
|
|
|
*
|
|
|
|
* The caller has to actually execute 'fm'. */
|
|
|
|
void
|
|
|
|
learn_execute(const struct ofpact_learn *learn, const struct flow *flow,
|
|
|
|
struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
|
|
|
|
{
|
|
|
|
const struct ofpact_learn_spec *spec;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_catchall(&fm->match);
|
|
|
|
fm->priority = learn->priority;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->cookie = htonll(0);
|
|
|
|
fm->cookie_mask = htonll(0);
|
2014-06-05 15:27:31 -07:00
|
|
|
fm->new_cookie = learn->cookie;
|
2013-06-27 15:27:15 -07:00
|
|
|
fm->modify_cookie = fm->new_cookie != OVS_BE64_MAX;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->table_id = learn->table_id;
|
|
|
|
fm->command = OFPFC_MODIFY_STRICT;
|
|
|
|
fm->idle_timeout = learn->idle_timeout;
|
|
|
|
fm->hard_timeout = learn->hard_timeout;
|
2014-11-07 18:18:48 +05:30
|
|
|
fm->importance = 0;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->buffer_id = UINT32_MAX;
|
|
|
|
fm->out_port = OFPP_NONE;
|
2014-06-05 21:53:34 -07:00
|
|
|
fm->flags = 0;
|
|
|
|
if (learn->flags & NX_LEARN_F_SEND_FLOW_REM) {
|
|
|
|
fm->flags |= OFPUTIL_FF_SEND_FLOW_REM;
|
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->ofpacts = NULL;
|
|
|
|
fm->ofpacts_len = 0;
|
2014-05-30 17:14:14 +09:00
|
|
|
fm->delete_reason = OFPRR_DELETE;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->fin_idle_timeout || learn->fin_hard_timeout) {
|
|
|
|
struct ofpact_fin_timeout *oft;
|
|
|
|
|
|
|
|
oft = ofpact_put_FIN_TIMEOUT(ofpacts);
|
|
|
|
oft->fin_idle_timeout = learn->fin_idle_timeout;
|
|
|
|
oft->fin_hard_timeout = learn->fin_hard_timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) {
|
2014-10-07 16:49:50 -07:00
|
|
|
struct ofpact_set_field *sf;
|
2012-07-03 22:17:14 -07:00
|
|
|
union mf_subvalue value;
|
|
|
|
|
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
|
|
|
mf_read_subfield(&spec->src, flow, &value);
|
|
|
|
} else {
|
|
|
|
value = spec->src_imm;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (spec->dst_type) {
|
|
|
|
case NX_LEARN_DST_MATCH:
|
2012-08-07 15:28:18 -07:00
|
|
|
mf_write_subfield(&spec->dst, &value, &fm->match);
|
2012-07-03 22:17:14 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_LOAD:
|
2014-10-07 16:49:50 -07:00
|
|
|
sf = ofpact_put_reg_load(ofpacts);
|
|
|
|
sf->field = spec->dst.field;
|
|
|
|
bitwise_copy(&value, sizeof value, 0,
|
|
|
|
&sf->value, spec->dst.field->n_bytes, spec->dst.ofs,
|
|
|
|
spec->n_bits);
|
|
|
|
bitwise_one(&sf->mask, spec->dst.field->n_bytes, spec->dst.ofs,
|
|
|
|
spec->n_bits);
|
2012-07-03 22:17:14 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_OUTPUT:
|
|
|
|
if (spec->n_bits <= 16
|
|
|
|
|| is_all_zeros(value.u8, sizeof value - 2)) {
|
2015-02-25 09:33:54 -08:00
|
|
|
ofp_port_t port = u16_to_ofp(ntohll(value.integer));
|
2012-07-03 22:17:14 -07:00
|
|
|
|
2013-06-19 16:58:44 -07:00
|
|
|
if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)
|
2012-07-03 22:17:14 -07:00
|
|
|
|| port == OFPP_IN_PORT
|
|
|
|
|| port == OFPP_FLOOD
|
|
|
|
|| port == OFPP_LOCAL
|
|
|
|
|| port == OFPP_ALL) {
|
|
|
|
ofpact_put_OUTPUT(ofpacts)->port = port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 17:29:44 -08:00
|
|
|
fm->ofpacts = ofpacts->data;
|
|
|
|
fm->ofpacts_len = ofpacts->size;
|
2012-07-03 22:17:14 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2013-05-14 18:24:43 -07:00
|
|
|
/* Perform a bitwise-OR on 'wc''s fields that are relevant as sources in
|
|
|
|
* the learn action 'learn'. */
|
|
|
|
void
|
|
|
|
learn_mask(const struct ofpact_learn *learn, struct flow_wildcards *wc)
|
|
|
|
{
|
|
|
|
const struct ofpact_learn_spec *spec;
|
|
|
|
union mf_subvalue value;
|
|
|
|
|
|
|
|
memset(&value, 0xff, sizeof value);
|
|
|
|
for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) {
|
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
|
|
|
mf_write_subfield_flow(&spec->src, &value, &wc->masks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
2012-07-03 22:17:14 -07:00
|
|
|
learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec)
|
2012-04-13 21:24:17 -07:00
|
|
|
{
|
|
|
|
const char *full_s = s;
|
|
|
|
struct mf_subfield dst;
|
|
|
|
union mf_subvalue imm;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
2015-05-20 18:47:21 -07:00
|
|
|
int err;
|
2012-04-13 21:24:17 -07:00
|
|
|
|
2015-05-20 18:47:21 -07:00
|
|
|
err = parse_int_string(s, imm.u8, sizeof imm.u8, (char **) &s);
|
|
|
|
if (err) {
|
2015-05-29 15:15:01 -07:00
|
|
|
return xasprintf("%s: too many bits in immediate value", full_s);
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(s, "->", 2)) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: missing `->' following value", full_s);
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
s += 2;
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
error = mf_parse_subfield(&dst, s);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
ofp-actions: Support experimenter OXMs in Nicira extensions.
Some of the Nicira extension actions include fixed-size 32-bit members that
designate NXM fields. These actions can't accommodate 64-bit experimenter
OXMs, so we need to figure out some kind of solution. This commit does
that, in different ways for different actions.
For some actions, I did not think it was worthwhile to worry about
experimenter OXM, so I just disabled use of them. This is what I did for
bundle, learn, and multipath actions.
Other actions could be gracefully reinterpreted to support experimenter
OXM. This is true of reg_move, which use NXM headers only at the end of
the action and such that using an experimenter OXM would make the action
longer (which unambigously signals to older OVS that the action is an
error, which is desired behavior since older OVS cannot interpret this
action). The stack push and pop actions are also in this category.
reg_load was the most frustrating case. In OpenFlow 1.5 we had already
eliminated this action in favor of OF1.5+ set_field. In other OpenFlow
versions, though, reg_load is more powerful than set_field because it
can modify partial fields. This commit therefore adds a new variant of
reg_load, called reg_load2, which is simply OF1.5+ set_field with a Nicira
extension header on it.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-09-11 22:09:03 -07:00
|
|
|
if (!mf_nxm_header(dst.field->id)) {
|
|
|
|
return xasprintf("%s: experimenter OXM field '%s' not supported",
|
|
|
|
full_s, s);
|
|
|
|
}
|
2012-04-13 21:24:17 -07:00
|
|
|
|
|
|
|
if (!bitwise_is_all_zeros(&imm, sizeof imm, dst.n_bits,
|
|
|
|
(8 * sizeof imm) - dst.n_bits)) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: value does not fit into %u bits",
|
|
|
|
full_s, dst.n_bits);
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->n_bits = dst.n_bits;
|
|
|
|
spec->src_type = NX_LEARN_SRC_IMMEDIATE;
|
|
|
|
spec->src_imm = imm;
|
|
|
|
spec->dst_type = NX_LEARN_DST_LOAD;
|
|
|
|
spec->dst = dst;
|
2013-07-08 10:15:00 -07:00
|
|
|
return NULL;
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
2011-09-12 16:19:57 -07:00
|
|
|
learn_parse_spec(const char *orig, char *name, char *value,
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_learn_spec *spec)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
|
|
|
if (mf_from_name(name)) {
|
|
|
|
const struct mf_field *dst = mf_from_name(name);
|
|
|
|
union mf_value imm;
|
|
|
|
char *error;
|
|
|
|
|
|
|
|
error = mf_parse_value(dst, value, &imm);
|
|
|
|
if (error) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->n_bits = dst->n_bits;
|
|
|
|
spec->src_type = NX_LEARN_SRC_IMMEDIATE;
|
2012-04-13 21:24:17 -07:00
|
|
|
memset(&spec->src_imm, 0, sizeof spec->src_imm);
|
|
|
|
memcpy(&spec->src_imm.u8[sizeof spec->src_imm - dst->n_bytes],
|
|
|
|
&imm, dst->n_bytes);
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->dst_type = NX_LEARN_DST_MATCH;
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->dst.field = dst;
|
|
|
|
spec->dst.ofs = 0;
|
|
|
|
spec->dst.n_bits = dst->n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (strchr(name, '[')) {
|
|
|
|
/* Parse destination and check prerequisites. */
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
|
|
|
|
|
|
|
error = mf_parse_subfield(&spec->dst, name);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
ofp-actions: Support experimenter OXMs in Nicira extensions.
Some of the Nicira extension actions include fixed-size 32-bit members that
designate NXM fields. These actions can't accommodate 64-bit experimenter
OXMs, so we need to figure out some kind of solution. This commit does
that, in different ways for different actions.
For some actions, I did not think it was worthwhile to worry about
experimenter OXM, so I just disabled use of them. This is what I did for
bundle, learn, and multipath actions.
Other actions could be gracefully reinterpreted to support experimenter
OXM. This is true of reg_move, which use NXM headers only at the end of
the action and such that using an experimenter OXM would make the action
longer (which unambigously signals to older OVS that the action is an
error, which is desired behavior since older OVS cannot interpret this
action). The stack push and pop actions are also in this category.
reg_load was the most frustrating case. In OpenFlow 1.5 we had already
eliminated this action in favor of OF1.5+ set_field. In other OpenFlow
versions, though, reg_load is more powerful than set_field because it
can modify partial fields. This commit therefore adds a new variant of
reg_load, called reg_load2, which is simply OF1.5+ set_field with a Nicira
extension header on it.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-09-11 22:09:03 -07:00
|
|
|
if (!mf_nxm_header(spec->dst.field->id)) {
|
|
|
|
return xasprintf("%s: experimenter OXM field '%s' not supported",
|
|
|
|
orig, name);
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
|
|
|
/* Parse source and check prerequisites. */
|
|
|
|
if (value[0] != '\0') {
|
2013-07-08 10:15:00 -07:00
|
|
|
error = mf_parse_subfield(&spec->src, value);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2011-12-28 12:42:14 -08:00
|
|
|
if (spec->src.n_bits != spec->dst.n_bits) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: bit widths of %s (%u) and %s (%u) "
|
|
|
|
"differ", orig, name, spec->src.n_bits, value,
|
|
|
|
spec->dst.n_bits);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->src = spec->dst;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->n_bits = spec->src.n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
|
|
|
spec->dst_type = NX_LEARN_DST_MATCH;
|
|
|
|
} else if (!strcmp(name, "load")) {
|
|
|
|
if (value[strcspn(value, "[-")] == '-') {
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error = learn_parse_load_immediate(value, spec);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_reg_move move;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
error = nxm_parse_reg_move(&move, value);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->n_bits = move.src.n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->src = move.src;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->dst_type = NX_LEARN_DST_LOAD;
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->dst = move.dst;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "output")) {
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error = mf_parse_subfield(&spec->src, value);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->n_bits = spec->src.n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
|
|
|
spec->dst_type = NX_LEARN_DST_OUTPUT;
|
|
|
|
} else {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: unknown keyword %s", orig, name);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
|
|
|
return NULL;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
learn_parse__(char *orig, char *arg, struct ofpbuf *ofpacts)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_learn *learn;
|
2012-08-07 15:28:18 -07:00
|
|
|
struct match match;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *name, *value;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
learn = ofpact_put_LEARN(ofpacts);
|
|
|
|
learn->idle_timeout = OFP_FLOW_PERMANENT;
|
|
|
|
learn->hard_timeout = OFP_FLOW_PERMANENT;
|
|
|
|
learn->priority = OFP_DEFAULT_PRIORITY;
|
2011-09-12 16:19:57 -07:00
|
|
|
learn->table_id = 1;
|
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_catchall(&match);
|
2011-09-12 16:19:57 -07:00
|
|
|
while (ofputil_parse_key_value(&arg, &name, &value)) {
|
|
|
|
if (!strcmp(name, "table")) {
|
|
|
|
learn->table_id = atoi(value);
|
|
|
|
if (learn->table_id == 255) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: table id 255 not valid for `learn' "
|
|
|
|
"action", orig);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "priority")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->priority = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "idle_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->idle_timeout = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "hard_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->hard_timeout = atoi(value);
|
2012-02-15 10:37:03 -08:00
|
|
|
} else if (!strcmp(name, "fin_idle_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->fin_idle_timeout = atoi(value);
|
2012-02-15 10:37:03 -08:00
|
|
|
} else if (!strcmp(name, "fin_hard_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->fin_hard_timeout = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "cookie")) {
|
2014-06-05 15:27:31 -07:00
|
|
|
learn->cookie = htonll(strtoull(value, NULL, 0));
|
2014-06-05 21:37:04 -07:00
|
|
|
} else if (!strcmp(name, "send_flow_rem")) {
|
2014-06-05 21:53:34 -07:00
|
|
|
learn->flags |= NX_LEARN_F_SEND_FLOW_REM;
|
|
|
|
} else if (!strcmp(name, "delete_learned")) {
|
|
|
|
learn->flags |= NX_LEARN_F_DELETE_LEARNED;
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_learn_spec *spec;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
2012-07-03 22:17:14 -07:00
|
|
|
|
|
|
|
spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
|
2015-03-02 17:29:44 -08:00
|
|
|
learn = ofpacts->header;
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->n_specs++;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
error = learn_parse_spec(orig, name, value, spec);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
/* Update 'match' to allow for satisfying destination
|
2011-09-12 16:19:57 -07:00
|
|
|
* prerequisites. */
|
2012-07-03 22:17:14 -07:00
|
|
|
if (spec->src_type == NX_LEARN_SRC_IMMEDIATE
|
|
|
|
&& spec->dst_type == NX_LEARN_DST_MATCH) {
|
2012-08-07 15:28:18 -07:00
|
|
|
mf_write_subfield(&spec->dst, &spec->src_imm, &match);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 22:00:25 -07:00
|
|
|
ofpact_finish_LEARN(ofpacts, &learn);
|
2011-09-27 13:12:04 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parses 'arg' as a set of arguments to the "learn" action and appends a
|
|
|
|
* matching OFPACT_LEARN action to 'ofpacts'. ovs-ofctl(8) describes the
|
|
|
|
* format parsed.
|
|
|
|
*
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string.
|
|
|
|
*
|
|
|
|
* If 'flow' is nonnull, then it should be the flow from a struct match that is
|
|
|
|
* the matching rule for the learning action. This helps to better validate
|
|
|
|
* the action's arguments.
|
|
|
|
*
|
|
|
|
* Modifies 'arg'. */
|
2014-12-15 14:10:38 +01:00
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
learn_parse(char *arg, struct ofpbuf *ofpacts)
|
|
|
|
{
|
|
|
|
char *orig = xstrdup(arg);
|
|
|
|
char *error = learn_parse__(orig, arg, ofpacts);
|
2011-09-27 13:12:04 -07:00
|
|
|
free(orig);
|
2013-07-08 10:15:00 -07:00
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Appends a description of 'learn' to 's', in the format that ovs-ofctl(8)
|
|
|
|
* describes. */
|
2011-09-12 16:19:57 -07:00
|
|
|
void
|
2012-07-03 22:17:14 -07:00
|
|
|
learn_format(const struct ofpact_learn *learn, struct ds *s)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
const struct ofpact_learn_spec *spec;
|
2012-08-07 15:28:18 -07:00
|
|
|
struct match match;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_catchall(&match);
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%slearn(%s%stable=%s%"PRIu8,
|
|
|
|
colors.learn, colors.end, colors.special, colors.end,
|
|
|
|
learn->table_id);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->idle_timeout != OFP_FLOW_PERMANENT) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sidle_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->idle_timeout);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->hard_timeout != OFP_FLOW_PERMANENT) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%shard_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->hard_timeout);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2012-02-15 10:37:03 -08:00
|
|
|
if (learn->fin_idle_timeout) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sfin_idle_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->fin_idle_timeout);
|
2012-02-15 10:37:03 -08:00
|
|
|
}
|
|
|
|
if (learn->fin_hard_timeout) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s,fin_hard_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->fin_hard_timeout);
|
2012-02-15 10:37:03 -08:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->priority != OFP_DEFAULT_PRIORITY) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s,priority=%s%"PRIu16,
|
|
|
|
colors.special, colors.end, learn->priority);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2014-06-05 21:53:34 -07:00
|
|
|
if (learn->flags & NX_LEARN_F_SEND_FLOW_REM) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%ssend_flow_rem%s", colors.value, colors.end);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2014-06-05 21:53:34 -07:00
|
|
|
if (learn->flags & NX_LEARN_F_DELETE_LEARNED) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sdelete_learned%s", colors.value, colors.end);
|
2014-06-05 21:53:34 -07:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->cookie != 0) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%scookie=%s%#"PRIx64,
|
|
|
|
colors.param, colors.end, ntohll(learn->cookie));
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) {
|
2011-09-12 16:19:57 -07:00
|
|
|
ds_put_char(s, ',');
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
switch (spec->src_type | spec->dst_type) {
|
2011-09-12 16:19:57 -07:00
|
|
|
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_MATCH:
|
2012-07-03 22:17:14 -07:00
|
|
|
if (spec->dst.ofs == 0
|
|
|
|
&& spec->dst.n_bits == spec->dst.field->n_bits) {
|
2011-09-12 16:19:57 -07:00
|
|
|
union mf_value value;
|
2011-12-01 08:33:55 -08:00
|
|
|
|
2011-09-12 16:19:57 -07:00
|
|
|
memset(&value, 0, sizeof value);
|
2012-07-03 22:17:14 -07:00
|
|
|
bitwise_copy(&spec->src_imm, sizeof spec->src_imm, 0,
|
|
|
|
&value, spec->dst.field->n_bytes, 0,
|
|
|
|
spec->dst.field->n_bits);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s%s=%s", colors.param,
|
|
|
|
spec->dst.field->name, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format(spec->dst.field, &value, NULL, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.param);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "=%s", colors.end);
|
2012-09-12 17:44:28 +09:00
|
|
|
mf_format_subvalue(&spec->src_imm, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_MATCH:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.param);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (spec->src.field != spec->dst.field ||
|
|
|
|
spec->src.ofs != spec->dst.ofs) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s=%s", colors.param, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_LOAD:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%sload:%s", colors.special, colors.end);
|
2012-09-12 17:44:28 +09:00
|
|
|
mf_format_subvalue(&spec->src_imm, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s->%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_LOAD:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%sload:%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s->%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_OUTPUT:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%soutput:%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s)%s", colors.learn, colors.end);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|