This will be used by at least the serialisation of flow mod messages with properties.
Signed-off-by: Simon Horman <[email protected]> --- v2 * first post --- ryu/ofproto/ofproto_v1_4_parser.py | 49 +++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index 26debbc..f270e23 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -833,6 +833,15 @@ class OFPTableModPropEviction(StringifyMixin): ofproto.OFP_TABLE_MOD_PROP_EVICTION_PACK_STR, buf, 0) return eviction + def serialize(self): + # fixup + self.length = ofproto.OFP_TABLE_MOD_PROP_EVICTION_SIZE + + buf = bytearray() + msg_pack_into(ofproto.OFP_TABLE_MOD_PROP_EVICTION_PACK_STR, buf, 0, + self.type, self.length, self.flags) + return buf + @OFPTableModProp.register_type(ofproto.OFPTMPT_VACANCY) class OFPTableModPropVacancy(StringifyMixin): @@ -852,9 +861,21 @@ class OFPTableModPropVacancy(StringifyMixin): ofproto.OFP_TABLE_MOD_PROP_VACANCY_PACK_STR, buf, 0) return vacancy + def serialize(self): + # fixup + self.length = ofproto.OFP_TABLE_MOD_PROP_VACANCY_SIZE + + buf = bytearray() + msg_pack_into(ofproto.OFP_TABLE_MOD_PROP_VACANCY_PACK_STR, buf, 0, + self.type, self.length, self.vacancy_down, + self.vacancy_up, self.vacancy) + return buf + @OFPTableModProp.register_type(ofproto.OFPTMPT_EXPERIMENTER) class OFPTableModPropExperimenter(StringifyMixin): + _DATA_ELEMENT_PACK_STR = '!I' + def __init__(self, type_=None, length=None, experimenter=None, exp_type=None, data=None): self.type = type_ @@ -872,16 +893,38 @@ class OFPTableModPropExperimenter(StringifyMixin): # Parse trailing data, a list of 4-byte words exp.data = [] - pack_str = '!I' - pack_size = struct.calcsize(pack_str) + pack_size = struct.calcsize(cls._DATA_ELEMENT_PACK_STR) offset = ofproto.OFP_TABLE_MOD_PROP_EXPERIMENTER_SIZE while offset < exp.length: - (word,) = struct.unpack_from(pack_str, buf, offset) + (word,) = struct.unpack_from(cls._DATA_ELEMENT_PACK_STR, + buf, offset) exp.data.append(word) offset += pack_size return exp + def serialize(self): + data_buf = bytearray() + if len(self.data): + ofproto_parser.msg_pack_into('!%dI' % len(self.data), + data_buf, 0, *self.data) + + #fixup + self.length = ofproto.OFP_TABLE_MOD_PROP_EXPERIMENTER_SIZE + self.length += len(data_buf) + + buf = bytearray() + msg_pack_into(ofproto.OFP_TABLE_MOD_PROP_EXPERIMENTER_PACK_STR, buf, + 0, self.type, self.length, self.experimenter, + self.exp_type) + buf += data_buf + + # Pad + pad_len = utils.round_up(self.length, 8) - self.length + ofproto_parser.msg_pack_into("%dx" % pad_len, buf, len(buf)) + + return buf + class OFPMatchField(StringifyMixin): _FIELDS_HEADERS = {} -- 1.8.5.2 ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
