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

William Emmanuel Yu wyu at ateneo.edu
Wed Sep 19 18:00:39 PDT 2012


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 --------------
A non-text attachment was scrubbed...
Name: flow_stats.py
Type: text/x-python
Size: 1024 bytes
Desc: not available
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20120920/840a3e38/attachment-0004.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: of_json.py
Type: text/x-python
Size: 8031 bytes
Desc: not available
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20120920/840a3e38/attachment-0005.py>


More information about the pox-dev mailing list