Hi Satoshi,

Thank you so much for the response.

My end goal is to pass a flow to the switch as soon as its up using OFv1.3.
I have written the following snippet of code but Im not sure where I am
going wrong. I would be obliged if you could help me out in this regard.

from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.topology import switches
from ryu.topology.event import EventSwitchEnter, EventSwitchLeave

class SwitchEventApp(app_manager.RyuApp):
  _CONTEXTS = {
    'switches': switches.Switches,
  }

  @set_ev_cls(EventSwitchEnter)
  def _ev_switch_enter_handler(self, ev):
    print('enter: %s' % ev)
    datapath = ev.msg.datapath (---->error on this line)
    ofproto = datapath.ofproto
    parser = datapath.ofproto_parser

    match = parser.OFPMatch()
    actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                       ofproto.OFPCML_NO_BUFFER)]
    self.add_flow(datapath, 0, match, actions)

  def add_flow(self, datapath, priority, match, actions):
    ofproto = datapath.ofproto
    parser = datapath.ofproto_parser

    inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]

    mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
                            match = match, instructions=inst)
    datapath.send_msg(mod)

The error I get is as follows:

ryu@ryu-vm:~/Desktop$ ryu-manager testSwitch.py
loading app testSwitch.py
loading app ryu.controller.ofp_handler
creating context switches
instantiating app testSwitch.py
instantiating app ryu.controller.ofp_handler
enter: EventSwitchEnter<dpid=427128799416224, 2 ports>
hub: uncaught exception: Traceback (most recent call last):
  File "/home/ryu/ryu/ryu/lib/hub.py", line 48, in _launch
    func(*args, **kwargs)
  File "/home/ryu/ryu/ryu/base/app_manager.py", line 110, in _event_loop
    handler(ev)
  File "/home/ryu/Desktop/testSwitch.py", line 19, in
_ev_switch_enter_handler
    datapath = ev.msg.datapath
AttributeError: 'EventSwitchEnter' object has no attribute 'msg'


I would be extremely obliged if you could help me here.

Regards,

Vinay Pai B.H.


On Tue, Feb 11, 2014 at 10:06 PM, Satoshi Kobayashi <
[email protected]> wrote:

> Hi Vinay,
>
> You can use EventSwitchEnter and EventSwitchLeave.
> (Note that this API is supported only by OpenFlow 1.0 and 1.3)
>
> ----------
> from ryu.base import app_manager
> from ryu.controller.handler import set_ev_cls
> from ryu.topology import switches
> from ryu.topology.event import EventSwitchEnter, EventSwitchLeave
>
> class SwitchEventApp(app_manager.RyuApp):
>
>     _CONTEXTS = {
>         'switches': switches.Switches,
>     }
>
>     @set_ev_cls(EventSwitchEnter)
>     def _ev_switch_enter_handler(self, ev):
>         print('enter: %s' % ev)
>
>     @set_ev_cls(EventSwitchLeave)
>     def _ev_switch_leave_handler(self, ev):
>         print('leave: %s' % ev)
>
> ----------
>
> Regards,
> Satoshi
>
>
>
> 2014-02-12 12:27 GMT+09:00 vinay pai <[email protected]>:
>
>> Hi All,
>>
>> I am traditionally a POX user and am more familiar with the APIs used
>> there. I have recently started using Ryu and am finding difficulty in
>> finding the appropriate APIs. In POX there is an API which is called when a
>> switch connects to the controller. It is _handle_ConnectionUp(). I am
>> searching for an equivalent event in Ryu. Should I be
>> using ryu.controller.handler.set_ev_cls(ev_cls, dispatchers=None) which the
>> negotiation phase as ryu.controller.handler.MAIN_DISPATCHER? or am I
>> missing a straight forward API.
>>
>> Apologies if the question has a very straight forward answer that I might
>> be missing out.
>>
>> Regards,
>>
>> Vinay Pai B.H.
>>
>> --
>> Vinay Pai B.H.
>> Grad Student - Computer Science
>> Viterbi School of Engineering
>> University of Southern California
>> Los Angeles, CA, USA
>>
>>
>> ------------------------------------------------------------------------------
>> Android apps run on BlackBerry 10
>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> Get your Android app in front of a whole new audience.  Start now.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Ryu-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>>
>>
>
>
> --
> Satoshi Kobayashi <[email protected]>
>



-- 
Vinay Pai B.H.
Grad Student - Computer Science
Viterbi School of Engineering
University of Southern California
Los Angeles, CA, USA
------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to