Fix "make dist" by adding forgotten files to sources lists.
[sliver-openvswitch.git] / switch / table-hash.c
index ba8ebff..6b5e945 100644 (file)
@@ -82,12 +82,6 @@ static int table_hash_insert(struct sw_table *swt, struct sw_flow *flow)
     } else {
         struct sw_flow *old_flow = *bucket;
         if (!flow_compare(&old_flow->key.flow, &flow->key.flow)) {
-            /* Keep stats from the original flow */
-            flow->used = old_flow->used;
-            flow->created = old_flow->created;
-            flow->packet_count = old_flow->packet_count;
-            flow->byte_count = old_flow->byte_count;
-
             *bucket = flow;
             flow_free(old_flow);
             retval = 1;
@@ -98,6 +92,37 @@ static int table_hash_insert(struct sw_table *swt, struct sw_flow *flow)
     return retval;
 }
 
+static int table_hash_modify(struct sw_table *swt, 
+        const struct sw_flow_key *key, uint16_t priority, int strict,
+        const struct ofp_action_header *actions, size_t actions_len) 
+{
+    struct sw_table_hash *th = (struct sw_table_hash *) swt;
+    unsigned int count = 0;
+
+    if (key->wildcards == 0) {
+        struct sw_flow **bucket = find_bucket(swt, key);
+        struct sw_flow *flow = *bucket;
+        if (flow && flow_matches_desc(&flow->key, key, strict)
+                && (!strict || (flow->priority == priority))) {
+            flow_replace_acts(flow, actions, actions_len);
+            count = 1;
+        }
+    } else {
+        unsigned int i;
+
+        for (i = 0; i <= th->bucket_mask; i++) {
+            struct sw_flow **bucket = &th->buckets[i];
+            struct sw_flow *flow = *bucket;
+            if (flow && flow_matches_desc(&flow->key, key, strict)
+                    && (!strict || (flow->priority == priority))) {
+                flow_replace_acts(flow, actions, actions_len);
+                count++;
+            }
+        }
+    }
+    return count;
+}
+
 /* Caller must update n_flows. */
 static void
 do_delete(struct sw_flow **bucket)
@@ -111,6 +136,7 @@ do_delete(struct sw_flow **bucket)
  * priority. */
 static int table_hash_delete(struct sw_table *swt,
                              const struct sw_flow_key *key, 
+                             uint16_t out_port,
                              uint16_t priority, int strict)
 {
     struct sw_table_hash *th = (struct sw_table_hash *) swt;
@@ -119,7 +145,8 @@ 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 && !flow_compare(&flow->key.flow, &key->flow)) {
+        if (flow && !flow_compare(&flow->key.flow, &key->flow)
+                && flow_has_out_port(flow, out_port)) {
             do_delete(bucket);
             count = 1;
         }
@@ -129,7 +156,8 @@ static int table_hash_delete(struct sw_table *swt,
         for (i = 0; i <= th->bucket_mask; i++) {
             struct sw_flow **bucket = &th->buckets[i];
             struct sw_flow *flow = *bucket;
-            if (flow && flow_del_matches(&flow->key, key, strict)) {
+            if (flow && flow_matches_desc(&flow->key, key, strict)
+                    && flow_has_out_port(flow, out_port)) {
                 do_delete(bucket);
                 count++;
             }
@@ -169,7 +197,7 @@ static void table_hash_destroy(struct sw_table *swt)
 }
 
 static int table_hash_iterate(struct sw_table *swt,
-                              const struct sw_flow_key *key,
+                              const struct sw_flow_key *key, uint16_t out_port,
                               struct sw_table_position *position,
                               int (*callback)(struct sw_flow *, void *private),
                               void *private) 
@@ -182,13 +210,17 @@ static int table_hash_iterate(struct sw_table *swt,
     if (key->wildcards == 0) {
         struct sw_flow *flow = table_hash_lookup(swt, key);
         position->private[0] = -1;
-        return flow ? callback(flow, private) : 0;
+        if (!flow || !flow_has_out_port(flow, out_port)) {
+            return 0;
+        }
+        return callback(flow, private);
     } else {
         int i;
 
         for (i = position->private[0]; i <= th->bucket_mask; i++) {
             struct sw_flow *flow = th->buckets[i];
-            if (flow && flow_matches_1wild(&flow->key, key)) {
+            if (flow && flow_matches_1wild(&flow->key, key)
+                    && flow_has_out_port(flow, out_port)) {
                 int error = callback(flow, private);
                 if (error) {
                     position->private[0] = i + 1;
@@ -208,6 +240,7 @@ static void table_hash_stats(struct sw_table *swt,
     stats->wildcards = 0;        /* No wildcards are supported. */
     stats->n_flows   = th->n_flows;
     stats->max_flows = th->bucket_mask + 1;
+    stats->n_lookup  = swt->n_lookup;
     stats->n_matched = swt->n_matched;
 }
 
@@ -235,6 +268,7 @@ struct sw_table *table_hash_create(unsigned int polynomial,
     swt = &th->swt;
     swt->lookup = table_hash_lookup;
     swt->insert = table_hash_insert;
+    swt->modify = table_hash_modify;
     swt->delete = table_hash_delete;
     swt->timeout = table_hash_timeout;
     swt->destroy = table_hash_destroy;
@@ -276,13 +310,26 @@ static int table_hash2_insert(struct sw_table *swt, struct sw_flow *flow)
     return table_hash_insert(t2->subtable[1], flow);
 }
 
+static int table_hash2_modify(struct sw_table *swt, 
+        const struct sw_flow_key *key, uint16_t priority, int strict,
+        const struct ofp_action_header *actions, size_t actions_len) 
+{
+    struct sw_table_hash2 *t2 = (struct sw_table_hash2 *) swt;
+    return (table_hash_modify(t2->subtable[0], key, priority, strict,
+                    actions, actions_len)
+            + table_hash_modify(t2->subtable[1], key, priority, strict,
+                    actions, actions_len));
+}
+
 static int table_hash2_delete(struct sw_table *swt,
                               const struct sw_flow_key *key, 
+                              uint16_t out_port,
                               uint16_t priority, int strict)
 {
     struct sw_table_hash2 *t2 = (struct sw_table_hash2 *) swt;
-    return (table_hash_delete(t2->subtable[0], key, priority, strict)
-            + table_hash_delete(t2->subtable[1], key, priority, strict));
+    return (table_hash_delete(t2->subtable[0], key, out_port, priority, strict)
+            + table_hash_delete(t2->subtable[1], key, out_port, priority, 
+                strict));
 }
 
 static void table_hash2_timeout(struct sw_table *swt, struct list *deleted)
@@ -301,7 +348,8 @@ static void table_hash2_destroy(struct sw_table *swt)
 }
 
 static int table_hash2_iterate(struct sw_table *swt,
-                               const struct sw_flow_key *key,
+                               const struct sw_flow_key *key, 
+                               uint16_t out_port,
                                struct sw_table_position *position,
                                int (*callback)(struct sw_flow *, void *),
                                void *private)
@@ -310,8 +358,8 @@ static int table_hash2_iterate(struct sw_table *swt,
     int i;
 
     for (i = position->private[1]; i < 2; i++) {
-        int error = table_hash_iterate(t2->subtable[i], key, position,
-                                       callback, private);
+        int error = table_hash_iterate(t2->subtable[i], key, out_port, 
+                                       position, callback, private);
         if (error) {
             return error;
         }
@@ -334,6 +382,7 @@ static void table_hash2_stats(struct sw_table *swt,
     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_lookup  = swt->n_lookup;
     stats->n_matched = swt->n_matched;
 }
 
@@ -360,6 +409,7 @@ struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
     swt = &t2->swt;
     swt->lookup = table_hash2_lookup;
     swt->insert = table_hash2_insert;
+    swt->modify = table_hash2_modify;
     swt->delete = table_hash2_delete;
     swt->timeout = table_hash2_timeout;
     swt->destroy = table_hash2_destroy;