From d8e649b0fb0ece8e5b69ef47f26511451d3723cd Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 21 Jul 2010 16:11:28 -0700 Subject: [PATCH] flow: Change function names to be less deceptive. Jesse pointed out that it's confusing that a function named flow_equal() doesn't compare all of the fields in the flow. Rename this function and a few others to have less surprising semantics. Suggested-by: Jesse Gross --- lib/classifier.c | 16 ++++++++-------- lib/flow.h | 14 +++++++------- ofproto/wdp-xflow.c | 2 +- tests/test-classifier.c | 7 +++---- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index 1aadfe5c1..7661ca348 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -249,7 +249,7 @@ void classifier_insert_exact(struct classifier *cls, struct cls_rule *rule) { hmap_insert(&cls->exact_table, &rule->node.hmap, - flow_hash(&rule->flow, 0)); + flow_hash_headers(&rule->flow, 0)); cls->n_rules++; } @@ -302,7 +302,7 @@ struct cls_rule * classifier_lookup_exact(const struct classifier *cls, const flow_t *flow) { return (!hmap_is_empty(&cls->exact_table) - ? search_exact_table(cls, flow_hash(flow, 0), flow) + ? search_exact_table(cls, flow_hash_headers(flow, 0), flow) : NULL); } @@ -335,7 +335,7 @@ classifier_find_rule_exactly(const struct classifier *cls, if (!target->wildcards) { /* Ignores 'priority'. */ - return search_exact_table(cls, flow_hash(target, 0), target); + return search_exact_table(cls, flow_hash_headers(target, 0), target); } assert(target->wildcards == (target->wildcards & OVSFW_ALL)); @@ -350,7 +350,7 @@ classifier_find_rule_exactly(const struct classifier *cls, return NULL; } else if (pos->flow.priority == target->priority && pos->flow.wildcards == target->wildcards && - flow_equal(target, &pos->flow)) { + flow_equal_headers(target, &pos->flow)) { return pos; } } @@ -369,7 +369,7 @@ classifier_rule_overlaps(const struct classifier *cls, const flow_t *target) const struct hmap *tbl; if (!target->wildcards) { - return search_exact_table(cls, flow_hash(target, 0), target) ? + return search_exact_table(cls, flow_hash_headers(target, 0), target) ? true : false; } @@ -458,7 +458,7 @@ classifier_for_each_match(const struct classifier *cls, } else { /* Optimization: there can be at most one match in the exact * table. */ - size_t hash = flow_hash(&target.flow, 0); + size_t hash = flow_hash_headers(&target.flow, 0); struct cls_rule *rule = search_exact_table(cls, hash, &target.flow); if (rule) { @@ -670,7 +670,7 @@ insert_exact_rule(struct classifier *cls, struct cls_rule *rule) struct cls_rule *old_rule; size_t hash; - hash = flow_hash(&rule->flow, 0); + hash = flow_hash_headers(&rule->flow, 0); old_rule = search_exact_table(cls, hash, &rule->flow); if (old_rule) { hmap_remove(&cls->exact_table, &old_rule->node.hmap); @@ -903,7 +903,7 @@ search_exact_table(const struct classifier *cls, size_t hash, HMAP_FOR_EACH_WITH_HASH (rule, struct cls_rule, node.hmap, hash, &cls->exact_table) { - if (flow_equal(&rule->flow, target)) { + if (flow_equal_headers(&rule->flow, target)) { return rule; } } diff --git a/lib/flow.h b/lib/flow.h index 2ccb2f2e4..b963afdd1 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -73,14 +73,14 @@ void flow_from_match(const struct ofp_match *, uint32_t priority, char *flow_to_string(const flow_t *); void flow_format(struct ds *, const flow_t *); void flow_print(FILE *, const flow_t *); -static inline int flow_compare(const flow_t *, const flow_t *); -static inline bool flow_equal(const flow_t *, const flow_t *); -static inline size_t flow_hash(const flow_t *, uint32_t basis); +static inline int flow_compare_headers(const flow_t *, const flow_t *); +static inline bool flow_equal_headers(const flow_t *, const flow_t *); +static inline size_t flow_hash_headers(const flow_t *, uint32_t basis); /* Compares members of 'a' and 'b' except for 'wildcards' and 'priority' and * returns a strcmp()-like return value. */ static inline int -flow_compare(const flow_t *a, const flow_t *b) +flow_compare_headers(const flow_t *a, const flow_t *b) { /* Assert that 'wildcards' and 'priority' are leading 32-bit fields. */ BUILD_ASSERT_DECL(offsetof(struct flow, wildcards) == 0); @@ -94,15 +94,15 @@ flow_compare(const flow_t *a, const flow_t *b) /* Returns true if all members of 'a' and 'b' are equal except for 'wildcards' * and 'priority', false otherwise. */ static inline bool -flow_equal(const flow_t *a, const flow_t *b) +flow_equal_headers(const flow_t *a, const flow_t *b) { - return !flow_compare(a, b); + return !flow_compare_headers(a, b); } /* Returns a hash value for 'flow' that does not include 'wildcards' or * 'priority', folding 'basis' into the hash value. */ static inline size_t -flow_hash(const flow_t *flow, uint32_t basis) +flow_hash_headers(const flow_t *flow, uint32_t basis) { /* Assert that 'wildcards' and 'priority' are leading 32-bit fields. */ BUILD_ASSERT_DECL(offsetof(struct flow, wildcards) == 0); diff --git a/ofproto/wdp-xflow.c b/ofproto/wdp-xflow.c index 4a78e16a2..d1e7c0cc8 100644 --- a/ofproto/wdp-xflow.c +++ b/ofproto/wdp-xflow.c @@ -412,7 +412,7 @@ wx_rule_execute(struct wx *wx, struct wx_rule *rule, * port simply because the xflow actions were composed for the wrong * scenario. */ if (rule->wr.cr.flow.wildcards - || !flow_equal(flow, &rule->wr.cr.flow)) + || !flow_equal_headers(flow, &rule->wr.cr.flow)) { struct wx_rule *super = rule->super ? rule->super : rule; if (wx_xlate_actions(wx, super->wr.actions, super->wr.n_actions, flow, diff --git a/tests/test-classifier.c b/tests/test-classifier.c index a2f681786..27fe97e19 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -111,9 +111,8 @@ tcls_insert(struct tcls *tcls, const struct test_rule *rule) const struct cls_rule *pos = &tcls->rules[i]->cls_rule; if (pos->flow.priority == priority && pos->flow.wildcards == rule->cls_rule.flow.wildcards - && flow_equal(&pos->flow, &rule->cls_rule.flow)) { - /* Exact match. - * XXX flow_equal should ignore wildcarded fields */ + && flow_equal_headers(&pos->flow, &rule->cls_rule.flow)) { + /* Exact match. */ free(tcls->rules[i]); tcls->rules[i] = xmemdup(rule, sizeof *rule); return tcls->rules[i]; @@ -396,7 +395,7 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) const struct test_rule *tr0 = test_rule_from_cls_rule(cr0); const struct test_rule *tr1 = test_rule_from_cls_rule(cr1); - assert(flow_equal(&cr0->flow, &cr1->flow)); + assert(flow_equal_headers(&cr0->flow, &cr1->flow)); assert(cr0->flow.wildcards == cr1->flow.wildcards); assert(cr0->flow.priority == cr1->flow.priority); /* Skip nw_src_mask, nw_dst_mask, and dl_tci_mask, because they -- 2.47.0