Signed-off-by: Simon Horman <[email protected]>
---
 ryu/ofproto/ofproto_v1_4_parser.py | 81 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 05b6c08..8cbe3f1 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -183,6 +183,87 @@ class OFPEchoRequest(MsgBase):
 
 
 @_register_parser
+@_set_msg_type(ofproto.OFPT_ERROR)
+class OFPErrorMsg(MsgBase):
+    """
+    Error message
+
+    The switch notifies controller of problems by this message.
+
+    ========== =========================================================
+    Attribute  Description
+    ========== =========================================================
+    type       High level type of error
+    code       Details depending on the type
+    data       Variable length data depending on the type and code
+    ========== =========================================================
+
+    ``type`` attribute corresponds to ``type_`` parameter of __init__.
+
+    Types and codes are defined in ``ryu.ofproto.ofproto``.
+
+    ============================= ===========
+    Type                          Code
+    ============================= ===========
+    OFPET_HELLO_FAILED            OFPHFC_*
+    OFPET_BAD_REQUEST             OFPBRC_*
+    OFPET_BAD_ACTION              OFPBAC_*
+    OFPET_BAD_INSTRUCTION         OFPBIC_*
+    OFPET_BAD_MATCH               OFPBMC_*
+    OFPET_FLOW_MOD_FAILED         OFPFMFC_*
+    OFPET_GROUP_MOD_FAILED        OFPGMFC_*
+    OFPET_PORT_MOD_FAILED         OFPPMFC_*
+    OFPET_TABLE_MOD_FAILED        OFPTMFC_*
+    OFPET_QUEUE_OP_FAILED         OFPQOFC_*
+    OFPET_SWITCH_CONFIG_FAILED    OFPSCFC_*
+    OFPET_ROLE_REQUEST_FAILED     OFPRRFC_*
+    OFPET_METER_MOD_FAILED        OFPMMFC_*
+    OFPET_TABLE_FEATURES_FAILED   OFPTFFC_*
+    OFPET_EXPERIMENTER            N/A
+    ============================= ===========
+
+    Example::
+
+        @set_ev_cls(ofp_event.EventOFPErrorMsg,
+                    [HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
+        def error_msg_handler(self, ev):
+            msg = ev.msg
+
+            self.logger.debug('OFPErrorMsg received: type=0x%02x code=0x%02x '
+                              'message=%s',
+                              msg.type, msg.code, utils.hex_array(msg.data))
+    """
+    def __init__(self, datapath, type_=None, code=None, data=None):
+        super(OFPErrorMsg, self).__init__(datapath)
+        self.type = type_
+        self.code = code
+        self.data = data
+
+    @classmethod
+    def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
+        type_, = struct.unpack_from('!H', buffer(buf),
+                                    ofproto.OFP_HEADER_SIZE)
+        if type_ == ofproto.OFPET_EXPERIMENTER:
+            return OFPErrorExperimenterMsg.parser(datapath, version, msg_type,
+                                                  msg_len, xid, buf)
+        msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type,
+                                             msg_len, xid, buf)
+        msg.type, msg.code = struct.unpack_from(
+            ofproto.OFP_ERROR_MSG_PACK_STR, msg.buf,
+            ofproto.OFP_HEADER_SIZE)
+        msg.data = msg.buf[ofproto.OFP_ERROR_MSG_SIZE:]
+        return msg
+
+    def _serialize_body(self):
+        assert self.data is not None
+        msg_pack_into(ofproto.OFP_ERROR_MSG_PACK_STR, self.buf,
+                      ofproto.OFP_HEADER_SIZE, self.type, self.code)
+        self.buf += self.data
+
+
+
+
+@_register_parser
 @_set_msg_type(ofproto.OFPT_ECHO_REPLY)
 class OFPEchoReply(MsgBase):
     """
-- 
1.8.4


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to