[ovs-dev] [PATCH 3/3] ovsdb: Use port 6632 as a default port for database connections.
Ben Pfaff
blp at nicira.com
Thu Mar 18 19:59:34 UTC 2010
Until now we have required a port number to be specified explicitly for
database connections. This commit adopts port 6632 as a default.
---
lib/jsonrpc.c | 20 +++++++++++++++++++-
lib/jsonrpc.h | 13 ++++++++++++-
ovsdb/SPECS | 2 ++
ovsdb/jsonrpc-server.c | 2 +-
ovsdb/ovsdb-client.c | 4 ++--
tests/test-jsonrpc.c | 6 +++---
tests/test-ovsdb.c | 3 ++-
7 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 5c7dfca..8be3f57 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -56,6 +56,24 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5);
static void jsonrpc_received(struct jsonrpc *);
static void jsonrpc_cleanup(struct jsonrpc *);
+/* This is just the same as stream_open() except that it uses the default
+ * JSONRPC ports if none is specified. */
+int
+jsonrpc_stream_open(const char *name, struct stream **streamp)
+{
+ return stream_open_with_default_ports(name, JSONRPC_TCP_PORT,
+ JSONRPC_SSL_PORT, streamp);
+}
+
+/* This is just the same as pstream_open() except that it uses the default
+ * JSONRPC ports if none is specified. */
+int
+jsonrpc_pstream_open(const char *name, struct pstream **pstreamp)
+{
+ return pstream_open_with_default_ports(name, JSONRPC_TCP_PORT,
+ JSONRPC_SSL_PORT, pstreamp);
+}
+
struct jsonrpc *
jsonrpc_open(struct stream *stream)
{
@@ -709,7 +727,7 @@ jsonrpc_session_connect(struct jsonrpc_session *s)
int error;
jsonrpc_session_disconnect(s);
- error = stream_open(reconnect_get_name(s->reconnect), &s->stream);
+ error = jsonrpc_stream_open(reconnect_get_name(s->reconnect), &s->stream);
if (error) {
reconnect_connect_failed(s->reconnect, time_msec(), error);
} else {
diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h
index ae8b9de..154c459 100644
--- a/lib/jsonrpc.h
+++ b/lib/jsonrpc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,21 @@
struct json;
struct jsonrpc_msg;
+struct pstream;
struct stream;
/* API for a JSON-RPC stream. */
+/* Default port numbers.
+ *
+ * There is nothing standard about these port numbers. They are simply what
+ * we have chosen. */
+#define JSONRPC_TCP_PORT 6632
+#define JSONRPC_SSL_PORT 6632
+
+int jsonrpc_stream_open(const char *name, struct stream **);
+int jsonrpc_pstream_open(const char *name, struct pstream **);
+
struct jsonrpc *jsonrpc_open(struct stream *);
void jsonrpc_close(struct jsonrpc *);
diff --git a/ovsdb/SPECS b/ovsdb/SPECS
index c926e21..cbd69de 100644
--- a/ovsdb/SPECS
+++ b/ovsdb/SPECS
@@ -251,6 +251,8 @@ over HTTP, for these reasons:
* The JSON-RPC specification for HTTP transport is incomplete.
+We are using TCP port 6632 for the database JSON-RPC connection.
+
The database wire protocol consists of the following JSON-RPC methods:
list_dbs
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 73c3c1c..84243d5 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -144,7 +144,7 @@ ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
struct pstream *listener;
int error;
- error = pstream_open(name, &listener);
+ error = jsonrpc_pstream_open(name, &listener);
if (error && error != EAFNOSUPPORT) {
VLOG_ERR_RL(&rl, "%s: listen failed: %s", name, strerror(error));
return;
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index a17c5aa..7a8310f 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -224,11 +224,11 @@ open_jsonrpc(const char *server)
struct stream *stream;
int error;
- error = stream_open_block(stream_open(server, &stream), &stream);
+ error = stream_open_block(jsonrpc_stream_open(server, &stream), &stream);
if (error == EAFNOSUPPORT) {
struct pstream *pstream;
- error = pstream_open(server, &pstream);
+ error = jsonrpc_pstream_open(server, &pstream);
if (error) {
ovs_fatal(error, "failed to connect or listen to \"%s\"", server);
}
diff --git a/tests/test-jsonrpc.c b/tests/test-jsonrpc.c
index f760b3c..d02a65f 100644
--- a/tests/test-jsonrpc.c
+++ b/tests/test-jsonrpc.c
@@ -185,7 +185,7 @@ do_listen(int argc OVS_UNUSED, char *argv[])
die_if_already_running();
- error = pstream_open(argv[1], &pstream);
+ error = jsonrpc_pstream_open(argv[1], &pstream);
if (error) {
ovs_fatal(error, "could not listen on \"%s\"", argv[1]);
}
@@ -274,7 +274,7 @@ do_request(int argc OVS_UNUSED, char *argv[])
ovs_fatal(0, "not a valid JSON-RPC request: %s", string);
}
- error = stream_open_block(stream_open(argv[1], &stream), &stream);
+ error = stream_open_block(jsonrpc_stream_open(argv[1], &stream), &stream);
if (error) {
ovs_fatal(error, "could not open \"%s\"", argv[1]);
}
@@ -313,7 +313,7 @@ do_notify(int argc OVS_UNUSED, char *argv[])
ovs_fatal(0, "not a JSON RPC-valid notification: %s", string);
}
- error = stream_open_block(stream_open(argv[1], &stream), &stream);
+ error = stream_open_block(jsonrpc_stream_open(argv[1], &stream), &stream);
if (error) {
ovs_fatal(error, "could not open \"%s\"", argv[1]);
}
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index 8cb6c94..41308d5 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -1764,7 +1764,8 @@ do_idl(int argc, char *argv[])
if (argc > 2) {
struct stream *stream;
- error = stream_open_block(stream_open(argv[1], &stream), &stream);
+ error = stream_open_block(jsonrpc_stream_open(argv[1], &stream),
+ &stream);
if (error) {
ovs_fatal(error, "failed to connect to \"%s\"", argv[1]);
}
--
1.6.6.1
More information about the dev
mailing list