From 732feb9311b72d96ee7ec341f82586804b64fcb8 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Wed, 30 Oct 2013 18:17:08 +0900 Subject: [PATCH] ofproto: Calculate some group stats at ofproto layer It seems to make sense to set the reference count and number of buckets at the protocol layer as it is known there. Signed-off-by: Simon Horman Signed-off-by: Ben Pfaff --- ofproto/ofproto.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index ddbab6cfd..6ea751028 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -5335,6 +5335,31 @@ ofproto_group_exists(const struct ofproto *ofproto, uint32_t group_id) return false; } +static uint32_t +group_get_ref_count(struct ofgroup *group) + OVS_EXCLUDED(ofproto_mutex) +{ + struct ofproto *ofproto = group->ofproto; + struct rule_criteria criteria; + struct rule_collection rules; + struct match match; + enum ofperr error; + uint32_t count; + + match_init_catchall(&match); + rule_criteria_init(&criteria, 0xff, &match, 0, htonll(0), htonll(0), + OFPP_ANY, group->group_id); + ovs_mutex_lock(&ofproto_mutex); + error = collect_rules_loose(ofproto, &criteria, &rules); + ovs_mutex_unlock(&ofproto_mutex); + rule_criteria_destroy(&criteria); + + count = !error && rules.n < UINT32_MAX ? rules.n : UINT32_MAX; + + rule_collection_destroy(&rules); + return count; +} + static void append_group_stats(struct ofgroup *group, struct list *replies) OVS_REQ_RDLOCK(group->rwlock) @@ -5346,14 +5371,16 @@ append_group_stats(struct ofgroup *group, struct list *replies) ogs.bucket_stats = xmalloc(group->n_buckets * sizeof *ogs.bucket_stats); + /* Provider sets the packet and byte counts, we do the rest. */ + ogs.ref_count = group_get_ref_count(group); + ogs.n_buckets = group->n_buckets; + error = (ofproto->ofproto_class->group_get_stats ? ofproto->ofproto_class->group_get_stats(group, &ogs) : EOPNOTSUPP); if (error) { - ogs.ref_count = UINT32_MAX; ogs.packet_count = UINT64_MAX; ogs.byte_count = UINT64_MAX; - ogs.n_buckets = group->n_buckets; memset(ogs.bucket_stats, 0xff, ogs.n_buckets * sizeof *ogs.bucket_stats); } -- 2.20.1