OpenFlow Spec defines that the data field should contain at least
64 bytes of the failed request that caused the error message to be
generated, unless otherwise specified.
But, the data field can be empty in some switch implementation,
this patch checks the data field length and skips parsing it if the
field does not contain enough bytes to parse.

Reported-by: Yury Yurochko <[email protected]>
Signed-off-by: IWASE Yusuke <[email protected]>
---
 ryu/controller/ofp_handler.py | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index b3c63df..7ec1c95 100644
--- a/ryu/controller/ofp_handler.py
+++ b/ryu/controller/ofp_handler.py
@@ -243,22 +243,29 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
     def error_msg_handler(self, ev):
         msg = ev.msg
         ofp = msg.datapath.ofproto
-        (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
-        self.logger.debug('EventOFPErrorMsg received.')
         self.logger.debug(
-            'version=%s, msg_type=%s, msg_len=%s, xid=%s', hex(msg.version),
-            hex(msg.msg_type), hex(msg.msg_len), hex(msg.xid))
-        self.logger.debug(
-            ' `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg.msg_type))
-        self.logger.debug(
-            "OFPErrorMsg(type=%s, code=%s, data=b'%s')", hex(msg.type),
-            hex(msg.code), utils.binary_str(msg.data))
-        self.logger.debug(
-            ' |-- type: %s', ofp.ofp_error_type_to_str(msg.type))
-        self.logger.debug(
-            ' |-- code: %s', ofp.ofp_error_code_to_str(msg.type, msg.code))
-        self.logger.debug(
-            ' `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s',
-            hex(version), hex(msg_type), hex(msg_len), hex(xid))
-        self.logger.debug(
-            '     `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg_type))
+            "EventOFPErrorMsg received.\n"
+            "version=%s, msg_type=%s, msg_len=%s, xid=%s\n"
+            " `-- msg_type: %s\n"
+            "OFPErrorMsg(type=%s, code=%s, data=b'%s')\n"
+            " |-- type: %s\n"
+            " |-- code: %s",
+            hex(msg.version), hex(msg.msg_type), hex(msg.msg_len),
+            hex(msg.xid), ofp.ofp_msg_type_to_str(msg.msg_type),
+            hex(msg.type), hex(msg.code), utils.binary_str(msg.data),
+            ofp.ofp_error_type_to_str(msg.type),
+            ofp.ofp_error_code_to_str(msg.type, msg.code))
+        if len(msg.data) >= ofp.OFP_HEADER_SIZE:
+            (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
+            self.logger.debug(
+                " `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s\n"
+                "     `-- msg_type: %s",
+                hex(version), hex(msg_type), hex(msg_len), hex(xid),
+                ofp.ofp_msg_type_to_str(msg_type))
+        else:
+            self.logger.warning(
+                "The data field sent from the switch is too short: "
+                "len(msg.data) < OFP_HEADER_SIZE\n"
+                "The OpenFlow Spec says that the data field should contain "
+                "at least 64 bytes of the failed request.\n"
+                "Please check the settings or implementation of your switch.")
-- 
1.9.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to