[pox-dev] How can POX get packet counts (or beta transferred) from a switch within a timeline.

Weiyang Mo moweiyang1988 at gmail.com
Wed Sep 19 19:33:41 PDT 2012


Hi, William,

Thanks very much. But I still have some questions about getting statistics.

As mentioned in POX wiki, We can use different statistics event to get
different types of statistics. What I want to get from a switch is (1) it's
switch ID (DPID) (2) all packet counts on each port

If I only use *"core.openflow.addListenerByName("FlowStatsReceived",
statsreceived)",* the things I can get is that the total packet counts from
all ports, but no DPID or inport number. Thus I guess I may need use
*"of.ofp_port_stats_request()" and
core.openflow.addListenerByName("PortStatsReceived", stat**sreceived)*
But here I meet with a problem. I tried similar things as *
ofp_flow_stats_request()* as follows:

*def countrequest ():
  swnum = 0
  for connection in core.openflow._connections.values():*
    *req1 = of.ofp_port_stats_request()
    re1 = of.ofp_stats_request(body = req1)*
*    connection.send(re1)*

-----------------------------------
In the launch() function, I do the following:
*Timer(5, countrequest, recurring = True)*
It reports an error which will not happend to ofp_flow_stats_request()

Traceback (most recent call last):
  File "/home/openflow/pox/pox/lib/recoco/recoco.py", line 276, in cycle
    rv = t.execute()
  File "/home/openflow/pox/pox/lib/recoco/recoco.py", line 94, in execute
    return self.gen.send(v)
  File "/home/openflow/pox/pox/lib/recoco/recoco.py", line 751, in run
    rv = self._callback(*self._args,**self._kw)
  File "/home/openflow/pox/ext/test1stat.py", line 270, in countrequest
    connection.send(re1)
  File "/home/openflow/pox/pox/openflow/of_01.py", line 573, in send
    data = data.pack()
  File "/home/openflow/pox/pox/openflow/libopenflow_01.py", line 2136, in
pack
    packed += struct.pack("!HH", self.type, self.flags)
error: cannot convert argument to integer

Is there anything that I don't do correctly?

And my another question is that even assuming I can add portstatlistener
and flowstatlistener as :

 core.openflow.addListenerByName("PortStatsReceived", statsreceived)
 core.openflow.addListenerByName("FlowStatsReceived", statsreceived)

Can I distinguish through statsreceived which event is which? Or can I
combine these two listeners together?
Thanks very much.

Weiyang











2012/9/19 William Emmanuel Yu <wyu at ateneo.edu>

