Thank you for the packet capture.
It looks like the switch sends malfold OF packets. What switch are you using?
I attached the patch which improve an error message. Can you please test it?

> OpenFlow Protocol
>     Header
>         Version: 0x01
>         Type: Packet In (AM) (10)
>         Length: 18
                  ^^ This should be rounded up to 20
                     And there should be 2 bytes padding at the end.

>         Transaction ID: 0
>     Packet In
>         Buffer ID: 4294967295
>         Frame Total Length: 48
>         Frame Recv Port: 2
>         Reason Sent: Action explicitly output to controller (1)

thanks,

>From 3617d9557a030b0241f6bb50212c6b36796779c7 Mon Sep 17 00:00:00 2001
Message-Id: 
<3617d9557a030b0241f6bb50212c6b36796779c7.1363859652.git.yamah...@valinux.co.jp>
From: Isaku Yamahata <[email protected]>
Date: Thu, 21 Mar 2013 18:51:39 +0900
Subject: [PATCH] ofproto_parser: dump packets if error is encountered during
 parse

Signed-off-by: Isaku Yamahata <[email protected]>
---
 ryu/ofproto/ofproto_parser.py |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py
index 26adead..92958b8 100644
--- a/ryu/ofproto/ofproto_parser.py
+++ b/ryu/ofproto/ofproto_parser.py
@@ -18,6 +18,7 @@ import logging
 import struct
 
 from ryu import exception
+from ryu import utils
 
 from . import ofproto_common
 
@@ -47,7 +48,15 @@ def msg(datapath, version, msg_type, msg_len, xid, buf):
     if msg_parser is None:
         raise exception.OFPUnknownVersion(version=version)
 
-    return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
+    try:
+        return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
+    except struct.error:
+        LOG.exception(
+            'Encounter an error during parsing OpenFlow packet from switch.'
+            'This implies switch sending a malfold OpenFlow packet.'
+            'version 0x%02x msg_type %d msg_len %d xid %d buf %s',
+            version, msg_type, msg_len, xid, utils.hex_array(buf))
+        raise
 
 
 class MsgBase(object):
-- 
1.7.10.4



On Mon, Mar 18, 2013 at 03:09:11PM +0800, can. wrote:
> Hello Isaku, 
> 
> A capture file is attached to the mail.
> The IP 10.0.2.15 is a virtual machine running mininet, and IP 10.109.242.118 
> is
> the host running ryu.
> I suspect that it's the first packetIn packets cause ryu to crash as you can
> see the FIN packets are only a few milliseconds after those packetIn packets.
> 
> 
> 2013/3/18 Isaku Yamahata <[email protected]>
> 
>     On Mon, Mar 18, 2013 at 09:59:46AM +0800, Can Zhang wrote:
>     > Hello,
> 
>     Hello.
> 
> 
>     > I encounter the errors below quite often recently:
>     > ----
>     > Traceback (most recent call last):
>     >   File "build/bdist.macosx-10.8-intel/egg/gevent/greenlet.py", line 390,
>     in run
>     >     result = self._run(*self.args, **self.kwargs)
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/
>     controller/
>     > controller.py", line 307, in datapath_connection_factory
>     >     datapath.serve()
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/
>     controller/
>     > controller.py", line 227, in serve
>     >     self._recv_loop()
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/
>     controller/
>     > controller.py", line 97, in deactivate
>     >     method(self)
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/
>     controller/
>     > controller.py", line 170, in _recv_loop
>     >     version, msg_type, msg_len, xid, buf)
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/ofproto/
>     > ofproto_parser.py", line 50, in msg
>     >     return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/ofproto/
>     > ofproto_v1_0_parser.py", line 52, in msg_parser
>     >     return parser(datapath, version, msg_type, msg_len, xid, buf)
>     >   File "/Library/Python/2.7/site-packages/ryu-1.7-py2.7.egg/ryu/ofproto/
>     > ofproto_v1_0_parser.py", line 1564, in parser
>     >     msg.buf, ofproto_v1_0.OFP_HEADER_SIZE)
>     > error: unpack_from requires a buffer of at least 12 bytes
>     > <Greenlet at 0x10d9f1d70: datapath_connection_factory(<socket at
>     0x10dd80fd0
>     > fileno=8 sock=10.109.242.11, ('10.109.242.118', 50694))> failed with
>     error
>     >
>     > ----
>     >
>     > For one of the triggers you may refer to   http://sourceforge.net/
>     mailarchive/
>     > forum.php?thread_name=
>     > 20130314.084438.1568838937885763874.fujita.tomonori%40lab.ntt.co.jp&
>     forum_name=
>     > ryu-devel
>     >
>     > It seems that if an app I write fails to meet some unknown standard, the
>     switch
>     > will send some packets that ryu cannot handle properly, and then ryu
>     crashes.
>     > Maybe this is a bug of ryu?
> 
>     You're right. Ryu should handle such OF packets more gracefully. Not 
> crash.
>     (And log it with understandable message?)
>     Anyway, can you post (a part of) your app to reproduce it easily?
>     Or can you post the packet capture that caused the crash?
> 
> 
>     > FYI, I'm using ryu with mininet(open vSwitch 1.9.0)
> 
>     If you'd like to use IPv6 support, OF v1.2+ needs to be enabled.
>     e.g.
>     ovs-vsctl set bridge s1 protocols=OpenFlow10,OpenFlow12,OpenFlow13
>     Since mininet is unaware of OF version, it should be done manually.
> 
>     thanks,
> 
>     >
>     >
>     > Best regards,
>     > Can Zhang
>     >
>     >
>     >
>     >
> 
>     >
>     
> ------------------------------------------------------------------------------
>     > Everyone hates slow websites. So do we.
>     > Make your web apps faster with AppDynamics
>     > Download AppDynamics Lite for free today:
>     > http://p.sf.net/sfu/appdyn_d2d_mar
>     > _______________________________________________
>     > Ryu-devel mailing list
>     > [email protected]
>     > https://lists.sourceforge.net/lists/listinfo/ryu-devel
>    
> 
>     --
>     yamahata
> 
> 
> 
> 
> --
> Best regards, 
> Can Zhang


> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel


-- 
yamahata

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to