From: Ben Pfaff Date: Sat, 29 Mar 2008 00:16:00 +0000 (-0700) Subject: Reverse the dependency of controller.c on forward.c. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1802309275c560527574daca93ee5a77bc19085;p=openvswitch Reverse the dependency of controller.c on forward.c. Now controller.c doesn't depend on datapath.c or forward.c, which brings us one step closer to a reasonable dependency hierarchy. --- diff --git a/switch/controller.c b/switch/controller.c index 8f06f67f..57e8b9e6 100644 --- a/switch/controller.c +++ b/switch/controller.c @@ -35,7 +35,6 @@ #include #include #include "buffer.h" -#include "forward.h" #include "poll-loop.h" #include "ofp-print.h" #include "util.h" @@ -70,7 +69,7 @@ try_send(struct controller_connection *cc) } void -controller_run(struct controller_connection *cc, struct datapath *dp) +controller_run(struct controller_connection *cc) { if (!cc->vconn) { if (time(0) >= cc->backoff_deadline) { @@ -101,22 +100,6 @@ controller_run(struct controller_connection *cc, struct datapath *dp) controller_disconnect(cc, 0); } } else { - int iterations; - - for (iterations = 0; iterations < 50; iterations++) { - struct buffer *buffer; - int error = vconn_recv(cc->vconn, &buffer); - if (!error) { - fwd_control_input(dp, buffer->data, buffer->size); - buffer_delete(buffer); - } else if (error == EAGAIN) { - break; - } else { - controller_disconnect(cc, error); - return; - } - } - while (cc->txq.n > 0) { int error = try_send(cc); if (error == EAGAIN) { @@ -125,7 +108,19 @@ controller_run(struct controller_connection *cc, struct datapath *dp) controller_disconnect(cc, error); return; } - } + } + } +} + +void +controller_run_wait(struct controller_connection *cc) +{ + if (cc->vconn) { + if (cc->txq.n) { + vconn_wait(cc->vconn, WAIT_SEND); + } + } else { + poll_timer_wait((cc->backoff_deadline - time(0)) * 1000); } } @@ -162,16 +157,26 @@ controller_disconnect(struct controller_connection *cc, int error) cc->backoff_deadline = now + cc->backoff; } +struct buffer * +controller_recv(struct controller_connection *cc) +{ + if (cc->vconn && cc->connected) { + struct buffer *buffer; + int error = vconn_recv(cc->vconn, &buffer); + if (!error) { + return buffer; + } else if (error != EAGAIN) { + controller_disconnect(cc, error); + } + } + return NULL; +} + void -controller_wait(struct controller_connection *cc) +controller_recv_wait(struct controller_connection *cc) { if (cc->vconn) { vconn_wait(cc->vconn, WAIT_RECV); - if (cc->txq.n) { - vconn_wait(cc->vconn, WAIT_SEND); - } - } else { - poll_timer_wait((cc->backoff_deadline - time(0)) * 1000); } } diff --git a/switch/controller.h b/switch/controller.h index 4bf0c036..c3108e41 100644 --- a/switch/controller.h +++ b/switch/controller.h @@ -52,10 +52,12 @@ struct controller_connection { void controller_init(struct controller_connection *, const char *name, bool reliable); -void controller_run(struct controller_connection *, struct datapath *); +void controller_run(struct controller_connection *); +void controller_run_wait(struct controller_connection *); void controller_connect(struct controller_connection *); void controller_disconnect(struct controller_connection *, int error); -void controller_wait(struct controller_connection *); +struct buffer *controller_recv(struct controller_connection *); +void controller_recv_wait(struct controller_connection *); void controller_send(struct controller_connection *, struct buffer *); #endif /* controller.h */ diff --git a/switch/forward.c b/switch/forward.c index d9e0027d..908b4dfa 100644 --- a/switch/forward.c +++ b/switch/forward.c @@ -37,6 +37,7 @@ #include #include #include +#include "controller.h" #include "datapath.h" #include "chain.h" #include "flow.h" @@ -49,6 +50,27 @@ static void execute_actions(struct datapath *, struct buffer *, static struct buffer *retrieve_buffer(uint32_t id); static void discard_buffer(uint32_t id); +void +fwd_run(struct datapath *dp) +{ + int i; + + for (i = 0; i < 50; i++) { + struct buffer *buffer = controller_recv(dp->cc); + if (!buffer) { + break; + } + fwd_control_input(dp, buffer->data, buffer->size); + buffer_delete(buffer); + } +} + +void +fwd_run_wait(struct datapath *dp) +{ + controller_recv_wait(dp->cc); +} + /* 'buffer' was received on 'in_port', a physical switch port between 0 and * OFPP_MAX. Process it according to 'chain'. */ void fwd_port_input(struct datapath *dp, struct buffer *buffer, int in_port) diff --git a/switch/forward.h b/switch/forward.h index 465c8c27..cffbafc9 100644 --- a/switch/forward.h +++ b/switch/forward.h @@ -53,6 +53,8 @@ struct sw_flow_key; #define PKT_COOKIE_BITS (32 - PKT_BUFFER_BITS) +void fwd_run(struct datapath *); +void fwd_run_wait(struct datapath *); void fwd_port_input(struct datapath *, struct buffer *, int in_port); int fwd_control_input(struct datapath *, const void *, size_t); diff --git a/switch/switch.c b/switch/switch.c index 0c649554..cbdc9654 100644 --- a/switch/switch.c +++ b/switch/switch.c @@ -41,6 +41,7 @@ #include "controller.h" #include "datapath.h" #include "fault.h" +#include "forward.h" #include "openflow.h" #include "poll-loop.h" #include "queue.h" @@ -92,10 +93,13 @@ main(int argc, char *argv[]) } for (;;) { - controller_run(&cc, dp); dp_run(dp); + fwd_run(dp); + controller_run(&cc); + dp_wait(dp); - controller_wait(&cc); + fwd_run_wait(dp); + controller_run_wait(&cc); poll_block(); }