diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2015-03-13 17:45:44 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-16 21:39:44 +0900 |
commit | 5d993c46ee5af7aca5ac13f0ae33734d8d67142e (patch) | |
tree | 21be46cda57f84e967116a3b14ecb3e889b2f797 | |
parent | f10f4f7cfd48327b60b4423cddf4066cc069a6d0 (diff) |
ryu.app.ofctl: Handle a race with connection close
Report the failure to the client rather than crashing.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/ofctl/exception.py | 9 | ||||
-rw-r--r-- | 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 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 |