[pox-dev] When controller collecting statistics, can it know which switch the statistics come from?

Murphy McCauley murphy.mccauley at gmail.com
Tue Oct 2 09:20:57 PDT 2012


The PortStatsReceived event is a subclass of StatsReply, which is:

class StatsReply (Event):
  """ Abstract superclass for all stats replies """
  def __init__ (self, connection, ofp, stats):
    Event.__init__(self)
    self.connection = connection
    self.ofp = ofp     # Raw ofp message(s)
    self.stats = stats # Processed

Connection objects keep track of the DPID of their switch, so what you want should be as easy as:

def handle_PortStatsReceived(event):
     print "stats received from", dpidToStr(event.connection.dpid)

-- Murphy

On Oct 2, 2012, at 9:02 AM, Weiyang Mo wrote:

> Hi,
>  
> I used following definition to send request and listen to reply:
>  
> def counter_request ():
>   swnum = 0
>   for connection in core.openflow._connections.values():
>     swnum += 1
>     connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
>     connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
>     time.sleep(0.1)
>   global switchnum
>   switchnum = swnum
>   print "total %i switches" % switchnum
>   global requestcycle
>   requestcycle +=1
>  
> def handle_PortStatsReceived(event):
>      "main body"
>  
> def launch ():
>   core.openflow.addListenerByName("PortStatsReceived", handle_PortStatsReceived)   
>   Timer(5, counter_request, recurring=True)
>  
> However I met with difficulties distinguishing switches when receving port status. The "PortStatsReceived" function will be triggered whenever a switch replys back, however the controller doesn't know which switch.  I also need switch information to distinguish the statistics, for example, put switch1 stats into table 1, switch2 stats into table2..
>  
> Since I have no knowledge that the reply is from which switch, I play a trick when I program "counter_request" to set a time interval for sending each switch ( e.g switch1's request is sent on 0.1s,5.1s... switch is on 0.2s,5.2s), then assume I receive "ports status reply" in this switch sequence. However this trick cannot help with too many switches, and it may not work after a long timeline since each switch has a difference respoding time. 
>  
> Is there any approach to get the switch information (especially dpid) from reply back when receving ports status?
>  
> Thanks very much.
>  
> Weiyang
> 




More information about the pox-dev mailing list