From 5792c5c64a194304b554e2c6b9a9a4c0216c08a4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 19 Jun 2009 14:09:09 -0700 Subject: [PATCH] dpif: Add new functions dp_run() and dp_wait(). 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 | 2 ++ lib/dpif-provider.h | 8 ++++++++ lib/dpif.c | 32 ++++++++++++++++++++++++++++++++ lib/dpif.h | 3 +++ secchan/main.c | 2 ++ vswitchd/ovs-vswitchd.c | 3 +++ 6 files changed, 50 insertions(+) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 2c8c7b09..4090e572 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -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, diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 902064c5..020d0670 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -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". diff --git a/lib/dpif.c b/lib/dpif.c index 4159dbd0..8c33736b 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -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) { diff --git a/lib/dpif.h b/lib/dpif.h index 5302197e..213bd2bc 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -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 *); diff --git a/secchan/main.c b/secchan/main.c index d1037a81..c886abe0 100644 --- a/secchan/main.c +++ b/secchan/main.c @@ -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(); } diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index e95ee0aa..4352f5f7 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -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(); } -- 2.30.2