On Mon, 24 Nov 2014 21:07:00 +0800
Shih-Hong Shen <[email protected]> wrote:

> Hi,
> 
> I'm a new for ryu controller.
> I am trying to understand the code of simple_switch_13.py.

If you are a new for Ryu, I would recommend you to read only
simple_switch_13.py instead of the core of Ryu, which use some
complicated Python magics. You can write your applications without
knowing how @set_ev_cls works.

> But I have some problems about this simple file,
> 
> 1) I cannot understand the decorator how to work, just like the follow code:
> 
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)def
> _switch_features_handler(self, ev):
>     datapath = ev.msg.datapath
>     ....

Again, you can write handlers without knowing how the above decorator
works. You are still interested in, then the following is a starting point:

https://github.com/osrg/ryu/blob/master/ryu/controller/handler.py#L49

In short, the function add 'callers' attribute to a handler. Then when
this application starts, register_instance() registers the handler:

https://github.com/osrg/ryu/blob/master/ryu/controller/handler.py#L81

If you are interested in how registered handlers work, check out the following:

https://github.com/osrg/ryu/blob/master/ryu/base/app_manager.py

> 
> 2)  Why the function is represented register an event?  How does it work?
> 
> def _set_ev_cls_dec111(handler):
> 
>         if 'callers' not in dir(handler):
> 
>             handler.callers = {}
> 
>         for e in _listify(ev_cls):
> 
>             handler.callers[e] = _Caller(_listify(dispatchers),
> e.__module__)
> 
>         return handler
> 
>     return _set_ev_cls_dec
> 
> 
> Could you please kindly tell me above two question?
> Could you please use some simple instances to explain the question?
> 
> Thank you very much for your kindly help.
> 
> 
> -- 
> Sincerely,
> 
> Andy Shen

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to