summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/ofproto/ofproto_v1_2_parser.py12
-rw-r--r--ryu/tests/unit/ofproto/test_parser_v12.py12
2 files changed, 21 insertions, 3 deletions
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py
index 32a7313d..f5a1b242 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -1931,7 +1931,11 @@ class OFPMatchField(object):
def __init__(self, header):
self.header = header
- self.n_bytes = struct.calcsize(self.pack_str)
+ hasmask = (header >> 8) & 1
+ if hasmask:
+ self.n_bytes = (header & 0xff) / 2
+ else:
+ self.n_bytes = header & 0xff
self.length = 0
@staticmethod
@@ -1942,9 +1946,11 @@ class OFPMatchField(object):
@classmethod
def parser(cls, buf, offset):
(header,) = struct.unpack_from('!I', buf, offset)
- # TODO: handle unknown field
cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
- field = cls_.field_parser(header, buf, offset)
+ if cls_:
+ field = cls_.field_parser(header, buf, offset)
+ else:
+ field = OFPMatchField(header)
field.length = (header & 0xff) + 4
return field
diff --git a/ryu/tests/unit/ofproto/test_parser_v12.py b/ryu/tests/unit/ofproto/test_parser_v12.py
index be10443a..e3f3fb42 100644
--- a/ryu/tests/unit/ofproto/test_parser_v12.py
+++ b/ryu/tests/unit/ofproto/test_parser_v12.py
@@ -3403,6 +3403,18 @@ class TestOFPMatch(unittest.TestCase):
eq_(res.fields[0].header, header)
eq_(res.fields[0].value, value)
+ def test_parse_unknown_field(self):
+ buf = bytearray()
+ ofproto_parser.msg_pack_into('!HH', buf, 0, ofproto_v1_2.OFPMT_OXM,
+ 4 + 6)
+ header = ofproto_v1_2.oxm_tlv_header(36, 2)
+ ofproto_parser.msg_pack_into('!IH', buf, 4, header, 1)
+ header = ofproto_v1_2.OXM_OF_ETH_TYPE
+ ofproto_v1_2_parser.msg_pack_into('!IH', buf, 10, header, 1)
+
+ match = OFPMatch()
+ res = match.parser(str(buf), 0)
+
def test_set_in_port(self):
header = ofproto_v1_2.OXM_OF_IN_PORT
value = in_port = 0xfff8