Hi,

How about using the "User-Defined Events" in your own RyuApp?

The followings are snippets for the "User-Defined Events":

$ cat ryu/app/event_sender.py 
# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ryu.base import app_manager
from ryu.controller import event
from ryu.lib import hub


# A user defined event class
class TestEvent(event.EventBase):
    def __init__(self, msg):
        super(TestEvent, self).__init__()
        self.msg = msg


class EventSender(app_manager.RyuApp):
    # Register user defined events which this RyuApp would generate
    _EVENTS = [TestEvent]

    def _periodic_event_loop(self):
        while True:
            hub.sleep(5)
            ev = TestEvent('TEST EVENT')
            self.logger.info('*** Send event: event.msg = %s', ev.msg)
            self.send_event_to_observers(ev)

    def start(self):
        super(EventSender, self).start()
        # Start user defined event loop
        self.threads.append(hub.spawn(self._periodic_event_loop))
$ 
$ 
$ cat ryu/app/event_receiver.py 
# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ryu.app import event_sender
from ryu.base import app_manager
from ryu.controller.handler import set_ev_cls


class EventReceiver(app_manager.RyuApp):

    # Catch a user defined event with "set_ev_cls" decorator
    @set_ev_cls(event_sender.TestEvent)
    def _test_event_handler(self, ev):
        self.logger.info('*** Received event: ev.msg = %s', ev.msg)
$ 
$ 
$ python setup.py install
$ 
$ 
$ ryu-manager ryu.app.event_sender ryu.app.event_receiver
loading app ryu.app.event_sender
loading app ryu.app.event_receiver
instantiating app ryu.app.event_receiver of EventReceiver
instantiating app ryu.app.event_sender of EventSender
*** Send event: event.msg = TEST EVENT
*** Received event: ev.msg = TEST EVENT
*** Send event: event.msg = TEST EVENT
*** Received event: ev.msg = TEST EVENT
...
...


Thanks,
Iwase


On 2016年01月11日 12:59, Anees Mohsin Hadi Al-Najjar wrote:
> Hi Guys,
> 
>  
> 
> Kindly, is there any way to trigger an event to Ryu controller at each 
> certain time, e.g. for each 5 sec?
> 
>  
> 
> Thanks a lot
> 
>  
> 
> Anees AL-Najjar
> 
> RHD Student*
> *School of Information Technology and Electrical Engineering (ITEE)
> Office: 331, Building (78)
> 
> University of Queensland
> 
> Emails: 1- [email protected] <mailto:[email protected]>
> 
>             [email protected] <mailto:[email protected]>
> 
> Moibile: +61420407168
> 
>  
> 
> 
> 
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
> 
> 
> 
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to