dpif: Add new functions dp_run() and dp_wait().
authorBen Pfaff <blp@nicira.com>
Fri, 19 Jun 2009 21:09:09 +0000 (14:09 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 6 Jul 2009 16:07:24 +0000 (09:07 -0700)
The upcoming netdev-based dpif needs a hook where it can process packets
and throw them against the flow table, and this provides a suitable place.

lib/dpif-linux.c
lib/dpif-provider.h
lib/dpif.c
lib/dpif.h
secchan/main.c
vswitchd/ovs-vswitchd.c

index 2c8c7b0..4090e57 100644 (file)
@@ -355,6 +355,8 @@ dpif_linux_recv_wait(struct dpif *dpif_)
 const struct dpif_class dpif_linux_class = {
     "",                         /* This is the default class. */
     "linux",
+    NULL,                       /* run */
+    NULL,                       /* wait */
     dpif_linux_open,
     dpif_linux_close,
     dpif_linux_delete,
index 902064c..020d067 100644 (file)
@@ -62,6 +62,14 @@ struct dpif_class {
     /* Class name, for use in error messages. */
     const char *name;
 
+    /* Performs periodic work needed by dpifs of this class, if any is
+     * necessary. */
+    void (*run)(void);
+
+    /* Arranges for poll_block() to wake up if the "run" member function needs
+     * to be called. */
+    void (*wait)(void);
+
     /* Attempts to open an existing dpif, if 'create' is false, or to open an
      * existing dpif or create a new one, if 'create' is true.  'name' is the
      * full dpif name provided by the user, e.g. "udatapath:/var/run/mypath".
index 4159dbd..8c33736 100644 (file)
@@ -61,6 +61,38 @@ static void log_flow_put(struct dpif *, int error,
 static bool should_log_flow_message(int error);
 static void check_rw_odp_flow(struct odp_flow *);
 
+/* Performs periodic work needed by all the various kinds of dpifs.
+ *
+ * If your program opens any dpifs, it must call this function within its main
+ * poll loop. */
+void
+dp_run(void)
+{
+    int i;
+    for (i = 0; i < N_DPIF_CLASSES; i++) {
+        const struct dpif_class *class = dpif_classes[i];
+        if (class->run) {
+            class->run();
+        }
+    }
+}
+
+/* Arranges for poll_block() to wake up when dp_run() needs to be called.
+ *
+ * If your program opens any dpifs, it must call this function within its main
+ * poll loop. */
+void
+dp_wait(void)
+{
+    int i;
+    for (i = 0; i < N_DPIF_CLASSES; i++) {
+        const struct dpif_class *class = dpif_classes[i];
+        if (class->wait) {
+            class->wait();
+        }
+    }
+}
+
 static int
 do_open(const char *name_, bool create, struct dpif **dpifp)
 {
index 5302197..213bd2b 100644 (file)
@@ -30,6 +30,9 @@
 struct dpif;
 struct ofpbuf;
 
+void dp_run(void);
+void dp_wait(void);
+
 int dpif_open(const char *name, struct dpif **);
 int dpif_create(const char *name, struct dpif **);
 void dpif_close(struct dpif *);
index d1037a8..c886abe 100644 (file)
@@ -198,9 +198,11 @@ main(int argc, char *argv[])
             ovs_fatal(error, "unrecoverable datapath error");
         }
         unixctl_server_run(unixctl);
+        dp_run();
 
         ofproto_wait(ofproto);
         unixctl_server_wait(unixctl);
+        dp_wait();
         poll_block();
     }
 
index e95ee0a..4352f5f 100644 (file)
@@ -28,6 +28,7 @@
 #include "command-line.h"
 #include "compiler.h"
 #include "daemon.h"
+#include "dpif.h"
 #include "fault.h"
 #include "leak-checker.h"
 #include "mgmt.h"
@@ -100,6 +101,7 @@ main(int argc, char *argv[])
             need_reconfigure = true;
         }
         unixctl_server_run(unixctl);
+        dp_run();
 
         if (need_reconfigure) {
             poll_immediate_wake();
@@ -108,6 +110,7 @@ main(int argc, char *argv[])
         mgmt_wait();
         bridge_wait();
         unixctl_server_wait(unixctl);
+        dp_wait();
         poll_block();
     }