blob: 9d709a0b747a56513c2500f4a4a20cf3b67415cb [file] [log] [blame]
Ray Milkey43ee97f2015-09-04 15:14:40 -07001#! /usr/bin/env python
2
3import requests
4
5from requests.auth import HTTPBasicAuth
6import sys
7
8
9
10if len(sys.argv) != 6:
11 print "usage: create-flow onos-node name device in-port out-port"
12 sys.exit(1)
13
14node = sys.argv[1]
15name = sys.argv[2]
16device = sys.argv[3]
17inPort = sys.argv[4]
18outPort = sys.argv[5]
19
20flowJsonTemplate = \
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
42flowJson = flowJsonTemplate.format(inPort, outPort)
Ray Milkeyead5c912016-11-04 09:45:03 +010043payload = {'appId': 'org.onosproject.cli'}
44flowRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device,
Ray Milkey43ee97f2015-09-04 15:14:40 -070045 auth=HTTPBasicAuth('onos', 'rocks'),
Ray Milkeyead5c912016-11-04 09:45:03 +010046 data=flowJson,
47 params=payload)
Ray Milkey43ee97f2015-09-04 15:14:40 -070048
Ray Milkeyead5c912016-11-04 09:45:03 +010049if flowRequest.status_code != 201:
50 print flowRequest.text
Ray Milkey43ee97f2015-09-04 15:14:40 -070051 sys.exit(1)
52
Ray Milkeyead5c912016-11-04 09:45:03 +010053location = flowRequest.headers["location"]
Ray Milkey43ee97f2015-09-04 15:14:40 -070054print "@stc " + name + "Location=" + location
55sys.exit(0)
56
57
58