Ray Milkey
Committed by Gerrit Code Review

STC scenario for creating flows directly via the REST API

Change-Id: I1c007a860f79f9bacdb0b893a480d2f4dc050c65
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)
43 +intentRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device,
44 + auth=HTTPBasicAuth('onos', 'rocks'),
45 + data=flowJson)
46 +
47 +if intentRequest.status_code != 201:
48 + print intentRequest.text
49 + sys.exit(1)
50 +
51 +location = intentRequest.headers["location"]
52 +print "@stc " + name + "Location=" + location
53 +sys.exit(0)
54 +
55 +
56 +
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-create-flows"
17 + description="Network Flow Creation Test Using REST API">
18 + <!-- TODO: parametrize this via recipes -->
19 + <group name="Net-Create-Flows">
20 +
21 + <!-- Make sure that reactive forwarding is off -->
22 + <step name="Net-Create-Flows.Uninstall-Reactive-Forwarding"
23 + exec="onos ${OC1} app deactivate org.onosproject.fwd org.onosproject.ifwd"/>
24 + <step name="Net-Create-Flows.Check-Apps" requires="^"
25 + exec="onos-check-apps ${OC1} fwd,ifwd excludes"/>
26 +
27 + <!-- Force discovery of hosts -->
28 + <step name="Net-Create-Flows.Find-Host-1" requires="^"
29 + exec="onos-mininet sendAndExpect h1 ping -c1 -w1 h4 --expect 100% packet loss"/>
30 + <step name="Net-Create-Flows.Find-Host-2" requires="^"
31 + exec="onos-mininet sendAndExpect h4 ping -c1 -w1 h1 --expect 100% packet loss"/>
32 +
33 +
34 + <!-- Use REST API to create a point to point intent in each direction -->
35 + <step name="Net-Create-Flows.1-to-Host" requires="Net-Create-Flows.Find-Host-2"
36 + exec="create-flow.py ${OC1} f1 of:0000000000000001 5 1"/>
37 + <step name="Net-Create-Flows.1-to-19" requires="^"
38 + exec="create-flow.py ${OC1} f2 of:0000000000000001 1 2"/>
39 + <step name="Net-Create-Flows.19-to-7" requires="^"
40 + exec="create-flow.py ${OC1} f3 of:0000000000000019 2 8"/>
41 + <step name="Net-Create-Flows.7-to-4" requires="^"
42 + exec="create-flow.py ${OC1} f4 of:0000000000000007 2 3"/>
43 + <step name="Net-Create-Flows.4-to-Host" requires="^"
44 + exec="create-flow.py ${OC1} f5 of:0000000000000004 1 3"/>
45 +
46 + <step name="Net-Create-Flows.Host-to-1" requires="^"
47 + exec="create-flow.py ${OC1} f6 of:0000000000000001 1 5"/>
48 + <step name="Net-Create-Flows.19-to-1" requires="^"
49 + exec="create-flow.py ${OC1} f7 of:0000000000000001 2 1"/>
50 + <step name="Net-Create-Flows.7-to-19" requires="^"
51 + exec="create-flow.py ${OC1} f8 of:0000000000000019 8 2"/>
52 + <step name="Net-Create-Flows.4-to-7" requires="^"
53 + exec="create-flow.py ${OC1} f9 of:0000000000000007 3 2"/>
54 + <step name="Net-Create-Flows.Host-to-4" requires="^"
55 + exec="create-flow.py ${OC1} f10 of:0000000000000004 3 1"/>
56 +
57 + <!-- Check that connectivity was established -->
58 + <step name="Net-Create-Flows.Ping-XY" requires="^"
59 + exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
60 + <step name="Net-Create-Flows.Ping-YX" requires="^"
61 + exec="onos-mininet sendAndExpect h4 ping -c1 h1 --expect \ 0% packet loss"/>
62 +
63 + <!-- Use REST API to remove the flows. -->
64 + <step name="Net-Create-Flows.Delete-f1" requires="^"
65 + exec="curl -f -X DELETE -uonos:rocks ${f1Location}"/>
66 + <step name="Net-Create-Flows.Delete-f2" requires="^"
67 + exec="curl -f -X DELETE -uonos:rocks ${f2Location}"/>
68 + <step name="Net-Create-Flows.Delete-f3" requires="^"
69 + exec="curl -f -X DELETE -uonos:rocks ${f3Location}"/>
70 + <step name="Net-Create-Flows.Delete-f4" requires="^"
71 + exec="curl -f -X DELETE -uonos:rocks ${f4Location}"/>
72 + <step name="Net-Create-Flows.Delete-f5" requires="^"
73 + exec="curl -f -X DELETE -uonos:rocks ${f5Location}"/>
74 + <step name="Net-Create-Flows.Delete-f6" requires="^"
75 + exec="curl -f -X DELETE -uonos:rocks ${f6Location}"/>
76 + <step name="Net-Create-Flows.Delete-f7" requires="^"
77 + exec="curl -f -X DELETE -uonos:rocks ${f7Location}"/>
78 + <step name="Net-Create-Flows.Delete-f8" requires="^"
79 + exec="curl -f -X DELETE -uonos:rocks ${f8Location}"/>
80 + <step name="Net-Create-Flows.Delete-f9" requires="^"
81 + exec="curl -f -X DELETE -uonos:rocks ${f9Location}"/>
82 + <step name="Net-Create-Flows.Delete-f10" requires="^"
83 + exec="curl -f -X DELETE -uonos:rocks ${f10Location}"/>
84 +
85 + <!-- Ping again to be sure the path was removed. -->
86 + <step name="Net-Create-Flows.Fail-Ping-XY" requires="^"
87 + exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 100% packet loss"/>
88 + <step name="Net-Create-Flows.Fail-Ping-YX" requires="^"
89 + exec="onos-mininet sendAndExpect h4 ping -c1 h1 --expect \ 100% packet loss"/>
90 +
91 +
92 + </group>
93 +</scenario>
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
32 <import file="${ONOS_SCENARIOS}/net-rest.xml"/> 32 <import file="${ONOS_SCENARIOS}/net-rest.xml"/>
33 <dependency name="Net-REST" requires="Net-Setup,P2P-Intent-Connectivity"/> 33 <dependency name="Net-REST" requires="Net-Setup,P2P-Intent-Connectivity"/>
34 34
35 + <import file="${ONOS_SCENARIOS}/net-create-flows.xml"/>
36 + <dependency name="Net-Create-Flows" requires="Net-Setup,P2P-Intent-Connectivity,Net-REST"/>
37 +
35 <import file="${ONOS_SCENARIOS}/net-teardown.xml"/> 38 <import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
36 - <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,~P2P-Intent-Connectivity,~Net-REST"/> 39 + <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,
40 + ~P2P-Intent-Connectivity,
41 + ~Net-REST,
42 + ~Net-Create-Flows"/>
37 </group> 43 </group>
38 </scenario> 44 </scenario>
......