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>
This commit is contained in:
YAMAMOTO Takashi 2015-03-13 17:45:44 +09:00 committed by FUJITA Tomonori
parent f10f4f7cfd
commit 5d993c46ee
2 changed files with 21 additions and 4 deletions

View File

@ -35,3 +35,12 @@ class OFError(_ExceptionBase):
"""OFPErrorMsg is received.""" """OFPErrorMsg is received."""
message = 'OpenFlow errors %(result)s' message = 'OpenFlow errors %(result)s'
class InvalidDatapath(_ExceptionBase):
"""Datapath is invalid.
This can happen when the bridge disconnects.
"""
message = 'Datapath Invalid %(result)s'

View File

@ -109,18 +109,26 @@ class OfctlService(app_manager.RyuApp):
@set_ev_cls(event.SendMsgRequest, MAIN_DISPATCHER) @set_ev_cls(event.SendMsgRequest, MAIN_DISPATCHER)
def _handle_send_msg(self, req): 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: if req.reply_cls is not None:
self._observe_msg(req.reply_cls) self._observe_msg(req.reply_cls)
msg = req.msg
datapath = msg.datapath
datapath.set_xid(msg) datapath.set_xid(msg)
xid = msg.xid xid = msg.xid
barrier = datapath.ofproto_parser.OFPBarrierRequest(datapath) barrier = datapath.ofproto_parser.OFPBarrierRequest(datapath)
datapath.set_xid(barrier) datapath.set_xid(barrier)
barrier_xid = barrier.xid barrier_xid = barrier.xid
si = self._switches[datapath.id]
assert xid not in si.results assert xid not in si.results
assert xid not in si.xids assert xid not in si.xids
assert barrier_xid not in si.barriers assert barrier_xid not in si.barriers