#include <config.h>
#include "rconn.h"
-#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
static void report_error(struct rconn *, int error);
static void disconnect(struct rconn *, int error);
static void flush_queue(struct rconn *);
+static void close_monitor(struct rconn *, size_t idx, int retval);
static void copy_to_monitor(struct rconn *, const struct ofpbuf *);
static bool is_connected_state(enum state);
static bool is_admitted_msg(const struct ofpbuf *);
rconn_connect_unreliably(struct rconn *rc,
struct vconn *vconn, const char *name)
{
- assert(vconn != NULL);
+ ovs_assert(vconn != NULL);
rconn_disconnect(rc);
rconn_set_target__(rc, vconn_get_name(vconn), name);
rc->reliable = false;
rc->name, (unsigned int) (time_now() - base));
version = rconn_get_version(rc);
- assert(version >= 0 && version <= 0xff);
+ ovs_assert(version >= 0 && version <= 0xff);
/* Ordering is important here: rconn_send() can transition to BACKOFF,
* and we don't want to transition back to IDLE if so, because then we
if (rc->vconn) {
vconn_run(rc->vconn);
}
- for (i = 0; i < rc->n_monitors; i++) {
+ for (i = 0; i < rc->n_monitors; ) {
+ struct ofpbuf *msg;
+ int retval;
+
vconn_run(rc->monitors[i]);
+
+ /* Drain any stray message that came in on the monitor connection. */
+ retval = vconn_recv(rc->monitors[i], &msg);
+ if (!retval) {
+ ofpbuf_delete(msg);
+ } else if (retval != EAGAIN) {
+ close_monitor(rc, i, retval);
+ continue;
+ }
+ i++;
}
do {
}
for (i = 0; i < rc->n_monitors; i++) {
vconn_run_wait(rc->monitors[i]);
+ vconn_recv_wait(rc->monitors[i]);
}
timeo = timeout(rc);
rconn_send_with_limit(struct rconn *rc, struct ofpbuf *b,
struct rconn_packet_counter *counter, int queue_limit)
{
- int retval;
- retval = (counter->n_packets >= queue_limit
- ? EAGAIN
- : rconn_send(rc, b, counter));
- if (retval) {
+ if (counter->n_packets < queue_limit) {
+ return rconn_send(rc, b, counter);
+ } else {
COVERAGE_INC(rconn_overflow);
+ ofpbuf_delete(b);
+ return EAGAIN;
}
- return retval;
}
/* Returns the total number of packets successfully sent on the underlying
rconn_add_monitor(struct rconn *rc, struct vconn *vconn)
{
if (rc->n_monitors < ARRAY_SIZE(rc->monitors)) {
- int version = vconn_get_version(rc->vconn);
-
- /* Override the allowed versions of the snoop vconn so that
- * only the version of the controller connection is allowed.
- * This is because the snoop will see the same messages as the
- * controller */
- vconn_set_allowed_versions(vconn, 1u << version);
-
VLOG_INFO("new monitor connection from %s", vconn_get_name(vconn));
rc->monitors[rc->n_monitors++] = vconn;
} else {
rconn_packet_counter_destroy(struct rconn_packet_counter *c)
{
if (c) {
- assert(c->ref_cnt > 0);
+ ovs_assert(c->ref_cnt > 0);
if (!--c->ref_cnt && !c->n_packets) {
free(c);
}
void
rconn_packet_counter_dec(struct rconn_packet_counter *c, unsigned int n_bytes)
{
- assert(c->n_packets > 0);
- assert(c->n_bytes >= n_bytes);
+ ovs_assert(c->n_packets > 0);
+ ovs_assert(c->n_bytes >= n_bytes);
c->n_bytes -= n_bytes;
c->n_packets--;
if (!c->n_packets) {
- assert(!c->n_bytes);
+ ovs_assert(!c->n_bytes);
if (!c->ref_cnt) {
free(c);
}
rc->state_entered = time_now();
}
+static void
+close_monitor(struct rconn *rc, size_t idx, int retval)
+{
+ VLOG_DBG("%s: closing monitor connection to %s: %s",
+ rconn_get_name(rc), vconn_get_name(rc->monitors[idx]),
+ ovs_retval_to_string(retval));
+ rc->monitors[idx] = rc->monitors[--rc->n_monitors];
+}
+
static void
copy_to_monitor(struct rconn *rc, const struct ofpbuf *b)
{
if (!retval) {
clone = NULL;
} else if (retval != EAGAIN) {
- VLOG_DBG("%s: closing monitor connection to %s: %s",
- rconn_get_name(rc), vconn_get_name(vconn),
- strerror(retval));
- rc->monitors[i] = rc->monitors[--rc->n_monitors];
+ close_monitor(rc, i, retval);
continue;
}
i++;