Skip to content

Commit

Permalink
ovsdb: enable jasonrpc-server to service monitor2 request
Browse files Browse the repository at this point in the history
ovsdb-server now accepts the new "monitor2" request. The next
patch will switch IDL to use monitor2 by default.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Dec 11, 2015
1 parent 52553ae commit 92f8d65
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Post-v2.5.0
---------------------

- ovsdb-server:
* New "monitor2" and "update2" extensions to RFC 7047.

v2.5.0 - xx xxx xxxx
---------------------
Expand Down
39 changes: 33 additions & 6 deletions ovsdb/jsonrpc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "timeval.h"
#include "transaction.h"
#include "trigger.h"
#include "monitor.h"
#include "openvswitch/vlog.h"

VLOG_DEFINE_THIS_MODULE(ovsdb_jsonrpc_server);
Expand Down Expand Up @@ -82,7 +81,7 @@ static void ovsdb_jsonrpc_trigger_complete_done(
/* Monitors. */
static struct jsonrpc_msg *ovsdb_jsonrpc_monitor_create(
struct ovsdb_jsonrpc_session *, struct ovsdb *, struct json *params,
const struct json *request_id);
enum ovsdb_monitor_version, const struct json *request_id);
static struct jsonrpc_msg *ovsdb_jsonrpc_monitor_cancel(
struct ovsdb_jsonrpc_session *,
struct json_array *params,
Expand Down Expand Up @@ -845,11 +844,15 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s,
if (!reply) {
reply = execute_transaction(s, db, request);
}
} else if (!strcmp(request->method, "monitor")) {
} else if (!strcmp(request->method, "monitor") ||
!strcmp(request->method, "monitor2")) {
struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply);
if (!reply) {
int l = strlen(request->method) - strlen("monitor");
enum ovsdb_monitor_version version = l ? OVSDB_MONITOR_V2
: OVSDB_MONITOR_V1;
reply = ovsdb_jsonrpc_monitor_create(s, db, request->params,
request->id);
version, request->id);
}
} else if (!strcmp(request->method, "monitor_cancel")) {
reply = ovsdb_jsonrpc_monitor_cancel(s, json_array(request->params),
Expand Down Expand Up @@ -1040,6 +1043,7 @@ struct ovsdb_jsonrpc_monitor {
struct ovsdb_monitor *dbmon;
uint64_t unflushed; /* The first transaction that has not been
flushed to the jsonrpc remote client. */
enum ovsdb_monitor_version version;
};

static struct ovsdb_jsonrpc_monitor *
Expand Down Expand Up @@ -1155,6 +1159,7 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_monitor *dbmon,
static struct jsonrpc_msg *
ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
struct json *params,
enum ovsdb_monitor_version version,
const struct json *request_id)
{
struct ovsdb_jsonrpc_monitor *m = NULL;
Expand Down Expand Up @@ -1186,6 +1191,7 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
m->db = db;
m->dbmon = ovsdb_monitor_create(db, m);
m->unflushed = 0;
m->version = version;
hmap_insert(&s->monitors, &m->node, json_hash(monitor_id, 0));
m->monitor_id = json_clone(monitor_id);

Expand Down Expand Up @@ -1296,7 +1302,7 @@ ovsdb_jsonrpc_monitor_compose_update(struct ovsdb_jsonrpc_monitor *m,
bool initial)
{
return ovsdb_monitor_get_update(m->dbmon, initial, &m->unflushed,
OVSDB_MONITOR_V1);
m->version);
}

static bool
Expand All @@ -1322,6 +1328,27 @@ ovsdb_jsonrpc_monitor_destroy(struct ovsdb_jsonrpc_monitor *m)
free(m);
}

static struct jsonrpc_msg *
ovsdb_jsonrpc_create_notify(const struct ovsdb_jsonrpc_monitor *m,
struct json *params)
{
const char *method;

switch(m->version) {
case OVSDB_MONITOR_V1:
method = "update";
break;
case OVSDB_MONITOR_V2:
method = "update2";
break;
case OVSDB_MONITOR_VERSION_MAX:
default:
OVS_NOT_REACHED();
}

return jsonrpc_create_notify(method, params);
}

static void
ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *s)
{
Expand All @@ -1336,7 +1363,7 @@ ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *s)
struct json *params;

params = json_array_create_2(json_clone(m->monitor_id), json);
msg = jsonrpc_create_notify("update", params);
msg = ovsdb_jsonrpc_create_notify(m, params);
jsonrpc_session_send(s->js, msg);
}
}
Expand Down

0 comments on commit 92f8d65

Please sign in to comment.