dpif: Include TCP flags in "ovs-dpctl dump-flows" output.
authorBen Pfaff <blp@nicira.com>
Thu, 5 Apr 2012 17:24:56 +0000 (10:24 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 19 Apr 2012 03:28:40 +0000 (20:28 -0700)
Signed-off-by: Ben Pfaff <blp@nicira.com>
NEWS
lib/dpif.c
lib/packets.c
lib/packets.h
tests/test-netflow.c

diff --git a/NEWS b/NEWS
index ac00335..9c73352 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,7 +11,7 @@ post-v1.6.0
     - ovs-test:
         - Added support for spawning ovs-test server from the client.
         - Now ovs-test is able to automatically create test bridges and ports.
-
+    - "ovs-dpctl dump-flows" now prints observed TCP flags in TCP flows.
 
 
 v1.6.0 - xx xxx xxxx
index 35df1e5..e000e13 100644 (file)
@@ -697,7 +697,10 @@ dpif_flow_stats_format(const struct dpif_flow_stats *stats, struct ds *s)
     } else {
         ds_put_format(s, "never");
     }
-    /* XXX tcp_flags? */
+    if (stats->tcp_flags) {
+        ds_put_cstr(s, ", flags:");
+        packet_format_tcp_flags(s, stats->tcp_flags);
+    }
 }
 
 /* Deletes all flows from 'dpif'.  Returns 0 if successful, otherwise a
index 8fb7f6b..cd9227b 100644 (file)
@@ -496,3 +496,40 @@ packet_get_tcp_flags(const struct ofpbuf *packet, const struct flow *flow)
         return 0;
     }
 }
+
+/* Appends a string representation of the TCP flags value 'tcp_flags'
+ * (e.g. obtained via packet_get_tcp_flags() or TCP_FLAGS) to 's', in the
+ * format used by tcpdump. */
+void
+packet_format_tcp_flags(struct ds *s, uint8_t tcp_flags)
+{
+    if (!tcp_flags) {
+        ds_put_cstr(s, "none");
+        return;
+    }
+
+    if (tcp_flags & TCP_SYN) {
+        ds_put_char(s, 'S');
+    }
+    if (tcp_flags & TCP_FIN) {
+        ds_put_char(s, 'F');
+    }
+    if (tcp_flags & TCP_PSH) {
+        ds_put_char(s, 'P');
+    }
+    if (tcp_flags & TCP_RST) {
+        ds_put_char(s, 'R');
+    }
+    if (tcp_flags & TCP_URG) {
+        ds_put_char(s, 'U');
+    }
+    if (tcp_flags & TCP_ACK) {
+        ds_put_char(s, '.');
+    }
+    if (tcp_flags & 0x40) {
+        ds_put_cstr(s, "[40]");
+    }
+    if (tcp_flags & 0x80) {
+        ds_put_cstr(s, "[80]");
+    }
+}
index 34a8b4e..dc71b05 100644 (file)
@@ -470,5 +470,6 @@ void packet_set_tcp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst);
 void packet_set_udp_port(struct ofpbuf *, ovs_be16 src, ovs_be16 dst);
 
 uint8_t packet_get_tcp_flags(const struct ofpbuf *, const struct flow *);
+void packet_format_tcp_flags(struct ds *, uint8_t);
 
 #endif /* packets.h */
index 7d02887..5f30c63 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "command-line.h"
 #include "daemon.h"
+#include "dynamic-string.h"
 #include "netflow.h"
 #include "ofpbuf.h"
 #include "packets.h"
@@ -87,31 +88,10 @@ print_netflow(struct ofpbuf *buf)
             printf(", TCP %"PRIu16" > %"PRIu16,
                    ntohs(rec->src_port), ntohs(rec->dst_port));
             if (rec->tcp_flags) {
-                putchar(' ');
-                if (rec->tcp_flags & TCP_SYN) {
-                    putchar('S');
-                }
-                if (rec->tcp_flags & TCP_FIN) {
-                    putchar('F');
-                }
-                if (rec->tcp_flags & TCP_PSH) {
-                    putchar('P');
-                }
-                if (rec->tcp_flags & TCP_RST) {
-                    putchar('R');
-                }
-                if (rec->tcp_flags & TCP_URG) {
-                    putchar('U');
-                }
-                if (rec->tcp_flags & TCP_ACK) {
-                    putchar('.');
-                }
-                if (rec->tcp_flags & 0x40) {
-                    printf("[40]");
-                }
-                if (rec->tcp_flags & 0x80) {
-                    printf("[80]");
-                }
+                struct ds s = DS_EMPTY_INITIALIZER;
+                packet_format_tcp_flags(&s, rec->tcp_flags);
+                printf(" %s", ds_cstr(&s));
+                ds_destroy(&s);
             }
             break;