<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello,<BR> <BR>Thank you, it is OK<BR>what I did:<BR>    from pox.openflow.of_json import *<BR>    core.openflow.addListeners(self)<BR>    core.openflow.addListenerByName("FlowStatsReceived", self._handle_flowstats_received)<BR>    def _handle_flowstats_received (self, event)<BR> <BR> <BR>Best regards,<BR><br><br><font color="#800000" face="Lucida Handwriting, Cursive"><strong>Eng Amer Alghadhban</strong></font><br>
<font color="#800000" face="Lucida Handwriting"><strong>COE</strong></font><br>
<font color="#800000" face="Lucida Handwriting"><strong>SANS-GCFW</strong></font><br>
<strong><font color="#800000"><font face="Lucida Handwriting">CEH, </font><font face="Lucida Handwriting">SCNP, </font><font face="Lucida Handwriting">CCNA</font></font></strong><br><br> <BR><div><hr id="stopSpelling">Subject: Re: [pox-dev] Listeners in class<br>From: murphy.mccauley@gmail.com<br>Date: Wed, 6 Nov 2013 10:48:22 -0800<br>CC: amer7777@hotmail.com; pox-dev@lists.noxrepo.org<br>To: sul4bh@gmail.com<br><br>On Nov 6, 2013, at 9:39 AM, Sulabh Bista <<a href="mailto:sul4bh@gmail.com">sul4bh@gmail.com</a>> wrote:<br><div><br class="ecxApple-interchange-newline"><blockquote><div dir="ltr">I don't think there are flow and port status events. I guess these are not 'events' at all and you should fetch them when you require them.</div></blockquote><div><br></div><div>There are, in fact (mentioned in the Statistics Events section of the manual).  Though you may need to send requests to get them to fire. :)</div><div><br></div><blockquote><div class="ecxgmail_extra"><div class="ecxgmail_quote">On Wed, Nov 6, 2013 at 12:30 PM, Sulabh Bista <span dir="ltr"><<a href="mailto:sul4bh@gmail.com" target="_blank">sul4bh@gmail.com</a>></span> wrote:<br>

<blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div dir="ltr"><div><font face="arial, sans-serif">Use the event name with proper case as:</font></div><span style="font-family: arial,sans-serif; font-size: 13px;">self.addListenersByname("</span><font face="arial, sans-serif">FlowStatsReceived", self._handle_flowstate_</font><span style="font-family: arial,sans-serif; font-size: 13px;">received)</span><br></div></blockquote></div></div></blockquote><div><br></div><div>This is good advice.  Also use the correct name, as done here (the original had "flow*state*received" which I think would have raised an exception...).  Adding by name is sometimes convenient, but it's fairly "unstructured".  A safer bet is to actually use the event class itself (addListener(of.FlowStatsReceived, ...)).</div><div><br></div><div>But there's a bigger problem here.  Events are raised by specific objects.  Does "self" raise the <span style="font-family: arial, sans-serif;">FlowStatsReceived event?  Considering it wants to *handle* that event, probably not.  (Continued below.)</span></div><br><blockquote><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div class="ecxHOEnZb"><div class="h5"><div class="ecxgmail_extra"><div class="ecxgmail_quote">On Wed, Nov 6, 2013 at 9:01 AM, Amer <span dir="ltr"><<a href="mailto:amer7777@hotmail.com" target="_blank">amer7777@hotmail.com</a>></span> wrote:<br>


<blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">Hello,<br>
<br>
I would like to add listeners to flow and port status in <a href="http://l3.learning.py/" target="_blank">l3.learning.py</a>.<br>
There is a command<br>
Self.listento(core)<br></blockquote></div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>Sidenote: .listenTo() isn't used much anymore (the version of l3_learning in dart doesn't, for example).  Use .addListenersByName().</div><div><br></div><blockquote><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div class="ecxHOEnZb"><div class="h5"><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">
But it is not calling flow or port status function<br></blockquote></div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>It wouldn't.  You're telling it to listen to events on the core object.  Take a look at the events raised by the core object:</div><div><a href="https://github.com/noxrepo/pox/blob/carp/pox/core.py#L177" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/core.py#L177</a></div><div><br></div><div>None of them have anything to do with OpenFlow.</div><br><blockquote><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div class="ecxHOEnZb"><div class="h5"><div class="ecxgmail_extra"><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">
I tried with self.addListenersByname("flowstatereceived", self._handle_flowstate_received)<br>
and without self<br>
<br>
But it is not work<br></blockquote></div></div></div></div></blockquote></div></div></blockquote><div><br></div></div>Coming back to this, your event source here is "self", but this object probably doesn't raise the flow stats event (neither does the core object as mentioned just above).  POX raises OpenFlow events on the OpenFlow nexus (core.openflow) and on individual Connection objects, so you need to listen to those objects.  See:<div><a href="https://github.com/noxrepo/pox/blob/carp/pox/openflow/__init__.py#L306" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/openflow/__init__.py#L306</a></div><div><a href="https://github.com/noxrepo/pox/blob/carp/pox/openflow/of_01.py#L571" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/openflow/of_01.py#L571</a></div><div><div><br></div><div>You might want to skim through the "The Event System" and "OpenFlow Events" section of the manual.</div></div><div><br></div><div><br></div><div>TLDR:</div><div>Examples...</div><div><br></div><div>If you want to listen to all OpenFlow events, name your methods correctly and then use:</div><div>core.openflow.addListeners(self)</div><div><br></div><div>If you want to listen to a specific event on a specific connection with a specific method, try:</div><div>some_connection.addListenerByName("FlowStatsReceived", self._handle_flowstate_received)<br><br></div><div>Examples in code (there are many, but here are three at random):</div><div><div><a href="https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_learning.py#L182" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_learning.py#L182</a></div></div><div><a href="https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_learning.py#L86" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_learning.py#L86</a></div><div><a href="https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_pairs.py#L85" target="_blank">https://github.com/noxrepo/pox/blob/carp/pox/forwarding/l2_pairs.py#L85</a></div><div><br></div><div><br></div><div>Hope  that's helpful.</div><div><br></div><div>-- Murphy</div></div>                                        </div></body>
</html>