STC scenario to test administrative enable and disable of a port

Change-Id: I69026a7ada071bf06f3505666712778350b6969f
(cherry picked from commit f16975bffab4ec4e8c4e99662232c3ade0197532)
diff --git a/tools/test/scenarios/bin/onos-change-device-portstate b/tools/test/scenarios/bin/onos-change-device-portstate
new file mode 100755
index 0000000..bc69d98
--- /dev/null
+++ b/tools/test/scenarios/bin/onos-change-device-portstate
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+
+import requests
+
+from requests.auth import HTTPBasicAuth
+import sys
+
+
+
+if len(sys.argv) != 5:
+    print "usage: change-device-portstate onos-node device-id port new_enabled_state"
+    sys.exit(1)
+
+node = sys.argv[1]
+device_id = sys.argv[2]
+port = sys.argv[3]
+new_enabled_state = sys.argv[4]
+
+payload = '{ "enabled": ' + new_enabled_state + ' }'
+
+change_request = requests.post('http://' + node + ':8181/onos/v1/devices/' + device_id + '/portstate/' + port,
+                               auth=HTTPBasicAuth('onos', 'rocks'),
+                               data=payload)
+
+if change_request.status_code != 200:
+    print change_request.text
+    sys.exit(1)
+
+sys.exit(0)
+
+
+
diff --git a/tools/test/scenarios/net-port-disable-enable.xml b/tools/test/scenarios/net-port-disable-enable.xml
new file mode 100644
index 0000000..b77b420
--- /dev/null
+++ b/tools/test/scenarios/net-port-disable-enable.xml
@@ -0,0 +1,91 @@
+<!--
+  ~ Copyright 2018-present Open Networking Foundation
+  ~
+  ~ 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-port-disable-enable" description="Network port enable-disable test">
+    <!-- Note: This scenario is tailored using 'topo' recipe mechanism; see topos/*.recipe files -->
+    <group name="Net-Port-Disable-Enable">
+
+        <step name="Query-Link-1f"
+              exec="find-link.py ${OC1} unused ${OPSS1} ${OPSP1} ${OPDS1} ${OPDP1}"/>
+        <step name="Query-Link-1b"
+              exec="find-link.py ${OC1} unused ${OPDS1} ${OPDP1} ${OPSS1} ${OPSP1}"/>
+        <step name="Query-Link-2f"
+              exec="find-link.py ${OC1} unused ${OPSS2} ${OPSP2} ${OPDS2} ${OPDP2}"/>
+        <step name="Query-Link-2b"
+              exec="find-link.py ${OC1} unused ${OPDS2} ${OPDP2} ${OPSS2} ${OPSP2}"/>
+
+        <step name="Port-Ping-1"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c1 ${OPD} --expect \ 0% packet loss"
+              requires="~Query-Link-1f, ~Query-Link-1b"/>
+
+        <step name="Port-1-Down" requires="~Port-Ping-1"
+              exec="onos-change-device-portstate ${OC1} ${OPSS1} ${OPSP1} false"/>
+        <step name="Query-Link-3f"
+              exec="find-link.py ${OC1} unused ${OPSS1} ${OPSP1} ${OPDS1} ${OPDP1}"
+              env="!"
+              requires="Port-1-Down"/>
+        <step name="Query-Link-3b"
+              exec="find-link.py ${OC1} unused ${OPDS1} ${OPDP1} ${OPSS1} ${OPSP1}"
+              env="!"
+              requires="Port-1-Down"/>
+
+        <step name="Port-Ping-2-Prep" requires="~Port-1-Down"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c5 ${OPD} --expect ."/>
+        <step name="Port-Ping-2" requires="~Port-Ping-2-Prep"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c1 ${OPD} --expect \ 0% packet loss"/>
+
+        <step name="Port-2-Down" requires="~Port-Ping-2"
+              exec="onos-change-device-portstate ${OC1} ${OPSS2} ${OPSP2} false"/>
+        <step name="Query-Link-4f"
+              exec="find-link.py ${OC1} unused ${OPSS2} ${OPSP2} ${OPDS2} ${OPDP2}"
+              env="!"
+              requires="Port-2-Down"/>
+        <step name="Query-Link-4b"
+              exec="find-link.py ${OC1} unused ${OPDS2} ${OPDP2} ${OPSS2} ${OPSP2}"
+              env="!"
+              requires="Port-2-Down"/>
+
+        <step name="Port-Ping-3" requires="~Port-2-Down"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c1 -w1 ${OPD} --expect 100% packet loss"/>
+
+        <step name="Port-1-Up" requires="~Port-Ping-3"
+              exec="onos-change-device-portstate ${OC1} ${OPSS1} ${OPSP1} true"/>
+        <step name="Query-Link-5f"
+              exec="find-link.py ${OC1} unused ${OPSS1} ${OPSP1} ${OPDS1} ${OPDP1}"
+              requires="Port-1-Up"/>
+        <step name="Query-Link-5b"
+              exec="find-link.py ${OC1} unused ${OPDS1} ${OPDP1} ${OPSS1} ${OPSP1}"
+              requires="Port-1-Up"/>
+
+        <step name="Port-Ping-4-Prep" requires="~Port-1-Up"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c5 ${OPD} --expect ."/>
+        <step name="Port-Ping-4" requires="~Port-Ping-4-Prep"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c1 ${OPD} --expect \ 0% packet loss"/>
+
+        <step name="Port-2-Up" requires="~Port-Ping-4"
+              exec="onos-change-device-portstate ${OC1} ${OPSS2} ${OPSP2} true"/>
+        <step name="Query-Link-6f"
+              exec="find-link.py ${OC1} unused ${OPSS2} ${OPSP2} ${OPDS2} ${OPDP2}"
+              requires="Port-2-Up"/>
+        <step name="Query-Link-6b"
+              exec="find-link.py ${OC1} unused ${OPDS2} ${OPDP2} ${OPSS2} ${OPSP2}"
+              requires="Port-2-Up"/>
+
+        <step name="Port-Ping-5-Prep" requires="~Port-2-Up"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c5 ${OPD} --expect ."/>
+        <step name="Port-Ping-5" requires="~Port-Ping-5-Prep"
+              exec="onos-mininet sendAndExpect ${OPS} ping -c1 ${OPD} --expect \ 0% packet loss"/>
+    </group>
+</scenario>
diff --git a/tools/test/scenarios/net-reactive-fwd.xml b/tools/test/scenarios/net-reactive-fwd.xml
index b3968dc..0558697 100644
--- a/tools/test/scenarios/net-reactive-fwd.xml
+++ b/tools/test/scenarios/net-reactive-fwd.xml
@@ -23,7 +23,10 @@
         <import file="${ONOS_SCENARIOS}/net-link-down-up.xml" namespace="Net-Reactive-Fwd"/>
         <dependency name="Net-Reactive-Fwd.Net-Link-Down-Up" requires="~Net-Reactive-Fwd.Net-Pingall"/>
 
+        <import file="${ONOS_SCENARIOS}/net-port-disable-enable.xml" namespace="Net-Reactive-Fwd"/>
+        <dependency name="Net-Reactive-Fwd.Net-Port-Disable-Enable" requires="~Net-Reactive-Fwd.Net-Link-Down-Up"/>
+
         <import file="${ONOS_SCENARIOS}/net-deactivate-fwd.xml" namespace="Net-Reactive-Fwd"/>
-        <dependency name="Net-Reactive-Fwd.Net-Deactivate-Fwd" requires="~Net-Reactive-Fwd.Net-Link-Down-Up"/>
+        <dependency name="Net-Reactive-Fwd.Net-Deactivate-Fwd" requires="~Net-Reactive-Fwd.Net-Port-Disable-Enable"/>
     </group>
 </scenario>
diff --git a/tools/test/topos/default.recipe b/tools/test/topos/default.recipe
index b08c896..c6b4e55 100644
--- a/tools/test/topos/default.recipe
+++ b/tools/test/topos/default.recipe
@@ -11,4 +11,16 @@
 export OPS=h1
 export OPD=h4
 export OPL1="s4 s7"
-export OPL2="s4 s5"
\ No newline at end of file
+export OPL2="s4 s5"
+
+# Variables for device port up down up scenario.
+export OPSS1="of:0000000000000004"
+export OPSP1="3"
+export OPDS1="of:0000000000000007"
+export OPDP1="3"
+export OPSS2="of:0000000000000005"
+export OPSP2="2"
+export OPDS2="of:0000000000000004"
+export OPDP2="2"
+
+