ofproto: Reinterpret meaning of OpenFlow hard timeouts with OFPFC_MODIFY.
authorBen Pfaff <blp@nicira.com>
Fri, 19 Aug 2011 17:33:09 +0000 (10:33 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 13 Sep 2011 18:46:09 +0000 (11:46 -0700)
I finally found a good use for hard timeouts in OpenFlow, but they require
a slight reinterpretation of the meaning of hard timeouts.  Until now, a
hard timeout meant that a flow would be removed the specified number of
seconds after a flow was created.  Intervening modifications with
OFPFC_MODIFY(_STRICT) had no effect on the hard timeout; the flow would
still be deleted the specified number of seconds after its original
creation.

This commit changes the effect of OFPFC_MODIFY(_STRICT).  Now, modifying
a flow resets its hard timeout counter.  A flow will time out the specified
number of seconds after creation or after the last time it is modified,
whichever comes later.

ofproto/ofproto-dpif.c
ofproto/ofproto-provider.h
ofproto/ofproto.c

index 7174748..9392045 100644 (file)
@@ -2009,7 +2009,7 @@ rule_expire(struct rule_dpif *rule)
     /* Has 'rule' expired? */
     now = time_msec();
     if (rule->up.hard_timeout
-        && now > rule->up.created + rule->up.hard_timeout * 1000) {
+        && now > rule->up.modified + rule->up.hard_timeout * 1000) {
         reason = OFPRR_HARD_TIMEOUT;
     } else if (rule->up.idle_timeout && list_is_empty(&rule->facets)
                && now > rule->used + rule->up.idle_timeout * 1000) {
index 6e29ed9..b1c6972 100644 (file)
@@ -107,8 +107,9 @@ struct rule {
     ovs_be64 flow_cookie;        /* Controller-issued identifier. */
 
     long long int created;       /* Creation time. */
+    long long int modified;      /* Time of last modification. */
     uint16_t idle_timeout;       /* In seconds from time of last use. */
-    uint16_t hard_timeout;       /* In seconds from time of creation. */
+    uint16_t hard_timeout;       /* In seconds from last modification. */
     uint8_t table_id;            /* Index in ofproto's 'tables' array. */
     bool send_flow_removed;      /* Send a flow removed message? */
 
index 33cd85e..b96fa6e 100644 (file)
@@ -2252,7 +2252,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn,
     rule->cr = fm->cr;
     rule->pending = NULL;
     rule->flow_cookie = fm->cookie;
-    rule->created = time_msec();
+    rule->created = rule->modified = time_msec();
     rule->idle_timeout = fm->idle_timeout;
     rule->hard_timeout = fm->hard_timeout;
     rule->table_id = table - ofproto->tables;
@@ -2315,6 +2315,8 @@ modify_flows__(struct ofproto *ofproto, struct ofconn *ofconn,
             rule->actions = ofputil_actions_clone(fm->actions, fm->n_actions);
             rule->n_actions = fm->n_actions;
             rule->ofproto->ofproto_class->rule_modify_actions(rule);
+        } else {
+            rule->modified = time_msec();
         }
         rule->flow_cookie = fm->cookie;
     }
@@ -2944,7 +2946,9 @@ ofoperation_complete(struct ofoperation *op, int error)
         break;
 
     case OFOPERATION_MODIFY:
-        if (error) {
+        if (!error) {
+            rule->modified = time_msec();
+        } else {
             free(rule->actions);
             rule->actions = op->actions;
             rule->n_actions = op->n_actions;