[ovs-dev] [PATCH v2] ofproto: update flow_stats flags on flow_stats_request

Daniel Baluta dbaluta at ixiacom.com
Wed Sep 11 21:56:53 UTC 2013


This is a first step in implementing 'on demand flow counters'.

We save relevant flow_mod flags (OFPUTIL_FF_SEND_FLOW_REM,
OFPUTIL_FF_NO_PKT_COUNTS, OFPUTIL_FF_NO_BYT_COUNTS) into newly created rule
when a new flow is added, and echo them back in the flow stats request.

Notice that we remove send_flow_removed flag from struct rule/struct ofoperation
and we replace it with an enum tracking all ofputil_flow_mod_flags.

Signed-off-by: Daniel Baluta <dbaluta at ixiacom.com>
---
v2 -> v1
    * replaced send_flow_removed member from struct rule with flags.
    * replaced send_flow_removed member from struct ofoperation with flags.
    * look only at relevant flags in struct rule (see commit message for info).

This is just only compile tested.
 ofproto/ofproto-provider.h |    2 +-
 ofproto/ofproto.c          |   51 ++++++++++++++++++++++++++++++++------------
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h
index 0b8a5e5..4cbf47f 100644
--- a/ofproto/ofproto-provider.h
+++ b/ofproto/ofproto-provider.h
@@ -231,7 +231,7 @@ struct rule {
     long long int modified;      /* Time of last modification. */
     long long int used;          /* Last use; time created if never used. */
     uint8_t table_id;            /* Index in ofproto's 'tables' array. */
-    bool send_flow_removed;      /* Send a flow removed message? */
+    enum ofputil_flow_mod_flags flags;
 
     struct ovs_mutex timeout_mutex;
     uint16_t hard_timeout OVS_GUARDED; /* In seconds from ->modified. */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index abf14f2..f718881 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -131,11 +131,11 @@ struct ofoperation {
     /* OFOPERATION_DELETE. */
     enum ofp_flow_removed_reason reason; /* Reason flow was removed. */
 
-    ovs_be64 flow_cookie;       /* Rule's old flow cookie. */
-    uint16_t idle_timeout;      /* Rule's old idle timeout. */
-    uint16_t hard_timeout;      /* Rule's old hard timeout. */
-    bool send_flow_removed;     /* Rule's old 'send_flow_removed'. */
-    enum ofperr error;          /* 0 if no error. */
+    ovs_be64 flow_cookie;               /* Rule's old flow cookie. */
+    uint16_t idle_timeout;              /* Rule's old idle timeout. */
+    uint16_t hard_timeout;              /* Rule's old hard timeout. */
+    enum ofputil_flow_mod_flags flags;  /* Rule's old flags. */
+    enum ofperr error;                  /* 0 if no error. */
 };
 
 static struct ofoperation *ofoperation_create(struct ofopgroup *,
@@ -3156,11 +3156,16 @@ handle_flow_stats_request(struct ofconn *ofconn,
         ovs_mutex_unlock(&rule->timeout_mutex);
 
         fs.flags = 0;
-        if (rule->send_flow_removed) {
+        if (rule->flags & OFPUTIL_FF_SEND_FLOW_REM) {
             fs.flags |= OFPUTIL_FF_SEND_FLOW_REM;
-            /* FIXME: Implement OFPUTIL_FF_NO_PKT_COUNTS and
-               OFPUTIL_FF_NO_BYT_COUNTS. */
         }
+        if (rule->flags & OFPUTIL_FF_NO_PKT_COUNTS) {
+            fs.flags |= OFPUTIL_FF_NO_PKT_COUNTS;
+        }
+        if (rule->flags & OFPUTIL_FF_NO_BYT_COUNTS) {
+            fs.flags |= OFPUTIL_FF_NO_BYT_COUNTS;
+        }
+
         ofputil_append_flow_stats_reply(&fs, &replies);
     }
     ofconn_send_replies(ofconn, &replies);
@@ -3576,7 +3581,17 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn,
     ovs_mutex_unlock(&rule->timeout_mutex);
 
     rule->table_id = table - ofproto->tables;
-    rule->send_flow_removed = (fm->flags & OFPUTIL_FF_SEND_FLOW_REM) != 0;
+
+    if (fm->flags & OFPUTIL_FF_SEND_FLOW_REM) {
+        rule->flags |= OFPUTIL_FF_SEND_FLOW_REM;
+    }
+    if (fm->flags & OFPUTIL_FF_NO_PKT_COUNTS) {
+        rule->flags |= OFPUTIL_FF_NO_PKT_COUNTS;
+    }
+    if (fm->flags & OFPUTIL_FF_NO_BYT_COUNTS) {
+        rule->flags |= OFPUTIL_FF_NO_BYT_COUNTS;
+    }
+
     rule->ofpacts = xmemdup(fm->ofpacts, fm->ofpacts_len);
     rule->ofpacts_len = fm->ofpacts_len;
     rule->meter_id = find_meter(rule->ofpacts, rule->ofpacts_len);
@@ -3663,8 +3678,15 @@ modify_flows__(struct ofproto *ofproto, struct ofconn *ofconn,
             rule->hard_timeout = fm->hard_timeout;
             ovs_mutex_unlock(&rule->timeout_mutex);
 
-            rule->send_flow_removed = (fm->flags
-                                       & OFPUTIL_FF_SEND_FLOW_REM) != 0;
+            if (fm->flags & OFPUTIL_FF_SEND_FLOW_REM) {
+                rule->flags |= OFPUTIL_FF_SEND_FLOW_REM;
+            }
+            if (fm->flags & OFPUTIL_FF_NO_PKT_COUNTS) {
+                rule->flags |= OFPUTIL_FF_NO_PKT_COUNTS;
+            }
+            if (fm->flags & OFPUTIL_FF_NO_BYT_COUNTS) {
+                rule->flags |= OFPUTIL_FF_NO_BYT_COUNTS;
+            }
 
             if (fm->idle_timeout || fm->hard_timeout) {
                 if (!rule->eviction_group) {
@@ -3838,7 +3860,8 @@ ofproto_rule_send_removed(struct rule *rule, uint8_t reason)
 {
     struct ofputil_flow_removed fr;
 
-    if (ofproto_rule_is_hidden(rule) || !rule->send_flow_removed) {
+    if (ofproto_rule_is_hidden(rule) ||
+        !(rule->flags & OFPUTIL_FF_SEND_FLOW_REM)) {
         return;
     }
 
@@ -5553,7 +5576,7 @@ ofopgroup_complete(struct ofopgroup *group)
                     op->ofpacts = NULL;
                     op->ofpacts_len = 0;
                 }
-                rule->send_flow_removed = op->send_flow_removed;
+                rule->flags = op->flags;
             }
             break;
 
@@ -5611,7 +5634,7 @@ ofoperation_create(struct ofopgroup *group, struct rule *rule,
     op->idle_timeout = rule->idle_timeout;
     op->hard_timeout = rule->hard_timeout;
     ovs_mutex_unlock(&rule->timeout_mutex);
-    op->send_flow_removed = rule->send_flow_removed;
+    op->flags = rule->flags;
 
     group->n_running++;
 
-- 
1.7.10.4




More information about the dev mailing list