[ovs-dev] [packet_in 06/13] ofp-print: Print checksum in ofp_packet_to_string().

Ethan Jackson ethan at nicira.com
Thu Dec 29 01:52:33 UTC 2011


This will improve the unit tests of future patches.
---
 lib/ofp-print.c    |   13 +++++++++++++
 tests/ofp-print.at |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 0417e9d..37c5823 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -60,6 +60,19 @@ ofp_packet_to_string(const void *data, size_t len)
     ofpbuf_use_const(&buf, data, len);
     flow_extract(&buf, 0, 0, 0, &flow);
     flow_format(&ds, &flow);
+
+    if (buf.l7) {
+        if (flow.nw_proto == IPPROTO_TCP) {
+            struct tcp_header *th = buf.l4;
+            ds_put_format(&ds, " tcp_csum:%"PRIx16,
+                          ntohs(th->tcp_csum));
+        } else if (flow.nw_proto == IPPROTO_UDP) {
+            struct udp_header *uh = buf.l4;
+            ds_put_format(&ds, " udp_csum:%"PRIx16,
+                          ntohs(uh->udp_csum));
+        }
+    }
+
     ds_put_char(&ds, '\n');
 
     return ds_cstr(&ds);
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index 3f764a4..d7368d9 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -237,7 +237,7 @@ dnl The tcpdump output format differs slightly from one version to another,
 dnl so trim off the end of the line where differences appear.
 AT_CHECK([cat stdout], [0], [dnl
 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=3 data_len=60 buffer=0x00000111
-priority:0,tunnel:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:06) type:0800 proto:6 tos:0 ttl:64 ip(192.168.0.1->192.168.0.2) port(10031->0)
+priority:0,tunnel:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:06) type:0800 proto:6 tos:0 ttl:64 ip(192.168.0.1->192.168.0.2) port(10031->0) tcp_csum:26e8
 ])
 AT_CLEANUP
 
-- 
1.7.7.1




More information about the dev mailing list