Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | import sys |
| 5 | |
| 6 | from requests.auth import HTTPBasicAuth |
| 7 | |
| 8 | if len(sys.argv) != 4: |
| 9 | print "usage: find-flow onos-node name device-id" |
| 10 | sys.exit(1) |
| 11 | |
| 12 | node = sys.argv[1] |
| 13 | name = sys.argv[2] |
| 14 | deviceId = sys.argv[3] |
| 15 | |
| 16 | flowsRequest = requests.get('http://' + node + ':8181/onos/v1/flows/' + deviceId, |
| 17 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 18 | |
| 19 | if flowsRequest.status_code != 200: |
| 20 | print flowsRequest.text |
| 21 | sys.exit(1) |
| 22 | |
| 23 | flowsJson = flowsRequest.json() |
| 24 | |
| 25 | for 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 | |
| 36 | sys.exit(1) |
| 37 | |
| 38 | |
| 39 | |
| 40 | |