Use the IANA-assigned ports for OpenFlow and OVSDB.
[cascardo/ovs.git] / lib / jsonrpc.c
index 842d117..86531b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
 #include "reconnect.h"
 #include "stream.h"
 #include "timeval.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(jsonrpc);
 \f
@@ -46,7 +46,8 @@ struct jsonrpc {
     struct json_parser *parser;
 
     /* Output. */
-    struct list output;         /* Contains "struct ofpbuf"s. */
+    struct ovs_list output;     /* Contains "struct ofpbuf"s. */
+    size_t output_count;        /* Number of elements in "output". */
     size_t backlog;
 };
 
@@ -62,8 +63,7 @@ static void jsonrpc_error(struct jsonrpc *, int error);
 int
 jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp)
 {
-    return stream_open_with_default_port(name, OVSDB_OLD_PORT,
-                                         streamp, dscp);
+    return stream_open_with_default_port(name, OVSDB_PORT, streamp, dscp);
 }
 
 /* This is just the same as pstream_open() except that it uses the default
@@ -71,8 +71,7 @@ jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp)
 int
 jsonrpc_pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp)
 {
-    return pstream_open_with_default_port(name, OVSDB_OLD_PORT,
-                                          pstreamp, dscp);
+    return pstream_open_with_default_port(name, OVSDB_PORT, pstreamp, dscp);
 }
 
 /* Returns a new JSON-RPC stream that uses 'stream' for input and output.  The
@@ -118,12 +117,13 @@ jsonrpc_run(struct jsonrpc *rpc)
         struct ofpbuf *buf = ofpbuf_from_list(rpc->output.next);
         int retval;
 
-        retval = stream_send(rpc->stream, ofpbuf_data(buf), ofpbuf_size(buf));
+        retval = stream_send(rpc->stream, buf->data, buf->size);
         if (retval >= 0) {
             rpc->backlog -= retval;
             ofpbuf_pull(buf, retval);
-            if (!ofpbuf_size(buf)) {
+            if (!buf->size) {
                 list_remove(&buf->list_node);
+                rpc->output_count--;
                 ofpbuf_delete(buf);
             }
         } else {
@@ -255,10 +255,17 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
 
     buf = xmalloc(sizeof *buf);
     ofpbuf_use(buf, s, length);
-    ofpbuf_set_size(buf, length);
+    buf->size = length;
     list_push_back(&rpc->output, &buf->list_node);
+    rpc->output_count++;
     rpc->backlog += length;
 
+    if (rpc->output_count >= 50) {
+        VLOG_INFO_RL(&rl, "excessive sending backlog, jsonrpc: %s, num of"
+                     " msgs: %"PRIuSIZE", backlog: %"PRIuSIZE".", rpc->name,
+                     rpc->output_count, rpc->backlog);
+    }
+
     if (rpc->backlog == length) {
         jsonrpc_run(rpc);
     }
@@ -496,6 +503,7 @@ jsonrpc_cleanup(struct jsonrpc *rpc)
 
     ofpbuf_list_delete(&rpc->output);
     rpc->backlog = 0;
+    rpc->output_count = 0;
 }
 \f
 static struct jsonrpc_msg *
@@ -516,10 +524,10 @@ jsonrpc_create(enum jsonrpc_msg_type type, const char *method,
 static struct json *
 jsonrpc_create_id(void)
 {
-    static atomic_uint next_id = ATOMIC_VAR_INIT(0);
+    static atomic_count next_id = ATOMIC_COUNT_INIT(0);
     unsigned int id;
 
-    atomic_add(&next_id, 1, &id);
+    id = atomic_count_inc(&next_id);
     return json_integer_create(id);
 }
 
@@ -1124,21 +1132,9 @@ jsonrpc_session_set_dscp(struct jsonrpc_session *s,
                          uint8_t dscp)
 {
     if (s->dscp != dscp) {
-        if (s->pstream) {
-            int error;
+        pstream_close(s->pstream);
+        s->pstream = NULL;
 
-            error = pstream_set_dscp(s->pstream, dscp);
-            if (error) {
-                VLOG_ERR("%s: failed set_dscp %s",
-                         reconnect_get_name(s->reconnect),
-                         ovs_strerror(error));
-            }
-            /*
-             * XXX race window between setting dscp to listening socket
-             * and accepting socket. accepted socket may have old dscp value.
-             * Ignore this race window for now.
-             */
-        }
         s->dscp = dscp;
         jsonrpc_session_force_reconnect(s);
     }