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 <horms@verge.net.au>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Simon Horman 2014-02-04 13:27:58 +09:00 committed by FUJITA Tomonori
parent 29f7f1fa28
commit d86df914c3

View File

@ -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,