4 h = httplib2.Http(".cache")
5 h.add_credentials('admin', 'admin')
7 resp, content = h.request('http://localhost:8080/controller/nb/v2/statistics/default/flowstats', "GET")
8 allFlowStats = json.loads(content)
9 flowStats = allFlowStats['flowStatistics']
12 # These JSON dumps were handy when trying to parse the responses
13 #print json.dumps(flowStats[0]['flowStat'][1], indent = 2)
14 #print json.dumps(flowStats[4], indent = 2)
16 print "\nSwitch ID : " + fs['node']['@id']
17 print '{0:8} {1:8} {2:5} {3:15}'.format('Count', 'Action', 'Port', 'DestIP')
18 for aFlow in fs['flowStat']:
19 count = aFlow['packetCount']
20 actions = aFlow['flow']['actions']
24 if(type(actions) == type(list())):
25 actionType = actions[1]['@type']
26 actionPort = actions[1]['port']['@id']
28 actionType = actions['@type']
29 actionPort = actions['port']['@id']
30 dst = aFlow['flow']['match']['matchField'][0]['value']
31 print '{0:8} {1:8} {2:5} {3:15}'.format(count, actionType, actionPort, dst)