Add "self-sign" command to ofp-pki.
[sliver-openvswitch.git] / switch / chain.c
index 516c930..d64cd12 100644 (file)
@@ -1,24 +1,37 @@
-/* Copyright (C) 2008 Board of Trustees, Leland Stanford Jr. University.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
+ * Junior University
+ * 
+ * We are making the OpenFlow specification and associated documentation
+ * (Software) available for public use and benefit with the expectation
+ * that others will use, modify and enhance the Software and contribute
+ * those enhancements back to the community. However, since we would
+ * like to make the Software available for broadest use, with as few
+ * restrictions as possible permission is hereby granted, free of
+ * charge, to any person obtaining a copy of this Software to deal in
+ * the Software under the copyrights without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * 
+ * The name and trademarks of copyright holder(s) may NOT be used in
+ * advertising or publicity pertaining to the Software or any
+ * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "chain.h"
 #include <assert.h>
 #include <errno.h>
@@ -53,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);
@@ -76,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;
 }
@@ -101,74 +115,76 @@ 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.
- *
- * 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,
+        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;
-
 }
 
-/* Performs timeout processing on all the tables in 'chain'.  Returns the
- * number of flow entries deleted through expiration.
+/* Deletes from 'chain' any and all flows that match 'key'.   If 'strict' set, 
+ * wildcards and priority must match.  Returns the number of flows that were 
+ * deleted.
  *
- * Expensive as currently implemented, since it iterates through the entire
- * contents of each table.
- *
- * 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);
 }