Hi,

I am using Ryu version 4.6.
The following is an example of Ryu version 3.29.
The modify content is the same.

diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index 25b8776..f1b94b8 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -219,8 +219,10 @@ class Datapath(ofproto_protocol.ProtocolDesc):
      def _send_loop(self):
          try:
              while self.send_active:
-                buf = self.send_q.get()
-                self.socket.sendall(buf)
+                msg = self.send_q.get()
+                ev = ofp_event.ofp_msg_to_ev(msg)
+                self.ofp_brick.send_event_to_observers(ev, self.state)
+                self.socket.sendall(msg.buf)
          except IOError as ioe:
              LOG.debug("Socket error while sending data to switch at 
address %s: [%d] %s",
                        self.address, ioe.errno, ioe.strerror)
@@ -236,9 +238,9 @@ class Datapath(ofproto_protocol.ProtocolDesc):
              except hub.QueueEmpty:
                  pass

-    def send(self, buf):
+    def send(self, msg):
          if self.send_q:
-            self.send_q.put(buf)
+            self.send_q.put(msg)

      def set_xid(self, msg):
          self.xid += 1
@@ -252,7 +254,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
              self.set_xid(msg)
          msg.serialize()
          # LOG.debug('send_msg %s', msg)
-        self.send(msg.buf)
+        self.send(msg)

      def serve(self):
          send_thr = hub.spawn(self._send_loop)


diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index 3e7c598..aef4cfd 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -63,6 +63,13 @@ class SimpleSwitch13(app_manager.RyuApp):
                                      match=match, instructions=inst)
          datapath.send_msg(mod)

+    @set_ev_cls(ofp_event.EventOFPFlowMod, MAIN_DISPATCHER)
+    def _flow_mod_handler(self, ev):
+        msg = ev.msg
+        ofproto = msg.datapath.ofproto
+        self.logger.info("msg.msg_type == ofproto.OFPT_FLOW_MOD : %s",
+                          msg.msg_type == ofproto.OFPT_FLOW_MOD)
+
      @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
      def _packet_in_handler(self, ev):
          # If you hit this you might want to increase


The following is the output result.

move onto main mode
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 00:00:00:00:00:01 ff:ff:ff:ff:ff:ff 1
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 00:00:00:00:00:02 00:00:00:00:00:01 2
EVENT ofp_event->SimpleSwitch13 EventOFPFlowMod
msg.msg_type == ofproto.OFPT_FLOW_MOD : True
EVENT ofp_event->SimpleSwitch13 EventOFPPacketIn
packet in 1 00:00:00:00:00:01 00:00:00:00:00:02 1
EVENT ofp_event->SimpleSwitch13 EventOFPFlowMod
msg.msg_type == ofproto.OFPT_FLOW_MOD : True


Thanks,


