Ray Milkey | 43ee97f | 2015-09-04 15:14:40 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | |
| 5 | from requests.auth import HTTPBasicAuth |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | |
| 10 | if len(sys.argv) != 6: |
| 11 | print "usage: create-flow onos-node name device in-port out-port" |
| 12 | sys.exit(1) |
| 13 | |
| 14 | node = sys.argv[1] |
| 15 | name = sys.argv[2] |
| 16 | device = sys.argv[3] |
| 17 | inPort = sys.argv[4] |
| 18 | outPort = sys.argv[5] |
| 19 | |
| 20 | flowJsonTemplate = \ |
| 21 | '{{' + \ |
| 22 | '"priority": 1,' + \ |
| 23 | '"isPermanent": true,' + \ |
| 24 | '"treatment": {{' + \ |
| 25 | '"instructions": [' + \ |
| 26 | '{{' + \ |
| 27 | '"type": "OUTPUT",' + \ |
| 28 | '"port": {}' + \ |
| 29 | '}}' + \ |
| 30 | ']' + \ |
| 31 | '}},' + \ |
| 32 | '"selector": {{' + \ |
| 33 | '"criteria": [' + \ |
| 34 | '{{' + \ |
| 35 | '"type": "IN_PORT",' + \ |
| 36 | '"port": {}' + \ |
| 37 | '}}' + \ |
| 38 | ']' + \ |
| 39 | '}}' + \ |
| 40 | '}}' |
| 41 | |
| 42 | flowJson = flowJsonTemplate.format(inPort, outPort) |
| 43 | intentRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device, |
| 44 | auth=HTTPBasicAuth('onos', 'rocks'), |
| 45 | data=flowJson) |
| 46 | |
| 47 | if intentRequest.status_code != 201: |
| 48 | print intentRequest.text |
| 49 | sys.exit(1) |
| 50 | |
| 51 | location = intentRequest.headers["location"] |
| 52 | print "@stc " + name + "Location=" + location |
| 53 | sys.exit(0) |
| 54 | |
| 55 | |
| 56 | |