Ray Milkey
Committed by Gerrit Code Review

STC scenario for testing network related REST APIs

Tests creating, fetching, and removing Intents via REST API
Tests fetching flows via REST API
Tests fetching links via REST API
Tests fetching hosts via REST API

Change-Id: Ib6aa5138e544d869ba46183ba21591c8a73ba367
1 -#! /usr/bin/env python
2 -
3 -import requests
4 -
5 -from requests.auth import HTTPBasicAuth
6 -
7 -r = requests.get('http://192.168.56.101:8181/onos/v1/flows', auth=HTTPBasicAuth('onos', 'rocks'))
8 -deviceId = "of:0000000000000001"
9 -port = 4
10 -flowsJson = r.json()
11 -
12 -for flow in flowsJson["flows"]:
13 - if deviceId == flow["deviceId"]:
14 - if flow["treatment"]["instructions"][0]["port"] == port:
15 - print flow
16 -
17 -
18 -
19 -
1 +<!--
2 + ~ Copyright 2015 Open Networking Laboratory
3 + ~
4 + ~ Licensed under the Apache License, Version 2.0 (the "License");
5 + ~ you may not use this file except in compliance with the License.
6 + ~ You may obtain a copy of the License at
7 + ~
8 + ~ http://www.apache.org/licenses/LICENSE-2.0
9 + ~
10 + ~ Unless required by applicable law or agreed to in writing, software
11 + ~ distributed under the License is distributed on an "AS IS" BASIS,
12 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + ~ See the License for the specific language governing permissions and
14 + ~ limitations under the License.
15 + -->
16 +<scenario name="net-rest"
17 + description="Network REST API test">
18 + <!-- TODO: parametrize this via recipes -->
19 + <group name="Net-REST">
20 +
21 + <!-- Make sure that reactive forwarding is off -->
22 + <step name="Net-REST.Uninstall-Reactive-Forwarding"
23 + exec="onos ${OC1} app deactivate org.onosproject.fwd org.onosproject.ifwd"/>
24 + <step name="Net-REST.Check-Apps" requires="^"
25 + exec="onos-check-apps ${OC1} fwd,ifwd excludes"/>
26 +
27 + <!-- Force discovery of hosts -->
28 + <step name="Net-REST.Find-Host-1" requires="^"
29 + exec="onos-mininet sendAndExpect h1 ping -c1 -w1 h4 --expect ."/>
30 + <step name="Net-REST.Find-Host-2" requires="^"
31 + exec="onos-mininet sendAndExpect h4 ping -c1 -w1 h1 --expect ."/>
32 +
33 + <!-- Verify some links using the REST API -->
34 + <step name="Net-REST.Query-Link-1" requires="Net-REST.Find-Host-2"
35 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-link.py
36 + ${OC1} link1 of:0000000000000001 5 of:0000000000000006 4"/>
37 + <step name="Net-REST.Validate-Link-1-State" requires="^"
38 + exec="test '${link1State}' == 'ACTIVE'"/>
39 + <step name="Net-REST.Validate-Link-1-Type" requires="^"
40 + exec="test '${link1Type}' == 'DIRECT'"/>
41 + <step name="Net-REST.Validate-Link-1-Src-Device" requires="^"
42 + exec="test '${link1SrcDevice}' == 'of:0000000000000001'"/>
43 + <step name="Net-REST.Validate-Link-1-Dst-Device" requires="^"
44 + exec="test '${link1DstDevice}' == 'of:0000000000000006'"/>
45 + <step name="Net-REST.Validate-Link-1-Src-Port" requires="^"
46 + exec="test '${link1SrcPort}' == '5'"/>
47 + <step name="Net-REST.Validate-Link-1-Dst-Port" requires="^"
48 + exec="test '${link1DstPort}' == '4'"/>
49 +
50 + <step name="Net-REST.Query-Link-2" requires="Net-REST.Find-Host-2"
51 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-link.py
52 + ${OC1} link2 of:0000000000000019 7 of:0000000000000006 3"/>
53 + <step name="Net-REST.Validate-Link-2-State" requires="^"
54 + exec="test '${link2State}' == 'ACTIVE'"/>
55 + <step name="Net-REST.Validate-Link-2-Type" requires="^"
56 + exec="test '${link2Type}' == 'DIRECT'"/>
57 + <step name="Net-REST.Validate-Link-2-Src-Device" requires="^"
58 + exec="test '${link2SrcDevice}' == 'of:0000000000000019'"/>
59 + <step name="Net-REST.Validate-Link-2-Dst-Device" requires="^"
60 + exec="test '${link2DstDevice}' == 'of:0000000000000006'"/>
61 + <step name="Net-REST.Validate-Link-2-Src-Port" requires="^"
62 + exec="test '${link2SrcPort}' == '7'"/>
63 + <step name="Net-REST.Validate-Link-2-Dst-Port" requires="^"
64 + exec="test '${link2DstPort}' == '3'"/>
65 +
66 + <!-- Verify the hosts using the REST API -->
67 + <step name="Net-REST.Query-Host-1" requires="Net-REST.Find-Host-2"
68 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-host.py
69 + ${OC1} host1 00:00:00:00:00:01/-1"/>
70 + <step name="Net-REST.Validate-Host-1-Id" requires="^"
71 + exec="test '${host1Id}' == '00:00:00:00:00:01/-1'"/>
72 + <step name="Net-REST.Validate-Host-1-Mac" requires="^"
73 + exec="test '${host1Mac}' == '00:00:00:00:00:01'"/>
74 + <step name="Net-REST.Validate-Host-1-Ip" requires="^"
75 + exec="test '${host1IpAddress}' == '10.0.0.1'"/>
76 +
77 + <step name="Net-REST.Query-Host-2" requires="Net-REST.Find-Host-2"
78 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-host.py
79 + ${OC1} host2 00:00:00:00:00:04/-1"/>
80 + <step name="Net-REST.Validate-Host-2-Id" requires="^"
81 + exec="test '${host2Id}' == '00:00:00:00:00:04/-1'"/>
82 + <step name="Net-REST.Validate-Host-2-Mac" requires="^"
83 + exec="test '${host2Mac}' == '00:00:00:00:00:04'"/>
84 + <step name="Net-REST.Validate-Host-2-Ip" requires="^"
85 + exec="test '${host2IpAddress}' == '10.0.0.4'"/>
86 +
87 + <!-- Verify a switch using the REST API -->
88 + <step name="Net-REST.Query-Dev-1" requires="Net-REST.Find-Host-2"
89 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-device.py
90 + ${OC1} dev1 of:0000000000000014"/>
91 + <step name="Net-REST.Validate-Dev1-Id" requires="^"
92 + exec="test '${dev1Id}' == 'of:0000000000000014'"/>
93 + <step name="Net-REST.Validate-Dev1-Type" requires="^"
94 + exec="test '${dev1Type}' == 'SWITCH'"/>
95 + <step name="Net-REST.Validate-Dev1-Available" requires="^"
96 + exec="test '${dev1Available}' == 'True'"/>
97 + <step name="Net-REST.Validate-Dev1-ChannelId" requires="^"
98 + exec="test '${dev1IpAddress}' == '192.168.56.102'"/>
99 +
100 + <!-- Use REST API to create a point to point intent in each direction -->
101 + <step name="Net-REST.Create-Intent-XY" requires="Net-REST.Find-Host-2"
102 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/create-intent.py
103 + ${OC1} xy of:0000000000000001 1 of:0000000000000004 1"/>
104 + <step name="Net-REST.Create-Intent-YX" requires="^"
105 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/create-intent.py
106 + ${OC1} yx of:0000000000000004 1 of:0000000000000001 1"/>
107 +
108 + <!-- Check that the intents can be fetched via the REST API -->
109 + <step name="Net-REST.Validate-Intent-XY-Installed"
110 + requires="Net-REST.Create-Intent-YX"
111 + exec="curl -f -uonos:rocks ${xyLocation}"/>
112 + <step name="Net-REST.Validate-Intent-YX-Installed"
113 + requires="Net-REST.Create-Intent-YX"
114 + exec="curl -f -uonos:rocks ${yxLocation}"/>
115 +
116 + <!-- Use REST API to query flows created by the intents -->
117 + <step name="Net-REST.Validate-Intent-XY-Flow-Installed"
118 + requires="Net-REST.Create-Intent-YX"
119 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-flow.py
120 + ${OC1} dev1out of:0000000000000001"/>
121 + <step name="Net-REST.Validate-XY-Flow-State" requires="^"
122 + exec="test '${dev1outFlowState}' == 'ADDED' -o '${dev1outFlowState}' == 'PENDING_ADD'"/>
123 + <step name="Net-REST.Validate-XY-Flow-Port" requires="^"
124 + exec="test ${dev1outFlowPort} -ge 1 -a ${dev1outFlowPort} -le 5"/>
125 +
126 + <step name="Net-REST.Validate-Intent-YX-Flow-Installed" requires="Net-REST.Create-Intent-YX"
127 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-flow.py
128 + ${OC1} dev4out of:0000000000000004"/>
129 + <step name="Net-REST.Validate-YX-Flow-State" requires="^"
130 + exec="test '${dev4outFlowState}' == 'ADDED' -o '${dev4outFlowState}' == 'PENDING_ADD'"/>
131 + <step name="Net-REST.Validate-YX-Flow-Port" requires="^"
132 + exec="test '${dev4outFlowPort}' == '3'"/>
133 +
134 + <!-- Check that connectivity was established -->
135 + <step name="Net-REST.Ping-XY" requires="Net-REST.Create-Intent-XY,Net-REST.Create-Intent-YX"
136 + exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
137 + <step name="Net-REST.Ping-YX" requires="^"
138 + exec="onos-mininet sendAndExpect h4 ping -c1 h1 --expect \ 0% packet loss"/>
139 +
140 + <!-- Remove the intents via the REST API -->
141 + <step name="Net-REST.Delete-Intent-XY"
142 + requires="Net-REST.Validate-Intent-XY-Installed,
143 + Net-REST.Validate-Intent-YX-Installed,
144 + Net-REST.Validate-Intent-XY-Flow-Installed,
145 + Net-REST.Validate-Intent-YX-Flow-Installed,
146 + Net-REST.Ping-XY,
147 + Net-REST.Ping-YX"
148 + exec="curl -f -X DELETE -uonos:rocks ${xyLocation}"/>
149 + <step name="Net-REST.Delete-Intent-YX" requires="^"
150 + exec="curl -f -X DELETE -uonos:rocks ${yxLocation}"/>
151 +
152 + <!-- Use REST API to be sure that flows are no longer installed -->
153 + <step name="Net-REST.Validate-XY-Flows-Removed" requires="Net-REST.Delete-Intent-XY"
154 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-flow.py
155 + ${OC1} dev1out of:0000000000000001"
156 + env="!"/>
157 + <step name="Net-REST.Validate-YX-Flows-Removed" requires="Net-REST.Delete-Intent-YX"
158 + exec="${ONOS_ROOT}/tools/test/scenarios/net-rest/find-flow.py
159 + ${OC1} dev4out of:0000000000000004"
160 + env="!"/>
161 +
162 + <!-- Check that the deleted intents no longer appear in the REST API -->
163 + <step name="Net-REST.Validate-Intent-XY-Removed" requires="Net-REST.Delete-Intent-XY"
164 + exec="curl -f -uonos:rocks ${xyLocation}" env="!"/>
165 + <step name="Net-REST.Validate-Intent-YX-Removed" requires="Net-REST.Delete-Intent-YX"
166 + exec="curl -f -uonos:rocks ${yxLocation}" env="!"/>
167 +
168 + </group>
169 +</scenario>
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) != 7:
11 + print "usage: create-intent onos-node name ingressDevice ingressPort egressDevice egressPort"
12 + sys.exit(1)
13 +
14 +node = sys.argv[1]
15 +name = sys.argv[2]
16 +ingress = sys.argv[3]
17 +ingressPort = sys.argv[4]
18 +egress = sys.argv[5]
19 +egressPort = sys.argv[6]
20 +
21 +intentJsonTemplate = \
22 + '{{' + \
23 + '"type": "PointToPointIntent",' + \
24 + '"appId": "org.onosproject.cli",' + \
25 + '"ingressPoint": {{' + \
26 + ' "device": "{}",' + \
27 + ' "port": "{}"' + \
28 + '}},' + \
29 + '"egressPoint": {{' + \
30 + ' "device": "{}",' + \
31 + ' "port": "{}"' + \
32 + '}}' + \
33 + '}}'
34 +
35 +intentJson = intentJsonTemplate.format(ingress, ingressPort, egress, egressPort)
36 +intentRequest = requests.post('http://' + node + ':8181/onos/v1/intents/',
37 + auth=HTTPBasicAuth('onos', 'rocks'),
38 + data=intentJson)
39 +
40 +if intentRequest.status_code != 201:
41 + print intentRequest.text
42 + sys.exit(1)
43 +
44 +location = intentRequest.headers["location"]
45 +print "@stc " + name + "Location=" + location
46 +sys.exit(0)
47 +
48 +
49 +
1 +#! /usr/bin/env python
2 +
3 +import requests
4 +import sys
5 +import urllib
6 +
7 +from requests.auth import HTTPBasicAuth
8 +
9 +if len(sys.argv) != 4:
10 + print "usage: find-device onos-node name device-id"
11 + sys.exit(1)
12 +
13 +node = sys.argv[1]
14 +name = sys.argv[2]
15 +id = sys.argv[3]
16 +
17 +deviceRequest = requests.get('http://' + node + ':8181/onos/v1/devices/' +
18 + urllib.quote_plus(id),
19 + auth=HTTPBasicAuth('onos', 'rocks'))
20 +
21 +if deviceRequest.status_code != 200:
22 + print deviceRequest.text
23 + sys.exit(1)
24 +
25 +deviceJson = deviceRequest.json()
26 +
27 +print "@stc " + name + "Id=" + deviceJson["id"]
28 +print "@stc " + name + "Type=" + deviceJson["type"]
29 +print "@stc " + name + "Available=" + str(deviceJson["available"])
30 +channelId = deviceJson["annotations"]["channelId"]
31 +channelIdWords = channelId.split(':')
32 +print "@stc " + name + "IpAddress=" + channelIdWords[0]
33 +
34 +sys.exit(0)
35 +
36 +
37 +
38 +
39 +
1 +#! /usr/bin/env python
2 +
3 +import requests
4 +import sys
5 +
6 +from requests.auth import HTTPBasicAuth
7 +
8 +if len(sys.argv) != 4:
9 + print "usage: find-flow onos-node name device-id"
10 + sys.exit(1)
11 +
12 +node = sys.argv[1]
13 +name = sys.argv[2]
14 +deviceId = sys.argv[3]
15 +
16 +flowsRequest = requests.get('http://' + node + ':8181/onos/v1/flows/' + deviceId,
17 + auth=HTTPBasicAuth('onos', 'rocks'))
18 +
19 +if flowsRequest.status_code != 200:
20 + print flowsRequest.text
21 + sys.exit(1)
22 +
23 +flowsJson = flowsRequest.json()
24 +
25 +for flow in flowsJson["flows"]:
26 + if deviceId == flow["deviceId"]:
27 + for criterion in flow["selector"]["criteria"]:
28 + if criterion["type"] == 'IN_PORT' and criterion["port"] > 0:
29 + for instruction in flow["treatment"]["instructions"]:
30 + if instruction["port"] > 0 and instruction["type"] == 'OUTPUT':
31 + print "@stc " + name + "FlowState=" + flow["state"]
32 + print "@stc " + name + "FlowId=" + flow["id"]
33 + print "@stc " + name + "FlowPort=" + str(instruction["port"])
34 + sys.exit(0)
35 +
36 +sys.exit(1)
37 +
38 +
39 +
40 +
1 +#! /usr/bin/env python
2 +
3 +import requests
4 +import sys
5 +import urllib
6 +
7 +from requests.auth import HTTPBasicAuth
8 +
9 +if len(sys.argv) != 4:
10 + print "usage: find-host onos-node name device-id"
11 + sys.exit(1)
12 +
13 +node = sys.argv[1]
14 +name = sys.argv[2]
15 +id = sys.argv[3]
16 +
17 +hostRequest = requests.get('http://' + node + ':8181/onos/v1/hosts/' +
18 + urllib.quote_plus(id),
19 + auth=HTTPBasicAuth('onos', 'rocks'))
20 +
21 +if hostRequest.status_code != 200:
22 + print hostRequest.text
23 + sys.exit(1)
24 +
25 +hostJson = hostRequest.json()
26 +
27 +print "@stc " + name + "Id=" + hostJson["id"]
28 +print "@stc " + name + "Mac=" + hostJson["mac"]
29 +print "@stc " + name + "IpAddress=" + hostJson["ipAddresses"][0]
30 +
31 +sys.exit(0)
32 +
33 +
34 +
35 +
36 +
1 +#! /usr/bin/env python
2 +
3 +import requests
4 +import sys
5 +
6 +from requests.auth import HTTPBasicAuth
7 +
8 +if len(sys.argv) != 7:
9 + print "usage: find-link onos-node name src-device-id src-port dst-device-id dst-port"
10 + sys.exit(1)
11 +
12 +node = sys.argv[1]
13 +name = sys.argv[2]
14 +srcDeviceId = sys.argv[3]
15 +srcPort = sys.argv[4]
16 +dstDeviceId = sys.argv[5]
17 +dstPort = sys.argv[6]
18 +
19 +
20 +linksRequest = requests.get('http://' + node + ':8181/onos/v1/links?device=' +
21 + srcDeviceId + '&port=' + srcPort,
22 + auth=HTTPBasicAuth('onos', 'rocks'))
23 +
24 +if linksRequest.status_code != 200:
25 + print linksRequest.text
26 + sys.exit(1)
27 +
28 +linksJson = linksRequest.json()
29 +
30 +for link in linksJson["links"]:
31 + if srcDeviceId == link["src"]["device"]:
32 + if dstDeviceId == link["dst"]["device"]:
33 + print "@stc " + name + "SrcDevice=" + link["src"]["device"]
34 + print "@stc " + name + "SrcPort=" + link["src"]["port"]
35 + print "@stc " + name + "DstDevice=" + link["dst"]["device"]
36 + print "@stc " + name + "DstPort=" + link["dst"]["port"]
37 + print "@stc " + name + "Type=" + link["type"]
38 + print "@stc " + name + "State=" + link["state"]
39 + sys.exit(0)
40 +
41 +sys.exit(1)
42 +
43 +
44 +
45 +
...@@ -29,7 +29,10 @@ ...@@ -29,7 +29,10 @@
29 <import file="${ONOS_SCENARIOS}/net-point-intent.xml"/> 29 <import file="${ONOS_SCENARIOS}/net-point-intent.xml"/>
30 <dependency name="P2P-Intent-Connectivity" requires="Net-Setup,~Reactive-Forwarding.Net-Link-Down-Up,Host-Intent-Connectivity"/> 30 <dependency name="P2P-Intent-Connectivity" requires="Net-Setup,~Reactive-Forwarding.Net-Link-Down-Up,Host-Intent-Connectivity"/>
31 31
32 + <import file="${ONOS_SCENARIOS}/net-rest.xml"/>
33 + <dependency name="Net-REST" requires="Net-Setup,P2P-Intent-Connectivity"/>
34 +
32 <import file="${ONOS_SCENARIOS}/net-teardown.xml"/> 35 <import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
33 - <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,~P2P-Intent-Connectivity"/> 36 + <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,~P2P-Intent-Connectivity,~Net-REST"/>
34 </group> 37 </group>
35 </scenario> 38 </scenario>
......