On Wed, Oct 21, 2015 at 09:45:28PM -0700, Andy Zhou wrote:
> ovsdb-server now accepts the new "monitor2" request. The next
> patch will switch IDL to use monitor2 by default.
> 
> Signed-off-by: Andy Zhou <az...@nicira.com>

I think that the NEWS item can be clearer and that the jsonrpc-code can
be a little cleaner:

diff --git a/NEWS b/NEWS
index 3bac6e3..8b28ad9 100644
--- a/NEWS
+++ b/NEWS
@@ -28,7 +28,8 @@ 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.
+   - ovsdb-server:
+     * New "monitor2" and "update2" extensions to RFC 7047.
 
 
 v2.4.0 - 20 Aug 2015
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 53c97cd..0ea42b6 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -833,6 +833,20 @@ execute_transaction(struct ovsdb_jsonrpc_session *s, 
struct ovsdb *db,
     return NULL;
 }
 
+static struct jsonrpc_msg *
+ovsdb_jsonrpc_session_handle_monitor(struct ovsdb_jsonrpc_session *s,
+                                     struct jsonrpc_msg *request,
+                                     enum ovsdb_monitor_version version)
+{
+    struct jsonrpc_msg *reply;
+    struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply);
+    if (!reply) {
+        reply = ovsdb_jsonrpc_monitor_create(s, db, request->params,
+                                             version, request->id);
+    }
+    return reply;
+}
+
 static void
 ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s,
                                   struct jsonrpc_msg *request)
@@ -844,16 +858,12 @@ ovsdb_jsonrpc_session_got_request(struct 
ovsdb_jsonrpc_session *s,
         if (!reply) {
             reply = execute_transaction(s, db, request);
         }
-    } 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,
-                                                 version, request->id);
-        }
+    } else if (!strcmp(request->method, "monitor")) {
+        reply = ovsdb_jsonrpc_session_handle_monitor(s, request,
+                                                     OVSDB_MONITOR_V1);
+    } else if (!strcmp(request->method, "monitor2")) {
+        reply = ovsdb_jsonrpc_session_handle_monitor(s, request,
+                                                     OVSDB_MONITOR_V2);
     } else if (!strcmp(request->method, "monitor_cancel")) {
         reply = ovsdb_jsonrpc_monitor_cancel(s, json_array(request->params),
                                              request->id);
@@ -1332,20 +1342,7 @@ 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();
-    }
-
+    const char *method = m->version == OVSDB_MONITOR_V1 ? "update" : "update2";
     return jsonrpc_create_notify(method, params);
 }
 


Acked-by: Ben Pfaff <b...@ovn.org>
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to