Re: [Ryu-devel] Increasing timeouts
Brought to you by:
nz_gizmoguy
|
From: Yusuke I. <iwa...@gm...> - 2015-04-14 06:46:24
|
Hi Govind,
I think your app needs some modification.
1. The method name "_packet_in_handler" is duplicated.
If you need to add another method for Packet-In,
Please change the method name.
2. Import module of "tcp" packet lib is missing.
+ from ryu.lib.packet import tcp
3. If the processing of sending OFPFlowMod messase from "add_flow" method,
L2 swtiching functions are lost.
I recommend you to reuse "add_flow" method with some modification.
Then how about the following? I modified the simple_switch.py.
Please note that there are some TODOs.
$ git diff
diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py
index 8fd3d21..b9a785b 100644
--- a/ryu/app/simple_switch.py
+++ b/ryu/app/simple_switch.py
@@ -29,6 +29,7 @@ from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
+from ryu.lib.packet import tcp
class SimpleSwitch(app_manager.RyuApp):
@@ -38,7 +39,7 @@ class SimpleSwitch(app_manager.RyuApp):
super(SimpleSwitch, self).__init__(*args, **kwargs)
self.mac_to_port = {}
- def add_flow(self, datapath, in_port, dst, actions):
+ def add_flow(self, datapath, in_port, dst, actions, idle_timeout):
ofproto = datapath.ofproto
match = datapath.ofproto_parser.OFPMatch(
@@ -46,8 +47,8 @@ class SimpleSwitch(app_manager.RyuApp):
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,
+ command=ofproto.OFPFC_ADD, idle_timeout=idle_timeout,
+ hard_timeout=0, priority=ofproto.OFP_DEFAULT_PRIORITY,
flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
datapath.send_msg(mod)
@@ -59,10 +60,16 @@ class SimpleSwitch(app_manager.RyuApp):
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
+ pkt_tcp = pkt.get_protocol(tcp.tcp)
dst = eth.dst
src = eth.src
+ dst_port = None
+ if pkt_tcp:
+ dst_port = pkt_tcp.dst_port
+ print "dst_port = %d" % dst_port
+
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
@@ -80,7 +87,15 @@ class SimpleSwitch(app_manager.RyuApp):
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
- self.add_flow(datapath, msg.in_port, dst, actions)
+ if dst_port is None:
+ # TODO: in case of non-TCP packet.
+ # If install a flow, no longer packet-in comes.
+ # Please handle this case as you want.
+ pass
+ elif dst_port<5000:
+ self.add_flow(datapath, msg.in_port, dst, actions, 100)
+ else:
+ self.add_flow(datapath, msg.in_port, dst, actions, 30)
data = None
if msg.buffer_id == ofproto.OFP_NO_BUFFER:
Thanks,
Iwase
On 2015年04月14日 08:10, Govind Prasad wrote:
> Hi Yusuke,
>
> Please let me know if you need any more information on this to achieve the desired result.
>
> Thanks a lot for your esteemed support !!!
>
> Regards,
> Govind Prasad
>
> On Mon, Apr 13, 2015 at 1:56 PM, Govind Prasad <pr....@gm... <mailto:pr....@gm...>> wrote:
>
> Hi Yusuke,
>
> The following is my openflow version:
>
> govind@govind-RYU-virtual-machine:~/ryu$ ovs-vswitchd --version
> ovs-vswitchd (Open vSwitch) 2.0.2
> Compiled Aug 15 2014 14:31:03
> OpenFlow versions 0x1:0x1
>
> when I run the controller script "simple_switch_scott.py" my edited file (also attached herewith for your reference), I am not able to see the logs for flow modification in the switch as shown below:
>
> 2015-04-13T18:49:00.223Z|00624|rconn|INFO|s1<->tcp:127.0.0.1:6633 <http://127.0.0.1:6633>: connecting...
> 2015-04-13T18:49:00.238Z|00625|rconn|INFO|s1<->tcp:127.0.0.1:6633 <http://127.0.0.1:6633>: connected
>
> However, when I run the normal simple_switch.py script, I get a flow mod message from controller to switch as shown below:
>
> 2015-04-13T18:40:45.951Z|00416|rconn|INFO|s1<->tcp:127.0.0.1:6633 <http://127.0.0.1:6633>: connected
> 2015-04-13T18:41:59.927Z|00417|ofproto|INFO|s1: 2 flow_mods 10 s ago (2 adds)
>
>
> Please suggest what should be my next step to achieve the desired result.
>
> Regards,
> Govind Prasad
>
> On Mon, Apr 13, 2015 at 1:42 AM, Yusuke Iwase <iwa...@gm... <mailto:iwa...@gm...>> wrote:
>
> Hi Govind,
>
> Did you get any error messages from ryu-manager?
> If not, first, please check OpenFlow version of your swtich.
> ("simple_switch.py" is OpenFlow 1.0 App.)
>
> And, by capturing packet with Wireshark, you can get the helpful information for debug.
> (e.g. whether Controller sends FlowMod message? Switch sends any Error Message?...etc)
>
> Thanks,
> Iwase
>
> On 2015年04月13日 15:02, Govind Prasad wrote:
> > Hi Yusuke,
> >
> > Thanks for the suggestion, I tried the following code in "simple_switch.py" however when I send TCP packets from h1 to h2 using iperf in mininet, the packets are getting transmitted but the flows are not getting written in the switch table:
> >
> > @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> > def _packet_in_handler(self, ev):
> > msg = ev.msg
> >
> > pkt = packet.Packet(msg.data)
> > pkt_tcp = pkt.get_protocol(tcp.tcp)
> >
> > if pkt_tcp:
> > mod = datapath.ofproto_parser.OFPFlowMod(
> > datapath=datapath, match=match, cookie=0,
> > command=ofproto.OFPFC_ADD, idle_timeout=100, hard_timeout=0,
> > priority=ofproto.OFP_DEFAULT_PRIORITY,
> > flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
> > datapath.send_msg(mod)
> > else:
> > mod = datapath.ofproto_parser.OFPFlowMod(
> > datapath=datapath, match=match, cookie=0,
> > command=ofproto.OFPFC_ADD, idle_timeout=30, hard_timeout=0,
> > priority=ofproto.OFP_DEFAULT_PRIORITY,
> > flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
> > datapath.send_msg(mod)
> >
> >
> > can you please advise whether I am doing it right as I am not very good in programming and started learning python these days.
> >
> > Appreciate your help!!!
> >
> > Regards,
> > Govind Prasad
> >
> >
> >
> > On Sun, Apr 12, 2015 at 8:30 PM, Yusuke Iwase <iwa...@gm... <mailto:iwa...@gm...> <mailto:iwa...@gm... <mailto:iwa...@gm...>>> wrote:
> >
> > Hi Govind,
> >
> > > 4. If port numbe is greater than 5000, idle timeout is 100 seconds.
> >
> > You can parse the Packet-In data and get the port number by using packet library.
> >
> > e.g.)
> > @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> > def _packet_in_handler(self, ev):
> > msg = ev.msg
> >
> > pkt = packet.Packet(msg.data)
> > pkt_tcp = pkt.get_protocol(tcp.tcp)
> >
> > if pkt_tcp:
> > dst_port = pkt_tcp.dst_port
> > print "dst_port = %d" % dst_port
> >
> >
> > For more information of packet library, please refer to the Ryu-Book.
> > (http://osrg.github.io/ryu-book/en/html/packet_lib.html)
> >
> > Thanks,
> > Iwase
> >
> > On 2015年04月13日 08:18, Govind Prasad wrote:
> > > Hi yusuke,
> > >
> > > Thanks fir the info however can you please specify how to implement the following scenario:
> > >
> > > 1. Iperf client send the tcp message on port 8000
> > > 2. Iperf server receives the tcp port through ovs
> > > 3. Ryu asks the ovs to write the flow with default values
> > > 4. If port numbe is greater than 5000, idle timeout is 100 seconds.
> > >
> > > This is what I want to implement. Can you please guide.
> > >
> > > Regard,
> > > Govind
> > >
> > > Sent from my iPhone
> > >
> > >> On Apr 10, 2015, at 10:23 AM, Govind Prasad <pr....@gm... <mailto:pr....@gm...> <mailto:pr....@gm... <mailto:pr....@gm...>>> wrote:
> > >>
> > >> Hi Yusuke,
> > >>
> > >> Thanks a lot for the response, I will check and reply with my queries today.
> > >>
> > >> Thanks once again!!!
> > >>
> > >> Regards,
> > >> Govind
> > >>
> > >> Sent from my iPhone
> > >>
> > >>> On Apr 10, 2015, at 12:45 AM, Yusuke Iwase <iwa...@gm... <mailto:iwa...@gm...> <mailto:iwa...@gm... <mailto:iwa...@gm...>>> wrote:
> > >>>
> > >>> Hi Govind,
> > >>>
> > >>> To learn "How to implement Ryu Application", please refer to the ryu-book.
> > >>> The first chapter shows implementation of a simple switching hub.
> > >>> (http://osrg.github.io/ryu-book/en/html/switching_hub.html)
> > >>>
> > >>> And, to set the idle timeout, please refer to "OpenFlow protocol API reference" on the Ryu-Documentations.
> > >>> If you use OpenFlow 1.3, the following section is helpful for you.
> > >>> (http://ryu.readthedocs.org/en/latest/ofproto_v1_3_ref.html#modify-state-messages)
> > >>>
> > >>> Thanks,
> > >>> Iwase
> > >>>
> > >>>> On 2015年04月08日 23:44, Govind prasad wrote:
> > >>>>
> > >>>> Hi experts,
> > >>>>
> > >>>> I am working on an application which works as follows:
> > >>>>
> > >>>> 1. The switch gets the first TCP packet
> > >>>> 2. It sends the packet to the controller
> > >>>> 3. The controller invokes an application which was looking for TCP packets.
> > >>>> 4. The application sets a extended idle timeout (fore ample 1 hour) and sends the flow back to the controller.
> > >>>> 5. Now the controller sends the flow modification message for this flow with the extended idle timeout.
> > >>>>
> > >>>> Can anyone help me in building this application which extends the idle timeout. I am very new to sdn and programming so would require your esteemed support on this.
> > >>>>
> > >>>> Regards,
> > >>>> Govind
> > >>>> Sent from my iPhone
> > >>>> ------------------------------------------------------------------------------
> > >>>> 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
> > >>>> Ryu...@li... <mailto:Ryu...@li...> <mailto:Ryu...@li... <mailto:Ryu...@li...>>
> > >>>> 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
> > >>> Ryu...@li... <mailto:Ryu...@li...> <mailto:Ryu...@li... <mailto:Ryu...@li...>>
> > >>> 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
> > > Ryu...@li... <mailto:Ryu...@li...> <mailto:Ryu...@li... <mailto:Ryu...@li...>>
> > > 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
> > Ryu...@li... <mailto:Ryu...@li...>
> > 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
> Ryu...@li...
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
|