[ovs-dev] [PATCH] dpif: Avoid use of "struct ovs_dp_stats" in platform-independent modules.

Ben Pfaff blp at nicira.com
Tue Oct 4 21:17:46 UTC 2011


Over time we wish to reduce the number of datapath-protocol.h definitions
used directly outside of Linux-specific code.  This commit removes use of
"struct ovs_dp_stats" from platform-independent code.
---
 lib/dpif-linux.c       |    9 +++++++--
 lib/dpif-netdev.c      |    2 +-
 lib/dpif-provider.h    |    2 +-
 lib/dpif.c             |    2 +-
 lib/dpif.h             |   11 ++++++++++-
 ofproto/ofproto-dpif.c |    2 +-
 utilities/ovs-dpctl.c  |   14 +++++++-------
 7 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index c104dfd..9414dec 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -330,7 +330,7 @@ dpif_linux_wait(struct dpif *dpif OVS_UNUSED)
 }
 
 static int
-dpif_linux_get_stats(const struct dpif *dpif_, struct ovs_dp_stats *stats)
+dpif_linux_get_stats(const struct dpif *dpif_, struct dpif_dp_stats *stats)
 {
     struct dpif_linux_dp dp;
     struct ofpbuf *buf;
@@ -338,7 +338,12 @@ dpif_linux_get_stats(const struct dpif *dpif_, struct ovs_dp_stats *stats)
 
     error = dpif_linux_dp_get(dpif_, &dp, &buf);
     if (!error) {
-        *stats = dp.stats;
+        memset(stats, 0, sizeof *stats);
+        stats->n_frags  = dp.stats.n_frags;
+        stats->n_hit    = dp.stats.n_hit;
+        stats->n_missed = dp.stats.n_missed;
+        stats->n_lost   = dp.stats.n_lost;
+        stats->n_flows  = dp.stats.n_flows;
         ofpbuf_delete(buf);
     }
     return error;
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 191cd1b..a5f4151 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -297,7 +297,7 @@ dpif_netdev_destroy(struct dpif *dpif)
 }
 
 static int
-dpif_netdev_get_stats(const struct dpif *dpif, struct ovs_dp_stats *stats)
+dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
 {
     struct dp_netdev *dp = get_dp_netdev(dpif);
     memset(stats, 0, sizeof *stats);
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index ff7e3eb..8cdedcd 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -108,7 +108,7 @@ struct dpif_class {
     void (*wait)(struct dpif *dpif);
 
     /* Retrieves statistics for 'dpif' into 'stats'. */
-    int (*get_stats)(const struct dpif *dpif, struct ovs_dp_stats *stats);
+    int (*get_stats)(const struct dpif *dpif, struct dpif_dp_stats *stats);
 
     /* Retrieves 'dpif''s current treatment of IP fragments into '*drop_frags':
      * true indicates that fragments are dropped, false indicates that
diff --git a/lib/dpif.c b/lib/dpif.c
index eec761a..aae0ffe 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -378,7 +378,7 @@ dpif_delete(struct dpif *dpif)
 /* Retrieves statistics for 'dpif' into 'stats'.  Returns 0 if successful,
  * otherwise a positive errno value. */
 int
-dpif_get_dp_stats(const struct dpif *dpif, struct ovs_dp_stats *stats)
+dpif_get_dp_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
 {
     int error = dpif->dpif_class->get_stats(dpif, stats);
     if (error) {
diff --git a/lib/dpif.h b/lib/dpif.h
index 1f1913a..f7ffbce 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -59,7 +59,16 @@ const char *dpif_base_name(const struct dpif *);
 
 int dpif_delete(struct dpif *);
 
-int dpif_get_dp_stats(const struct dpif *, struct ovs_dp_stats *);
+/* Statisticss for a dpif as a whole. */
+struct dpif_dp_stats {
+    uint64_t n_frags;           /* Number of dropped IP fragments. */
+    uint64_t n_hit;             /* Number of flow table matches. */
+    uint64_t n_missed;          /* Number of flow table misses. */
+    uint64_t n_lost;            /* Number of misses not sent to userspace. */
+    uint64_t n_flows;           /* Number of flows present. */
+};
+int dpif_get_dp_stats(const struct dpif *, struct dpif_dp_stats *);
+
 int dpif_get_drop_frags(const struct dpif *, bool *drop_frags);
 int dpif_set_drop_frags(struct dpif *, bool drop_frags);
 
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 3c00544..f24cafd 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -710,7 +710,7 @@ static void
 get_tables(struct ofproto *ofproto_, struct ofp_table_stats *ots)
 {
     struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
-    struct ovs_dp_stats s;
+    struct dpif_dp_stats s;
 
     strcpy(ots->name, "classifier");
 
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index e724e74..4d0d3c2 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -366,17 +366,17 @@ show_dpif(struct dpif *dpif)
 {
     struct dpif_port_dump dump;
     struct dpif_port dpif_port;
-    struct ovs_dp_stats stats;
+    struct dpif_dp_stats stats;
     struct netdev *netdev;
 
     printf("%s:\n", dpif_name(dpif));
     if (!dpif_get_dp_stats(dpif, &stats)) {
-        printf("\tlookups: frags:%llu, hit:%llu, missed:%llu, lost:%llu\n",
-               (unsigned long long int) stats.n_frags,
-               (unsigned long long int) stats.n_hit,
-               (unsigned long long int) stats.n_missed,
-               (unsigned long long int) stats.n_lost);
-        printf("\tflows: %llu\n", (unsigned long long int)stats.n_flows);
+        printf("\tlookups: frags:%"PRIu64, stats.n_frags);
+        printf(" hit:%"PRIu64, stats.n_hit);
+        printf(" missed:%"PRIu64, stats.n_missed);
+        printf(" lost:%"PRIu64"\n", stats.n_lost);
+
+        printf("\tflows: %"PRIu64"\n", stats.n_flows);
     }
     DPIF_PORT_FOR_EACH (&dpif_port, &dump, dpif) {
         printf("\tport %u: %s", dpif_port.port_no, dpif_port.name);
-- 
1.7.4.4




More information about the dev mailing list