Hi Iwase,
I am already using topology.api and event, switches from ryu.topology. So this
code seems really simplified and organized to me. I will try this one and let
you know about what I found.
Thanking you
Sakib
On Wednesday, 8 April 2015, 4:53, Yusuke Iwase <[email protected]>
wrote:
Hi Sakib,
Please keep mailing list.
Ryu-devel <[email protected]>
> if I decorate my function with
> this(*@handler.set_ev_cls(event.EventLinkDelete)*) events
> I do not know how to get a datapath instance in my function so that i can
> call the add_flow
> function.
How about the following code?
e.g.)
...
from ryu.topology import api
from ryu.topology.event import EventLinkAdd, EventLinkDelete
...
...
class *YourApp*(app_manager.RyuApp):
...
...
@set_ev_cls(EventLinkAdd, MAIN_DISPATCHER)
def _link_add_handler(self, ev):
# Get link info
link = ev.link
self.logger.info("link add: %s", link.to_dict())
# Get datapath
src_sw = api.get_switch(self, link.src.dpid)[0]
src_dp = src_sw.dp
dst_sw = api.get_switch(self, link.dst.dpid)[0]
dst_dp = dst_sw.dp
self.logger.info("src_dp: %s, dst_dp: %s", src_dp, dst_dp)
@set_ev_cls(EventLinkDelete, MAIN_DISPATCHER)
def _link_delete_handler(self, ev):
# Get link info
link_dict = ev.link.to_dict()
self.logger.info("link delete: %s", link_dict)
# Get datapath
src_sw = api.get_switch(self, link.src.dpid)[0]
src_dp = src_sw.dp
dst_sw = api.get_switch(self, link.dst.dpid)[0]
dst_dp = dst_sw.dp
self.logger.info("src_dp: %s, dst_dp: %s", src_dp, dst_dp)
I'm sorry, I couldn't simplify the code for getting datapath instances by
topology.api module...
Thanks,
Iwase
On 2015年04月07日 18:58, MD.Badruzzaman Shakib wrote:
> Hello Iwase,
>
> Thank you for your response. I want to detect the link_add and link_delete
> events and also I need a datapath object to add/delete flow. I set the
> functions as follows-
>
> @handler.set_ev_cls(event.EventLinkAdd)
> def link_add_handler(self, ev):
>
> and
>
> @handler.set_ev_cls(event.EventLinkDelete)
> def link_del_handler(self, ev):
>
> I imported the following things in my application-
>
> from ryu.controller import ofp_event
> from ryu.controller import handler
> from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
> from ryu.controller.handler import set_ev_cls
>
> if I decorate my function with
> this(*@handler.set_ev_cls(event.EventLinkDelete)*) events I do not know how
> to get a datapath instance in my function so that i can call the add_flow
> function.
>
> Sorry I am not good in python. But can you please tell me, is it possible to
> do something like following so that i can have both -
>
>
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> @handler.set_ev_cls(event.EventLinkDelete)
> def link_del_handler(self, ev) :
>
>
> Thanking you
> Sakib
>
>
>
>
>
> On Tuesday, 7 April 2015, 4:11, Yusuke Iwase <[email protected]> wrote:
>
>
>
> Hi Sakib,
>
> On 2015年04月07日 10:02, MD.Badruzzaman Shakib wrote:
> > Hello everyone,
> >
> > I want to add/delete flows from my application when link_add/link_delete
>occurs. I create two separate handler function for link_add and link_delete
>which are decorated with corresponding event function. But in those functions
>I only have src, dst and src_port(connected to dst). But without any datapath
>object (ryu.controller.controller.Datapath) I cannot call my add_flow
>function. My add_flow function is given below. Can anyone please tell me how
>can I call the add_flow function from another function beside
>_packet_in_handler with the information(src, src_port, dst) i have? Is there
>any better process to add/delete flows without using packet_in_handler?
>
> What "event" did you set to your link_add/link_delete functions?
> You can get Datapath instance from Event instance("ev") in the event
>handlers.
>
> e.g.)
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> def switch_features_handler(self, ev):
> datapath = ev.msg.datapath
>
> Thanks,
> Iwase
>
>
> >
> > def add_flow(self, datapath, dst, actions):
> > ofproto = datapath.ofproto
> >
> > match = datapath.ofproto_parser.OFPMatch(
>
> > eth_type=0x800, ipv4_dst=dst)
> >
> > inst =
>[datapath.ofproto_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
>actions)]
> >
> > mod = datapath.ofproto_parser.OFPFlowMod(
> > datapath=datapath, match=match, cookie=0,
> > command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
> > priority=ofproto.OFP_DEFAULT_PRIORITY,
> > flags=ofproto.OFPFF_SEND_FLOW_REM, instructions= inst)
> >
> > datapath.send_msg(mod)
> >
> > Thanking you
> > Sakib
>
> >
> >
> >
> >
>------------------------------------------------------------------------------
> > BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
> > Develop your own process in accordance with the BPMN 2 standard
> > Learn Process modeling best practices with Bonita BPM through live
>exercises
> > http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
><http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual->event?utm_
> > source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
> >
> >
> >
> > _______________________________________________
> > Ryu-devel mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.sourceforge.net/lists/listinfo/ryu-devel
> >
>
>
>------------------------------------------------------------------------------
> BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
> Develop your own process in accordance with the BPMN 2 standard
> Learn Process modeling best practices with Bonita BPM through live
>exercises
> http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
><http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual->event?utm_
> source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
> _______________________________________________
> Ryu-devel mailing list
> [email protected] <mailto:[email protected]>
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
>
>
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel