diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-07-05 02:39:33 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-07-06 01:05:50 +0900 |
commit | ff0efc8bab2e15bf140319132d5479dad7326544 (patch) | |
tree | d785257eccfdc5a82cd57063a5a54db1e76b1c9e | |
parent | 7eac608b18f0be8d260e3a51ebbdcb5bff8b1dfc (diff) |
of1.2: add common field_parser for MT* classes
Most of MT* classes can use this helper classmethod.
We get value and mask values but don't set them to an instance. It's
done later.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_2_parser.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py index 4c04e5ea..43ad0de5 100644 --- a/ryu/ofproto/ofproto_v1_2_parser.py +++ b/ryu/ofproto/ofproto_v1_2_parser.py @@ -1862,10 +1862,20 @@ class OFPMatchField(object): (header,) = struct.unpack_from('!I', buf, offset) # TODO: handle unknown field cls_ = OFPMatchField._FIELDS_HEADERS.get(header) - field = cls_.parser(header, buf, offset) + field = cls_.field_parser(header, buf, offset) field.length = (header & 0xff) + 4 return field + @classmethod + def field_parser(cls, header, buf, offset): + hasmask = (header >> 8) & 1 + if hasmask: + pack_str = '!' + cls.pack_str[1:] * 2 + (value, mask) = struct.unpack_from(pack_str, buf, offset + 4) + else: + (value,) = struct.unpack_from(cls.pack_str, buf, offset + 4) + return cls(header) + def _put_header(self, buf, offset): ofproto_parser.msg_pack_into('!I', buf, offset, self.header) self.length += 4 |