STC scenario for creating flows directly via the REST API
Change-Id: I1c007a860f79f9bacdb0b893a480d2f4dc050c65
diff --git a/tools/test/scenarios/bin/create-flow.py b/tools/test/scenarios/bin/create-flow.py
new file mode 100755
index 0000000..4e9b452
--- /dev/null
+++ b/tools/test/scenarios/bin/create-flow.py
@@ -0,0 +1,56 @@
+#! /usr/bin/env python
+
+import requests
+
+from requests.auth import HTTPBasicAuth
+import sys
+
+
+
+if len(sys.argv) != 6:
+ print "usage: create-flow onos-node name device in-port out-port"
+ sys.exit(1)
+
+node = sys.argv[1]
+name = sys.argv[2]
+device = sys.argv[3]
+inPort = sys.argv[4]
+outPort = sys.argv[5]
+
+flowJsonTemplate = \
+ '{{' + \
+ '"priority": 1,' + \
+ '"isPermanent": true,' + \
+ '"treatment": {{' + \
+ '"instructions": [' + \
+ '{{' + \
+ '"type": "OUTPUT",' + \
+ '"port": {}' + \
+ '}}' + \
+ ']' + \
+ '}},' + \
+ '"selector": {{' + \
+ '"criteria": [' + \
+ '{{' + \
+ '"type": "IN_PORT",' + \
+ '"port": {}' + \
+ '}}' + \
+ ']' + \
+ '}}' + \
+ '}}'
+
+flowJson = flowJsonTemplate.format(inPort, outPort)
+intentRequest = requests.post('http://' + node + ':8181/onos/v1/flows/' + device,
+ auth=HTTPBasicAuth('onos', 'rocks'),
+ data=flowJson)
+
+if intentRequest.status_code != 201:
+ print intentRequest.text
+ sys.exit(1)
+
+location = intentRequest.headers["location"]
+print "@stc " + name + "Location=" + location
+sys.exit(0)
+
+
+
diff --git a/tools/test/scenarios/net-create-flows.xml b/tools/test/scenarios/net-create-flows.xml
new file mode 100644
index 0000000..6a6a80b
--- /dev/null
+++ b/tools/test/scenarios/net-create-flows.xml
@@ -0,0 +1,93 @@
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<scenario name="net-create-flows"
+ description="Network Flow Creation Test Using REST API">
+ <!-- TODO: parametrize this via recipes -->
+ <group name="Net-Create-Flows">
+
+ <!-- Make sure that reactive forwarding is off -->
+ <step name="Net-Create-Flows.Uninstall-Reactive-Forwarding"
+ exec="onos ${OC1} app deactivate org.onosproject.fwd org.onosproject.ifwd"/>
+ <step name="Net-Create-Flows.Check-Apps" requires="^"
+ exec="onos-check-apps ${OC1} fwd,ifwd excludes"/>
+
+ <!-- Force discovery of hosts -->
+ <step name="Net-Create-Flows.Find-Host-1" requires="^"
+ exec="onos-mininet sendAndExpect h1 ping -c1 -w1 h4 --expect 100% packet loss"/>
+ <step name="Net-Create-Flows.Find-Host-2" requires="^"
+ exec="onos-mininet sendAndExpect h4 ping -c1 -w1 h1 --expect 100% packet loss"/>
+
+
+ <!-- Use REST API to create a point to point intent in each direction -->
+ <step name="Net-Create-Flows.1-to-Host" requires="Net-Create-Flows.Find-Host-2"
+ exec="create-flow.py ${OC1} f1 of:0000000000000001 5 1"/>
+ <step name="Net-Create-Flows.1-to-19" requires="^"
+ exec="create-flow.py ${OC1} f2 of:0000000000000001 1 2"/>
+ <step name="Net-Create-Flows.19-to-7" requires="^"
+ exec="create-flow.py ${OC1} f3 of:0000000000000019 2 8"/>
+ <step name="Net-Create-Flows.7-to-4" requires="^"
+ exec="create-flow.py ${OC1} f4 of:0000000000000007 2 3"/>
+ <step name="Net-Create-Flows.4-to-Host" requires="^"
+ exec="create-flow.py ${OC1} f5 of:0000000000000004 1 3"/>
+
+ <step name="Net-Create-Flows.Host-to-1" requires="^"
+ exec="create-flow.py ${OC1} f6 of:0000000000000001 1 5"/>
+ <step name="Net-Create-Flows.19-to-1" requires="^"
+ exec="create-flow.py ${OC1} f7 of:0000000000000001 2 1"/>
+ <step name="Net-Create-Flows.7-to-19" requires="^"
+ exec="create-flow.py ${OC1} f8 of:0000000000000019 8 2"/>
+ <step name="Net-Create-Flows.4-to-7" requires="^"
+ exec="create-flow.py ${OC1} f9 of:0000000000000007 3 2"/>
+ <step name="Net-Create-Flows.Host-to-4" requires="^"
+ exec="create-flow.py ${OC1} f10 of:0000000000000004 3 1"/>
+
+ <!-- Check that connectivity was established -->
+ <step name="Net-Create-Flows.Ping-XY" requires="^"
+ exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
+ <step name="Net-Create-Flows.Ping-YX" requires="^"
+ exec="onos-mininet sendAndExpect h4 ping -c1 h1 --expect \ 0% packet loss"/>
+
+ <!-- Use REST API to remove the flows. -->
+ <step name="Net-Create-Flows.Delete-f1" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f1Location}"/>
+ <step name="Net-Create-Flows.Delete-f2" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f2Location}"/>
+ <step name="Net-Create-Flows.Delete-f3" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f3Location}"/>
+ <step name="Net-Create-Flows.Delete-f4" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f4Location}"/>
+ <step name="Net-Create-Flows.Delete-f5" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f5Location}"/>
+ <step name="Net-Create-Flows.Delete-f6" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f6Location}"/>
+ <step name="Net-Create-Flows.Delete-f7" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f7Location}"/>
+ <step name="Net-Create-Flows.Delete-f8" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f8Location}"/>
+ <step name="Net-Create-Flows.Delete-f9" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f9Location}"/>
+ <step name="Net-Create-Flows.Delete-f10" requires="^"
+ exec="curl -f -X DELETE -uonos:rocks ${f10Location}"/>
+
+ <!-- Ping again to be sure the path was removed. -->
+ <step name="Net-Create-Flows.Fail-Ping-XY" requires="^"
+ exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 100% packet loss"/>
+ <step name="Net-Create-Flows.Fail-Ping-YX" requires="^"
+ exec="onos-mininet sendAndExpect h4 ping -c1 h1 --expect \ 100% packet loss"/>
+
+
+ </group>
+</scenario>
diff --git a/tools/test/scenarios/net-smoke.xml b/tools/test/scenarios/net-smoke.xml
index b411765..53a5729 100644
--- a/tools/test/scenarios/net-smoke.xml
+++ b/tools/test/scenarios/net-smoke.xml
@@ -32,7 +32,13 @@
<import file="${ONOS_SCENARIOS}/net-rest.xml"/>
<dependency name="Net-REST" requires="Net-Setup,P2P-Intent-Connectivity"/>
+ <import file="${ONOS_SCENARIOS}/net-create-flows.xml"/>
+ <dependency name="Net-Create-Flows" requires="Net-Setup,P2P-Intent-Connectivity,Net-REST"/>
+
<import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
- <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,~P2P-Intent-Connectivity,~Net-REST"/>
+ <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,
+ ~P2P-Intent-Connectivity,
+ ~Net-REST,
+ ~Net-Create-Flows"/>
</group>
</scenario>