summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-03-31 04:21:35 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-04-01 17:29:16 +0900
commite772be871793879368fe8afdfecb463c61b20d04 (patch)
tree2a436e3b40f351a54de1dbf0aad6ae96d0841ddf
parent77a6afa309339799d192b03c04406152b03df8b6 (diff)
bgp: use hub.Event to wait for the core_service boot instead of sleep
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/api/core.py5
-rw-r--r--ryu/services/protocols/bgp/application.py10
-rw-r--r--ryu/services/protocols/bgp/core.py2
-rw-r--r--ryu/services/protocols/bgp/core_manager.py3
4 files changed, 12 insertions, 8 deletions
diff --git a/ryu/services/protocols/bgp/api/core.py b/ryu/services/protocols/bgp/api/core.py
index 0580f615..284f9f93 100644
--- a/ryu/services/protocols/bgp/api/core.py
+++ b/ryu/services/protocols/bgp/api/core.py
@@ -37,9 +37,10 @@ def start(**kwargs):
raise RuntimeConfigError('Current context has to be stopped to start '
'a new context.')
+ waiter = kwargs.pop('waiter')
common_config = CommonConf(**kwargs)
- eventlet.spawn(CORE_MANAGER.start, *[], **{'common_conf': common_config})
- eventlet.sleep(2)
+ eventlet.spawn(CORE_MANAGER.start, *[], **{'common_conf': common_config,
+ 'waiter' : waiter})
return True
diff --git a/ryu/services/protocols/bgp/application.py b/ryu/services/protocols/bgp/application.py
index dbff33d8..2df49f52 100644
--- a/ryu/services/protocols/bgp/application.py
+++ b/ryu/services/protocols/bgp/application.py
@@ -20,6 +20,8 @@ import imp
import logging
import traceback
+from ryu.lib import hub
+
from ryu.services.protocols.bgp.api.base import call
from ryu.services.protocols.bgp.base import add_bgp_error_metadata
from ryu.services.protocols.bgp.base import BGPSException
@@ -150,11 +152,9 @@ class BaseApplication(object):
common_settings[LABEL_RANGE] = label_range
# Start BGPS core service
- call('core.start', **common_settings)
- # Give chance for core to start running
-
- # TODO(Team): How to wait for core start to happen?!
- eventlet.sleep(3)
+ waiter = hub.Event()
+ call('core.start', waiter=waiter, **common_settings)
+ waiter.wait()
LOG.debug('Core started %s' % CORE_MANAGER.started)
# Core manager started add configured neighbor and vrfs
diff --git a/ryu/services/protocols/bgp/core.py b/ryu/services/protocols/bgp/core.py
index fe445eb0..42bbe151 100644
--- a/ryu/services/protocols/bgp/core.py
+++ b/ryu/services/protocols/bgp/core.py
@@ -215,6 +215,8 @@ class CoreService(Factory, Activity):
# Reactively establish bgp-session with peer by listening on
# server port for connection requests.
server_addr = (CORE_IP, self._common_config.bgp_server_port)
+ waiter = kwargs.pop('waiter')
+ waiter.set()
server_thread = self._listen_tcp(server_addr, self.start_protocol)
server_thread.wait()
diff --git a/ryu/services/protocols/bgp/core_manager.py b/ryu/services/protocols/bgp/core_manager.py
index 8d26a3bc..fbee25f4 100644
--- a/ryu/services/protocols/bgp/core_manager.py
+++ b/ryu/services/protocols/bgp/core_manager.py
@@ -41,7 +41,8 @@ class _CoreManager(Activity):
self._core_service = CoreService(self._common_conf,
self._neighbors_conf,
self._vrfs_conf)
- core_activity = self._spawn_activity(self._core_service)
+ waiter = kwargs.pop('waiter')
+ core_activity = self._spawn_activity(self._core_service, waiter=waiter)
core_activity.wait()
def get_core_service(self):