[ovs-dev] [eviction 10/12] ofproto: Move 'used' from ofproto_dpif into ofproto.

Ethan Jackson ethan at nicira.com
Mon Jan 23 21:52:45 UTC 2012


Looks cleaner.

Ethan

On Fri, Jan 13, 2012 at 16:43, Ben Pfaff <blp at nicira.com> wrote:
> This will allow the upcoming flow table eviction policy code to determine
> which flows will expire soon.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
>  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 b628e29..1fe83bb 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -1,5 +1,8 @@
>  post-v1.5.0
>  ------------------------
> +    - 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 5acd349..9ca3f71 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
> @@ -3070,7 +3068,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;
> @@ -3470,9 +3468,7 @@ facet_update_time(struct ofproto_dpif *ofproto, struct facet *facet,
>  {
>     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);
>     }
>  }
> @@ -3527,7 +3523,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);
>     }
>  }
>
> @@ -3887,7 +3883,6 @@ rule_construct(struct rule *rule_)
>         return error;
>     }
>
> -    rule->used = rule->up.created;
>     rule->packet_count = 0;
>     rule->byte_count = 0;
>
> @@ -3972,10 +3967,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 2d647fe..9fb5eff 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 abaa8f7..357c488 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -2573,7 +2573,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;
> @@ -2778,6 +2778,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.
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev



More information about the dev mailing list