Skip to content

Commit

Permalink
Add "Manager" and "manager_options" to allow options for OVSDB connec…
Browse files Browse the repository at this point in the history
…tions.

I'm retaining the "managers" column in the Open_vSwitch table for now, but
I hope that applications transition to using "manager_options" eventually
so that we could drop it.

CC: Andrew Lambeth <[email protected]>
CC: Jeremy Stribling <[email protected]>
  • Loading branch information
blp committed Nov 5, 2010
1 parent 928ef38 commit 94db540
Show file tree
Hide file tree
Showing 12 changed files with 528 additions and 1,060 deletions.
13 changes: 13 additions & 0 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,16 @@ jsonrpc_session_force_reconnect(struct jsonrpc_session *s)
{
reconnect_force_reconnect(s->reconnect, time_msec());
}

void
jsonrpc_session_set_max_backoff(struct jsonrpc_session *s, int max_backoff)
{
reconnect_set_backoff(s->reconnect, 0, max_backoff);
}

void
jsonrpc_session_set_probe_interval(struct jsonrpc_session *s,
int probe_interval)
{
reconnect_set_probe_interval(s->reconnect, probe_interval);
}
5 changes: 5 additions & 0 deletions lib/jsonrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,9 @@ bool jsonrpc_session_is_connected(const struct jsonrpc_session *);
unsigned int jsonrpc_session_get_seqno(const struct jsonrpc_session *);
void jsonrpc_session_force_reconnect(struct jsonrpc_session *);

void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
int max_backofF);
void jsonrpc_session_set_probe_interval(struct jsonrpc_session *,
int probe_interval);

#endif /* jsonrpc.h */
61 changes: 53 additions & 8 deletions ovsdb/jsonrpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ static void ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_wait_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_set_all_options(
struct ovsdb_jsonrpc_remote *, const struct ovsdb_jsonrpc_options *);

/* Triggers. */
static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *,
Expand Down Expand Up @@ -88,8 +90,8 @@ struct ovsdb_jsonrpc_remote {
struct list sessions; /* List of "struct ovsdb_jsonrpc_session"s. */
};

static void ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *,
const char *name);
static struct ovsdb_jsonrpc_remote *ovsdb_jsonrpc_server_add_remote(
struct ovsdb_jsonrpc_server *, const char *name);
static void ovsdb_jsonrpc_server_del_remote(struct shash_node *);

struct ovsdb_jsonrpc_server *
Expand All @@ -114,8 +116,17 @@ ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
free(svr);
}

/* Sets 'svr''s current set of remotes to the names in 'new_remotes'. The data
* values in 'new_remotes' are ignored.
struct ovsdb_jsonrpc_options *
ovsdb_jsonrpc_default_options(void)
{
struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
options->probe_interval = RECONNECT_DEFAULT_PROBE_INTERVAL;
options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
return options;
}

/* Sets 'svr''s current set of remotes to the names in 'new_remotes', with
* options in the struct ovsdb_jsonrpc_options supplied as the data values.
*
* A remote is an active or passive stream connection method, e.g. "pssl:" or
* "tcp:1.2.3.4". */
Expand All @@ -131,13 +142,22 @@ ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
}
}
SHASH_FOR_EACH (node, new_remotes) {
if (!shash_find(&svr->remotes, node->name)) {
ovsdb_jsonrpc_server_add_remote(svr, node->name);
const struct ovsdb_jsonrpc_options *options = node->data;
struct ovsdb_jsonrpc_remote *remote;

remote = shash_find_data(&svr->remotes, node->name);
if (!remote) {
remote = ovsdb_jsonrpc_server_add_remote(svr, node->name);
if (!remote) {
continue;
}
}

ovsdb_jsonrpc_session_set_all_options(remote, options);
}
}

static void
static struct ovsdb_jsonrpc_remote *
ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
const char *name)
{
Expand All @@ -148,7 +168,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
error = jsonrpc_pstream_open(name, &listener);
if (error && error != EAFNOSUPPORT) {
VLOG_ERR_RL(&rl, "%s: listen failed: %s", name, strerror(error));
return;
return NULL;
}

remote = xmalloc(sizeof *remote);
Expand All @@ -160,6 +180,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
if (!listener) {
ovsdb_jsonrpc_session_create(remote, jsonrpc_session_open(name));
}
return remote;
}

