ofproto_parser: dump packets if error is encountered during parse

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Isaku Yamahata 2013-10-29 18:00:16 +09:00 committed by FUJITA Tomonori
parent 3ba951f403
commit 7fd7e84491
2 changed files with 17 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import sys
import functools
from ryu import exception
from ryu import utils
from ryu.lib import stringify
from . import ofproto_common
@ -51,7 +52,15 @@ def msg(datapath, version, msg_type, msg_len, xid, buf):
if msg_parser is None:
raise exception.OFPUnknownVersion(version=version)
return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
try:
return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
except struct.error:
LOG.exception(
'Encounter an error during parsing OpenFlow packet from switch.'
'This implies switch sending a malfold 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))
raise
def create_list_of_base_attributes(f):

View File

@ -94,7 +94,13 @@ def round_up(x, y):
def hex_array(data):
return ' '.join(hex(ord(chr)) for chr in data)
"""Convert string into array of hexes to be printed."""
return ' '.join(hex(ord(char)) for char in data)
def bytearray_to_hex(data):
"""Convert bytearray into array of hexes to be printed."""
return ' '.join(hex(byte) for byte in data)
# the following functions are taken from OpenStack