Add support for OFPFC_MODIFY Flow Mod command.
[openvswitch] / switch / chain.c
index ce8fe9d8c6c24505c2e41dfdcd5e76a887352490..0388951da8ff9ff9dd0f7ec180470b1582562435 100644 (file)
@@ -31,6 +31,7 @@
  * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "chain.h"
 #include <assert.h>
 #include <errno.h>
 #define THIS_MODULE VLM_chain
 #include "vlog.h"
 
-/* Set of tables chained together in sequence from cheap to expensive. */
-#define CHAIN_MAX_TABLES 4
-struct sw_chain {
-    int n_tables;
-    struct sw_table *tables[CHAIN_MAX_TABLES];
-};
-
 /* Attempts to append 'table' to the set of tables in 'chain'.  Returns 0 or
  * negative error.  If 'table' is null it is assumed that table creation failed
  * due to out-of-memory. */
@@ -72,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);
@@ -95,8 +87,10 @@ 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)
+        if (flow) {
+            t->n_matched++;
             return flow;
+        }
     }
     return NULL;
 }
@@ -120,74 +114,74 @@ 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'.  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.
- *
- * The caller need not hold any locks. */
+ * 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,
+        const struct ofp_action *actions, int n_actions)
 {
     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, actions, n_actions);
     }
 
     return count;
-
 }
 
-/* Performs timeout processing on all the tables in 'chain'.  Returns the
- * number of flow entries deleted through expiration.
- *
- * Expensive as currently implemented, since it iterates through the entire
- * contents of each table.
+/* Deletes from 'chain' any and all flows that match 'key'.  Returns the number
+ * of flows that were deleted.
  *
- * The caller need not hold any locks. */
+ * 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_timeout(struct sw_chain *chain, struct datapath *dp)
+chain_delete(struct sw_chain *chain, const struct sw_flow_key *key, 
+             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->timeout(dp, t);
+        count += t->delete(t, key, priority, strict);
     }
+
     return count;
+
 }
 
-/* Destroys 'chain', which must not have any users. */
+/* Deletes timed-out flow entries from all the tables in 'chain' and appends
+ * the deleted flows to 'deleted'.
+ *
+ * Expensive as currently implemented, since it iterates through the entire
+ * contents of each table. */
 void
-chain_destroy(struct sw_chain *chain)
+chain_timeout(struct sw_chain *chain, struct list *deleted)
 {
     int i;
 
     for (i = 0; i < chain->n_tables; i++) {
         struct sw_table *t = chain->tables[i];
-        t->destroy(t);
+        t->timeout(t, deleted);
     }
-    free(chain);
 }
 
-/* Prints statistics for each of the tables in 'chain'. */
+/* Destroys 'chain', which must not have any users. */
 void
-chain_print_stats(struct sw_chain *chain)
+chain_destroy(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);
+        t->destroy(t);
     }
+    free(chain);
 }