[ovs-dev] [PATCH 5/5] bridge: Update device statistics in database when netdevs disappear.

Ben Pfaff blp at nicira.com
Thu Jul 29 23:06:12 UTC 2010


It is useful for network device statistics in the database to be accurate
at least when the devices are added to the database and just before they
are removed from the database.  Initial statistics are easy and they are
already implemented.  This commit implements final statistics, using the
netdev statistics now passed up by the netdev layer.

CC: Peter Balland <peter at nicira.com>
---
 vswitchd/bridge.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index b73405d..218dc28 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -190,7 +190,7 @@ static struct ovsdb_idl *idl;
 
 /* Each time this timer expires, the bridge fetches statistics for every
  * interface and pushes them into the database. */
-#define IFACE_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
+#define IFACE_STATS_INTERVAL (60 * 1000) /* In milliseconds. */
 static long long int iface_stats_timer = LLONG_MIN;
 
 static struct bridge *bridge_create(const struct ovsrec_bridge *br_cfg);
@@ -1068,7 +1068,7 @@ dpid_from_hash(const void *data, size_t n)
 }
 
 static void
-iface_refresh_stats(struct iface *iface)
+iface_refresh_stats__(struct iface *iface, const struct netdev_stats *stats)
 {
     struct iface_stat {
         char *name;
@@ -1095,15 +1095,9 @@ iface_refresh_stats(struct iface *iface)
     int64_t values[N_STATS];
     int n;
 
-    struct netdev_stats stats;
-
-    /* Intentionally ignore return value, since errors will set 'stats' to
-     * all-1s, and we will deal with that correctly below. */
-    netdev_get_stats(iface->netdev, &stats);
-
     n = 0;
     for (s = iface_stats; s < &iface_stats[N_STATS]; s++) {
-        uint64_t value = *(uint64_t *) (((char *) &stats) + s->offset);
+        uint64_t value = *(uint64_t *) (((char *) stats) + s->offset);
         if (value != UINT64_MAX) {
             keys[n] = s->name;
             values[n] = value;
@@ -1114,6 +1108,18 @@ iface_refresh_stats(struct iface *iface)
     ovsrec_interface_set_statistics(iface->cfg, keys, values, n);
 }
 
+static void
+iface_refresh_stats(struct iface *iface)
+{
+    struct netdev_stats stats;
+
+    /* Intentionally ignore return value, since errors will set 'stats' to
+     * all-1s, and we will deal with that correctly below. */
+    netdev_get_stats(iface->netdev, &stats);
+
+    iface_refresh_stats__(iface, &stats);
+}
+
 void
 bridge_run(void)
 {
@@ -2452,6 +2458,12 @@ bridge_port_changed_ofhook_cb(enum ofp_port_reason reason,
     port = iface->port;
 
     if (reason == OFPPR_DELETE) {
+        if (stats) {
+            struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl);
+            iface_refresh_stats__(iface, stats);
+            ovsdb_idl_txn_commit(txn);
+        }
+
         VLOG_WARN("bridge %s: interface %s deleted unexpectedly",
                   br->name, iface->name);
         iface_destroy(iface);
-- 
1.7.1





More information about the dev mailing list