summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYusuke Iwase <iwase.yusuke0@gmail.com>2015-07-22 14:12:31 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-07-22 19:01:01 +0900
commit3a9559e042f87f387d9027fa8fe02050ad8d1a97 (patch)
tree03ed029009aec1c8d14b038993d8baf3a610376a
parent188d47e0835819b13e4a94c43bd76872786751ca (diff)
ofproto_v1_5_parser: Move utility method to OFPPropBase
This patch moves get_rest() and serialize() from OFPTableFeatureProp to OFPPropBase in order to share it with other subclass. 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_5_parser.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/ryu/ofproto/ofproto_v1_5_parser.py b/ryu/ofproto/ofproto_v1_5_parser.py
index 5bf6da6c..525bc618 100644
--- a/ryu/ofproto/ofproto_v1_5_parser.py
+++ b/ryu/ofproto/ofproto_v1_5_parser.py
@@ -990,6 +990,32 @@ class OFPPropBase(StringifyMixin):
prop.length = length
return prop, rest
+ @classmethod
+ def get_rest(cls, buf):
+ (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0)
+ offset = struct.calcsize(cls._PACK_STR)
+ return buf[offset:length]
+
+ def serialize(self):
+ # Body
+ # serialize_body should be implemented by subclass
+ body = bytearray()
+ body += self.serialize_body()
+
+ # fixup
+ self.length = len(body) + struct.calcsize(self._PACK_STR)
+
+ # Header
+ buf = bytearray()
+ msg_pack_into(self._PACK_STR, buf, 0, self.type, self.length)
+ buf += body
+
+ # Pad
+ pad_len = utils.round_up(self.length, 8) - self.length
+ msg_pack_into("%dx" % pad_len, buf, len(buf))
+
+ return buf
+
class OFPPropCommonExperimenter4ByteData(StringifyMixin):
_PACK_STR = '!HHII'
@@ -2368,32 +2394,6 @@ class OFPTableFeaturesStats(StringifyMixin):
class OFPTableFeatureProp(OFPPropBase):
_TYPES = {}
- @classmethod
- def get_rest(cls, buf):
- (type_, length) = struct.unpack_from(cls._PACK_STR, buf, 0)
- offset = struct.calcsize(cls._PACK_STR)
- return buf[offset:length]
-
- def serialize(self):
- # Body
- # serialize_body should be implemented by subclass
- body = bytearray()
- body += self.serialize_body()
-
- # fixup
- self.length = len(body) + struct.calcsize(self._PACK_STR)
-
- # Header
- buf = bytearray()
- msg_pack_into(self._PACK_STR, buf, 0, self.type, self.length)
- buf += body
-
- # Pad
- pad_len = utils.round_up(self.length, 8) - self.length
- msg_pack_into("%dx" % pad_len, buf, len(buf))
-
- return buf
-
class OFPInstructionId(StringifyMixin):
_PACK_STR = '!HH' # type, len