[ovs-dev] [flow monitor 10/11] ofproto: Refactor rule_has_out_port() in terms of new ofp-util function.
Ben Pfaff
blp at nicira.com
Sat Jun 30 05:40:24 UTC 2012
An upcoming commit will introduce a second user for the new function
actions_output_to_port().
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/ofp-util.c | 15 +++++++++++++++
lib/ofp-util.h | 3 +++
ofproto/ofproto.c | 15 +++------------
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index b749389..6db215c 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -4058,6 +4058,21 @@ action_outputs_to_port(const union ofp_action *action, ovs_be16 port)
}
}
+bool
+actions_output_to_port(const union ofp_action *actions, size_t n_actions,
+ ovs_be16 port)
+{
+ const union ofp_action *oa;
+ size_t left;
+
+ OFPUTIL_ACTION_FOR_EACH_UNSAFE (oa, left, actions, n_actions) {
+ if (action_outputs_to_port(oa, port)) {
+ return true;
+ }
+ }
+ return false;
+}
+
/* "Normalizes" the wildcards in 'rule'. That means:
*
* 1. If the type of level N is known, then only the valid fields for that
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 28ba031..d80e038 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -682,7 +682,10 @@ ofputil_action_is_valid(const union ofp_action *a, size_t n_actions)
enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
const struct flow *, int max_ports);
+
bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
+bool actions_output_to_port(const union ofp_action *, size_t n_actions,
+ ovs_be16 port);
enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
union ofp_action **, size_t *);
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 9f67fe0..d4408f5 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1886,18 +1886,9 @@ ofproto_rule_destroy(struct rule *rule)
static bool
rule_has_out_port(const struct rule *rule, uint16_t out_port)
{
- const union ofp_action *oa;
- size_t left;
-
- if (out_port == OFPP_NONE) {
- return true;
- }
- OFPUTIL_ACTION_FOR_EACH_UNSAFE (oa, left, rule->actions, rule->n_actions) {
- if (action_outputs_to_port(oa, htons(out_port))) {
- return true;
- }
- }
- return false;
+ return (out_port == OFPP_NONE
+ || actions_output_to_port(rule->actions, rule->n_actions,
+ htons(out_port)));
}
/* Executes the actions indicated by 'rule' on 'packet' and credits 'rule''s
--
1.7.2.5
More information about the dev
mailing list