ofproto: Factor out check on rule->send_flow_removed in send_flow_removed().
authorBen Pfaff <blp@nicira.com>
Fri, 26 Mar 2010 21:37:16 +0000 (14:37 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 1 Apr 2010 21:41:07 +0000 (14:41 -0700)
There's no point in even iterating over the list of OpenFlow connections if
rule->send_flow_removed is false, since we'll never actually do anything
in that case anyway.

ofproto/ofproto.c

index 6ef8b3b..6976a0e 100644 (file)
@@ -3367,34 +3367,34 @@ uninstall_idle_flow(struct ofproto *ofproto, struct rule *rule)
 static void
 send_flow_removed(struct ofproto *p, struct rule *rule, uint8_t reason)
 {
-    long long int now = time_msec();
-    struct ofconn *ofconn;
-    struct ofconn *prev;
-    struct ofpbuf *buf = NULL;
-
     /* We limit the maximum number of queued flow expirations it by accounting
      * them under the counter for replies.  That works because preventing
      * OpenFlow requests from being processed also prevents new flows from
      * being added (and expiring).  (It also prevents processing OpenFlow
      * requests that would not add new flows, so it is imperfect.) */
 
-    prev = NULL;
-    LIST_FOR_EACH (ofconn, struct ofconn, node, &p->all_conns) {
-        if (rule->send_flow_removed && rconn_is_connected(ofconn->rconn)) {
-            if (prev) {
-                queue_tx(ofpbuf_clone(buf), prev, prev->reply_counter);
-            } else {
-                buf = compose_flow_removed(rule, now, reason);
+    if (rule->send_flow_removed) {
+        long long int now = time_msec();
+        struct ofconn *prev = NULL;
+        struct ofpbuf *buf = NULL;
+        struct ofconn *ofconn;
+
+        LIST_FOR_EACH (ofconn, struct ofconn, node, &p->all_conns) {
+            if (rconn_is_connected(ofconn->rconn)) {
+                if (prev) {
+                    queue_tx(ofpbuf_clone(buf), prev, prev->reply_counter);
+                } else {
+                    buf = compose_flow_removed(rule, now, reason);
+                }
+                prev = ofconn;
             }
-            prev = ofconn;
         }
-    }
-    if (prev) {
-        queue_tx(buf, prev, prev->reply_counter);
+        if (prev) {
+            queue_tx(buf, prev, prev->reply_counter);
+        }
     }
 }
 
-
 static void
 expire_rule(struct cls_rule *cls_rule, void *p_)
 {