diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2012-03-07 20:53:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-03-08 05:54:18 +0900 |
commit | 828f58b2a77e307d8ceb82cd8fdae27700166371 (patch) | |
tree | 22bd7592cd8f7d212fa329cac5163dd7e5b276ee | |
parent | bd738738829cec724c9a50007cf7667c826ae805 (diff) |
controller/network: fix key error
This patch fixes key error exception.
The switch may connect to the controller before network creation API call.
> Traceback (most recent call last):
> File "/usr/lib/pymodules/python2.7/gevent/greenlet.py", line 390, in run
> result = self._run(*self.args, **self.kwargs)
> File "/ryubin/ryu/controller/controller.py", line 237, in datapath_connection_factory
> datapath.serve()
> File "/ryubin/ryu/controller/controller.py", line 184, in serve
> self._recv_loop()
> File "/ryubin/ryu/controller/controller.py", line 63, in deactivate
> method(self)
> File "/ryubin/ryu/controller/controller.py", line 136, in _recv_loop
> self.ev_q.queue(ofp_event.ofp_msg_to_ev(msg))
> File "/ryubin/ryu/controller/dispatcher.py", line 106, in queue
> self._dispatcher(ev)
> File "/ryubin/ryu/controller/dispatcher.py", line 170, in __call__
> self.dispatch(ev)
> File "/ryubin/ryu/controller/dispatcher.py", line 187, in dispatch
> handled = self._dispatch(ev, self.events.get(ev.__class__, []))
> File "/ryubin/ryu/controller/dispatcher.py", line 178, in _dispatch
> ret = h(ev)
> File "/ryubin/ryu/app/simple_isolation.py", line 45, in switch_features_handler
> self.nw.add_datapath(ev.msg)
> File "/ryubin/ryu/controller/network.py", line 137, in add_datapath
> self.port_added(datapath, port_no)
> File "/ryubin/ryu/controller/network.py", line 144, in port_added
> dp = self.dpids[datapath.id]
> KeyError: None
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/network.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ryu/controller/network.py b/ryu/controller/network.py index e800bf0e..0c61ba07 100644 --- a/ryu/controller/network.py +++ b/ryu/controller/network.py @@ -28,6 +28,9 @@ class Network(object): self.networks = {} self.dpids = {} + def _dpids_setdefault(self, dpid): + return self.dpids.setdefault(dpid, {}) + def _check_nw_id_unknown(self, network_id): if network_id == self.nw_id_unknown: raise NetworkAlreadyExist(network_id=network_id) @@ -80,7 +83,7 @@ class Network(object): except KeyError: raise NetworkNotFound(network_id=network_id) - self.dpids.setdefault(dpid, {}) + self._dpids_setdefault(dpid) self.dpids[dpid][port] = network_id def create_port(self, network_id, dpid, port): @@ -132,7 +135,7 @@ class Network(object): datapath = ofp_switch_features.datapath dpid = ofp_switch_features.datapath_id ports = ofp_switch_features.ports - self.dpids.setdefault(dpid, {}) + self._dpids_setdefault(dpid) for port_no in ports: self.port_added(datapath, port_no) @@ -141,7 +144,7 @@ class Network(object): # skip fake output ports return - dp = self.dpids[datapath.id] + dp = self._dpids_setdefault(datapath.id) dp.setdefault(port_no, self.nw_id_unknown) def port_deleted(self, dpid, port_no): |