blob: 4e9b452bc0b23ec196a5a63dac43e98907d2ff28 [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)
43intentRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device,
44 auth=HTTPBasicAuth('onos', 'rocks'),
45 data=flowJson)
46
47if intentRequest.status_code != 201:
48 print intentRequest.text
49 sys.exit(1)
50
51location = intentRequest.headers["location"]
52print "@stc " + name + "Location=" + location
53sys.exit(0)
54
55
56