diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-07-23 16:03:35 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-07-31 21:06:38 +0900 |
commit | 620852451adcd1b19a46206a13c5e116669077b6 (patch) | |
tree | eac8dd755ceb25f0580cb8ae913035798504764b | |
parent | d88a62d9cf16dc09e12058f8446c672837e97a0e (diff) |
of13: more OFPMatch old api compat
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_3_parser.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py index f59c65d6..03a10443 100644 --- a/ryu/ofproto/ofproto_v1_3_parser.py +++ b/ryu/ofproto/ofproto_v1_3_parser.py @@ -349,7 +349,7 @@ class FlowWildcards(object): class OFPMatch(StringifyMixin): - def __init__(self, fields=[], type_=None, **kwargs): + def __init__(self, fields=[], type_=None, _normalize=False, **kwargs): super(OFPMatch, self).__init__() self._wc = FlowWildcards() self._flow = Flow() @@ -382,8 +382,12 @@ class OFPMatch(StringifyMixin): # eg. # OFPMatch(eth_src=('ff:ff:ff:00:00:00'), eth_type=0x800, # ipv4_src='10.0.0.1') - self._fields2 = dict(ofproto_v1_3.oxm_normalize_user(k, uv) for (k, uv) - in kwargs.iteritems()) + if _normalize: + self._fields2 = dict(ofproto_v1_3.oxm_normalize_user(k, uv) + for (k, uv) + in kwargs.iteritems()) + else: + self._fields2 = kwargs def __getitem__(self, key): return self._fields2[key] @@ -415,13 +419,33 @@ class OFPMatch(StringifyMixin): @classmethod def from_jsondict(cls, dict_): - o = super(OFPMatch, cls).from_jsondict(dict_, lambda x: x) + # XXX old api compat + # the following _normalize=False is a compat hack. + # see test_parser_v12. + o = super(OFPMatch, cls).from_jsondict(dict_, lambda x: x, + _normalize=False) # XXX old api compat # serialize and parse to fill OFPMatch.fields buf = bytearray() o.serialize(buf, 0) return OFPMatch.parser(str(buf), 0) + def __str__(self): + # XXX old api compat + if self._composed_with_old_api(): + # copy object first because serialize_old is destructive + o2 = OFPMatch() + o2.fields = self.fields[:] + # serialize and parse to fill OFPMatch._fields2 + buf = bytearray() + o2.serialize(buf, 0) + o = OFPMatch.parser(str(buf), 0) + else: + o = self + return super(OFPMatch, o).__str__() + + __repr__ = __str__ + def append_field(self, header, value, mask=None): self.fields.append(OFPMatchField.make(header, value, mask)) |