diff options
author | Yusuke Iwase <iwase.yusuke0@gmail.com> | 2015-08-19 11:02:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-20 18:28:40 +0900 |
commit | 90f75158b07af0bd9ebd1772a68a1e2d5889069f (patch) | |
tree | fb933439f9ae535b6d6fddaeb2b63969d3a54cfa | |
parent | 0b5dd61930c12a19b3fc5658a48bf6d461eb70b2 (diff) |
ofproto_v1_[45]_parser: Fix to parse experimenter_data
This patch fixes to parse experimenter_data of ofp_*_prop_experimenter
as a list of uint32_t values at OFPPropCommonExperimenter4ByteData.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_4_parser.py | 23 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_5_parser.py | 23 |
2 files changed, 40 insertions, 6 deletions
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index f9efba5a..d2c22f12 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -881,6 +881,8 @@ class OFPPropBase(StringifyMixin): class OFPPropCommonExperimenter4ByteData(StringifyMixin): _PACK_STR = '!HHII' + _EXPERIMENTER_DATA_PACK_STR = '!I' + _EXPERIMENTER_DATA_SIZE = 4 def __init__(self, type_=None, length=None, experimenter=None, exp_type=None, data=bytearray()): @@ -894,19 +896,34 @@ class OFPPropCommonExperimenter4ByteData(StringifyMixin): def parser(cls, buf): (type_, length, experimenter, exp_type) = struct.unpack_from( ofproto.OFP_PROP_EXPERIMENTER_PACK_STR, buf, 0) - data = buf[ofproto.OFP_PROP_EXPERIMENTER_SIZE:length] + + rest = buf[ofproto.OFP_PROP_EXPERIMENTER_SIZE:length] + data = [] + while rest: + (d,) = struct.unpack_from( + cls._EXPERIMENTER_DATA_PACK_STR, rest, 0) + data.append(d) + rest = rest[cls._EXPERIMENTER_DATA_SIZE:] + return cls(type_, length, experimenter, exp_type, data) def serialize(self): + offset = 0 + bin_data = bytearray() + for d in self.data: + msg_pack_into(self._EXPERIMENTER_DATA_PACK_STR, + bin_data, offset, d) + offset += self._EXPERIMENTER_DATA_SIZE + # fixup self.length = struct.calcsize(self._PACK_STR) - self.length += len(self.data) + self.length += len(bin_data) buf = bytearray() msg_pack_into(self._PACK_STR, buf, 0, self.type, self.length, self.experimenter, self.exp_type) - buf += self.data + buf += bin_data # Pad pad_len = utils.round_up(self.length, 8) - self.length diff --git a/ryu/ofproto/ofproto_v1_5_parser.py b/ryu/ofproto/ofproto_v1_5_parser.py index 998b4bd3..fb920615 100644 --- a/ryu/ofproto/ofproto_v1_5_parser.py +++ b/ryu/ofproto/ofproto_v1_5_parser.py @@ -1025,6 +1025,8 @@ class OFPPropBase(StringifyMixin): class OFPPropCommonExperimenter4ByteData(StringifyMixin): _PACK_STR = '!HHII' + _EXPERIMENTER_DATA_PACK_STR = '!I' + _EXPERIMENTER_DATA_SIZE = 4 def __init__(self, type_=None, length=None, experimenter=None, exp_type=None, data=bytearray()): @@ -1038,19 +1040,34 @@ class OFPPropCommonExperimenter4ByteData(StringifyMixin): def parser(cls, buf): (type_, length, experimenter, exp_type) = struct.unpack_from( ofproto.OFP_PROP_EXPERIMENTER_PACK_STR, buf, 0) - data = buf[ofproto.OFP_PROP_EXPERIMENTER_SIZE:length] + + rest = buf[ofproto.OFP_PROP_EXPERIMENTER_SIZE:length] + data = [] + while rest: + (d,) = struct.unpack_from( + cls._EXPERIMENTER_DATA_PACK_STR, rest, 0) + data.append(d) + rest = rest[cls._EXPERIMENTER_DATA_SIZE:] + return cls(type_, length, experimenter, exp_type, data) def serialize(self): + offset = 0 + bin_data = bytearray() + for d in self.data: + msg_pack_into(self._EXPERIMENTER_DATA_PACK_STR, + bin_data, offset, d) + offset += self._EXPERIMENTER_DATA_SIZE + # fixup self.length = struct.calcsize(self._PACK_STR) - self.length += len(self.data) + self.length += len(bin_data) buf = bytearray() msg_pack_into(self._PACK_STR, buf, 0, self.type, self.length, self.experimenter, self.exp_type) - buf += self.data + buf += bin_data # Pad pad_len = utils.round_up(self.length, 8) - self.length |