From f89a9be369851675b221d7b8417d019298b28a63 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 24 Jan 2014 16:49:56 +0900 Subject: [PATCH] ofctl.service: fix some crashes Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/app/ofctl/service.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py index eac8d681..0b53d99b 100644 --- a/ryu/app/ofctl/service.py +++ b/ryu/app/ofctl/service.py @@ -45,16 +45,26 @@ class OfctlService(app_manager.RyuApp): datapath = ev.msg.datapath id = datapath.id assert isinstance(id, (int, long)) - self.logger.info('add dpid %s datapath %s' % (id, datapath)) - self._switches[datapath.id] = _SwitchInfo(datapath=datapath) + old_info = self._switches.get(id, None) + new_info = _SwitchInfo(datapath=datapath) + self.logger.info('add dpid %s datapath %s new_info %s old_info %s' % + (id, datapath, new_info, old_info)) + self._switches[id] = new_info @set_ev_cls(ofp_event.EventOFPStateChange, DEAD_DISPATCHER) def _handle_dead(self, ev): datapath = ev.datapath id = datapath.id self.logger.info('del dpid %s datapath %s' % (id, datapath)) - datapath2 = self._switches.pop(id) - assert datapath2 == datapath + if id is None: + return + try: + info = self._switches[id] + except KeyError: + return + if info.datapath is datapath: + self.logger.info('forget info %s' % (info,)) + self._switches.pop(id) @set_ev_cls(event.GetDatapathRequest, MAIN_DISPATCHER) def _handle_get_datapath(self, req):