}
rconn = rconn_create(5, 5);
- rconn_connect(rconn, argv[0]);
+ rconn_connect(rconn, argv[0], NULL);
die_if_already_running();
daemonize();
time_t state_entered;
struct vconn *vconn;
- char *name;
+ char *name; /* Human-readable descriptive name. */
+ char *target; /* vconn name, passed to vconn_open(). */
bool reliable;
struct ovs_queue txq;
static unsigned int timeout(const struct rconn *);
static bool timed_out(const struct rconn *);
static void state_transition(struct rconn *, enum state);
-static void set_vconn_name(struct rconn *, const char *name);
+static void rconn_set_target__(struct rconn *,
+ const char *target, const char *name);
static int try_send(struct rconn *);
static void reconnect(struct rconn *);
static void report_error(struct rconn *, int error);
rc->vconn = NULL;
rc->name = xstrdup("void");
+ rc->target = xstrdup("void");
rc->reliable = false;
queue_init(&rc->txq);
return rc->probe_interval;
}
+/* Drops any existing connection on 'rc', then sets up 'rc' to connect to
+ * 'target' and reconnect as needed. 'target' should be a remote OpenFlow
+ * target in a form acceptable to vconn_open().
+ *
+ * If 'name' is nonnull, then it is used in log messages in place of 'target'.
+ * It should presumably give more information to a human reader than 'target',
+ * but it need not be acceptable to vconn_open(). */
void
-rconn_connect(struct rconn *rc, const char *name)
+rconn_connect(struct rconn *rc, const char *target, const char *name)
{
rconn_disconnect(rc);
- set_vconn_name(rc, name);
+ rconn_set_target__(rc, target, name);
rc->reliable = true;
reconnect(rc);
}
+/* Drops any existing connection on 'rc', then configures 'rc' to use
+ * 'vconn'. If the connection on 'vconn' drops, 'rc' will not reconnect on it
+ * own.
+ *
+ * By default, the target obtained from vconn_get_name(vconn) is used in log
+ * messages. If 'name' is nonnull, then it is used instead. It should
+ * presumably give more information to a human reader than the target, but it
+ * need not be acceptable to vconn_open(). */
void
-rconn_connect_unreliably(struct rconn *rc, struct vconn *vconn)
+rconn_connect_unreliably(struct rconn *rc,
+ struct vconn *vconn, const char *name)
{
assert(vconn != NULL);
rconn_disconnect(rc);
- set_vconn_name(rc, vconn_get_name(vconn));
+ rconn_set_target__(rc, vconn_get_name(vconn), name);
rc->reliable = false;
rc->vconn = vconn;
rc->last_connected = time_now();
vconn_close(rc->vconn);
rc->vconn = NULL;
}
- set_vconn_name(rc, "void");
+ rconn_set_target__(rc, "void", NULL);
rc->reliable = false;
rc->backoff = 0;
size_t i;
free(rc->name);
+ free(rc->target);
vconn_close(rc->vconn);
flush_queue(rc);
queue_destroy(&rc->txq);
VLOG_INFO("%s: connecting...", rc->name);
rc->n_attempted_connections++;
- retval = vconn_open(rc->name, OFP_VERSION, &rc->vconn);
+ retval = vconn_open(rc->target, OFP_VERSION, &rc->vconn);
if (!retval) {
rc->remote_ip = vconn_get_remote_ip(rc->vconn);
rc->local_ip = vconn_get_local_ip(rc->vconn);
}
}
-/* Returns 'rc''s name (the 'name' argument passed to rconn_new()). */
+/* Returns 'rc''s name. This is a name for human consumption, appropriate for
+ * use in log messages. It is not necessarily a name that may be passed
+ * directly to, e.g., vconn_open(). */
const char *
rconn_get_name(const struct rconn *rc)
{
return rc->name;
}
+/* Sets 'rc''s name to 'new_name'. */
+void
+rconn_set_name(struct rconn *rc, const char *new_name)
+{
+ free(rc->name);
+ rc->name = xstrdup(new_name);
+}
+
+/* Returns 'rc''s target. This is intended to be a string that may be passed
+ * directly to, e.g., vconn_open(). */
+const char *
+rconn_get_target(const struct rconn *rc)
+{
+ return rc->target;
+}
+
/* Returns true if 'rconn' is connected or in the process of reconnecting,
* false if 'rconn' is disconnected and will not reconnect on its own. */
bool
}
}
\f
-/* Set the name of the remote vconn to 'name' and clear out the cached IP
- * address and port information, since changing the name also likely changes
- * these values. */
+/* Set rc->target and rc->name to 'target' and 'name', respectively. If 'name'
+ * is null, 'target' is used.
+ *
+ * Also, clear out the cached IP address and port information, since changing
+ * the target also likely changes these values. */
static void
-set_vconn_name(struct rconn *rc, const char *name)
+rconn_set_target__(struct rconn *rc, const char *target, const char *name)
{
free(rc->name);
- rc->name = xstrdup(name);
+ rc->name = xstrdup(name ? name : target);
+ free(rc->target);
+ rc->target = xstrdup(target);
rc->local_ip = 0;
rc->remote_ip = 0;
rc->remote_port = 0;
void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval);
int rconn_get_probe_interval(const struct rconn *);
-void rconn_connect(struct rconn *, const char *name);
-void rconn_connect_unreliably(struct rconn *, struct vconn *vconn);
+void rconn_connect(struct rconn *, const char *target, const char *name);
+void rconn_connect_unreliably(struct rconn *,
+ struct vconn *, const char *name);
void rconn_reconnect(struct rconn *);
void rconn_disconnect(struct rconn *);
void rconn_destroy(struct rconn *);
void rconn_add_monitor(struct rconn *, struct vconn *);
const char *rconn_get_name(const struct rconn *);
+void rconn_set_name(struct rconn *, const char *new_name);
+const char *rconn_get_target(const struct rconn *);
+
bool rconn_is_alive(const struct rconn *);
bool rconn_is_connected(const struct rconn *);
bool rconn_is_admitted(const struct rconn *);
static void ofconn_run(struct ofconn *, struct ofproto *);
static void ofconn_wait(struct ofconn *);
static bool ofconn_receives_async_msgs(const struct ofconn *);
+static char *ofconn_make_name(const struct ofproto *, const char *target);
static void queue_tx(struct ofpbuf *msg, const struct ofconn *ofconn,
struct rconn_packet_counter *counter);
if (discovery) {
ofconn->discovery = discovery;
} else {
- rconn_connect(ofconn->rconn, c->target);
+ char *name = ofconn_make_name(ofproto, c->target);
+ rconn_connect(ofconn->rconn, c->target, name);
+ free(name);
}
hmap_insert(&ofproto->controllers, &ofconn->hmap_node,
hash_string(c->target, 0));
static const char *
ofconn_get_target(const struct ofconn *ofconn)
{
- return ofconn->discovery ? "discover" : rconn_get_name(ofconn->rconn);
+ return ofconn->discovery ? "discover" : rconn_get_target(ofconn->rconn);
}
static struct ofconn *
retval = pvconn_accept(p->listeners[i], OFP_VERSION, &vconn);
if (!retval) {
struct rconn *rconn;
+ char *name;
rconn = rconn_create(60, 0);
- rconn_connect_unreliably(rconn, vconn);
+ name = ofconn_make_name(p, vconn_get_name(vconn));
+ rconn_connect_unreliably(rconn, vconn, name);
+ free(name);
+
ofconn_create(p, rconn, OFCONN_TRANSIENT);
} else if (retval != EAGAIN) {
VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
}
if (discovery_run(ofconn->discovery, &controller_name)) {
if (controller_name) {
- rconn_connect(ofconn->rconn, controller_name);
+ char *ofconn_name = ofconn_make_name(p, controller_name);
+ rconn_connect(ofconn->rconn, controller_name, ofconn_name);
+ free(ofconn_name);
} else {
rconn_disconnect(ofconn->rconn);
}
return ofconn->miss_send_len > 0;
}
}
+
+/* Returns a human-readable name for an OpenFlow connection between 'ofproto'
+ * and 'target', suitable for use in log messages for identifying the
+ * connection.
+ *
+ * The name is dynamically allocated. The caller should free it (with free())
+ * when it is no longer needed. */
+static char *
+ofconn_make_name(const struct ofproto *ofproto, const char *target)
+{
+ return xasprintf("%s<->%s", dpif_base_name(ofproto->dpif), target);
+}
\f
/* Caller is responsible for initializing the 'cr' member of the returned
* rule. */
uint32_t remote_ip = rconn_get_remote_ip(rconn);
uint32_t local_ip = rconn_get_local_ip(rconn);
- status_reply_put(sr, "name=%s", rconn_get_name(rconn));
+ status_reply_put(sr, "name=%s", rconn_get_target(rconn));
if (remote_ip) {
status_reply_put(sr, "remote-ip="IP_FMT, IP_ARGS(&remote_ip));
status_reply_put(sr, "remote-port=%d",
new_switch(struct switch_ *sw, struct vconn *vconn)
{
sw->rconn = rconn_create(60, 0);
- rconn_connect_unreliably(sw->rconn, vconn);
+ rconn_connect_unreliably(sw->rconn, vconn, NULL);
sw->lswitch = lswitch_create(sw->rconn, learn_macs, exact_flows,
set_up_flows ? max_idle : -1,
action_normal);