On Apr 23, 2014, at 1:54 PM, Alison Chan <chan7...@kettering.edu> wrote:
> I am trying to access the port_no field of an ofp_port_stats reply > object. printing the object suggests that it is an ofp_port_stats > object, but trying to access its port_no field results in an > AttributeError: 'list' object has no attribute 'port_no'. How do I > access its port_no and other fields? Well there's your problem. ;) It's a list, not an ofp_port_stats. > [16:24:42] erinacity:~/Code/pox > alisonc $ ./pox.py openflow.of_01 py > [snip startup crap] > POX> import pox.openflow.libopenflow_01 as of > POX> > POX> def handle_port_stats(event): > ... print event.stats > ... print event.stats.port_no > ... > POX> core.openflow.addListenerByName("PortStatsReceived", handle_port_stats) > (<class 'pox.openflow.PortStatsReceived'>, 14) > POX> > core.openflow.connections[1].send(of.ofp_stats_request(body=of.ofp_port_stats_request(port_no=of.OFPP_NONE))) > POX> [<pox.openflow.libopenflow_01.ofp_port_stats object at > 0x2a57ad0>, <pox.openflow.libopenflow_01.ofp_port_stats object at > 0x2a57a10>, <pox.openflow.libopenflow_01.ofp_port_stats object at > 0x2a57b50>] And there's your list. Of ofp_port_stats. Try... print [p.port_no for p in event.stats] Or just print event.stats[0].port_no to print only the first one. > ERROR:core:Exception while handling OpenFlowNexus!PortStatsReceived... > Traceback (most recent call last): > File "/home/alisonc/Code/pox/pox/lib/revent/revent.py", line 231, in > raiseEventNoErrors > return self.raiseEvent(event, *args, **kw) > File "/home/alisonc/Code/pox/pox/lib/revent/revent.py", line 278, in > raiseEvent > rv = event._invoke(handler, *args, **kw) > File "/home/alisonc/Code/pox/pox/lib/revent/revent.py", line 156, in _invoke > return handler(self, *args, **kw) > File "<console>", line 3, in handle_port_stats > AttributeError: 'list' object has no attribute 'port_no' > > Cheers, > -- > Alison Chan > chan7...@kettering.edu > SMS: +1 909 278 7753 > Fax: +1 206 203 2793 -- Murphy