From 681ea7a0e98edf156aab79b062425d7ac638e415 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 9 Nov 2012 10:00:22 -0800 Subject: [PATCH] tests: Add tests for encoding and decoding OpenFlow hello messages. These tests helped me find the problems that I fixed in previous commits. Signed-off-by: Ben Pfaff --- tests/automake.mk | 1 + tests/ofp-print.at | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/ofp-util.at | 47 ++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + utilities/ovs-ofctl.c | 15 +++++++++++ 5 files changed, 123 insertions(+) create mode 100644 tests/ofp-util.at diff --git a/tests/automake.mk b/tests/automake.mk index 2977f76b..732839c9 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -16,6 +16,7 @@ TESTSUITE_AT = \ tests/daemon-py.at \ tests/ofp-actions.at \ tests/ofp-print.at \ + tests/ofp-util.at \ tests/ofp-errors.at \ tests/ovs-ofctl.at \ tests/odp.at \ diff --git a/tests/ofp-print.at b/tests/ofp-print.at index 980b57dc..bcf9d2c7 100644 --- a/tests/ofp-print.at +++ b/tests/ofp-print.at @@ -84,6 +84,65 @@ OFPT_HELLO (xid=0x0): ]) AT_CLEANUP +AT_SETUP([OFPT_HELLO with higher than supported version]) +AT_KEYWORDS([ofp-print]) +AT_CHECK([ovs-ofctl ofp-print "0f 00 00 08 00 00 00 00"], [0], +[dnl +OFPT_HELLO (OF 0x0f) (xid=0x0): + version bitmap: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f +]) +AT_CHECK([ovs-ofctl ofp-print "40 00 00 08 00 00 00 00"], [0], +[dnl +OFPT_HELLO (OF 0x40) (xid=0x0): + version bitmap: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f +]) +AT_CHECK([ovs-ofctl ofp-print "3f 00 00 18 00 00 00 00 00 01 00 0c aa aa aa aa aa aa aa aa 00 00 00 00"], [0], +[dnl +OFPT_HELLO (OF 0x3f) (xid=0x0): + version bitmap: 0x01, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1b, 0x1d, 0x1f +]) +AT_CLEANUP + +AT_SETUP([OFPT_HELLO with contradictory version bitmaps]) +AT_KEYWORDS([ofp-print]) +dnl Bitmap claims support for no versions at all. +AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' ofp-print "01 00 00 10 00 00 00 00 00 01 00 08 00 00 00 00"], [0], +[OFPT_HELLO (xid=0x0): + version bitmap: 0x01 + unknown data in hello: +00000000 01 00 00 10 00 00 00 00-00 01 00 08 00 00 00 00 |................| +], [dnl +ofp_util|WARN|peer does not support any OpenFlow version (between 0x01 and 0x1f) +]) +dnl Bitmap claims support for only versions above 0x1f. +AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' ofp-print "3f 00 00 18 00 00 00 00 00 01 00 0c 00 00 00 00 aa aa aa aa 00 00 00 00"], [0], +[OFPT_HELLO (OF 0x3f) (xid=0x0): + version bitmap: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f + unknown data in hello: +00000000 3f 00 00 18 00 00 00 00-00 01 00 0c 00 00 00 00 |?...............| +00000010 aa aa aa aa 00 00 00 00- |........ | +], [dnl +ofp_util|WARN|peer does not support any OpenFlow version (between 0x01 and 0x1f) +]) +dnl Bitmap claims support for nonexistent version 0x00. +AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' ofp-print "01 00 00 10 00 00 00 00 00 01 00 08 00 00 00 f1"], [0], [dnl +OFPT_HELLO (xid=0x0): + version bitmap: 0x04, 0x05, 0x06, 0x07 +], [dnl +ofp_util|WARN|peer claims to support invalid OpenFlow version 0x00 +]) +dnl Bitmap claims support for only nonexistent version 0x00. +AT_CHECK([ovs-ofctl '-vPATTERN:console:%c|%p|%m' ofp-print "01 00 00 10 00 00 00 00 00 01 00 08 00 00 00 01"], [0], [dnl +OFPT_HELLO (xid=0x0): + version bitmap: 0x01 + unknown data in hello: +00000000 01 00 00 10 00 00 00 00-00 01 00 08 00 00 00 01 |................| +], [dnl +ofp_util|WARN|peer claims to support invalid OpenFlow version 0x00 +ofp_util|WARN|peer does not support any OpenFlow version (between 0x01 and 0x1f) +]) +AT_CLEANUP + dnl OFPT_ERROR tests are in ofp-errors.at. AT_SETUP([OFPT_ECHO_REQUEST, empty payload]) diff --git a/tests/ofp-util.at b/tests/ofp-util.at new file mode 100644 index 00000000..e6dbfcfe --- /dev/null +++ b/tests/ofp-util.at @@ -0,0 +1,47 @@ +AT_BANNER([OpenFlow utilities]) + +AT_SETUP([encoding hellos]) +dnl All versions up to a max version supported: +AT_CHECK([ovs-ofctl encode-hello 0x2], [0], [dnl +00000000 01 00 00 08 00 00 00 01- +OFPT_HELLO (xid=0x1): + version bitmap: 0x01 +]) +AT_CHECK([ovs-ofctl encode-hello 0x6], [0], [dnl +00000000 02 00 00 08 00 00 00 01- +OFPT_HELLO (OF1.1) (xid=0x1): + version bitmap: 0x01, 0x02 +]) +AT_CHECK([ovs-ofctl encode-hello 0xe], [0], [dnl +00000000 03 00 00 08 00 00 00 01- +OFPT_HELLO (OF1.2) (xid=0x1): + version bitmap: 0x01, 0x02, 0x03 +]) +AT_CHECK([ovs-ofctl encode-hello 0x1e], [0], [dnl +00000000 04 00 00 08 00 00 00 01- +OFPT_HELLO (OF 0x04) (xid=0x1): + version bitmap: 0x01, 0x02, 0x03, 0x04 +]) + +dnl Some versions below max version missing. +AT_CHECK([ovs-ofctl encode-hello 0xc], [0], [dnl +00000000 03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 0c @&t@ +OFPT_HELLO (OF1.2) (xid=0x1): + version bitmap: 0x02, 0x03 +]) +AT_CHECK([ovs-ofctl encode-hello 0xa], [0], [dnl +00000000 03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 0a @&t@ +OFPT_HELLO (OF1.2) (xid=0x1): + version bitmap: 0x01, 0x03 +]) +AT_CHECK([ovs-ofctl encode-hello 0x8], [0], [dnl +00000000 03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 08 @&t@ +OFPT_HELLO (OF1.2) (xid=0x1): + version bitmap: 0x03 +]) +AT_CHECK([ovs-ofctl encode-hello 0x4], [0], [dnl +00000000 02 00 00 10 00 00 00 01-00 01 00 08 00 00 00 04 @&t@ +OFPT_HELLO (OF1.1) (xid=0x1): + version bitmap: 0x02 +]) +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index 2b4ccdb7..c330f2cf 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -77,6 +77,7 @@ m4_include([tests/daemon.at]) m4_include([tests/daemon-py.at]) m4_include([tests/ofp-actions.at]) m4_include([tests/ofp-print.at]) +m4_include([tests/ofp-util.at]) m4_include([tests/ofp-errors.at]) m4_include([tests/ovs-ofctl.at]) m4_include([tests/odp.at]) diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 900c3d8d..0c146a42 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -2718,6 +2718,20 @@ ofctl_ofp_print(int argc, char *argv[]) ofpbuf_uninit(&packet); } +/* "encode-hello BITMAP...": Encodes each BITMAP as an OpenFlow hello message + * and dumps each message in hex. */ +static void +ofctl_encode_hello(int argc OVS_UNUSED, char *argv[]) +{ + uint32_t bitmap = strtol(argv[1], NULL, 0); + struct ofpbuf *hello; + + hello = ofputil_encode_hello(bitmap); + ovs_hex_dump(stdout, hello->data, hello->size, 0, false); + ofp_print(stdout, hello->data, hello->size, verbosity); + ofpbuf_delete(hello); +} + static const struct command all_commands[] = { { "show", 1, 1, ofctl_show }, { "monitor", 1, 3, ofctl_monitor }, @@ -2758,6 +2772,7 @@ static const struct command all_commands[] = { { "check-vlan", 2, 2, ofctl_check_vlan }, { "print-error", 1, 1, ofctl_print_error }, { "ofp-print", 1, 2, ofctl_ofp_print }, + { "encode-hello", 1, 1, ofctl_encode_hello }, { NULL, 0, 0, NULL }, }; -- 2.30.2