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) |
Ray Milkey | ead5c91 | 2016-11-04 09:45:03 +0100 | [diff] [blame] | 43 | payload = {'appId': 'org.onosproject.cli'} |
| 44 | flowRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device, |
Ray Milkey | 43ee97f | 2015-09-04 15:14:40 -0700 | [diff] [blame] | 45 | auth=HTTPBasicAuth('onos', 'rocks'), |
Ray Milkey | ead5c91 | 2016-11-04 09:45:03 +0100 | [diff] [blame] | 46 | data=flowJson, |
| 47 | params=payload) |
Ray Milkey | 43ee97f | 2015-09-04 15:14:40 -0700 | [diff] [blame] | 48 | |
Ray Milkey | ead5c91 | 2016-11-04 09:45:03 +0100 | [diff] [blame] | 49 | if flowRequest.status_code != 201: |
| 50 | print flowRequest.text |
Ray Milkey | 43ee97f | 2015-09-04 15:14:40 -0700 | [diff] [blame] | 51 | sys.exit(1) |
| 52 | |
Ray Milkey | ead5c91 | 2016-11-04 09:45:03 +0100 | [diff] [blame] | 53 | location = flowRequest.headers["location"] |
Ray Milkey | 43ee97f | 2015-09-04 15:14:40 -0700 | [diff] [blame] | 54 | print "@stc " + name + "Location=" + location |
| 55 | sys.exit(0) |
| 56 | |
| 57 | |
| 58 | |