From: yamamoto <[email protected]>

Report the failure to the client rather than crashing.

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/app/ofctl/exception.py |  9 +++++++++
 ryu/app/ofctl/service.py   | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/ryu/app/ofctl/exception.py b/ryu/app/ofctl/exception.py
index 0155748..0c6555a 100644
--- a/ryu/app/ofctl/exception.py
+++ b/ryu/app/ofctl/exception.py
@@ -35,3 +35,12 @@ class OFError(_ExceptionBase):
     """OFPErrorMsg is received."""
 
     message = 'OpenFlow errors %(result)s'
+
+
+class InvalidDatapath(_ExceptionBase):
+    """Datapath is invalid.
+
+    This can happen when the bridge disconnects.
+    """
+
+    message = 'Datapath Invalid %(result)s'
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index fd0b7a7..18fb5df 100644
--- a/ryu/app/ofctl/service.py
+++ b/ryu/app/ofctl/service.py
@@ -109,18 +109,26 @@ class OfctlService(app_manager.RyuApp):
 
     @set_ev_cls(event.SendMsgRequest, MAIN_DISPATCHER)
     def _handle_send_msg(self, req):
+        msg = req.msg
+        datapath = msg.datapath
+
+        try:
+            si = self._switches[datapath.id]
+        except KeyError:
+            self.logger.error('unknown dpid %s' % (datapath.id,))
+            rep = event.Reply(exception=exception.
+                              InvalidDatapath(result=datapath.id))
+            self.reply_to_request(req, rep)
+            return
+
         if req.reply_cls is not None:
             self._observe_msg(req.reply_cls)
 
-        msg = req.msg
-        datapath = msg.datapath
         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
-- 
2.1.0


------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to