From: Isaku Yamahata <[email protected]> There is a race between RyuApp instantiation and starting its thread. Each RyuApp spawns an event-loop thread which handles events and may generate events when a RyuApp instance is created. Currently on startup, necessary RyuApps are created, and event-loop thread is created at the same time. Then event-piping (which events are delivered to which RyuApp) is done. This causes missing events if RyuApp which was create early generates events before finishing event-piping.
To address it, split RyuApp startup into three phases from two phase. - create RyuApp instances - event piping - then, start event-loop threads. Signed-off-by: Isaku Yamahata <[email protected]> Signed-off-by: YAMAMOTO Takashi <[email protected]> --- ryu/app/gre_tunnel.py | 10 ++++++++++ ryu/base/app_manager.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/ryu/app/gre_tunnel.py b/ryu/app/gre_tunnel.py index 10d1f30..3e9fbe7 100644 --- a/ryu/app/gre_tunnel.py +++ b/ryu/app/gre_tunnel.py @@ -400,6 +400,16 @@ class GRETunnel(app_manager.RyuApp): [dpset.EventDP, PortSet.EventTunnelKeyDel, PortSet.EventVMPort, PortSet.EventTunnelPort, ofp_event.EventOFPPacketIn]) + def start(self): + super(GRETunnel, self).start() + self.port_set.start() + + def stop(self): + app_mgr = app_manager.get_instance() + app_mgr.uninstantiate(self.port_set) + self.port_set = None + super(GRETunnel, self).stop() + # TODO: track active vm/tunnel ports @handler.set_ev_handler(dpset.EventDP) diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index 3e40daa..fc034db 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -64,6 +64,11 @@ class RyuApp(object): self.events = hub.Queue(128) self.replies = hub.Queue() self.logger = logging.getLogger(self.name) + + def start(self): + """ + Hook that is called after startup initialization is done. + """ self.threads.append(hub.spawn(self._event_loop)) def register_handler(self, ev_cls, handler): @@ -241,6 +246,9 @@ class AppManager(object): for ev_cls in i.event_handlers.keys(): LOG.debug(" CONSUMES %s" % (ev_cls.__name__,)) + for app in self.applications.values(): + app.start() + def close(self): def close_all(close_dict): for app in close_dict.values(): -- 1.8.3.1 ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
