From 7938d73f57d0474ba8539cec924fdb715b5a96cc Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Wed, 19 Mar 2014 15:37:40 +0900 Subject: of14: Add bundle add message support Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_4.py | 5 ++- ryu/ofproto/ofproto_v1_4_parser.py | 70 +++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/ryu/ofproto/ofproto_v1_4.py b/ryu/ofproto/ofproto_v1_4.py index 8b9431e1..0688491f 100644 --- a/ryu/ofproto/ofproto_v1_4.py +++ b/ryu/ofproto/ofproto_v1_4.py @@ -1451,7 +1451,10 @@ assert (calcsize(OFP_BUNDLE_CTRL_MSG_PACK_STR) + OFP_HEADER_SIZE == OFP_BUNDLE_CTRL_MSG_SIZE) # struct ofp_bundle_add_msg -OFP_BUNDLE_ADD_MSG_PACK_STR = '!IHH' + _OFP_HEADER_PACK_STR +_OFP_BUNDLE_ADD_MSG_0_PACK_STR = 'I2xH' +OFP_BUNDLE_ADD_MSG_0_PACK_STR = '!' + _OFP_BUNDLE_ADD_MSG_0_PACK_STR +OFP_BUNDLE_ADD_MSG_PACK_STR = (OFP_BUNDLE_ADD_MSG_0_PACK_STR + + _OFP_HEADER_PACK_STR) OFP_BUNDLE_ADD_MSG_SIZE = 24 assert (calcsize(OFP_BUNDLE_ADD_MSG_PACK_STR) + OFP_HEADER_SIZE == OFP_BUNDLE_ADD_MSG_SIZE) diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index 186684a7..087c4d2b 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -20,7 +20,8 @@ import itertools from ryu.lib import addrconv from ryu.lib import mac from ryu import utils -from ofproto_parser import StringifyMixin, MsgBase, msg_pack_into, msg_str_attr +from ofproto_parser import (StringifyMixin, MsgBase, MsgInMsgBase, + msg_pack_into, msg_str_attr) from . import ether from . import ofproto_parser from . import ofproto_common @@ -5850,3 +5851,70 @@ class OFPBundleCtrlMsg(MsgBase): self.buf, ofproto.OFP_HEADER_SIZE, self.bundle_id, self.type, self.flags) self.buf += bin_props + + +@_set_msg_type(ofproto.OFPT_BUNDLE_ADD_MESSAGE) +class OFPBundleAddMsg(MsgInMsgBase): + """ + Bundle control message + + The controller uses this message to create, destroy and commit bundles + + ================ ====================================================== + Attribute Description + ================ ====================================================== + bundle_id Id of the bundle + flags Bitmap of the following flags. + OFPBF_ATOMIC + OFPBF_ORDERED + message ``MsgBase`` subclass instance + properties List of ``OFPBundleProp`` subclass instance + ================ ====================================================== + + Example:: + + def send_bundle_add_message(self, datapath): + ofp = datapath.ofproto + ofp_parser = datapath.ofproto_parser + + msg = ofp_parser.OFPRoleRequest(datapath, ofp.OFPCR_ROLE_EQUAL, 0) + + req = ofp_parser.OFPBundleAddMsg(datapath, 7, [ofp.OFPBF_ATOMIC], + msg, []) + datapath.send_msg(req) + """ + def __init__(self, datapath, bundle_id, flags, message, properties): + super(OFPBundleAddMsg, self).__init__(datapath) + self.bundle_id = bundle_id + self.flags = flags + self.message = message + self.properties = properties + + def _serialize_body(self): + # The xid of the inner message must be the same as + # that of the outer message (OF1.4.0 7.3.9.2) + if self.message.xid != self.xid: + self.message.set_xid(self.xid) + + # Message + self.message.serialize() + tail_buf = self.message.buf + + # Pad + if len(self.properties) > 0: + message_len = len(tail_buf) + pad_len = utils.round_up(message_len, 8) - message_len + ofproto_parser.msg_pack_into("%dx" % pad_len, tail_buf, + message_len) + + # Properties + for p in self.properties: + tail_buf += p.serialize() + + # Head + msg_pack_into(ofproto.OFP_BUNDLE_ADD_MSG_0_PACK_STR, + self.buf, ofproto.OFP_HEADER_SIZE, self.bundle_id, + self.flags) + + # Finish + self.buf += tail_buf -- cgit v1.2.3