Fix "make dist" by adding forgotten files to sources lists.
[sliver-openvswitch.git] / switch / chain.c
index 2a19df0..8f09c00 100644 (file)
@@ -31,6 +31,7 @@
  * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "chain.h"
 #include <assert.h>
 #include <errno.h>
@@ -65,9 +66,7 @@ struct sw_chain *chain_create(void)
     if (chain == NULL)
         return NULL;
 
-    if (add_table(chain, table_mac_create(TABLE_MAC_NUM_BUCKETS, 
-                                          TABLE_MAC_MAX_FLOWS))
-        || add_table(chain, table_hash2_create(0x1EDC6F41, TABLE_HASH_MAX_FLOWS,
+    if (add_table(chain, table_hash2_create(0x1EDC6F41, TABLE_HASH_MAX_FLOWS,
                                                0x741B8CD7, TABLE_HASH_MAX_FLOWS))
         || add_table(chain, table_linear_create(TABLE_LINEAR_MAX_FLOWS))) {
         chain_destroy(chain);
@@ -88,8 +87,11 @@ chain_lookup(struct sw_chain *chain, const struct sw_flow_key *key)
     for (i = 0; i < chain->n_tables; i++) {
         struct sw_table *t = chain->tables[i];
         struct sw_flow *flow = t->lookup(t, key);
-        if (flow)
+        t->n_lookup++;
+        if (flow) {
+            t->n_matched++;
             return flow;
+        }
     }
     return NULL;
 }
@@ -113,21 +115,46 @@ chain_insert(struct sw_chain *chain, struct sw_flow *flow)
     return -ENOBUFS;
 }
 
-/* Deletes from 'chain' any and all flows that match 'key'.  Returns the number
- * of flows that were deleted.
+/* Modifies actions in 'chain' that match 'key'.  If 'strict' set, wildcards 
+ * and priority must match.  Returns the number of flows that were modified.
  *
  * Expensive in the general case as currently implemented, since it requires
  * iterating through the entire contents of each table for keys that contain
  * wildcards.  Relatively cheap for fully specified keys. */
 int
-chain_delete(struct sw_chain *chain, const struct sw_flow_key *key, int strict)
+chain_modify(struct sw_chain *chain, const struct sw_flow_key *key,
+        uint16_t priority, int strict,
+        const struct ofp_action_header *actions, size_t actions_len)
 {
     int count = 0;
     int i;
 
     for (i = 0; i < chain->n_tables; i++) {
         struct sw_table *t = chain->tables[i];
-        count += t->delete(t, key, strict);
+        count += t->modify(t, key, priority, strict, actions, actions_len);
+    }
+
+    return count;
+}
+
+/* Deletes from 'chain' any and all flows that match 'key'.  If 'out_port' 
+ * is not OFPP_NONE, then matching entries must have that port as an 
+ * argument for an output action.  If 'strict" is set, then wildcards and 
+ * priority must match.  Returns the number of flows that were deleted.
+ *
+ * Expensive in the general case as currently implemented, since it requires
+ * iterating through the entire contents of each table for keys that contain
+ * wildcards.  Relatively cheap for fully specified keys. */
+int
+chain_delete(struct sw_chain *chain, const struct sw_flow_key *key, 
+             uint16_t out_port, uint16_t priority, int strict)
+{
+    int count = 0;
+    int i;
+
+    for (i = 0; i < chain->n_tables; i++) {
+        struct sw_table *t = chain->tables[i];
+        count += t->delete(t, key, out_port, priority, strict);
     }
 
     return count;
@@ -162,19 +189,3 @@ chain_destroy(struct sw_chain *chain)
     }
     free(chain);
 }
-
-/* Prints statistics for each of the tables in 'chain'. */
-void
-chain_print_stats(struct sw_chain *chain)
-{
-    int i;
-
-    printf("\n");
-    for (i = 0; i < chain->n_tables; i++) {
-        struct sw_table *t = chain->tables[i];
-        struct sw_table_stats stats;
-        t->stats(t, &stats);
-        printf("%s: %lu/%lu flows\n",
-               stats.name, stats.n_flows, stats.max_flows);
-    }
-}