mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 22:06:10 +02:00
utils: Fix bytearray conversion
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 <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
828b6f48c4
commit
b1b02cec00
@ -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
|
||||
|
||||
|
||||
|
||||
17
ryu/utils.py
17
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user