The parameter buf is an instance of bytearray, but Ryu tries to convert it as 
string,
and outputs the error messages as a result.
This patch fixes this problem.

Signed-off-by: IWASE Yusuke <[email protected]>
---
 ryu/ofproto/ofproto_parser.py |  2 +-
 ryu/utils.py                  | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py
index 41ecc06..b883add 100644
--- a/ryu/ofproto/ofproto_parser.py
+++ b/ryu/ofproto/ofproto_parser.py
@@ -60,7 +60,7 @@ def msg(datapath, version, msg_type, msg_len, xid, buf):
             'Encounter an error during parsing OpenFlow packet from switch.'
             'This implies switch sending a malformed OpenFlow packet.'
             'version 0x%02x msg_type %d msg_len %d xid %d buf %s',
-            version, msg_type, msg_len, xid, utils.bytearray_to_hex(buf))
+            version, msg_type, msg_len, xid, utils.hex_array(buf))
         return None
 
 
diff --git a/ryu/utils.py b/ryu/utils.py
index a66b7fe..f0d2e3a 100644
--- a/ryu/utils.py
+++ b/ryu/utils.py
@@ -93,14 +93,25 @@ def round_up(x, y):
     return ((x + y - 1) / y) * y
 
 
-def hex_array(data):
+def _str_to_hex(data):
     """Convert string into array of hexes to be printed."""
     return ' '.join(hex(ord(char)) for char in data)
 
 
-def bytearray_to_hex(data):
+def _bytearray_to_hex(data):
     """Convert bytearray into array of hexes to be printed."""
-    return ' '.join(hex(ord(byte)) for byte in data)
+    return ' '.join(hex(byte) for byte in data)
+
+
+def hex_array(data):
+    """Convert string or bytearray into array of hexes to be printed."""
+    to_hex = {str: _str_to_hex,
+              bytearray: _bytearray_to_hex}
+    try:
+        return to_hex[type(data)](data)
+    except KeyError:
+        LOG.exception('%s is invalid data type' % type(data))
+        return None
 
 
 # the following functions are taken from OpenStack
-- 
1.9.1


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to