The way to handle multiple connections from the same datapath I took is mostly the same as in dpset, but it's always good to reinstall the LDAP Packet-In flows even while switch tries to reconnect to us.
Signed-off-by: Wei-Li Tang <[email protected]> --- ryu/topology/switches.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py index fb3af8e..66c79b5 100644 --- a/ryu/topology/switches.py +++ b/ryu/topology/switches.py @@ -471,12 +471,12 @@ class Switches(app_manager.RyuApp): def _register(self, dp): assert dp.id is not None - assert dp.id not in self.dps self.dps[dp.id] = dp - self.port_state[dp.id] = PortState() - for port in dp.ports.values(): - self.port_state[dp.id].add(port.port_no, port) + if not dp.id in self.port_state: + self.port_state[dp.id] = PortState() + for port in dp.ports.values(): + self.port_state[dp.id].add(port.port_no, port) def _unregister(self, dp): if dp.id in self.dps: @@ -526,10 +526,18 @@ class Switches(app_manager.RyuApp): LOG.debug(dp) if ev.state == MAIN_DISPATCHER: + MULTIPLE_CONNS = False + if dp.id in self.dps: + LOG.warning('multiple connections from %s', dpid_to_str(dp.id)) + MULTIPLE_CONNS = True + self._register(dp) switch = self._get_switch(dp.id) LOG.debug('register %s', switch) - self.send_event_to_observers(event.EventSwitchEnter(switch)) + + # Do not send EventSwitchEnter while multiple connections occured. + if not MULTIPLE_CONNS: + self.send_event_to_observers(event.EventSwitchEnter(switch)) if not self.link_discovery: return @@ -571,9 +579,12 @@ class Switches(app_manager.RyuApp): LOG.error('cannot install flow. unsupported version. %x', dp.ofproto.OFP_VERSION) - for port in switch.ports: - if not port.is_reserved(): - self._port_added(port) + # Do not add ports while multiple connections occured. + if not MULTIPLE_CONNS: + for port in switch.ports: + if not port.is_reserved(): + self._port_added(port) + self.lldp_event.set() elif ev.state == DEAD_DISPATCHER: -- 1.7.9.5 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
