ofproto-dpif: Add multiple table support.
[sliver-openvswitch.git] / ofproto / ofproto-dpif.c
index 2aea4e1..a865d21 100644 (file)
@@ -419,7 +419,7 @@ dealloc(struct ofproto *ofproto_)
 }
 
 static int
-construct(struct ofproto *ofproto_)
+construct(struct ofproto *ofproto_, int *n_tablesp)
 {
     struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
     const char *name = ofproto->up.name;
@@ -464,14 +464,11 @@ construct(struct ofproto *ofproto_)
 
     list_init(&ofproto->completions);
 
-    ofproto->up.tables = xmalloc(sizeof *ofproto->up.tables);
-    classifier_init(&ofproto->up.tables[0]);
-    ofproto->up.n_tables = 1;
-
     ofproto_dpif_unixctl_init();
 
     ofproto->has_bundle_action = false;
 
+    *n_tablesp = 255;
     return 0;
 }
 
@@ -492,14 +489,18 @@ destruct(struct ofproto *ofproto_)
 {
     struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
     struct rule_dpif *rule, *next_rule;
-    struct cls_cursor cursor;
+    struct classifier *table;
     int i;
 
     complete_operations(ofproto);
 
-    cls_cursor_init(&cursor, &ofproto->up.tables[0], NULL);
-    CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
-        ofproto_rule_destroy(&rule->up);
+    OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
+        struct cls_cursor cursor;
+
+        cls_cursor_init(&cursor, table, NULL);
+        CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
+            ofproto_rule_destroy(&rule->up);
+        }
     }
 
     for (i = 0; i < MAX_MIRRORS; i++) {
@@ -1747,7 +1748,7 @@ static int
 expire(struct ofproto_dpif *ofproto)
 {
     struct rule_dpif *rule, *next_rule;
-    struct cls_cursor cursor;
+    struct classifier *table;
     int dp_max_idle;
 
     /* Update stats for each flow in the datapath. */
@@ -1758,9 +1759,13 @@ expire(struct ofproto_dpif *ofproto)
     expire_facets(ofproto, dp_max_idle);
 
     /* Expire OpenFlow flows whose idle_timeout or hard_timeout has passed. */
-    cls_cursor_init(&cursor, &ofproto->up.tables[0], NULL);
-    CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
-        rule_expire(rule);
+    OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
+        struct cls_cursor cursor;
+
+        cls_cursor_init(&cursor, table, NULL);
+        CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
+            rule_expire(rule);
+        }
     }
 
     /* All outstanding data in existing flows has been accounted, so it's a
@@ -3920,7 +3925,7 @@ struct ofproto_trace {
 };
 
 static void
-trace_format_rule(struct ds *result, int level, const struct rule *rule)
+trace_format_rule(struct ds *result, int level, const struct rule_dpif *rule)
 {
     ds_put_char_multiple(result, '\t', level);
     if (!rule) {
@@ -3929,13 +3934,13 @@ trace_format_rule(struct ds *result, int level, const struct rule *rule)
     }
 
     ds_put_format(result, "Rule: cookie=%#"PRIx64" ",
-                  ntohll(rule->flow_cookie));
-    cls_rule_format(&rule->cr, result);
+                  ntohll(rule->up.flow_cookie));
+    cls_rule_format(&rule->up.cr, result);
     ds_put_char(result, '\n');
 
     ds_put_char_multiple(result, '\t', level);
     ds_put_cstr(result, "OpenFlow ");
-    ofp_print_actions(result, rule->actions, rule->n_actions);
+    ofp_print_actions(result, rule->up.actions, rule->up.n_actions);
     ds_put_char(result, '\n');
 }
 
@@ -3962,7 +3967,7 @@ trace_resubmit(struct action_xlate_ctx *ctx, struct rule_dpif *rule)
 
     ds_put_char(result, '\n');
     trace_format_flow(result, ctx->recurse + 1, "Resubmitted flow", trace);
-    trace_format_rule(result, ctx->recurse + 1, &rule->up);
+    trace_format_rule(result, ctx->recurse + 1, rule);
 }
 
 static void
@@ -4050,7 +4055,7 @@ ofproto_unixctl_trace(struct unixctl_conn *conn, const char *args_,
     ds_put_char(&result, '\n');
 
     rule = rule_dpif_lookup(ofproto, &flow);
-    trace_format_rule(&result, 0, &rule->up);
+    trace_format_rule(&result, 0, rule);
     if (rule) {
         struct ofproto_trace trace;
         struct ofpbuf *odp_actions;