[ovs-dev] [PATCH] ofproto: Store time since last connect and disconnect in Controller table.

Andrew Evans aevans at nicira.com
Mon Mar 14 06:40:47 UTC 2011


ovs-vswitchd writes only the duration of its connection to or disconnection
from each controller to the database. This changes that behavior to write the
time since both the last connection and disconnection events regardless of
connection state. This mirrors the new behavior for reporting database manager
connection status.

Requested-by: Peter Balland <peter at nicira.com>
Bug #4833.
---
 lib/rconn.c       |   16 ++++++++++++++--
 lib/rconn.h       |    1 +
 ofproto/ofproto.c |   20 ++++++++++----------
 ofproto/ofproto.h |    4 ++--
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/lib/rconn.c b/lib/rconn.c
index 443690b..03dbd76 100644
--- a/lib/rconn.c
+++ b/lib/rconn.c
@@ -81,6 +81,7 @@ struct rconn {
     time_t backoff_deadline;
     time_t last_received;
     time_t last_connected;
+    time_t last_disconnected;
     unsigned int packets_sent;
     unsigned int seqno;
     int last_error;
@@ -188,7 +189,8 @@ rconn_create(int probe_interval, int max_backoff)
     rc->max_backoff = max_backoff ? max_backoff : 8;
     rc->backoff_deadline = TIME_MIN;
     rc->last_received = time_now();
-    rc->last_connected = time_now();
+    rc->last_connected = TIME_MIN;
+    rc->last_disconnected = TIME_MIN;
     rc->seqno = 0;
 
     rc->packets_sent = 0;
@@ -792,13 +794,21 @@ rconn_get_successful_connections(const struct rconn *rc)
 }
 
 /* Returns the time at which the last successful connection was made by
- * 'rc'. */
+ * 'rc'. Returns TIME_MIN if never connected. */
 time_t
 rconn_get_last_connection(const struct rconn *rc)
 {
     return rc->last_connected;
 }
 
+/* Returns the time at which 'rc' was last disconnected. Returns TIME_MIN
+ * if never disconnected. */
+time_t
+rconn_get_last_disconnect(const struct rconn *rc)
+{
+    return rc->last_disconnected;
+}
+
 /* Returns the time at which the last OpenFlow message was received by 'rc'.
  * If no packets have been received on 'rc', returns the time at which 'rc'
  * was created. */
@@ -980,6 +990,7 @@ disconnect(struct rconn *rc, int error)
         time_t now = time_now();
 
         if (rc->state & (S_CONNECTING | S_ACTIVE | S_IDLE)) {
+            rc->last_disconnected = time_now();
             vconn_close(rc->vconn);
             rc->vconn = NULL;
             flush_queue(rc);
@@ -1005,6 +1016,7 @@ disconnect(struct rconn *rc, int error)
             question_connectivity(rc);
         }
     } else {
+        rc->last_disconnected = time_now();
         rconn_disconnect(rc);
     }
 }
diff --git a/lib/rconn.h b/lib/rconn.h
index 47b211b..8579399 100644
--- a/lib/rconn.h
+++ b/lib/rconn.h
@@ -81,6 +81,7 @@ const char *rconn_get_state(const struct rconn *);
 unsigned int rconn_get_attempted_connections(const struct rconn *);
 unsigned int rconn_get_successful_connections(const struct rconn *);
 time_t rconn_get_last_connection(const struct rconn *);
+time_t rconn_get_last_disconnect(const struct rconn *);
 time_t rconn_get_last_received(const struct rconn *);
 time_t rconn_get_creation_time(const struct rconn *);
 unsigned long int rconn_get_total_time_connected(const struct rconn *);
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index c7872ba..89277ad 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1367,7 +1367,7 @@ ofproto_is_alive(const struct ofproto *p)
 }
 
 void
-ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
+ofproto_get_ofproto_controller_info(const struct ofproto *ofproto,
                                     struct shash *info)
 {
     const struct ofconn *ofconn;
@@ -1396,15 +1396,15 @@ ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
         cinfo->pairs.values[cinfo->pairs.n++] =
             xstrdup(rconn_get_state(rconn));
 
-        if (rconn_is_admitted(rconn)) {
-            cinfo->pairs.keys[cinfo->pairs.n] = "time_connected";
-            cinfo->pairs.values[cinfo->pairs.n++] =
-                xasprintf("%ld", time_now() - rconn_get_last_connection(rconn));
-        } else {
-            cinfo->pairs.keys[cinfo->pairs.n] = "time_disconnected";
-            cinfo->pairs.values[cinfo->pairs.n++] =
-                xasprintf("%d", rconn_failure_duration(rconn));
-        }
+        cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_connect";
+        cinfo->pairs.values[cinfo->pairs.n++] =
+            rconn_get_last_connection(rconn) == TIME_MIN ? xstrdup("")
+            : xasprintf("%ld", time_now() - rconn_get_last_connection(rconn));
+
+        cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_disconnect";
+        cinfo->pairs.values[cinfo->pairs.n++] =
+            rconn_get_last_disconnect(rconn) == TIME_MIN ? xstrdup("")
+            : xasprintf("%ld", time_now() - rconn_get_last_disconnect(rconn));
     }
 }
 
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 2828c64..a32b9b9 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -41,8 +41,8 @@ struct ofproto_controller_info {
     bool is_connected;
     enum nx_role role;
     struct {
-        const char *keys[3];
-        const char *values[3];
+        const char *keys[4];
+        const char *values[4];
         size_t n;
     } pairs;
 };
-- 
1.7.2.3




More information about the dev mailing list