Use new method to describe table entries in OpenFlow wire protocol.
[sliver-openvswitch.git] / switch / table-hash.c
index 9b63290..46060a2 100644 (file)
@@ -52,7 +52,8 @@ static struct sw_flow **find_bucket(struct sw_table *swt,
                                     const struct sw_flow_key *key)
 {
     struct sw_table_hash *th = (struct sw_table_hash *) swt;
-    unsigned int crc = crc32_calculate(&th->crc32, key, sizeof *key);
+    unsigned int crc = crc32_calculate(&th->crc32, key, 
+            offsetof(struct sw_flow_key, wildcards));
     return &th->buckets[crc & th->bucket_mask];
 }
 
@@ -60,7 +61,7 @@ static struct sw_flow *table_hash_lookup(struct sw_table *swt,
                                          const struct sw_flow_key *key)
 {
     struct sw_flow *flow = *find_bucket(swt, key);
-    return flow && !memcmp(&flow->key, key, sizeof *key) ? flow : NULL;
+    return flow && !flow_compare(&flow->key.flow, &key->flow) ? flow : NULL;
 }
 
 static int table_hash_insert(struct sw_table *swt, struct sw_flow *flow)
@@ -79,7 +80,7 @@ static int table_hash_insert(struct sw_table *swt, struct sw_flow *flow)
         retval = 1;
     } else {
         struct sw_flow *old_flow = *bucket;
-        if (!memcmp(&old_flow->key, &flow->key, sizeof flow->key)) {
+        if (!flow_compare(&old_flow->key.flow, &flow->key.flow)) {
             *bucket = flow;
             flow_free(old_flow);
             retval = 1;
@@ -111,7 +112,7 @@ static int table_hash_delete(struct sw_table *swt,
     if (key->wildcards == 0) {
         struct sw_flow **bucket = find_bucket(swt, key);
         struct sw_flow *flow = *bucket;
-        if (flow && !memcmp(&flow->key, key, sizeof *key)) {
+        if (flow && !flow_compare(&flow->key.flow, &key->flow)) {
             do_delete(bucket);
             count = 1;
         }
@@ -180,7 +181,7 @@ static int table_hash_iterate(struct sw_table *swt,
 
         for (i = position->private[0]; i <= th->bucket_mask; i++) {
             struct sw_flow *flow = th->buckets[i];
-            if (flow && flow_matches(key, &flow->key)) {
+            if (flow && flow_matches_1wild(&flow->key, key)) {
                 int error = callback(flow, private);
                 if (error) {
                     position->private[0] = i + 1;
@@ -197,7 +198,8 @@ static void table_hash_stats(struct sw_table *swt,
 {
     struct sw_table_hash *th = (struct sw_table_hash *) swt;
     stats->name = "hash";
-    stats->n_flows = th->n_flows;
+    stats->wildcards = 0;        /* No wildcards are supported. */
+    stats->n_flows   = th->n_flows;
     stats->max_flows = th->bucket_mask + 1;
     stats->n_matched = swt->n_matched;
 }
@@ -211,6 +213,7 @@ struct sw_table *table_hash_create(unsigned int polynomial,
     th = malloc(sizeof *th);
     if (th == NULL)
         return NULL;
+    memset(th, '\0', sizeof *th);
 
     assert(!(n_buckets & (n_buckets - 1)));
     th->buckets = calloc(n_buckets, sizeof *th->buckets);
@@ -251,7 +254,7 @@ static struct sw_flow *table_hash2_lookup(struct sw_table *swt,
         
     for (i = 0; i < 2; i++) {
         struct sw_flow *flow = *find_bucket(t2->subtable[i], key);
-        if (flow && !memcmp(&flow->key, key, sizeof *key))
+        if (flow && !flow_compare(&flow->key.flow, &key->flow))
             return flow;
     }
     return NULL;
@@ -321,7 +324,8 @@ static void table_hash2_stats(struct sw_table *swt,
     for (i = 0; i < 2; i++)
         table_hash_stats(t2->subtable[i], &substats[i]);
     stats->name = "hash2";
-    stats->n_flows = substats[0].n_flows + substats[1].n_flows;
+    stats->wildcards = 0;        /* No wildcards are supported. */
+    stats->n_flows   = substats[0].n_flows + substats[1].n_flows;
     stats->max_flows = substats[0].max_flows + substats[1].max_flows;
     stats->n_matched = swt->n_matched;
 }
@@ -336,6 +340,7 @@ struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
     t2 = malloc(sizeof *t2);
     if (t2 == NULL)
         return NULL;
+    memset(t2, '\0', sizeof *t2);
 
     t2->subtable[0] = table_hash_create(poly0, buckets0);
     if (t2->subtable[0] == NULL)