| from requests.auth import HTTPBasicAuth |
| print "usage: find-flow onos-node name device-id" |
| flowsRequest = requests.get('http://' + node + ':8181/onos/v1/flows/' + deviceId, |
| auth=HTTPBasicAuth('onos', 'rocks')) |
| if flowsRequest.status_code != 200: |
| flowsJson = flowsRequest.json() |
| for flow in flowsJson["flows"]: |
| if deviceId == flow["deviceId"]: |
| for criterion in flow["selector"]["criteria"]: |
| if criterion["type"] == 'IN_PORT' and criterion["port"] > 0: |
| for instruction in flow["treatment"]["instructions"]: |
| if instruction["port"] > 0 and instruction["type"] == 'OUTPUT': |
| print "@stc " + name + "FlowState=" + flow["state"] |
| print "@stc " + name + "FlowId=" + flow["id"] |
| print "@stc " + name + "FlowPort=" + str(instruction["port"]) |