[ovs-dev] [nxm 15/42] classifier: Change classifier_find_rule_exactly() to take a cls_rule *.
Ben Pfaff
blp at nicira.com
Thu Oct 28 17:27:46 UTC 2010
There's no benefit to spelling out all of the components of a cls_rule
separately. Just use cls_rule itself.
---
lib/classifier.c | 26 +++++++++++++-------------
lib/classifier.h | 4 +---
ofproto/ofproto.c | 22 +++++++++++-----------
3 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/lib/classifier.c b/lib/classifier.c
index 779c7e8..091e0ca 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -266,31 +266,31 @@ classifier_lookup(const struct classifier *cls, const struct flow *flow,
struct cls_rule *
classifier_find_rule_exactly(const struct classifier *cls,
- const struct flow *target, uint32_t wildcards,
- unsigned int priority)
+ const struct cls_rule *target)
{
struct cls_bucket *bucket;
int table_idx;
uint32_t hash;
- if (!wildcards) {
- /* Ignores 'priority'. */
- return search_exact_table(cls, flow_hash(target, 0), target);
+ if (!target->wc.wildcards) {
+ /* Ignores 'target->priority'. */
+ return search_exact_table(cls, flow_hash(&target->flow, 0),
+ &target->flow);
}
- assert(wildcards == (wildcards & OVSFW_ALL));
- table_idx = table_idx_from_wildcards(wildcards);
- hash = hash_fields(target, table_idx);
+ assert(target->wc.wildcards == (target->wc.wildcards & OVSFW_ALL));
+ table_idx = table_idx_from_wildcards(target->wc.wildcards);
+ hash = hash_fields(&target->flow, table_idx);
HMAP_FOR_EACH_WITH_HASH (bucket, hmap_node, hash,
&cls->tables[table_idx]) {
- if (equal_fields(&bucket->fixed, target, table_idx)) {
+ if (equal_fields(&bucket->fixed, &target->flow, table_idx)) {
struct cls_rule *pos;
LIST_FOR_EACH (pos, node.list, &bucket->rules) {
- if (pos->priority < priority) {
+ if (pos->priority < target->priority) {
return NULL;
- } else if (pos->priority == priority &&
- pos->wc.wildcards == wildcards &&
- flow_equal(target, &pos->flow)) {
+ } else if (pos->priority == target->priority &&
+ pos->wc.wildcards == target->wc.wildcards &&
+ flow_equal(&target->flow, &pos->flow)) {
return pos;
}
}
diff --git a/lib/classifier.h b/lib/classifier.h
index 28be247..46df77d 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -158,9 +158,7 @@ void classifier_for_each_match(const struct classifier *,
const struct cls_rule *,
int include, cls_cb_func *, void *aux);
struct cls_rule *classifier_find_rule_exactly(const struct classifier *,
- const struct flow *target,
- uint32_t wildcards,
- unsigned int priority);
+ const struct cls_rule *);
#define CLASSIFIER_FOR_EACH_EXACT_RULE(RULE, MEMBER, CLS) \
HMAP_FOR_EACH (RULE, MEMBER.node.hmap, &(CLS)->exact_table)
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 3a9c6db..c051b47 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1323,11 +1323,12 @@ void
ofproto_delete_flow(struct ofproto *ofproto, const struct flow *flow,
uint32_t wildcards, unsigned int priority)
{
+ struct cls_rule target;
struct rule *rule;
+ cls_rule_from_flow(flow, wildcards, priority, &target);
rule = rule_from_cls_rule(classifier_find_rule_exactly(&ofproto->cls,
- flow, wildcards,
- priority));
+ &target));
if (rule) {
rule_remove(ofproto, rule);
}
@@ -3654,14 +3655,11 @@ add_flow(struct ofproto *p, struct ofconn *ofconn,
static struct rule *
find_flow_strict(struct ofproto *p, const struct ofp_flow_mod *ofm)
{
- uint32_t wildcards;
- struct flow flow;
+ struct cls_rule target;
- flow_from_match(&ofm->match, p->tun_id_from_cookie, ofm->cookie,
- &flow, &wildcards);
- return rule_from_cls_rule(classifier_find_rule_exactly(
- &p->cls, &flow, wildcards,
- ntohs(ofm->priority)));
+ cls_rule_from_match(&ofm->match, ntohs(ofm->priority),
+ p->tun_id_from_cookie, ofm->cookie, &target);
+ return rule_from_cls_rule(classifier_find_rule_exactly(&p->cls, &target));
}
static int
@@ -4301,13 +4299,15 @@ ofproto_update_used(struct ofproto *p)
for (i = 0; i < n_flows; i++) {
struct odp_flow *f = &flows[i];
+ struct cls_rule target;
struct rule *rule;
struct flow flow;
odp_flow_key_to_flow(&f->key, &flow);
+ cls_rule_from_flow(&flow, 0, UINT16_MAX, &target);
- rule = rule_from_cls_rule(
- classifier_find_rule_exactly(&p->cls, &flow, 0, UINT16_MAX));
+ rule = rule_from_cls_rule(classifier_find_rule_exactly(&p->cls,
+ &target));
if (rule && rule->installed) {
update_time(p, rule, &f->stats);
--
1.7.1
More information about the dev
mailing list