On 2016年09月14日 16:38, Maurizio Marrocco wrote:
> Hi,
> I'm using Ryu version 3.29 and the original file
> ryu/controller/controller.py is different from what you have posted to me.
> Can you send that modified version?
> Thanks
> Maurizio
>
>
>
>
> ------------------------------------------------------------------------
> *Da:* Shinpei Muraoka <shinpei.mura...@gmail.com>
> *Inviato:* mercoledì 14 settembre 2016 03.20
> *A:* soldie...@hotmail.it; ryu-devel@lists.sourceforge.net
> *Oggetto:* Re: [Ryu-devel] Ho to extract message type (e.g.
> pktIN/pktOut) from OpenFlow v1.3 header structure?
>
> Hi,
>
> @set_ev_cls() can be used only at the reception.
> By performing the following modifications,
> you can process separately each message types when controller sends a
> message.
>
> diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
> index 8300f1a..0911789 100644
> --- a/ryu/controller/controller.py
> +++ b/ryu/controller/controller.py
> @@ -293,9 +293,11 @@ class Datapath(ofproto_protocol.ProtocolDesc):
>       def _send_loop(self):
>           try:
>               while self.state != DEAD_DISPATCHER:
> -                buf = self.send_q.get()
> +                msg = self.send_q.get()
>                   self._send_q_sem.release()
> -                self.socket.sendall(buf)
> +                ev = ofp_event.ofp_msg_to_ev(msg)
> +                self.ofp_brick.send_event_to_observers(ev, self.state)
> +                self.socket.sendall(msg.buf)
>           except SocketTimeout:
>               LOG.debug("Socket timed out while sending data to switch
> at address %s",
>                         self.address)
> @@ -318,11 +320,11 @@ class Datapath(ofproto_protocol.ProtocolDesc):
>               # Finally, ensure the _recv_loop terminates.
>               self.close()
>
> -    def send(self, buf):
> +    def send(self, msg):
>           msg_enqueued = False
>           self._send_q_sem.acquire()
>           if self.send_q:
> -            self.send_q.put(buf)
> +            self.send_q.put(msg)
>               msg_enqueued = True
>           else:
>               self._send_q_sem.release()
> @@ -343,7 +345,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
>               self.set_xid(msg)
>           msg.serialize()
>           # LOG.debug('send_msg %s', msg)
> -        return self.send(msg.buf)
> +        return self.send(msg)
>
>       def _echo_request_loop(self):
>           if not self.max_unreplied_echo_requests:
>
>
>
> The following is an example of when to send the FlowMod.
>
> diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
> index 3e7c598..aef4cfd 100644
> --- a/ryu/app/simple_switch_13.py
> +++ b/ryu/app/simple_switch_13.py
> @@ -63,6 +63,13 @@ class SimpleSwitch13(app_manager.RyuApp):
>                                       match=match, instructions=inst)
>           datapath.send_msg(mod)
>
> +    @set_ev_cls(ofp_event.EventOFPFlowMod, MAIN_DISPATCHER)
> +    def _flow_mod_handler(self, ev):
> +        msg = ev.msg
> +        ofproto = msg.datapath.ofproto
> +        self.logger.info("msg.msg_type == ofproto.OFPT_FLOW_MOD : %s",
> +                          msg.msg_type == ofproto.OFPT_FLOW_MOD)
> +
>       @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
>       def _packet_in_handler(self, ev):
>           # If you hit this you might want to increase
>
>
>
> Please refer to the following about the event.
> http://ryu.readthedocs.io/en/latest/ryu_app_api.html?highlight=set_ev_cls#openflow-event-classes
>
>
> Please refer to the following about set_ev_cls.
> http://ryu.readthedocs.io/en/latest/ryu_app_api.html?highlight=set_ev_cls#ryu-controller-handler-set-ev-cls
>
>
> Thanks,
>
> On 2016年09月13日 17:53, Maurizio Marrocco wrote:
>> Hi
>> Thank you for fast reply.  I need decision of message type because I
>> would to implement a state machine based on that decision: arriving of
>> packetOut to switch.
>> In fact, I would to intercept PktOut. And how to do with @set_ev_cls()?
>> Maurizio.
>>
>>
>>
>> ------------------------------------------------------------------------
>> *Da:* Shinpei Muraoka <shinpei.mura...@gmail.com>
>> *Inviato:* martedì 13 settembre 2016 04.59
>> *A:* soldie...@hotmail.it; ryu-devel@lists.sourceforge.net
>> *Oggetto:* Re: [Ryu-devel] Ho to extract message type (e.g.
>> pktIN/pktOut) from OpenFlow v1.3 header structure?
>>
>> Hi,
>>
>> sorry. I responded a difficult answer.
>>
>> The following is example of the message type check.
>>
>>
>> diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
>> index 3e7c598..89dedb9 100644
>> --- a/ryu/app/simple_switch_13.py
>> +++ b/ryu/app/simple_switch_13.py
>> @@ -76,6 +76,9 @@ class SimpleSwitch13(app_manager.RyuApp):
>>           parser = datapath.ofproto_parser
>>           in_port = msg.match['in_port']
>>
>> +        self.logger.info("msg.msg_type == ofproto.OFPT_PACKET_IN : %s",
>> +                          msg.msg_type == ofproto.OFPT_PACKET_IN)
>> +
>>           pkt = packet.Packet(msg.data)
>>           eth = pkt.get_protocols(ethernet.ethernet)[0]
>>
>>
>> Message type for the check is defined in ofproto/ofproto_v1_3.py.
>>
>> Why do you need a decision of the message type?
>> I think it can check of message type by @set_ev_cls().
>>
>> Thanks,
>>
>> On 2016年09月12日 20:50, Maurizio Marrocco wrote:
>>> Hi, Shinpei. Sorry if I'm disturbing.
>>> I read the documentation
>>> (http://ryu.readthedocs.io/en/latest/ofproto_base.html#base-class-for-openflow-messages)
>>> but could not find examples of how to pick the type of message from the
>>> header OpenFlow.
>>> You could give me a hand? For example in simple_switch_13.py script, how
>>> can I use the class: class ryu.ofproto.ofproto_parser.MsgBase (* args,
>>> ** kwargs) to take msg_type == pktOut ?
>>> Thanks so much.
>>> Maurizio
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>> *Da:* Shinpei Muraoka <shinpei.mura...@gmail.com>
>>> *Inviato:* lunedì 12 settembre 2016 03.15
>>> *A:* soldie...@hotmail.it; ryu-devel@lists.sourceforge.net;
>>> ryu-devel@lists.sourceforge.net
>>> *Oggetto:* Re: [Ryu-devel] Ho to extract message type (e.g.
>>> pktIN/pktOut) from OpenFlow v1.3 header structure?
>>>
>>> Hi,
>>>
>>> Please refer to the following for extraction method of the type of
>>> OpenFlow message.
>>> http://ryu.readthedocs.io/en/latest/ofproto_base.html#base-class-for-openflow-messages
>>>
>>> Also, Please refer to the chapter 7.1.1 of OpenFlow Spec version 1.3.5
>>> for the type of OpenFlow message.
>>>
>>> Thanks,
>>>
>>> On 2016年09月10日 22:55, Maurizio Marrocco wrote:
>>>> Hi Ryu team.
>>>> The question is the following: How to extract message ofp_type (e.g.
>>>> OFPT_PACKET_OUT or OFPT_PACKET_IN) from openflow v1.3 ofp_header structure?
>>>> I would to do this statement:
>>>>
>>>> if(header(received PDU)==PacketOut)
>>>>     do something.
>>>>
>>>> Have some reference in the documentation about this and in general to
>>>> process the packets?
>>>> PS: I'm using RYU 3.29
>>>> Thanks.
>>>> Maurizio.
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Ryu-devel mailing list
>>>> Ryu-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>>>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>>
>>
>> _______________________________________________
>> Ryu-devel mailing list
>> Ryu-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>>
>
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> Ryu-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>

------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to