From 2cdcb8983d9e2f3d690ee5cb62593c05898fb26e Mon Sep 17 00:00:00 2001 From: Andrew Evans Date: Mon, 14 Mar 2011 13:19:20 -0700 Subject: [PATCH] ofproto: Store time since last connect and disconnect in Controller table. 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 Bug #4833. --- lib/rconn.c | 16 ++++++++++++++-- lib/rconn.h | 1 + ofproto/ofproto.c | 23 ++++++++++++++--------- ofproto/ofproto.h | 4 ++-- vswitchd/vswitch.xml | 30 +++++++++++++++--------------- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/lib/rconn.c b/lib/rconn.c index 443690b8..6a86de6c 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 = 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 47b211b2..8579399d 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 c7872baf..147ade3a 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; @@ -1376,6 +1376,9 @@ ofproto_get_ofproto_controller_info(const struct ofproto * ofproto, HMAP_FOR_EACH (ofconn, hmap_node, &ofproto->controllers) { const struct rconn *rconn = ofconn->rconn; + time_t now = time_now(); + time_t last_connection = rconn_get_last_connection(rconn); + time_t last_disconnect = rconn_get_last_disconnect(rconn); const int last_error = rconn_get_last_error(rconn); struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo); @@ -1396,14 +1399,16 @@ 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)); + if (last_connection != TIME_MIN) { + cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_connect"; + cinfo->pairs.values[cinfo->pairs.n++] + = xasprintf("%ld", (long int) (now - last_connection)); + } + + if (last_disconnect != TIME_MIN) { + cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_disconnect"; + cinfo->pairs.values[cinfo->pairs.n++] + = xasprintf("%ld", (long int) (now - last_disconnect)); } } } diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h index 2828c645..a32b9b91 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; }; diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index b084884c..244b24e5 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -1897,15 +1897,11 @@
other
Allows the controller access to all OpenFlow features.
-
-
master
Equivalent to other, except that there may be at most one master controller at a time. When a controller configures itself as master, any existing master is demoted to the slaverole.
-
-
slave
Allows the controller read-only access to OpenFlow features. Attempts to modify the flow table will be rejected with an @@ -1922,19 +1918,23 @@
A human-readable description of the last error on the connection to the controller; i.e. strerror(errno). This key will exist only if an error has occurred.
-
-
state
The state of the connection to the controller. Possible values - are: VOID, BACKOFF, - CONNECTING, ACTIVE, and - IDLE.
-
-
-
time_in_state
-
Seconds since connecting to (if currently connected) or - disconnecting from (if currently disconnected) this - controller.
+ are: VOID (connection is disabled), + BACKOFF (attempting to reconnect at an increasing + period), CONNECTING (attempting to connect), + ACTIVE (connected, remote host responsive), and + IDLE (remote host idle, sending keep-alive). These + values may change in the future. They are provided only for human + consumption. +
sec_since_connect
+
The amount of time since this controller last successfully + connected to the switch (in seconds). Value is empty if controller + has never successfully connected.
+
sec_since_disconnect
+
The amount of time since this controller last disconnected from + the switch (in seconds). Value is empty if controller has never + disconnected.
-- 2.30.2