Add table config to to struct ofproto and set it
when a table mod message is received.

This is in preparation for changing the behaviour of the switch
based on table config.

Cc: Andy Zhou <az...@nicira.com>
Signed-off-by: Simon Horman <ho...@verge.net.au>
---
 ofproto/ofproto-provider.h | 13 ++++++++++++-
 ofproto/ofproto.c          | 27 ++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h
index 2844e4c..5ea3c78 100644
--- a/ofproto/ofproto-provider.h
+++ b/ofproto/ofproto-provider.h
@@ -211,6 +211,8 @@ enum oftable_flags {
  * Thread-safety
  * =============
  *
+ * cls
+ * ---
  * A cls->rwlock read-lock holder prevents rules from being added or deleted.
  *
  * Adding or removing rules requires holding ofproto_mutex AND the cls->rwlock
@@ -227,7 +229,12 @@ enum oftable_flags {
  * removing the rule from the classifier, release a ref_count from the rule
  * ('cls''s reference to the rule).
  *
- * Refer to the thread-safety notes on struct rule for more information.*/
+ * Refer to the thread-safety notes on struct rule for more information.
+ *
+ * config
+ * ------
+ * config is guarded by config_rwlock.
+ */
 struct oftable {
     enum oftable_flags flags;
     struct classifier cls;      /* Contains "struct rule"s. */
@@ -258,6 +265,10 @@ struct oftable {
     uint32_t eviction_group_id_basis;
     struct hmap eviction_groups_by_id;
     struct heap eviction_groups_by_size;
+
+    /* Table config */
+    enum ofp_table_config config OVS_GUARDED;
+    struct ovs_rwlock config_rwlock;
 };
 
 /* Assigns TABLE to each oftable, in turn, in OFPROTO.
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 2ccbcee..bb86d9f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -5776,9 +5776,31 @@ handle_group_mod(struct ofconn *ofconn, const struct 
ofp_header *oh)
     }
 }
 
+static void
+table_set_config(struct oftable *table, uint32_t config)
+{
+    ovs_rwlock_wrlock(&table->config_rwlock);
+    table->config = config;
+    ovs_rwlock_unlock(&table->config_rwlock);
+}
+
+static void
+table_mod(struct ofproto *ofproto, const struct ofputil_table_mod *tm)
+{
+    if (tm->table_id == OFPTT_ALL) {
+        int i;
+        for (i = 0; i < ofproto->n_tables; i++) {
+            table_set_config(&ofproto->tables[i], tm->config);
+        }
+    } else {
+        table_set_config(&ofproto->tables[tm->table_id], tm->config);
+    }
+}
+
 static enum ofperr
 handle_table_mod(struct ofconn *ofconn, const struct ofp_header *oh)
 {
+    struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
     struct ofputil_table_mod tm;
     enum ofperr error;
 
@@ -5792,7 +5814,7 @@ handle_table_mod(struct ofconn *ofconn, const struct 
ofp_header *oh)
         return error;
     }
 
-    /* XXX Actual table mod support is not implemented yet. */
+    table_mod(ofproto, &tm);
     return 0;
 }
 
@@ -6626,6 +6648,8 @@ oftable_init(struct oftable *table)
     memset(table, 0, sizeof *table);
     classifier_init(&table->cls);
     table->max_flows = UINT_MAX;
+    ovs_rwlock_init(&table->config_rwlock);
+    table_set_config(table, OFPTC_TABLE_MISS_CONTROLLER);
 }
 
 /* Destroys 'table', including its classifier and eviction groups.
@@ -6639,6 +6663,7 @@ oftable_destroy(struct oftable *table)
     ovs_rwlock_unlock(&table->cls.rwlock);
     oftable_disable_eviction(table);
     classifier_destroy(&table->cls);
+    ovs_rwlock_destroy(&table->config_rwlock);
     free(table->name);
 }
 
-- 
1.8.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to