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]> --- Changes v4 -> v5: - fix GRE tunnel app It directly uses RyuApp so that it needs modification. Changes v1 -> v2: - improve commit message app/gre_tunnel: teach RyuApp start/stop Since GRETunnel directly creates RyuApp, PortSet. So it needs to be updated. 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 38212df..29acd25 100644 --- a/ryu/app/gre_tunnel.py +++ b/ryu/app/gre_tunnel.py @@ -396,6 +396,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 4d902d4..94196c5 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -63,6 +63,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): @@ -234,6 +239,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.1.5 ------------------------------------------------------------------------------ Get your SQL database under version control now! Version control is standard for application code, but databases havent caught up. So what steps can you take to put your SQL databases under version control? Why should you start doing it? Read more to find out. http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
