[ovs-dev,mointor2,6/9] ovsdb: enable jasonrpc-server to service monitor2 request
diff mbox

Message ID 1445489131-21483-6-git-send-email-azhou@nicira.com
State Changes Requested
Headers show

Commit Message

Andy Zhou Oct. 22, 2015, 4:45 a.m. UTC
ovsdb-server now accepts the new "monitor2" request. The next
patch will switch IDL to use monitor2 by default.

Signed-off-by: Andy Zhou <azhou@nicira.com>
---
 NEWS                   |  1 +
 ovsdb/jsonrpc-server.c | 39 +++++++++++++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 6 deletions(-)

Patch
diff mbox

diff --git a/NEWS b/NEWS
index 9b9dff2..19e4409 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@  Post-v2.4.0
    - Add support for connection tracking through the new "ct" action
      and "ct_state"/"ct_zone"/"ct_mark"/"ct_label" match fields.  Only
      available on Linux kernels with the connection tracking module loaded.
+   - Add "monitor2" and "update2", which are RFC 7047 extions.
 
 
 v2.4.0 - 20 Aug 2015
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 729b368..53c97cd 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -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);
@@ -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,
@@ -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),
@@ -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 *
@@ -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;
@@ -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);
 
@@ -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
@@ -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)
 {
@@ -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);
         }
     }