From 1745cd08c93adaa11268526309addefd51604394 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 13 Jan 2012 16:40:59 -0800 Subject: [PATCH] ofproto: Move 'used' from ofproto_dpif into ofproto. This will allow the upcoming flow table eviction policy code to determine which flows will expire soon. Signed-off-by: Ben Pfaff --- NEWS | 3 +++ ofproto/ofproto-dpif.c | 15 +++++---------- ofproto/ofproto-provider.h | 6 ++++-- ofproto/ofproto.c | 10 +++++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 96c86c42..415b9f28 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ post-v1.5.0 - Logging to console and file will have UTC timestamp as a default for all the daemons. An example of the default format is 2012-01-27T16:35:17Z. ovs-appctl can be used to change the default format as before. + - ofproto-provider interface: + - "struct rule" has a new member "used" that ofproto implementations + should maintain by updating with ofproto_rule_update_used(). v1.5.0 - xx xxx xxxx diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index a6087bf3..840e74bd 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -76,8 +76,6 @@ struct ofproto_dpif; struct rule_dpif { struct rule up; - long long int used; /* Time last used; time created if not used. */ - /* These statistics: * * - Do include packets and bytes from facets that have been deleted or @@ -3088,7 +3086,7 @@ rule_expire(struct rule_dpif *rule) && 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) { + && now > rule->up.used + rule->up.idle_timeout * 1000) { reason = OFPRR_IDLE_TIMEOUT; } else { return; @@ -3611,9 +3609,7 @@ facet_update_time(struct facet *facet, long long int used) struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto); if (used > facet->used) { facet->used = used; - if (used > facet->rule->used) { - facet->rule->used = used; - } + ofproto_rule_update_used(&facet->rule->up, used); netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, used); } } @@ -3668,7 +3664,7 @@ push_resubmit(struct action_xlate_ctx *ctx, struct rule_dpif *rule) if (rule) { rule->packet_count += push->packets; rule->byte_count += push->bytes; - rule->used = MAX(push->used, rule->used); + ofproto_rule_update_used(&rule->up, push->used); } } @@ -4034,7 +4030,6 @@ rule_construct(struct rule *rule_) return error; } - rule->used = rule->up.created; rule->packet_count = 0; rule->byte_count = 0; @@ -4118,10 +4113,10 @@ rule_execute(struct rule *rule_, const struct flow *flow, size = packet->size; if (execute_odp_actions(ofproto, flow, odp_actions->data, odp_actions->size, packet)) { - rule->used = time_msec(); + ofproto_rule_update_used(&rule->up, time_msec()); rule->packet_count++; rule->byte_count += size; - flow_push_stats(rule, flow, 1, size, rule->used); + flow_push_stats(rule, flow, 1, size, rule->up.used); } ofpbuf_delete(odp_actions); diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 2d647fe3..9fb5effd 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -136,8 +136,9 @@ struct rule { 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 last modification. */ + long long int used; /* Last use; time created if never used. */ + uint16_t hard_timeout; /* In seconds from ->modified. */ + uint16_t idle_timeout; /* In seconds from ->used. */ uint8_t table_id; /* Index in ofproto's 'tables' array. */ bool send_flow_removed; /* Send a flow removed message? */ @@ -151,6 +152,7 @@ rule_from_cls_rule(const struct cls_rule *cls_rule) return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL; } +void ofproto_rule_update_used(struct rule *, long long int used); void ofproto_rule_expire(struct rule *, uint8_t reason); void ofproto_rule_destroy(struct rule *); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 3dab46a4..b27a41c7 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -2580,7 +2580,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn, rule->cr = fm->cr; rule->pending = NULL; rule->flow_cookie = fm->cookie; - rule->created = rule->modified = time_msec(); + rule->created = rule->modified = rule->used = time_msec(); rule->idle_timeout = fm->idle_timeout; rule->hard_timeout = fm->hard_timeout; rule->table_id = table - ofproto->tables; @@ -2785,6 +2785,14 @@ ofproto_rule_send_removed(struct rule *rule, uint8_t reason) connmgr_send_flow_removed(rule->ofproto->connmgr, &fr); } +void +ofproto_rule_update_used(struct rule *rule, long long int used) +{ + if (used > rule->used) { + rule->used = used; + } +} + /* Sends an OpenFlow "flow removed" message with the given 'reason' (either * OFPRR_HARD_TIMEOUT or OFPRR_IDLE_TIMEOUT), and then removes 'rule' from its * ofproto. -- 2.30.2