From e50abca5be5f0682012f6c0ef9b010708e56be07 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Tue, 20 Dec 2011 19:56:43 -0800 Subject: [PATCH] ofp-print: Print checksum in ofp_packet_to_string(). This will improve the unit tests of future patches. Signed-off-by: Ethan Jackson --- lib/ofp-print.c | 13 +++++++++++++ tests/ofp-print.at | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index fe4af4c80..20b653776 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 5734174d5..aa3a2186b 100644 --- a/tests/ofp-print.at +++ b/tests/ofp-print.at @@ -233,7 +233,7 @@ c0 a8 00 02 27 2f 00 00 78 50 cc 5b 57 af 42 1e \ 50 00 02 00 26 e8 00 00 00 00 00 00 00 00 \ "], [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 -- 2.43.0