[ovs-discuss] [ACLv2 02/19] ofproto: Add ofproto_get_flow_stats functions.

Jesse Gross jesse at nicira.com
Sat Aug 15 02:13:10 UTC 2009


The function allows aggregate packet and byte counts to be retrieved
for flows that match the given flow and wildcards.  The set of flows
to be matched against can either be the normal OpenFlow flows or the
currently active exact match flows in the kernel.
---
 ofproto/ofproto.c |   33 ++++++++++++++++++++++++++++++++-
 ofproto/ofproto.h |    3 +++
 2 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 38960ee..80bb43f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2499,6 +2499,7 @@ struct aggregate_stats_cbdata {
     uint64_t packet_count;
     uint64_t byte_count;
     uint32_t n_flows;
+    bool hidden_rules;
 };
 
 static void
@@ -2507,8 +2508,13 @@ aggregate_stats_cb(struct cls_rule *rule_, void *cbdata_)
     struct rule *rule = rule_from_cls_rule(rule_);
     struct aggregate_stats_cbdata *cbdata = cbdata_;
     uint64_t packet_count, byte_count;
+    bool is_hidden;
 
-    if (rule_is_hidden(rule) || !rule_has_out_port(rule, cbdata->out_port)) {
+    is_hidden = rule_is_hidden(rule);
+
+    if ((!cbdata->hidden_rules && is_hidden) ||
+        (cbdata->hidden_rules && !is_hidden) ||
+        !rule_has_out_port(rule, cbdata->out_port)) {
         return;
     }
 
@@ -2541,6 +2547,7 @@ handle_aggregate_stats_request(struct ofproto *p, struct ofconn *ofconn,
     cbdata.packet_count = 0;
     cbdata.byte_count = 0;
     cbdata.n_flows = 0;
+    cbdata.hidden_rules = false;
     cls_rule_from_match(&target, &asr->match, 0);
     classifier_for_each_match(&p->cls, &target,
                               table_id_to_include(asr->table_id),
@@ -2555,6 +2562,30 @@ handle_aggregate_stats_request(struct ofproto *p, struct ofconn *ofconn,
     return 0;
 }
 
+void
+ofproto_get_flow_stats(struct ofproto *ofproto, const flow_t *flow,
+                       uint32_t wildcards, bool hidden_rules,
+                       uint64_t *packet_count, uint64_t *byte_count)
+{
+    struct cls_rule target;
+    struct aggregate_stats_cbdata cbdata;
+
+    cls_rule_from_flow(&target, flow, wildcards, 0);
+
+    cbdata.ofproto = ofproto;
+    cbdata.out_port = htons(OFPP_NONE);
+    cbdata.packet_count = 0;
+    cbdata.byte_count = 0;
+    cbdata.n_flows = 0;
+    cbdata.hidden_rules = hidden_rules;
+
+    classifier_for_each_match(&ofproto->cls, &target, CLS_INC_ALL,
+                              aggregate_stats_cb, &cbdata);
+
+    *packet_count = cbdata.packet_count;
+    *byte_count = cbdata.byte_count;
+}
+
 static int
 handle_stats_request(struct ofproto *p, struct ofconn *ofconn,
                      struct ofp_header *oh)
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 88ae701..b6d8396 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -80,6 +80,9 @@ bool ofproto_get_discovery(const struct ofproto *);
 const char *ofproto_get_controller(const struct ofproto *);
 void ofproto_get_listeners(const struct ofproto *, struct svec *);
 void ofproto_get_snoops(const struct ofproto *, struct svec *);
+void ofproto_get_flow_stats(struct ofproto *ofproto, const flow_t *flow,
+                            uint32_t wildcards, bool hidden_rules,
+                            uint64_t *packet_count, uint64_t *byte_count);
 
 /* Functions for use by ofproto implementation modules, not by clients. */
 int ofproto_send_packet(struct ofproto *, const flow_t *,
-- 
1.6.0.4





More information about the discuss mailing list