aboutsummaryrefslogtreecommitdiff
path: root/lib/dpif.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-09-29 15:36:14 -0700
committerBen Pfaff <blp@nicira.com>2011-09-30 08:58:10 -0700
commit572b70687b27ef6fdd1ed90d1ac932d6de35701f (patch)
tree9d648b8dfbf7e0f06ea841154f02a667d8218ac6 /lib/dpif.c
parenta946b636edd932994a8972cf23168e4c08b21e8e (diff)
flow: Move flow_extract_stats() to dpif.c, as dpif_flow_stats_extract().
The "flow" module is concerned only with OpenFlow flows these days. It shouldn't have anything to do with ODP or dpifs. However, it included dpif.h just to implement flow_extract_stats(). This function is a better fit for dpif.c, so this commit moves it there and removes the dpif.h #include from flow.h and flow.c This commit also removes a few more dpif.h #includes that weren't needed.
Diffstat (limited to 'lib/dpif.c')
-rw-r--r--lib/dpif.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/dpif.c b/lib/dpif.c
index 2d21a9ff..82b60180 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -661,6 +661,26 @@ dpif_port_poll_wait(const struct dpif *dpif)
dpif->dpif_class->port_poll_wait(dpif);
}
+/* Extracts the flow stats for a packet. The 'flow' and 'packet'
+ * arguments must have been initialized through a call to flow_extract().
+ */
+void
+dpif_flow_stats_extract(const struct flow *flow, struct ofpbuf *packet,
+ struct dpif_flow_stats *stats)
+{
+ memset(stats, 0, sizeof(*stats));
+
+ if ((flow->dl_type == htons(ETH_TYPE_IP)) && packet->l4) {
+ if ((flow->nw_proto == IPPROTO_TCP) && packet->l7) {
+ struct tcp_header *tcp = packet->l4;
+ stats->tcp_flags = TCP_FLAGS(tcp->tcp_ctl);
+ }
+ }
+
+ stats->n_bytes = packet->size;
+ stats->n_packets = 1;
+}
+
/* Appends a human-readable representation of 'stats' to 's'. */
void
dpif_flow_stats_format(const struct dpif_flow_stats *stats, struct ds *s)