#include <errno.h>
#include <string.h>
#include "buffer.h"
-#include "forward.h"
#include "poll-loop.h"
#include "ofp-print.h"
#include "util.h"
}
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) {
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) {
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);
}
}
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);
}
}
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 */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include "controller.h"
#include "datapath.h"
#include "chain.h"
#include "flow.h"
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)
#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);
#include "controller.h"
#include "datapath.h"
#include "fault.h"
+#include "forward.h"
#include "openflow.h"
#include "poll-loop.h"
#include "queue.h"
}
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();
}