blob: a5bf9bab3289a49ff9062a08c305c975432bbca0 [file] [log] [blame]
Carmelo Casconeb34d8e12020-09-28 16:16:59 -07001#! /usr/bin/env python3
Ray Milkey43ee97f2015-09-04 15:14:40 -07002import requests
3
4from requests.auth import HTTPBasicAuth
5import sys
6
7
8
9if len(sys.argv) != 6:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070010 print("usage: create-flow onos-node name device in-port out-port")
Ray Milkey43ee97f2015-09-04 15:14:40 -070011 sys.exit(1)
12
13node = sys.argv[1]
14name = sys.argv[2]
15device = sys.argv[3]
16inPort = sys.argv[4]
17outPort = sys.argv[5]
18
19flowJsonTemplate = \
20 '{{' + \
21 '"priority": 1,' + \
22 '"isPermanent": true,' + \
23 '"treatment": {{' + \
24 '"instructions": [' + \
25 '{{' + \
26 '"type": "OUTPUT",' + \
27 '"port": {}' + \
28 '}}' + \
29 ']' + \
30 '}},' + \
31 '"selector": {{' + \
32 '"criteria": [' + \
33 '{{' + \
34 '"type": "IN_PORT",' + \
35 '"port": {}' + \
36 '}}' + \
37 ']' + \
38 '}}' + \
39 '}}'
40
41flowJson = flowJsonTemplate.format(inPort, outPort)
Ray Milkeyead5c912016-11-04 09:45:03 +010042payload = {'appId': 'org.onosproject.cli'}
43flowRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device,
Ray Milkey43ee97f2015-09-04 15:14:40 -070044 auth=HTTPBasicAuth('onos', 'rocks'),
Ray Milkeyead5c912016-11-04 09:45:03 +010045 data=flowJson,
46 params=payload)
Ray Milkey43ee97f2015-09-04 15:14:40 -070047
Ray Milkeyead5c912016-11-04 09:45:03 +010048if flowRequest.status_code != 201:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070049 print(flowRequest.text)
Ray Milkey43ee97f2015-09-04 15:14:40 -070050 sys.exit(1)
51
Ray Milkeyead5c912016-11-04 09:45:03 +010052location = flowRequest.headers["location"]
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070053print("@stc " + name + "Location=" + location)
Ray Milkey43ee97f2015-09-04 15:14:40 -070054sys.exit(0)
55
56
57