From d86df914c3d1b8ea202ab710b2fac358423df8ed Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Tue, 4 Feb 2014 13:27:58 +0900 Subject: [PATCH] of14: Add generic OFPropBase class Add generic OFPropBase class and make OFPPortProp a subclass of it. This is to allow other properties classes to be implemented as subclasses of OFPPropBase, simplifying their implementation. Signed-off-by: Simon Horman Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_4_parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index 7a446133..4077f207 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -749,7 +749,7 @@ class OFPMatch(StringifyMixin): return OFPMatch(_ordered_fields=fields) -class OFPPortPropUnknown(StringifyMixin): +class OFPPropUnknown(StringifyMixin): def __init__(self, type_=None, length=None, buf=None): self.buf = buf @@ -758,9 +758,9 @@ class OFPPortPropUnknown(StringifyMixin): return cls(buf=buf) -class OFPPortProp(StringifyMixin): +class OFPPropBase(StringifyMixin): _PACK_STR = '!HH' - _TYPES = {} + # _TYPES = {} must be an attribute of subclass def __init__(self, type_, length=None): self.type = type_ @@ -781,13 +781,17 @@ class OFPPortProp(StringifyMixin): try: subcls = cls._TYPES[type_] except KeyError: - subcls = OFPPortPropUnknown + subcls = OFPPropUnknown prop = subcls.parser(buf) prop.type = type_ prop.length = length return prop, rest +class OFPPortProp(OFPPropBase): + _TYPES = {} + + @OFPPortProp.register_type(ofproto.OFPPDPT_ETHERNET) class OFPPortDescPropEthernet(StringifyMixin): def __init__(self, type_=None, length=None, curr=None, advertised=None,