summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/app/ofctl/exception.py9
-rw-r--r--ryu/app/ofctl/service.py16
2 files changed, 21 insertions, 4 deletions
diff --git a/ryu/app/ofctl/exception.py b/ryu/app/ofctl/exception.py
index 01557488..0c6555ac 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 bc05f878..2e04c27d 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