Signed-off-by: Simon Horman <[email protected]>
---
 ryu/ofproto/ofproto_v1_4.py        |  7 +++++
 ryu/ofproto/ofproto_v1_4_parser.py | 54 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/ryu/ofproto/ofproto_v1_4.py b/ryu/ofproto/ofproto_v1_4.py
index b5139c6..c9316ce 100644
--- a/ryu/ofproto/ofproto_v1_4.py
+++ b/ryu/ofproto/ofproto_v1_4.py
@@ -604,6 +604,13 @@ OFPRR_GROUP_DELETE = 3  # Group was removed.
 OFPRR_METER_DELETE = 4  # Meter was removed.
 OFPRR_EVICTION = 5  # Switch eviction to free resources.
 
+# struct ofp_port_status
+OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PORT_PACK_STR
+OFP_PORT_STATUS_DESC_OFFSET = OFP_HEADER_SIZE + 8
+OFP_PORT_STATUS_SIZE = 56
+assert (calcsize(OFP_PORT_STATUS_PACK_STR) + OFP_HEADER_SIZE ==
+        OFP_PORT_STATUS_SIZE)
+
 # struct ofp_flow_removed
 _OFP_FLOW_REMOVED_PACK_STR0 = 'QHBBIIHHQQ'
 OFP_FLOW_REMOVED_PACK_STR = '!' + _OFP_FLOW_REMOVED_PACK_STR0 + \
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 5c289a8..fbc5f1c 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -3382,6 +3382,60 @@ class OFPBarrierReply(MsgBase):
         super(OFPBarrierReply, self).__init__(datapath)
 
 
+@_register_parser
+@_set_msg_type(ofproto.OFPT_PORT_STATUS)
+class OFPPortStatus(MsgBase):
+    """
+    Port status message
+
+    The switch notifies controller of change of ports.
+
+    ================ ======================================================
+    Attribute        Description
+    ================ ======================================================
+    reason           One of the following values.
+                     OFPPR_ADD
+                     OFPPR_DELETE
+                     OFPPR_MODIFY
+    desc             instance of ``OFPPort``
+    ================ ======================================================
+
+    Example::
+
+        @set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
+        def port_status_handler(self, ev):
+            msg = ev.msg
+            dp = msg.datapath
+            ofp = dp.ofproto
+
+            if msg.reason == ofp.OFPPR_ADD:
+                reason = 'ADD'
+            elif msg.reason == ofp.OFPPR_DELETE:
+                reason = 'DELETE'
+            elif msg.reason == ofp.OFPPR_MODIFY:
+                reason = 'MODIFY'
+            else:
+                reason = 'unknown'
+
+            self.logger.debug('OFPPortStatus received: reason=%s desc=%s',
+                              reason, msg.desc)
+    """
+    def __init__(self, datapath, reason=None, desc=None):
+        super(OFPPortStatus, self).__init__(datapath)
+        self.reason = reason
+        self.desc = desc
+
+    @classmethod
+    def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
+        msg = super(OFPPortStatus, cls).parser(datapath, version, msg_type,
+                                               msg_len, xid, buf)
+        msg.reason = struct.unpack_from(
+            ofproto.OFP_PORT_STATUS_PACK_STR, msg.buf,
+            ofproto.OFP_HEADER_SIZE)[0]
+        msg.desc = OFPPort.parser(msg.buf, ofproto.OFP_PORT_STATUS_DESC_OFFSET)
+        return msg
+
+
 @_set_msg_type(ofproto.OFPT_PACKET_OUT)
 class OFPPacketOut(MsgBase):
     """
-- 
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=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to