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 <[email protected]>
> *Inviato:* martedì 13 settembre 2016 04.59
> *A:* [email protected]; [email protected]
> *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 <[email protected]>
>> *Inviato:* lunedì 12 settembre 2016 03.15
>> *A:* [email protected]; [email protected];
>> [email protected]
>> *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
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>>>
>
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel