classifier: Change classifier_find_rule_exactly() to take a cls_rule *.
authorBen Pfaff <blp@nicira.com>
Thu, 14 Oct 2010 20:25:36 +0000 (13:25 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Oct 2010 16:53:51 +0000 (09:53 -0700)
There's no benefit to spelling out all of the components of a cls_rule
separately.  Just use cls_rule itself.

lib/classifier.c
lib/classifier.h
ofproto/ofproto.c

index 779c7e88c5d1172d1b98992f585cb475a8e93842..091e0ca1fcb430d8e9181a5d55e8b293c4a4fdbf 100644 (file)
@@ -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;
                 }
             }
index 28be2471a7629d3e5edfc2df34b59c66c2a4edbe..46df77d7f60d1bb60868748d3a6dac0d3551a82c 100644 (file)
@@ -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)
index 727f39605198dc388bdb24ea720b0ed4af797a53..4d2172e55486348fda6dbfba65dd9c0c928b1692 100644 (file)
@@ -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);
     }
@@ -3652,14 +3653,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
@@ -4299,13 +4297,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);