mirror of
https://github.com/openvswitch/ovs
synced 2025-10-19 14:37:21 +00:00
OpenFlow actions have always been somewhat awkward to handle. Moreover, over time we've started creating actions that require more complicated parsing. When we maintain those actions internally in their wire format, we end up parsing them multiple times, whenever we have to look at the set of actions. When we add support for OpenFlow 1.1 or later protocols, the situation will get worse, because these newer protocols support many of the same actions but with different representations. It becomes unrealistic to handle each protocol in its wire format. This commit adopts a new strategy, by converting OpenFlow actions into an internal form from the wire format when they are read, and converting them back to the wire format when flows are dumped. I believe that this will be more maintainable over time. Thanks to Simon Horman and Pravin Shelar for reviews. Signed-off-by: Ben Pfaff <blp@nicira.com>
106 lines
2.9 KiB
C
106 lines
2.9 KiB
C
/*
|
|
* Copyright (c) 2011, 2012 Nicira, Inc.
|
|
*
|
|
* 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 "autopath.h"
|
|
|
|
#include <inttypes.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "flow.h"
|
|
#include "meta-flow.h"
|
|
#include "nx-match.h"
|
|
#include "ofp-actions.h"
|
|
#include "ofp-errors.h"
|
|
#include "ofp-util.h"
|
|
#include "openflow/nicira-ext.h"
|
|
#include "vlog.h"
|
|
|
|
VLOG_DEFINE_THIS_MODULE(autopath);
|
|
|
|
void
|
|
autopath_parse(struct ofpact_autopath *ap, const char *s_)
|
|
{
|
|
char *s;
|
|
int id_int;
|
|
char *id_str, *dst, *save_ptr;
|
|
|
|
ofpact_init_AUTOPATH(ap);
|
|
|
|
s = xstrdup(s_);
|
|
save_ptr = NULL;
|
|
id_str = strtok_r(s, ", ", &save_ptr);
|
|
dst = strtok_r(NULL, ", ", &save_ptr);
|
|
|
|
if (!dst) {
|
|
ovs_fatal(0, "%s: not enough arguments to autopath action", s_);
|
|
}
|
|
|
|
id_int = atoi(id_str);
|
|
if (id_int < 1 || id_int > UINT32_MAX) {
|
|
ovs_fatal(0, "%s: autopath id %d is not in valid range "
|
|
"1 to %"PRIu32, s_, id_int, UINT32_MAX);
|
|
}
|
|
ap->port = id_int;
|
|
|
|
mf_parse_subfield(&ap->dst, dst);
|
|
if (ap->dst.n_bits < 16) {
|
|
ovs_fatal(0, "%s: %d-bit destination field has %u possible values, "
|
|
"less than required 65536",
|
|
s_, ap->dst.n_bits, 1u << ap->dst.n_bits);
|
|
}
|
|
|
|
free(s);
|
|
}
|
|
|
|
enum ofperr
|
|
autopath_from_openflow(const struct nx_action_autopath *nap,
|
|
struct ofpact_autopath *autopath)
|
|
{
|
|
ofpact_init_AUTOPATH(autopath);
|
|
autopath->dst.field = mf_from_nxm_header(ntohl(nap->dst));
|
|
autopath->dst.ofs = nxm_decode_ofs(nap->ofs_nbits);
|
|
autopath->dst.n_bits = nxm_decode_n_bits(nap->ofs_nbits);
|
|
autopath->port = ntohl(nap->id);
|
|
|
|
if (autopath->dst.n_bits < 16) {
|
|
VLOG_WARN("at least 16 bit destination is required for autopath "
|
|
"action.");
|
|
return OFPERR_OFPBAC_BAD_ARGUMENT;
|
|
}
|
|
|
|
return autopath_check(autopath, NULL);
|
|
}
|
|
|
|
enum ofperr
|
|
autopath_check(const struct ofpact_autopath *autopath, const struct flow *flow)
|
|
{
|
|
return mf_check_dst(&autopath->dst, flow);
|
|
}
|
|
|
|
void
|
|
autopath_to_nxast(const struct ofpact_autopath *autopath,
|
|
struct ofpbuf *openflow)
|
|
{
|
|
struct nx_action_autopath *ap = ofputil_put_NXAST_AUTOPATH(openflow);
|
|
|
|
ap->ofs_nbits = nxm_encode_ofs_nbits(autopath->dst.ofs,
|
|
autopath->dst.n_bits);
|
|
ap->dst = htonl(autopath->dst.field->nxm_header);
|
|
ap->id = htonl(autopath->port);
|
|
}
|