> Hi,
>
> Attached is a flow_stats.py file that contains a sample for getting
> stats from all switches connected to the controller (flow_stats.py).
> Attached is also a file of_json.py (from Murphy) which is a helper
> library to convert the output into JSON format (which is much more
> readable than the current classes).
>
> Good luck!
>
> On Wed, 2012-09-19 at 10:41 -0700, Weiyang Mo wrote:
> > Hi, Seungwon,
> >
> > Thanks very much.
> >
> > Now it works and I can make some logical programming to do my routing
> > algorithm.
> >
> > Best
> >
> > Weiyang
> >
> >
> > 2012/9/19 Seungwon Shin <seungwon.shin at gmail.com>
> >         Hi, Weiyang
> >
> >
> >         In the case of collecting the statistical information for a
> >         flow table
> >         You can register your listener like
> >         --> core.openflow.addListenerByName("TableStatsReceived",
> >         <your handler>)
> >
> >
> >         and your handler can parse..
> >
> >
> >         def <your handler>(event):
> >            for item in event.stats
> >                print item.wildcards
> >
> >
> >
> >
> >         You can find more information by looking at the following
> >         classes in POX source code (libopenflow_01.py)
> >
> >
> >         class ofp_flow_stats
> >
> >
> >         class ofp_table_stats
> >
> >
> >         ….
> >
> >
> >         Each class has its __init__ function, and you will find all
> >         variables for stats in the function.
> >         The variables that you are looking for should be one of them.
> >         (E.g., wildcards is an initial variable of ofp_table_stats
> >         class).
> >
> >
> >         Best,
> >         Seungwon
> >
> >
> >
> >         On Sep 19, 2012, at 11:49 AM, Weiyang Mo
> >         <moweiyang1988 at gmail.com> wrote:
> >
> >         > Hi,William,
> >         >
> >         > Thanks for your advice and that's what I already did. What I
> >         > meant is that although I sent such request, I don't have
> >         > ideas how to get the reply back. I do modifications as
> >         > follows in forwarding.l2_learning, which sends request right
> >         > after sending flow entry request.
> >         >
> >         >            msg = of.ofp_flow_mod()
> >         >             msg.match = of.ofp_match.from_packet(packet)
> >         >             msg.match.in_port = packet_in.in_port
> >         >             msg.idle_timeout = 30
> >         >             msg.hard_timeout = 30
> >         >             msg.actions.append(of.ofp_action_output(port =
> >         > out_port))
> >         >             self.connection.send(msg)
> >         >
> >         > "-----------------------------------------------------"
> >         >            req = of.ofp_flow_stats_request()
> >         >            re = of.ofp_stats_request(body = req)
> >         >            self.connection.send(re)
> >         >
> >         > When I try pinging between hosts, it works correctly and the
> >         > statistics request has been sent. The question is  that the
> >         > switches sent "stats  reply back" to controller ( I detect
> >         > them through wireshark) however from controller side, I
> >         > don't now how to catch the reply packet and parse it as I
> >         > want.
> >         >
> >         > Any advice?
> >         >
> >         > Thanks very much.
> >         >
> >         > Weiyang
> >         >
> >         >
> >         > 2012/9/19 William Emmanuel Yu <wyu at ateneo.edu>
> >         >         Hi Weiyang,
> >         >
> >         >         Did you check out ofp_flow_stats_request()?
> >         >
> >         >         import pox.openflow.libopenflow_01 as of
> >         >         fsr = of.ofp_flow_stats_request()
> >         >         sr = of.ofp_stats_request(body = fsr)
> >         >         switch.send(sr)
> >         >
> >         >         Check out:
> >         >         https://groups.google.com/forum/?fromgroups=#!
> >         >         topic/pox_dev/sSlfqm5Okls
> >         >
> >         >         Good luck!
> >         >
> >         >         On Tue, 2012-09-18 at 08:21 -0700, Weiyang Mo wrote:
> >         >         > Hi,All,
> >         >         >
> >         >         > I try to use packet counts from switches within a
> >         >         time period (e.g
> >         >         > 10secs) to do some routing.  In the documentation
> >         >         > https://openflow.stanford.edu/display/ONL/POX
> >         >
> >         >         > +Wiki#POXWiki-StatisticEvent it mentions that it's
> >         >         possible to do this
> >         >         > using a timer. I guess using 'time to wake' to
> >         >         call a counting
> >         >         > function may help.
> >         >         >
> >         >         > However I'm not famiiar with getting statistics
> >         >         from a switch. More
> >         >         > than one flow, I want to get total packet counts
> >         >         within 10 seconds
> >         >         > from all flow entries. Could you please help to
> >         >         give me a simple
> >         >         > examples about this?
> >         >         >
> >         >         > Thanks very much.
> >         >         >
> >         >         > Best
> >         >         >
> >         >         > Weiyang
> >         >         >
> >         >         >
> >         >
> >         >
> >         >         --
> >         >         -------------------------------------------------------
> >         >         William Emmanuel S. Yu, Ph.D. (杨怀义)
> >         >         Department of Information Systems and Computer
> >         >         Science
> >         >         Ateneo de Manila University
> >         >         email  :  wyu at ateneo dot edu
> >         >         blog   :  http://hip2b2.yutivo.org/
> >         >         web    :  http://CNG.ateneo.edu/cng/wyu/
> >         >         phone  :  +63(2)4266001 loc. 4186
> >         >         GPG    :  http://CNG.ateneo.net/cng/wyu/wyy.pgp
> >         >
> >         >         Confidentiality Issue:  This message is intended
> >         >         only for the use of the
> >         >         addressee and may contain information that is
> >         >         privileged and
> >         >         confidential. If you are not the intended recipient,
> >         >         you are hereby
> >         >         notified that any use or dissemination of this
> >         >         communication is strictly
> >         >         prohibited.  If you have received this communication
> >         >         in error, please
> >         >         notify us immediately by reply and delete this
> >         >         message from your system.
> >         >
> >         >
> >
> >
> >
>
> --
> -------------------------------------------------------
> William Emmanuel S. Yu, Ph.D. (杨怀义)
> Department of Information Systems and Computer Science
> Ateneo de Manila University
> email  :  wyu at ateneo dot edu
> blog   :  http://hip2b2.yutivo.org/
> web    :  http://CNG.ateneo.edu/cng/wyu/
> phone  :  +63(2)4266001 loc. 4186
> GPG    :  http://CNG.ateneo.net/cng/wyu/wyy.pgp
>
> Confidentiality Issue:  This message is intended only for the use of the
> addressee and may contain information that is privileged and
> confidential. If you are not the intended recipient, you are hereby
> notified that any use or dissemination of this communication is strictly
> prohibited.  If you have received this communication in error, please
> notify us immediately by reply and delete this message from your system.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20120919/606f28c9/attachment-0002.htm>


More information about the pox-dev mailing list