bundle: New action "bundle_load".
[openvswitch] / ovsdb / jsonrpc-server.c
index 3edcfffbdaa2ecdc5f3d2c5e22c7fc913bfa3170..e999adafe5f84f79fdec6fccb253ff83c08b2756 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ struct ovsdb_jsonrpc_remote;
 struct ovsdb_jsonrpc_session;
 
 /* Message rate-limiting. */
-struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
 
 /* Sessions. */
 static struct ovsdb_jsonrpc_session *ovsdb_jsonrpc_session_create(
@@ -53,6 +53,9 @@ static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_set_all_options(
     struct ovsdb_jsonrpc_remote *, const struct ovsdb_jsonrpc_options *);
+static void ovsdb_jsonrpc_session_get_status(
+    const struct ovsdb_jsonrpc_remote *,
+    struct shash *);
 
 /* Triggers. */
 static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *,
@@ -138,6 +141,7 @@ ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
 
     SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
         if (!shash_find(new_remotes, node->name)) {
+            VLOG_INFO("%s: remote deconfigured", node->name);
             ovsdb_jsonrpc_server_del_remote(node);
         }
     }
@@ -194,6 +198,21 @@ ovsdb_jsonrpc_server_del_remote(struct shash_node *node)
     free(remote);
 }
 
+void
+ovsdb_jsonrpc_server_get_remote_status(const struct ovsdb_jsonrpc_server *svr,
+                                       struct shash *statuses)
+{
+    struct shash_node *node;
+
+    shash_init(statuses);
+
+    SHASH_FOR_EACH (node, &svr->remotes) {
+        const struct ovsdb_jsonrpc_remote *remote = node->data;
+
+        ovsdb_jsonrpc_session_get_status(remote, statuses);
+    }
+}
+
 /* Forces all of the JSON-RPC sessions managed by 'svr' to disconnect and
  * reconnect. */
 void
@@ -420,6 +439,44 @@ ovsdb_jsonrpc_session_set_all_options(
     }
 }
 
+static void
+ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote,
+                                 struct shash *shash)
+{
+    const struct ovsdb_jsonrpc_session *s;
+    const struct jsonrpc_session *js;
+    const char *name;
+    struct ovsdb_jsonrpc_remote_status *status;
+    struct reconnect_stats rstats;
+
+    /* We only look at the first session in the list. There should be only one
+     * node in the list for outbound connections. We don't track status for
+     * each individual inbound connection if someone configures the DB that
+     * way. Since outbound connections are the norm, this is fine. */
+    if (list_is_empty(&remote->sessions)) {
+        return;
+    }
+    s = CONTAINER_OF(remote->sessions.next, struct ovsdb_jsonrpc_session, node);
+    js = s->js;
+    if (!js) {
+        return;
+    }
+    name = jsonrpc_session_get_name(js);
+
+    status = xzalloc(sizeof *status);
+    shash_add(shash, name, status);
+
+    status->is_connected = jsonrpc_session_is_connected(js);
+    status->last_error = jsonrpc_session_get_status(js);
+
+    jsonrpc_session_get_reconnect_stats(js, &rstats);
+    status->state = rstats.state;
+    status->sec_since_connect = rstats.msec_since_connect == UINT_MAX
+        ? UINT_MAX : rstats.msec_since_connect / 1000;
+    status->sec_since_disconnect = rstats.msec_since_disconnect == UINT_MAX
+        ? UINT_MAX : rstats.msec_since_disconnect / 1000;
+}
+
 static const char *
 get_db_name(const struct ovsdb_jsonrpc_session *s)
 {