---
v5
* As suggested by YAMAMOTO Takashi
  - Only add padding if there are properties present
  - Don't  assign tail_buf twice
  - xid of inner and outer messages should be the same

v4
* Inherit MsgInMsgBase instead of MsgBase
  - This is a new mechanism to allow messages inside messages

v2 - v3
* No change
---
 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 8b9431e..0688491 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 186684a..087c4d2 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
-- 
1.8.5.2


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to