--- /dev/null
+/* Copyright (c) 2009 The Board of Trustees of The Leland Stanford Junior
+ * University
+ *
+ * We are making the OpenFlow specification and associated documentation
+ * (Software) available for public use and benefit with the expectation
+ * that others will use, modify and enhance the Software and contribute
+ * those enhancements back to the community. However, since we would
+ * like to make the Software available for broadest use, with as few
+ * restrictions as possible permission is hereby granted, free of
+ * charge, to any person obtaining a copy of this Software to deal in
+ * the Software under the copyrights without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * The name and trademarks of copyright holder(s) may NOT be used in
+ * advertising or publicity pertaining to the Software or any
+ * derivatives without specific, written prior permission.
+ */
+
+#include <config.h>
+#include "odp-util.h"
+#include <stdlib.h>
+#include <string.h>
+#include "util.h"
+
+void
+odp_actions_init(struct odp_actions *actions)
+{
+ actions->actions = NULL;
+ actions->n_actions = 0;
+ actions->allocated_actions = 0;
+}
+
+void
+odp_actions_free(struct odp_actions *actions)
+{
+ free(actions->actions);
+}
+
+union odp_action *
+odp_actions_add(struct odp_actions *actions, uint16_t type)
+{
+ union odp_action *a;
+ if (actions->n_actions >= actions->allocated_actions) {
+ actions->actions = x2nrealloc(actions->actions,
+ &actions->allocated_actions,
+ sizeof *actions->actions);
+ }
+ a = &actions->actions[actions->n_actions++];
+ memset(a, 0, sizeof *a);
+ a->type = type;
+ return a;
+}
+
--- /dev/null
+/* Copyright (c) 2009 The Board of Trustees of The Leland Stanford Junior
+ * University
+ *
+ * We are making the OpenFlow specification and associated documentation
+ * (Software) available for public use and benefit with the expectation
+ * that others will use, modify and enhance the Software and contribute
+ * those enhancements back to the community. However, since we would
+ * like to make the Software available for broadest use, with as few
+ * restrictions as possible permission is hereby granted, free of
+ * charge, to any person obtaining a copy of this Software to deal in
+ * the Software under the copyrights without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * The name and trademarks of copyright holder(s) may NOT be used in
+ * advertising or publicity pertaining to the Software or any
+ * derivatives without specific, written prior permission.
+ */
+
+#ifndef ODP_UTIL_H
+#define ODP_UTIL_H 1
+
+#include <stdint.h>
+#include "openflow/datapath-protocol.h"
+#include "openflow/openflow.h"
+
+struct odp_actions {
+ union odp_action *actions;
+ size_t n_actions, allocated_actions;
+};
+
+void odp_actions_init(struct odp_actions *);
+void odp_actions_free(struct odp_actions *);
+union odp_action *odp_actions_add(struct odp_actions *, uint16_t type);
+
+static inline uint16_t
+ofp_port_to_odp_port(uint16_t ofp_port)
+{
+ switch (ofp_port) {
+ case OFPP_LOCAL:
+ return ODPP_LOCAL;
+ case OFPP_NONE:
+ return ODPP_NONE;
+ default:
+ return ofp_port;
+ }
+}
+
+static inline uint16_t
+odp_port_to_ofp_port(uint16_t odp_port)
+{
+ switch (odp_port) {
+ case ODPP_LOCAL:
+ return OFPP_LOCAL;
+ case ODPP_NONE:
+ return OFPP_NONE;
+ default:
+ return odp_port;
+ }
+}
+
+#endif /* odp-util.h */
#include "in-band.h"
#include "netdev.h"
#include "netflow.h"
+#include "odp-util.h"
#include "ofp-print.h"
#include "ofpbuf.h"
#include "openflow/datapath-protocol.h"
static void ofport_free(struct ofport *);
static void hton_ofp_phy_port(struct ofp_phy_port *);
-struct odp_actions {
- union odp_action *actions;
- size_t n_actions, allocated_actions;
-};
-
-static void init_actions(struct odp_actions *);
-static void free_actions(struct odp_actions *);
static void xlate_actions(const union ofp_action *in, size_t n_in,
const flow_t *flow, struct ofproto *ofproto,
struct odp_actions *out);
xlate_actions(actions, n_actions, flow, p, &odp_actions);
error = dpif_execute(&p->dpif, flow->in_port, odp_actions.actions,
odp_actions.n_actions, packet);
- free_actions(&odp_actions);
+ odp_actions_free(&odp_actions);
return error;
}
odp_flow.actions = odp_actions.actions;
odp_flow.n_actions = odp_actions.n_actions;
dpif_flow_add(&p->dpif, &odp_flow);
- free_actions(&odp_actions);
+ odp_actions_free(&odp_actions);
}
\f
static void
return 0;
}
-static uint16_t
-ofp_port_to_odp_port(uint16_t ofp_port)
-{
- switch (ofp_port) {
- case OFPP_LOCAL:
- return ODPP_LOCAL;
- case OFPP_NONE:
- return ODPP_NONE;
- default:
- return ofp_port;
- }
-}
-
-static uint16_t
-odp_port_to_ofp_port(uint16_t odp_port)
-{
- switch (odp_port) {
- case ODPP_LOCAL:
- return OFPP_LOCAL;
- case ODPP_NONE:
- return OFPP_NONE;
- default:
- return odp_port;
- }
-}
-
-static void
-init_actions(struct odp_actions *actions)
-{
- actions->actions = NULL;
- actions->n_actions = 0;
- actions->allocated_actions = 0;
-}
-
-static void
-free_actions(struct odp_actions *actions)
-{
- free(actions->actions);
-}
-
-static union odp_action *
-add_action(struct odp_actions *actions, uint16_t type)
-{
- union odp_action *a;
- if (actions->n_actions >= actions->allocated_actions) {
- actions->actions = x2nrealloc(actions->actions,
- &actions->allocated_actions,
- sizeof *actions->actions);
- }
- a = &actions->actions[actions->n_actions++];
- memset(a, 0, sizeof *a);
- a->type = type;
- return a;
-}
-
static void
add_output_action(struct odp_actions *actions, uint16_t port)
{
- add_action(actions, ODPAT_OUTPUT)->output.port = port;
+ odp_actions_add(actions, ODPAT_OUTPUT)->output.port = port;
}
static void
add_output_group_action(struct odp_actions *actions, uint16_t group)
{
- add_action(actions, ODPAT_OUTPUT_GROUP)->output_group.group = group;
+ odp_actions_add(actions, ODPAT_OUTPUT_GROUP)->output_group.group = group;
}
static void
add_controller_action(struct odp_actions *actions,
const struct ofp_action_output *oao)
{
- union odp_action *a = add_action(actions, ODPAT_CONTROLLER);
+ union odp_action *a = odp_actions_add(actions, ODPAT_CONTROLLER);
a->controller.arg = oao->max_len ? ntohs(oao->max_len) : UINT32_MAX;
}
switch (subtype) {
case NXAST_SNAT:
nas = (const struct nx_action_snat *) nah;
- oa = add_action(ctx->out, ODPAT_SNAT);
+ oa = odp_actions_add(ctx->out, ODPAT_SNAT);
oa->snat.port = ntohs(nas->port);
break;
break;
case OFPAT_SET_VLAN_VID:
- oa = add_action(ctx->out, ODPAT_SET_VLAN_VID);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_VLAN_VID);
oa->vlan_vid.vlan_vid = ia->vlan_vid.vlan_vid;
break;
case OFPAT_SET_VLAN_PCP:
- oa = add_action(ctx->out, ODPAT_SET_VLAN_PCP);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_VLAN_PCP);
oa->vlan_pcp.vlan_pcp = ia->vlan_pcp.vlan_pcp;
break;
case OFPAT_STRIP_VLAN:
- add_action(ctx->out, ODPAT_STRIP_VLAN);
+ odp_actions_add(ctx->out, ODPAT_STRIP_VLAN);
break;
case OFPAT_SET_DL_SRC:
- oa = add_action(ctx->out, ODPAT_SET_DL_SRC);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_DL_SRC);
memcpy(oa->dl_addr.dl_addr,
((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
break;
case OFPAT_SET_DL_DST:
- oa = add_action(ctx->out, ODPAT_SET_DL_DST);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_DL_DST);
memcpy(oa->dl_addr.dl_addr,
((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
break;
case OFPAT_SET_NW_SRC:
- oa = add_action(ctx->out, ODPAT_SET_NW_SRC);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_NW_SRC);
oa->nw_addr.nw_addr = ia->nw_addr.nw_addr;
break;
case OFPAT_SET_TP_SRC:
- oa = add_action(ctx->out, ODPAT_SET_TP_SRC);
+ oa = odp_actions_add(ctx->out, ODPAT_SET_TP_SRC);
oa->tp_port.tp_port = ia->tp_port.tp_port;
break;
struct odp_actions *out)
{
struct action_xlate_ctx ctx;
- init_actions(out);
+ odp_actions_init(out);
ctx.in = in;
ctx.n_in = n_in;
ctx.flow = flow;
p, &actions);
dpif_execute(&p->dpif, flow.in_port, actions.actions, actions.n_actions,
&payload);
- free_actions(&actions);
+ odp_actions_free(&actions);
ofpbuf_delete(buffer);
return 0;
if (!error) {
*byte_count = packet->size;
}
- free_actions(&actions);
+ odp_actions_free(&actions);
ofpbuf_delete(packet);
return 0;
}
rule_destroy(displaced_rule);
}
- free_actions(&actions);
+ odp_actions_free(&actions);
}
return buffer_error;
}
odp_flow.actions = actions.actions;
odp_flow.n_actions = actions.n_actions;
dpif_flow_add(&p->dpif, &odp_flow);
- free_actions(&actions);
+ odp_actions_free(&actions);
update_stats(rule, &odp_flow.stats);
}
rule_make_actions(p, old_sr, &actions);
dpif_execute(&p->dpif, msg->port,
actions.actions, actions.n_actions, &payload);
- free_actions(&actions);
+ odp_actions_free(&actions);
ofpbuf_delete(packet);
return;
} else {
/* Execute subrule on packet. */
dpif_execute(&p->dpif, msg->port, actions.actions, actions.n_actions,
&payload);
- free_actions(&actions);
+ odp_actions_free(&actions);
ofpbuf_delete(packet);
}
\f
rule_make_actions(p, sub, &actions);
dpif_flow_set_actions(&p->dpif, flow, actions.actions,
actions.n_actions);
- free_actions(&actions);
+ odp_actions_free(&actions);
}
}
return true;