event: Add sync flag and event src for request/reply

- To distinguish synchronous request or not.
- Event src is needed for asynchronous request too.

Signed-off-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMADA Hideki 2013-03-14 19:16:05 +09:00 committed by FUJITA Tomonori
parent 9126ac201f
commit c249e76c3e
2 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,7 @@ from gevent.queue import Queue
from ryu import utils
from ryu.controller.handler import register_instance
from ryu.controller.controller import Datapath
from ryu.controller.event import EventRequestBase, EventReplyBase
LOG = logging.getLogger('ryu.base.app_manager')
@ -87,10 +88,12 @@ class RyuApp(object):
return observers
def send_reply(self, rep):
assert isinstance(rep, EventReplyBase)
SERVICE_BRICKS[rep.dst].replies.put(rep)
def send_request(self, req):
req.src = self.name
assert isinstance(req, EventRequestBase)
req.sync = True
self.send_event(req.dst, req)
# going to sleep for the reply
return self.replies.get()
@ -107,6 +110,8 @@ class RyuApp(object):
def send_event(self, name, ev):
if name in SERVICE_BRICKS:
if isinstance(ev, EventRequestBase):
ev.src = self.name
LOG.debug("EVENT %s->%s %s" %
(self.name, name, ev.__class__.__name__))
SERVICE_BRICKS[name]._send_event(ev)

View File

@ -21,9 +21,11 @@ class EventBase(object):
class EventRequestBase(EventBase):
def __init__(self, dst):
def __init__(self):
super(EventRequestBase, self).__init__()
self.dst = dst
self.dst = None # app.name of provide the event.
self.src = None
self.sync = False
class EventReplyBase(EventBase):