From f25b4a812c5353325e6ef3e658f19db040d96039 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 23 May 2012 09:33:22 -0700 Subject: [PATCH] ofp-print: Print the type of truncated messages, when available. The function ofputil_decode_msg_type_partial() can figure out the type of a truncated OpenFlow message, if the message is long enough that its type can be determined, so we should print this information. This is especially valuable for printing OFPT_ERROR messages, in which the inner OpenFlow message is often truncated to 64 bytes. Signed-off-by: Ben Pfaff --- lib/ofp-print.c | 20 ++++++++++++++++++-- tests/ofp-errors.at | 32 ++++++++++++++++++++++++++------ tests/ofp-print.at | 8 ++++---- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 48b8daa9..3d3b9193 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1519,6 +1519,14 @@ ofp_print_version(const struct ofp_header *oh, ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid)); } +static void +ofp_header_to_string__(const struct ofp_header *oh, + const struct ofputil_msg_type *type, struct ds *string) +{ + ds_put_cstr(string, ofputil_msg_type_name(type)); + ofp_print_version(oh, string); +} + static void ofp_to_string__(const struct ofp_header *oh, const struct ofputil_msg_type *type, struct ds *string, @@ -1527,8 +1535,7 @@ ofp_to_string__(const struct ofp_header *oh, enum ofputil_msg_code code; const void *msg = oh; - ds_put_cstr(string, ofputil_msg_type_name(type)); - ofp_print_version(oh, string); + ofp_header_to_string__(oh, type, string); code = ofputil_msg_type_code(type); switch (code) { case OFPUTIL_MSG_INVALID: @@ -1730,6 +1737,15 @@ ofp_to_string(const void *oh_, size_t len, int verbosity) ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n", len); } else if (ntohs(oh->length) > len) { + const struct ofputil_msg_type *type; + enum ofperr error; + + error = ofputil_decode_msg_type_partial(oh, len, &type); + if (!error) { + ofp_header_to_string__(oh, type, &string); + ds_put_char(&string, '\n'); + } + ds_put_format(&string, "(***truncated to %zu bytes from %"PRIu16"***)\n", len, ntohs(oh->length)); diff --git a/tests/ofp-errors.at b/tests/ofp-errors.at index 331a8f8a..b45a33a5 100644 --- a/tests/ofp-errors.at +++ b/tests/ofp-errors.at @@ -18,10 +18,28 @@ AT_CLEANUP AT_SETUP([OFPT_ERROR with type OFPET_BAD_REQUEST - OF1.0]) AT_KEYWORDS([ofp-print ofp-errors]) -AT_CHECK([ovs-ofctl ofp-print 01010014000000000001000601bbccddeeff0011], [0], [dnl +AT_CHECK([ovs-ofctl ofp-print 0101001400000000000100060105ccddeeff0011], [0], [dnl OFPT_ERROR (xid=0x0): OFPBRC_BAD_LEN +OFPT_FEATURES_REQUEST (xid=0xeeff0011): (***truncated to 8 bytes from 52445***) -00000000 01 bb cc dd ee ff 00 11- |........ | +00000000 01 05 cc dd ee ff 00 11- |........ | +]) +AT_CLEANUP + +AT_SETUP([OFPT_ERROR prints type of truncated inner messages]) +AT_KEYWORDS([ofp-print ofp-errors]) +AT_CHECK([ovs-ofctl ofp-print "0101004c092529d500010006 \ +01 06 00 e0 00 00 00 01 00 00 50 54 00 00 00 01 \ +00 00 01 00 02 00 00 00 00 00 00 87 00 00 0f ff \ +ff fe 50 54 00 00 00 01 62 72 30 00 00 00 00 00 \ +00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01"], [0], [dnl +OFPT_ERROR (xid=0x92529d5): OFPBRC_BAD_LEN +OFPT_FEATURES_REPLY (xid=0x1): +(***truncated to 64 bytes from 224***) +00000000 01 06 00 e0 00 00 00 01-00 00 50 54 00 00 00 01 |..........PT....| +00000010 00 00 01 00 02 00 00 00-00 00 00 87 00 00 0f ff |................| +00000020 ff fe 50 54 00 00 00 01-62 72 30 00 00 00 00 00 |..PT....br0.....| +00000030 00 00 00 00 00 00 00 00-00 00 00 01 00 00 00 01 |................| ]) AT_CLEANUP @@ -45,18 +63,20 @@ dnl Error type 3, code 1 is OFPFMFC_OVERLAP in OF1.0 dnl and OFPBIC_UNSUP_INST in OF1.1, so check that value in both versions. AT_SETUP([OFPT_ERROR with type OFPFMFC_OVERLAP - OF1.0]) AT_KEYWORDS([ofp-print ofp-errors]) -AT_CHECK([ovs-ofctl ofp-print 01010014000000000003000101bbccddeeff0011], [0], [dnl +AT_CHECK([ovs-ofctl ofp-print 0101001400000000000300010106ccddeeff0011], [0], [dnl OFPT_ERROR (xid=0x0): OFPFMFC_OVERLAP +OFPT_FEATURES_REPLY (xid=0xeeff0011): (***truncated to 8 bytes from 52445***) -00000000 01 bb cc dd ee ff 00 11- |........ | +00000000 01 06 cc dd ee ff 00 11- |........ | ]) AT_CLEANUP AT_SETUP([OFPT_ERROR with type OFPBIC_UNSUP_INST - OF1.1]) AT_KEYWORDS([ofp-print ofp-errors]) -AT_CHECK([ovs-ofctl ofp-print 02010014000000000003000102bbccddeeff0011], [0], [dnl +AT_CHECK([ovs-ofctl ofp-print 0201001400000000000300010206ccddeeff0011], [0], [dnl OFPT_ERROR (OF1.1) (xid=0x0): OFPBIC_UNSUP_INST +OFPT_FEATURES_REPLY (OF1.1) (xid=0xeeff0011): (***truncated to 8 bytes from 52445***) -00000000 02 bb cc dd ee ff 00 11- |........ | +00000000 02 06 cc dd ee ff 00 11- |........ | ]) AT_CLEANUP diff --git a/tests/ofp-print.at b/tests/ofp-print.at index 1fe54f17..3e992058 100644 --- a/tests/ofp-print.at +++ b/tests/ofp-print.at @@ -26,17 +26,17 @@ AT_CLEANUP AT_SETUP([truncated message]) AT_KEYWORDS([ofp-print]) -AT_CHECK([ovs-ofctl ofp-print 01bbccddeeff0011], [0], [dnl +AT_CHECK([ovs-ofctl ofp-print 0110ccddeeff0011], [0], [dnl (***truncated to 8 bytes from 52445***) -00000000 01 bb cc dd ee ff 00 11- |........ | +00000000 01 10 cc dd ee ff 00 11- |........ | ]) AT_CLEANUP AT_SETUP([message only uses part of buffer]) AT_KEYWORDS([ofp-print]) -AT_CHECK([ovs-ofctl ofp-print 01bb0009eeff00112233], [0], [dnl +AT_CHECK([ovs-ofctl ofp-print 01100009eeff00112233], [0], [dnl (***only uses 9 bytes out of 10***) -00000000 01 bb 00 09 ee ff 00 11-22 33 |........"3 | +00000000 01 10 00 09 ee ff 00 11-22 33 |........"3 | ]) # " AT_CLEANUP -- 2.30.2