static void
Expand Down Expand Up @@ -252,6 +273,8 @@ struct ovsdb_jsonrpc_session {
static void ovsdb_jsonrpc_session_close(struct ovsdb_jsonrpc_session *);
static int ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_wait(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_set_options(
struct ovsdb_jsonrpc_session *, const struct ovsdb_jsonrpc_options *);
static void ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *,
struct jsonrpc_msg *);
static void ovsdb_jsonrpc_session_got_notify(struct ovsdb_jsonrpc_session *,
Expand Down Expand Up @@ -318,6 +341,14 @@ ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
return jsonrpc_session_is_alive(s->js) ? 0 : ETIMEDOUT;
}

static void
ovsdb_jsonrpc_session_set_options(struct ovsdb_jsonrpc_session *session,
const struct ovsdb_jsonrpc_options *options)
{
jsonrpc_session_set_max_backoff(session->js, options->max_backoff);
jsonrpc_session_set_probe_interval(session->js, options->probe_interval);
}

static void
ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote)
{
Expand Down Expand Up @@ -375,6 +406,20 @@ ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote)
}
}

/* Sets the options for all of the JSON-RPC sessions managed by 'remote' to
* 'options'. */
static void
ovsdb_jsonrpc_session_set_all_options(
struct ovsdb_jsonrpc_remote *remote,
const struct ovsdb_jsonrpc_options *options)
{
struct ovsdb_jsonrpc_session *s;

LIST_FOR_EACH (s, node, &remote->sessions) {
ovsdb_jsonrpc_session_set_options(s, options);
}
}

static const char *
get_db_name(const struct ovsdb_jsonrpc_session *s)
{
Expand Down
7 changes: 7 additions & 0 deletions ovsdb/jsonrpc-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ struct shash;
struct ovsdb_jsonrpc_server *ovsdb_jsonrpc_server_create(struct ovsdb *);
void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *);

/* Options for a remote. */
struct ovsdb_jsonrpc_options {
int max_backoff; /* Maximum reconnection backoff, in msec. */
int probe_interval; /* Max idle time before probing, in msec. */
};
struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(void);

void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
const struct shash *);

Expand Down
30 changes: 25 additions & 5 deletions ovsdb/ovsdb-server.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,31 @@ Adds \fIremote\fR as a connection method used by \fBovsdb\-server\fR.
.
.IP "\fBdb:\fItable\fB,\fIcolumn\fR"
Reads additional connection methods from \fIcolumn\fR in all of the
rows in \fItable\fR within the \fBovsdb\-server\fR database. The
\fIcolumn\fR must have type string or set of strings. The connection
methods in the column must have one of the forms described above. As
the contents of \fIcolumn\fR changes, \fBovsdb\-server\fR also adds
and drops connection methods accordingly.
rows in \fItable\fR. As the contents of \fIcolumn\fR changes,
\fBovsdb\-server\fR also adds and drops connection methods
accordingly.
.IP
If \fIcolumn\fR's type is string or set of strings, then the
connection methods are taken directly from the column. The connection
methods in the column must have one of the forms described above.
.IP
If \fIcolumn\fR's type is UUID or set of UUIDs and references a table,
then each UUID is looked up in the referenced table to obtain a row.
The following columns in the row, if present and of the correct type,
configure a connection method. Any additional columns are ignored.
.RS
.IP "\fBtarget\fR (string)"
Connection method, in one of the forms described above. This column
is mandatory: if it is missing or empty then no connection method can
be configured.
.IP "\fBmax_backoff\fR (integer)"
Maximum number of milliseconds to wait between connection attempts.
.IP "\fBinactivity_probe\fR (integer)
Maximum number of milliseconds of idle time on connection to
client before sending an inactivity probe message.
.RE
.IP
It is an error for \fIcolumn\fR to have another type.
.RE
.
.IP "\fB\-\-run=\fIcommand\fR]"
Expand Down
Loading

0 comments on commit 94db540

Please sign in to comment.