diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2013-11-22 16:45:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-11-22 14:50:15 -0800 |
commit | 5dd45aea0c9c2967d465f53fe707ed536c32ce5b (patch) | |
tree | 20e63ae8878a69f8a9ca4be2cf2e43c3dc2357f4 | |
parent | b7235b395a270e80bbf9ffadbff3098bd9a7d6de (diff) |
base/app_manager: RyuApp initialization race at startup
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 <yamahata@valinux.co.jp>
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/gre_tunnel.py | 10 | ||||
-rw-r--r-- | ryu/base/app_manager.py | 8 |
2 files changed, 18 insertions, 0 deletions
diff --git a/ryu/app/gre_tunnel.py b/ryu/app/gre_tunnel.py index 10d1f30a..3e9fbe72 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 a5f1c4cf..21e129b5 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): @@ -240,6 +245,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(): |