From c16b232f38a64121ab23251b5b40f7d9fde575b2 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 31 Jan 2012 16:45:07 +0900 Subject: app: event dumper application This app dumps events occurred in specified dispatcher. Signed-off-by: Isaku Yamahata Signed-off-by: FUJITA Tomonori --- bin/ryu-manager | 11 +++++--- ryu/app/event_dumper.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 ryu/app/event_dumper.py diff --git a/bin/ryu-manager b/bin/ryu-manager index e8350fe9..61df86c6 100755 --- a/bin/ryu-manager +++ b/bin/ryu-manager @@ -28,17 +28,19 @@ log.earlyInitLog(logging.DEBUG) from ryu import flags from ryu import utils +from ryu.app import wsapi from ryu.base.app_manager import AppManager from ryu.controller import controller -from ryu.app import wsapi -from ryu.app import rest +from ryu.controller import dpset from ryu.controller import network FLAGS = gflags.FLAGS gflags.DEFINE_multistring('app_lists', ['ryu.app.simple_isolation.SimpleIsolation', - 'ryu.app.rest.restapi'], + 'ryu.app.rest.restapi', + # 'ryu.app.event_dumper.EventDumper', + ], 'application module name to run') @@ -48,9 +50,10 @@ def main(): log.initLog() nw = network.network() + dpset_ = dpset.create_dpset() app_mgr = AppManager() - app_mgr.load_apps(FLAGS.app_lists, network=nw) + app_mgr.load_apps(FLAGS.app_lists, network=nw, dpset=dpset_) services = [] diff --git a/ryu/app/event_dumper.py b/ryu/app/event_dumper.py new file mode 100644 index 00000000..977b34ad --- /dev/null +++ b/ryu/app/event_dumper.py @@ -0,0 +1,71 @@ +# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2012 Isaku Yamahata +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gflags +import logging + +from ryu.controller import dispatcher +from ryu.controller.handler import set_ev_cls + +LOG = logging.getLogger('ryu.app.event_dumper') + +FLAGS = gflags.FLAGS +gflags.DEFINE_multistring('dump_queue', [], + 'list of dispatcher name to dump event: default any') +gflags.DEFINE_multistring('dump_dispatcher', [], + 'list of dispatcher name to dump event: default any') + + +class EventDumper(object): + def __init__(self, *_args, **_kwargs): + # EventDispatcher can be created and cloned before us. + # So register it explicitly + for ev_q in dispatcher.EventQueue.event_queues: + if ev_q == dispatcher.QUEUE_EV_Q: + continue + LOG.info('%s: registering q %s dispatcher %s', + __name__, ev_q.name, ev_q.dispatcher.name) + self._register_dump_handler(ev_q, ev_q.dispatcher) + + @staticmethod + def _need_dump(name, name_list): + return len(name_list) == 0 or name in name_list + + def _register_dump_handler(self, ev_q, dispatcher): + if (self._need_dump(ev_q.name, FLAGS.dump_queue) or + self._need_dump(dispatcher.name, FLAGS.dump_dispatcher)): + dispatcher.register_all_handler(self._dump_event) + + @set_ev_cls(dispatcher.EventQueueCreate, dispatcher.QUEUE_EV_DISPATCHER) + def queue_create(self, ev): + if ev.create: + LOG.info('%s: queue created %s', __name__, ev.ev_q.name) + else: + LOG.info('%s: queue deleted %s', __name__, ev.ev_q.name) + + self._dump_event(ev) + self._register_dump_handler(ev.ev_q, ev.dispatcher) + + @set_ev_cls(dispatcher.EventDispatcherChange, + dispatcher.QUEUE_EV_DISPATCHER) + def dispatcher_change(self, ev): + LOG.info('%s: dispatcher change q %s dispatcher %s -> %s', __name__, + ev.ev_q.name, ev.old_dispatcher.name, ev.new_dispatcher.name) + + self._dump_event(ev) + self._register_dump_handler(ev.ev_q, ev.new_dispatcher) + + def _dump_event(self, ev): + LOG.info('%s: event %s', __name__, ev) -- cgit v1.2.3