ofproto: Use active time for Flow Expiration duration (OpenFlow 0.9)
authorJustin Pettit <jpettit@nicira.com>
Fri, 13 Nov 2009 00:52:17 +0000 (16:52 -0800)
committerJustin Pettit <jpettit@nicira.com>
Sat, 23 Jan 2010 02:08:04 +0000 (18:08 -0800)
In pre-0.9 versions of OpenFlow, the duration field in the flow
expiration message was the amount of time that the flow was in a table.
If a long idle timeout was set, it could be difficult to determine how
long the flow was actually active.  In OpenFlow 0.9, this was changed to
only be the length of time that the flow was active.

NOTE: OVS at this point is not wire-compatible with OpenFlow 0.9 until the
final commit in this OpenFlow 0.9 set.

ofproto/ofproto.c

index dbb1a21..f25813f 100644 (file)
@@ -3264,12 +3264,13 @@ compose_flow_exp(const struct rule *rule, long long int now, uint8_t reason)
 {
     struct ofp_flow_expired *ofe;
     struct ofpbuf *buf;
+    long long int last_used = rule->used ? now - rule->used : 0;
 
     ofe = make_openflow(sizeof *ofe, OFPT_FLOW_EXPIRED, &buf);
     flow_to_match(&rule->cr.flow, rule->cr.wc.wildcards, &ofe->match);
     ofe->priority = htons(rule->cr.priority);
     ofe->reason = reason;
-    ofe->duration = htonl((now - rule->created) / 1000);
+    ofe->duration = htonl((now - rule->created - last_used) / 1000);
     ofe->packet_count = htonll(rule->packet_count);
     ofe->byte_count = htonll(rule->byte_count);