summaryrefslogtreecommitdiff
path: root/ofproto
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-06-30 10:04:09 -0700
committerBen Pfaff <blp@nicira.com>2011-06-30 10:04:09 -0700
commitb4b8c7812bdfdc5a6fda4251453d8e3409486b98 (patch)
treedf0184912e82dd6897fa4f89cfc0028033a356f4 /ofproto
parent8f93e93c807d3acd06fb3b367276f574164b1a9c (diff)
downloadopenvswitch-b4b8c7812bdfdc5a6fda4251453d8e3409486b98.tar.gz
ofp-util: Simplify iteration through OpenFlow actions.
The existing actions_first() and actions_next() iterator functions are not much like the other iteration constructs found throughout the Open vSwitch tree. Also, they only work with actions that have already been validated, so there are cases where they cannot be used. This commit adds new macros for iterating through OpenFlow actions, one for actions that have been validated and one for actions that have not, and adapts the existing users. The following commit will further refine action parsing and add more users.
Diffstat (limited to 'ofproto')
-rw-r--r--ofproto/ofproto-dpif.c9
-rw-r--r--ofproto/ofproto.c10
2 files changed, 8 insertions, 11 deletions
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index c3ef8f757..5ce05d6e4 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -3115,8 +3115,8 @@ do_xlate_actions(const union ofp_action *in, size_t n_in,
struct action_xlate_ctx *ctx)
{
const struct ofport_dpif *port;
- struct actions_iterator iter;
const union ofp_action *ia;
+ size_t left;
port = get_ofp_port(ctx->ofproto, ctx->flow.in_port);
if (port
@@ -3128,9 +3128,9 @@ do_xlate_actions(const union ofp_action *in, size_t n_in,
return;
}
- for (ia = actions_first(&iter, in, n_in); ia; ia = actions_next(&iter)) {
- enum ofp_action_type type = ntohs(ia->type);
+ OFPUTIL_ACTION_FOR_EACH_UNSAFE (ia, left, in, n_in) {
const struct ofp_action_dl_addr *oada;
+ enum ofp_action_type type = ntohs(ia->type);
switch (type) {
case OFPAT_OUTPUT:
@@ -3852,8 +3852,7 @@ trace_format_rule(struct ds *result, int level, const struct rule *rule)
ds_put_char_multiple(result, '\t', level);
ds_put_cstr(result, "OpenFlow ");
- ofp_print_actions(result, (const struct ofp_action_header *) rule->actions,
- rule->n_actions * sizeof *rule->actions);
+ ofp_print_actions(result, rule->actions, rule->n_actions);
ds_put_char(result, '\n');
}
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 64adef669..efa3686e0 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1398,13 +1398,12 @@ static bool
rule_has_out_port(const struct rule *rule, uint16_t out_port)
{
const union ofp_action *oa;
- struct actions_iterator i;
+ size_t left;
if (out_port == OFPP_NONE) {
return true;
}
- for (oa = actions_first(&i, rule->actions, rule->n_actions); oa;
- oa = actions_next(&i)) {
+ OFPUTIL_ACTION_FOR_EACH_UNSAFE (oa, left, rule->actions, rule->n_actions) {
if (action_outputs_to_port(oa, htons(out_port))) {
return true;
}
@@ -1921,7 +1920,6 @@ static void
flow_stats_ds(struct rule *rule, struct ds *results)
{
uint64_t packet_count, byte_count;
- size_t act_len = sizeof *rule->actions * rule->n_actions;
rule->ofproto->ofproto_class->rule_get_stats(rule,
&packet_count, &byte_count);
@@ -1936,8 +1934,8 @@ flow_stats_ds(struct rule *rule, struct ds *results)
ds_put_format(results, "n_bytes=%"PRIu64", ", byte_count);
cls_rule_format(&rule->cr, results);
ds_put_char(results, ',');
- if (act_len > 0) {
- ofp_print_actions(results, &rule->actions->header, act_len);
+ if (rule->n_actions > 0) {
+ ofp_print_actions(results, rule->actions, rule->n_actions);
} else {
ds_put_cstr(results, "drop");
}