blob: a2f2e4d1c07ff2f833fa46925dee4f5e2dd94edd [file] [log] [blame]
Ray Milkey4ff514c2015-09-01 09:02:03 -07001#! /usr/bin/env python
2
3import requests
4import sys
5
6from requests.auth import HTTPBasicAuth
7
8if len(sys.argv) != 4:
9 print "usage: find-flow onos-node name device-id"
10 sys.exit(1)
11
12node = sys.argv[1]
13name = sys.argv[2]
14deviceId = sys.argv[3]
15
16flowsRequest = requests.get('http://' + node + ':8181/onos/v1/flows/' + deviceId,
17 auth=HTTPBasicAuth('onos', 'rocks'))
18
19if flowsRequest.status_code != 200:
20 print flowsRequest.text
21 sys.exit(1)
22
23flowsJson = flowsRequest.json()
24
25for flow in flowsJson["flows"]:
26 if deviceId == flow["deviceId"]:
27 for criterion in flow["selector"]["criteria"]:
28 if criterion["type"] == 'IN_PORT' and criterion["port"] > 0:
29 for instruction in flow["treatment"]["instructions"]:
30 if instruction["port"] > 0 and instruction["type"] == 'OUTPUT':
31 print "@stc " + name + "FlowState=" + flow["state"]
32 print "@stc " + name + "FlowId=" + flow["id"]
33 print "@stc " + name + "FlowPort=" + str(instruction["port"])
34 sys.exit(0)
35
36sys.exit(1)
37
38
39
40