On Sat, 14 Feb 2015 14:37:48 +0800
Zang MingJie <zealot0...@gmail.com> wrote:

> I have submitted a pull request
> 
> https://github.com/kghost/ryu/commit/f03b0373d292eff638ee99f07717989f0be4bad8

Thanks! Please send a patch with your Signed-off-by instead of a pull request.

>From f03b0373d292eff638ee99f07717989f0be4bad8 Mon Sep 17 00:00:00 2001
From: Zang MingJie <zealot0...@gmail.com>
Date: Fri, 13 Feb 2015 20:02:29 +0800
Subject: [PATCH] Fix req hang after openflow reconnect

---
 ryu/app/ofctl/exception.py |  9 +++++++++
 ryu/app/ofctl/service.py   | 18 ++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/ryu/app/ofctl/exception.py b/ryu/app/ofctl/exception.py
index 0155748..068fa80 100644
--- a/ryu/app/ofctl/exception.py
+++ b/ryu/app/ofctl/exception.py
@@ -31,6 +31,15 @@ class UnexpectedMultiReply(_ExceptionBase):
     message = 'Unexpected Multi replies %(result)s'
 
 
+class OFDead(_ExceptionBase):
+    """Connection to switch is closed."""
+
+    message = 'OpenFlow connection closed'
+
+    def __init__(self):
+        super(OFDead, self).__init__(result=None)
+
+
 class OFError(_ExceptionBase):
     """OFPErrorMsg is received."""
 
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index fd0b7a7..5da5034 100644
--- a/ryu/app/ofctl/service.py
+++ b/ryu/app/ofctl/service.py
@@ -91,6 +91,13 @@ class OfctlService(app_manager.RyuApp):
             info = self._switches[id]
         except KeyError:
             return
+        # make sure no more msg can be inserted
+        (xids, info.xids) = (info.xids, None)
+        for xid, req in xids.items():
+            if req.reply_cls is not None:
+                self._unobserve_msg(req.reply_cls)
+            rep = event.Reply(exception=exception.OFDead())
+            self.reply_to_request(req, rep)
         if info.datapath is datapath:
             self.logger.debug('forget info %s' % (info,))
             self._switches.pop(id)
@@ -107,20 +114,27 @@ class OfctlService(app_manager.RyuApp):
         rep = event.Reply(result=datapath)
         self.reply_to_request(req, rep)
 
-    @set_ev_cls(event.SendMsgRequest, MAIN_DISPATCHER)
+    @set_ev_cls(event.SendMsgRequest, [])

@set_ev_cls(event.SendMsgRequest)

?

     def _handle_send_msg(self, req):
         if req.reply_cls is not None:
             self._observe_msg(req.reply_cls)
 
         msg = req.msg
         datapath = msg.datapath
+        si = self._switches.get(datapath.id, None)
+        if (si is None or
+                datapath.state not in [CONFIG_DISPATCHER, MAIN_DISPATCHER] or
+                si.datapath != datapath):
+            rep = event.Reply(exception=exception.OFDead())
+            self.reply_to_request(req, rep)
+            return
+
         datapath.set_xid(msg)
         xid = msg.xid
         barrier = datapath.ofproto_parser.OFPBarrierRequest(datapath)
         datapath.set_xid(barrier)
         barrier_xid = barrier.xid
 
-        si = self._switches[datapath.id]
         assert xid not in si.results
         assert xid not in si.xids
         assert barrier_xid not in si.barriers
-- 
1.9.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to