diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-07-23 16:03:15 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-07-31 21:06:37 +0900 |
commit | 150fac2f6ae8a610dd3fbbc2844b51f5e3069375 (patch) | |
tree | 21b53aa7a48499d194adc9e5fecfd314b803baad | |
parent | e0addad0538806427f4288bd9c1f5531d71e0941 (diff) |
of12: new match field parser
add a new match field parser which fills OFPMatch attributes used
by the new api.
the old parser which fills match.fields is kept for now but will be
removed later.
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_2_parser.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py index 35cff821..950a171e 100644 --- a/ryu/ofproto/ofproto_v1_2_parser.py +++ b/ryu/ofproto/ofproto_v1_2_parser.py @@ -1892,14 +1892,43 @@ class OFPMatch(StringifyMixin): # ofp_match adjustment offset += 4 length -= 4 + + # XXXcompat + cls.parser_old(match, buf, offset, length) + + fields = {} + while length > 0: + hdr_pack_str = '!I' + (header, ) = struct.unpack_from(hdr_pack_str, buf, offset) + hdr_len = struct.calcsize(hdr_pack_str) + oxm_type = header >> 9 # class|field + oxm_hasmask = ofproto_v1_2.oxm_tlv_header_extract_hasmask(header) + value_len = ofproto_v1_2.oxm_tlv_header_extract_length(header) + value_pack_str = '!%ds' % value_len + assert struct.calcsize(value_pack_str) == value_len + (value, ) = struct.unpack_from(value_pack_str, buf, + offset + hdr_len) + if oxm_hasmask: + (mask, ) = struct.unpack_from(value_pack_str, buf, + offset + hdr_len + value_len) + else: + mask = None + k, uv = ofproto_v1_2.oxm_to_user(oxm_type, value, mask) + fields[k] = uv + field_len = hdr_len + (header & 0xff) + offset += field_len + length -= field_len + match._fields2 = fields + return match + + @staticmethod + def parser_old(match, buf, offset, length): while length > 0: field = OFPMatchField.parser(buf, offset) offset += field.length length -= field.length match.fields.append(field) - return match - def set_in_port(self, port): self._wc.ft_set(ofproto_v1_2.OFPXMT_OFB_IN_PORT) self._flow.in_port = port |