/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <config.h>
#include "rconn.h"
-#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#define MAX_MONITORS 8
struct vconn *monitors[8];
size_t n_monitors;
+
+ uint32_t allowed_versions;
};
+uint32_t rconn_get_allowed_versions(const struct rconn *rconn)
+{
+ return rconn->allowed_versions;
+}
+
static unsigned int elapsed_in_this_state(const struct rconn *);
static unsigned int timeout(const struct rconn *);
static bool timed_out(const struct rconn *);
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 *);
* 8 seconds is used.
*
* The new rconn is initially unconnected. Use rconn_connect() or
- * rconn_connect_unreliably() to connect it. */
+ * rconn_connect_unreliably() to connect it.
+ *
+ * Connections made by the rconn will automatically negotiate an OpenFlow
+ * protocol version acceptable to both peers on the connection. The version
+ * negotiated will be one of those in the 'allowed_versions' bitmap: version
+ * 'x' is allowed if allowed_versions & (1 << x) is nonzero. (The underlying
+ * vconn will treat an 'allowed_versions' of 0 as OFPUTIL_DEFAULT_VERSIONS.)
+ */
struct rconn *
-rconn_create(int probe_interval, int max_backoff, uint8_t dscp)
+rconn_create(int probe_interval, int max_backoff, uint8_t dscp,
+ uint32_t allowed_versions)
{
struct rconn *rc = xzalloc(sizeof *rc);
rconn_set_dscp(rc, dscp);
rc->n_monitors = 0;
+ rc->allowed_versions = allowed_versions;
return rc;
}
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;
VLOG_INFO("%s: connecting...", rc->name);
}
rc->n_attempted_connections++;
- retval = vconn_open(rc->target, OFP10_VERSION, &rc->vconn, rc->dscp);
+ retval = vconn_open(rc->target, rc->allowed_versions, rc->dscp,
+ &rc->vconn);
if (!retval) {
rc->remote_ip = vconn_get_remote_ip(rc->vconn);
rc->local_ip = vconn_get_local_ip(rc->vconn);
rc->backoff_deadline = time_now() + rc->backoff;
state_transition(rc, S_CONNECTING);
} else {
- VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval));
+ VLOG_WARN("%s: connection failed (%s)",
+ rc->name, ovs_strerror(retval));
rc->backoff_deadline = TIME_MAX; /* Prevent resetting backoff. */
disconnect(rc, retval);
}
} else if (retval != EAGAIN) {
if (rconn_logging_connection_attempts__(rc)) {
VLOG_INFO("%s: connection failed (%s)",
- rc->name, strerror(retval));
+ rc->name, ovs_strerror(retval));
}
disconnect(rc, retval);
} else if (timed_out(rc)) {
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_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);
}
enum vlog_level level = rc->reliable ? VLL_INFO : VLL_DBG;
VLOG(level, "%s: connection closed by peer", rc->name);
} else {
- VLOG_WARN("%s: connection dropped (%s)", rc->name, strerror(error));
+ VLOG_WARN("%s: connection dropped (%s)",
+ rc->name, ovs_strerror(error));
}
}
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++;
case OFPTYPE_GET_CONFIG_REQUEST:
case OFPTYPE_GET_CONFIG_REPLY:
case OFPTYPE_SET_CONFIG:
+ /* FIXME: Change the following once they are implemented: */
+ case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
+ case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
+ case OFPTYPE_GET_ASYNC_REQUEST:
+ case OFPTYPE_GET_ASYNC_REPLY:
+ case OFPTYPE_GROUP_STATS_REQUEST:
+ case OFPTYPE_GROUP_STATS_REPLY:
+ case OFPTYPE_GROUP_DESC_STATS_REQUEST:
+ case OFPTYPE_GROUP_DESC_STATS_REPLY:
+ case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
+ case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
+ case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
+ case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
return false;
case OFPTYPE_PACKET_IN:
case OFPTYPE_PACKET_OUT:
case OFPTYPE_FLOW_MOD:
case OFPTYPE_PORT_MOD:
+ case OFPTYPE_METER_MOD:
case OFPTYPE_BARRIER_REQUEST:
case OFPTYPE_BARRIER_REPLY:
case OFPTYPE_DESC_STATS_REQUEST:
case OFPTYPE_QUEUE_STATS_REPLY:
case OFPTYPE_PORT_DESC_STATS_REQUEST:
case OFPTYPE_PORT_DESC_STATS_REPLY:
+ case OFPTYPE_METER_STATS_REQUEST:
+ case OFPTYPE_METER_STATS_REPLY:
+ case OFPTYPE_METER_CONFIG_STATS_REQUEST:
+ case OFPTYPE_METER_CONFIG_STATS_REPLY:
+ case OFPTYPE_METER_FEATURES_STATS_REQUEST:
+ case OFPTYPE_METER_FEATURES_STATS_REPLY:
case OFPTYPE_ROLE_REQUEST:
case OFPTYPE_ROLE_REPLY:
case OFPTYPE_SET_FLOW_FORMAT: