diff options
author | Victor Orlikowski <vjo@duke.edu> | 2016-01-27 05:53:15 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-31 13:19:27 +0900 |
commit | e3d07218924fe67c292d4070027bf5881029df18 (patch) | |
tree | 85cbb710c71350beaff6c36a259706761053e9fd | |
parent | 14379f280bcc4b3f8d24b0db8c50076141ccdbc0 (diff) |
Reconnected event additions and cleanups
This patch adds ports to the EventDPReconnected in dpset, and adds an EventSwitchReconnected to the topology module.
Signed-off-by: Victor J. Orlikowski <vjo@duke.edu>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/dpset.py | 4 | ||||
-rw-r--r-- | ryu/topology/event.py | 5 | ||||
-rw-r--r-- | ryu/topology/switches.py | 38 |
3 files changed, 31 insertions, 16 deletions
diff --git a/ryu/controller/dpset.py b/ryu/controller/dpset.py index 2682777b..1ec6a338 100644 --- a/ryu/controller/dpset.py +++ b/ryu/controller/dpset.py @@ -56,6 +56,8 @@ class EventDP(EventDPBase): class EventDPReconnected(EventDPBase): def __init__(self, dp): super(EventDPReconnected, self).__init__(dp) + # port list, which should not change across reconnects + self.ports = [] class EventPortBase(EventDPBase): @@ -138,6 +140,7 @@ class DPSet(app_manager.RyuApp): self.send_event_to_observers(ev) if send_dp_reconnected: ev = EventDPReconnected(dp) + ev.ports = self.port_state.get(dp.id, {}).values() self.send_event_to_observers(ev) def _unregister(self, dp): @@ -163,7 +166,6 @@ class DPSet(app_manager.RyuApp): """ This method returns the ryu.controller.controller.Datapath instance for the given Datapath ID. - Raises KeyError if no such a datapath connected to this controller. """ return self.dps.get(dp_id) diff --git a/ryu/topology/event.py b/ryu/topology/event.py index c54152bf..e7b682c9 100644 --- a/ryu/topology/event.py +++ b/ryu/topology/event.py @@ -41,6 +41,11 @@ class EventSwitchLeave(EventSwitchBase): super(EventSwitchLeave, self).__init__(switch) +class EventSwitchReconnected(EventSwitchBase): + def __init__(self, switch): + super(EventSwitchReconnected, self).__init__(switch) + + class EventPortBase(event.EventBase): def __init__(self, port): super(EventPortBase, self).__init__() diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py index e21f00eb..d429effd 100644 --- a/ryu/topology/switches.py +++ b/ryu/topology/switches.py @@ -499,6 +499,7 @@ class Switches(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION, ofproto_v1_2.OFP_VERSION, ofproto_v1_3.OFP_VERSION, ofproto_v1_4.OFP_VERSION] _EVENTS = [event.EventSwitchEnter, event.EventSwitchLeave, + event.EventSwitchReconnected, event.EventPortAdd, event.EventPortDelete, event.EventPortModify, event.EventLinkAdd, event.EventLinkDelete, @@ -551,8 +552,9 @@ class Switches(app_manager.RyuApp): def _unregister(self, dp): if dp.id in self.dps: - del self.dps[dp.id] - del self.port_state[dp.id] + if (self.dps[dp.id] == dp): + del self.dps[dp.id] + del self.port_state[dp.id] def _get_switch(self, dpid): if dpid in self.dps: @@ -606,16 +608,18 @@ class Switches(app_manager.RyuApp): if ev.state == MAIN_DISPATCHER: dp_multiple_conns = False if dp.id in self.dps: - LOG.warning('multiple connections from %s', dpid_to_str(dp.id)) + LOG.warning('Multiple connections from %s', dpid_to_str(dp.id)) dp_multiple_conns = True + (self.dps[dp.id]).close() self._register(dp) switch = self._get_switch(dp.id) LOG.debug('register %s', switch) - # Do not send event while dp has multiple connections. if not dp_multiple_conns: self.send_event_to_observers(event.EventSwitchEnter(switch)) + else: + self.send_event_to_observers(event.EventSwitchReconnected(switch)) if not self.link_discovery: return @@ -669,19 +673,23 @@ class Switches(app_manager.RyuApp): # dp.id is None when datapath dies before handshake if dp.id is None: return + switch = self._get_switch(dp.id) - self._unregister(dp) - LOG.debug('unregister %s', switch) - self.send_event_to_observers(event.EventSwitchLeave(switch)) + if switch: + if switch.dp is dp: + self._unregister(dp) + LOG.debug('unregister %s', switch) - if not self.link_discovery: - return + self.send_event_to_observers(event.EventSwitchLeave(switch)) - for port in switch.ports: - if not port.is_reserved(): - self.ports.del_port(port) - self._link_down(port) - self.lldp_event.set() + if not self.link_discovery: + return + + for port in switch.ports: + if not port.is_reserved(): + self.ports.del_port(port) + self._link_down(port) + self.lldp_event.set() @set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER) def port_status_handler(self, ev): @@ -766,7 +774,7 @@ class Switches(app_manager.RyuApp): try: src_dpid, src_port_no = LLDPPacket.lldp_parse(msg.data) except LLDPPacket.LLDPUnknownFormat as e: - # This handler can receive all the packtes which can be + # This handler can receive all the packets which can be # not-LLDP packet. Ignore it silently return |