ofproto-dpif: Factor controller optimization out of execute_odp_actions().
authorBen Pfaff <blp@nicira.com>
Tue, 27 Sep 2011 22:34:39 +0000 (15:34 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 14 Oct 2011 21:08:44 +0000 (14:08 -0700)
An upcoming commit will use this code separately from
execute_odp_actions(), so this prepares for that.

ofproto/ofproto-dpif.c

index a638349bd6630448bc0d72adec413b9862ba186d..be3f7430d0d683d772968c1adc289e55488b5d93 100644 (file)
@@ -266,6 +266,11 @@ static struct facet *facet_lookup_valid(struct ofproto_dpif *,
                                         const struct flow *);
 static bool facet_revalidate(struct ofproto_dpif *, struct facet *);
 
+static bool execute_controller_action(struct ofproto_dpif *,
+                                      const struct flow *,
+                                      const struct nlattr *odp_actions,
+                                      size_t actions_len,
+                                      struct ofpbuf *packet);
 static void facet_execute(struct ofproto_dpif *, struct facet *,
                           struct ofpbuf *packet);
 
@@ -2213,23 +2218,15 @@ facet_free(struct facet *facet)
     free(facet);
 }
 
-/* Executes, within 'ofproto', the 'n_actions' actions in 'actions' on
- * 'packet', which arrived on 'in_port'.
- *
- * Takes ownership of 'packet'. */
 static bool
-execute_odp_actions(struct ofproto_dpif *ofproto, const struct flow *flow,
-                    const struct nlattr *odp_actions, size_t actions_len,
-                    struct ofpbuf *packet)
-{
-    struct odputil_keybuf keybuf;
-    struct ofpbuf key;
-    int error;
-
-    if (actions_len == 0) {
-        return true;
-    } else if (odp_actions->nla_type == OVS_ACTION_ATTR_USERSPACE
-               && NLA_ALIGN(odp_actions->nla_len) == actions_len) {
+execute_controller_action(struct ofproto_dpif *ofproto,
+                          const struct flow *flow,
+                          const struct nlattr *odp_actions, size_t actions_len,
+                          struct ofpbuf *packet)
+{
+    if (actions_len
+        && odp_actions->nla_type == OVS_ACTION_ATTR_USERSPACE
+        && NLA_ALIGN(odp_actions->nla_len) == actions_len) {
         /* As an optimization, avoid a round-trip from userspace to kernel to
          * userspace.  This also avoids possibly filling up kernel packet
          * buffers along the way.
@@ -2243,6 +2240,27 @@ execute_odp_actions(struct ofproto_dpif *ofproto, const struct flow *flow,
         send_packet_in_action(ofproto, packet, nl_attr_get_u64(nla), flow,
                               false);
         return true;
+    } else {
+        return false;
+    }
+}
+
+/* Executes, within 'ofproto', the 'n_actions' actions in 'actions' on
+ * 'packet', which arrived on 'in_port'.
+ *
+ * Takes ownership of 'packet'. */
+static bool
+execute_odp_actions(struct ofproto_dpif *ofproto, const struct flow *flow,
+                    const struct nlattr *odp_actions, size_t actions_len,
+                    struct ofpbuf *packet)
+{
+    struct odputil_keybuf keybuf;
+    struct ofpbuf key;
+    int error;
+
+    if (execute_controller_action(ofproto, flow, odp_actions, actions_len,
+                                  packet)) {
+        return true;
     }
 
     ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);