Fixes to allow running p4 trellis scenario

Change-Id: I4882668168521b9119692ecd696189b2b8d5f9de
(cherry picked from commit a61ba5792d9e7a25d3446f37179fbf13ac152098)
diff --git a/tools/test/bin/onos-find-device b/tools/test/bin/onos-find-device
new file mode 100755
index 0000000..fbf1692
--- /dev/null
+++ b/tools/test/bin/onos-find-device
@@ -0,0 +1,26 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Finds a device in the system.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+aux=/tmp/stc/stc-$$.log
+trap "rm -f $aux 2>/dev/null" EXIT
+
+echo onos-find-device: $*
+
+target=${1:-$OCI}
+id=$2
+
+onos $target "onos:devices" | tee $aux
+cat $aux | fgrep "id=$id"
+
+if [ $? -ne 0 ]
+then
+    exit 1;
+fi
+
+exit 0
+
diff --git a/tools/test/bin/onos-push-bmv2 b/tools/test/bin/onos-push-bmv2
index 271c31d..d72f41e 100755
--- a/tools/test/bin/onos-push-bmv2
+++ b/tools/test/bin/onos-push-bmv2
@@ -10,9 +10,6 @@
 user=$ONOS_WEB_USER
 pass=$ONOS_WEB_PASS
 
-ssh $ONOS_USER@$node sudo rm -f ~/bmv2-mininet
-scp -qr $ONOS_ROOT/tools/dev/mininet/bmv2.py $ONOS_USER@[$node]:~/bmv2-mininet
-ssh $ONOS_USER@$node "
-       echo 'export ONOS_WEB_USER=`$user`' >> ~/.bashrc
-       echo 'export ONOS_WEB_PASS=`$pass`' >> ~/.bashrc
-      "
\ No newline at end of file
+ssh $ONOS_USER@$node "sudo rm -rf ~/bmv2-mininet"
+ssh $ONOS_USER@$node "mkdir ~/bmv2-mininet"
+scp -qr $ONOS_ROOT/tools/dev/mininet/bmv2.py $ONOS_USER@[$node]:~/bmv2-mininet/
diff --git a/tools/test/scenarios/bin/mininet-p4-trellis b/tools/test/scenarios/bin/mininet-p4-trellis
index 889fb77..aeb9ef6 100755
--- a/tools/test/scenarios/bin/mininet-p4-trellis
+++ b/tools/test/scenarios/bin/mininet-p4-trellis
@@ -1,18 +1,19 @@
 #!/bin/bash
 
 remote=$ONOS_USER@$OCN
+remote_scp=$ONOS_USER@[$OCN]
 mininet="ssh -t -t $remote screen -L -S mininet"
 
 CONTROLLERS="$OC1"
 
-echo >/tmp/invoke_trellis_p4 "cd routing/trellis && sudo -E env PYTHONPATH=$PYTHONPATH:~/bmv2-mininet ./trellisp4.py --onos-ip '$CONTROLLERS'"
+echo >/tmp/invoke_trellis_p4 "export ONOS_WEB_USER=$ONOS_WEB_USER && export ONOS_WEB_PASS=$ONOS_WEB_PASS && cd routing/trellis && sudo -E env PYTHONPATH=$PYTHONPATH:/home/sdn/bmv2-mininet ./trellisp4.py --onos-ip '$CONTROLLERS'"
 chmod +x /tmp/invoke_trellis_p4
-scp /tmp/invoke_trellis_p4 [$remote]:
+scp /tmp/invoke_trellis_p4 $remote_scp:
 
 ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
     (
     $mininet ./invoke_trellis_p4
-    scp [$remote]:$log /tmp/mininet.log
+    scp $remote_scp:$log /tmp/mininet.log
     ssh $remote rm -f $log
     ) &
 
diff --git a/tools/test/scenarios/net-setup-trellis-p4.xml b/tools/test/scenarios/net-setup-trellis-p4.xml
index e4bc2ee..f27263a 100644
--- a/tools/test/scenarios/net-setup-trellis-p4.xml
+++ b/tools/test/scenarios/net-setup-trellis-p4.xml
@@ -86,7 +86,7 @@
               exec="onos-mininet wait 10"/>
 
         <!-- clean up local routing repo if necessary -->
-        <step name="Trellis-Net-P4-Setup.Clean-Routing"
+        <step delay="10" name="Trellis-Net-P4-Setup.Clean-Routing"
               requires="Trellis-Net-P4-Setup.Start-Mininet"
               exec="onos-clean-routing ${routing_root}"/>
     </group>
diff --git a/tools/test/scenarios/net-trellis-p4-devices.xml b/tools/test/scenarios/net-trellis-p4-devices.xml
new file mode 100644
index 0000000..1b79eab
--- /dev/null
+++ b/tools/test/scenarios/net-trellis-p4-devices.xml
@@ -0,0 +1,37 @@
+<!--
+  ~ 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-trellis-p4-devices" description="Trellis P4 network device check steps">
+
+        <group name="Net-Trellis-P4-Devices">
+
+            <step name="Net-Trellis-P4-Devices.Device-1"
+                  exec="onos-find-device ${OC1} device:bmv2:s204"/>
+
+            <step name="Net-Trellis-P4-Devices.Device-2"
+                  exec="onos-find-device ${OC1} device:bmv2:s205"/>
+
+            <step name="Net-Trellis-P4-Devices.Device-3"
+                  exec="onos-find-device ${OC1} device:bmv2:s226"/>
+
+            <step name="Net-Trellis-P4-Devices.Device-4"
+                  exec="onos-find-device ${OC1} device:bmv2:s227"/>
+
+        </group>
+
+</scenario>
\ No newline at end of file
diff --git a/tools/test/scenarios/net-trellis-p4-links.xml b/tools/test/scenarios/net-trellis-p4-links.xml
new file mode 100644
index 0000000..bc4192b
--- /dev/null
+++ b/tools/test/scenarios/net-trellis-p4-links.xml
@@ -0,0 +1,90 @@
+<!--
+  ~ 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-trellis-p4-links" description="Trellis P4 network link check steps">
+
+        <group name="Net-Trellis-P4-Links">
+            <!-- Verify some links using the REST API -->
+
+            <!-- Bi-Directional link between s204 and s226 -->
+            <!-- Link 1 -->
+            <step name="Net-Trellis-HAG-Links.Query-204-226-Link-1"
+                  exec="find-link.py ${OC1} link_204_226_1_ device:bmv2:s204 1 device:bmv2:s226 1"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-State" requires="^"
+                  exec="test '${link_204_226_1_State}' == 'ACTIVE'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-Type" requires="^"
+                  exec="test '${link_204_226_1_Type}' == 'DIRECT'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-Src-Device" requires="^"
+                  exec="test '${link_204_226_1_SrcDevice}' == 'device:bmv2:s204'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-Dst-Device" requires="^"
+                  exec="test '${link_204_226_1_DstDevice}' == 'device:bmv2:s226'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-Src-Port" requires="^"
+                  exec="test '${link_204_226_1_SrcPort}' == '1'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-204-226-Link-1-Dst-Port" requires="^"
+                  exec="test '${link_204_226_1_DstPort}' == '1'"/>
+
+            <step name="Net-Trellis-HAG-Links.Query-226-204-Link-2"
+                  exec="find-link.py ${OC1} link_226_204_2_ device:bmv2:s226 1 device:bmv2:s204 1"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-State" requires="^"
+                  exec="test '${link_226_204_2_State}' == 'ACTIVE'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-Type" requires="^"
+                  exec="test '${link_226_204_2_Type}' == 'DIRECT'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-Src-Device" requires="^"
+                  exec="test '${link_226_204_2_SrcDevice}' == 'device:bmv2:s226'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-Dst-Device" requires="^"
+                  exec="test '${link_226_204_2_DstDevice}' == 'device:bmv2:s204'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-Src-Port" requires="^"
+                  exec="test '${link_226_204_2_SrcPort}' == '1'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-226-204-Link-2-Dst-Port" requires="^"
+                  exec="test '${link_226_204_2_DstPort}' == '1'"/>
+
+            <!-- Bi-Directional link between s205 and s227 -->
+            <!-- Link 1 -->
+            <step name="Net-Trellis-HAG-Links.Query-205-227-Link-1"
+                  exec="find-link.py ${OC1} link_205_227_1_ device:bmv2:s205 2 device:bmv2:s227 2"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-State" requires="^"
+                  exec="test '${link_205_227_1_State}' == 'ACTIVE'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-Type" requires="^"
+                  exec="test '${link_205_227_1_Type}' == 'DIRECT'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-Src-Device" requires="^"
+                  exec="test '${link_205_227_1_SrcDevice}' == 'device:bmv2:s205'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-Dst-Device" requires="^"
+                  exec="test '${link_205_227_1_DstDevice}' == 'device:bmv2:s227'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-Src-Port" requires="^"
+                  exec="test '${link_205_227_1_SrcPort}' == '2'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-205-227-Link-1-Dst-Port" requires="^"
+                  exec="test '${link_205_227_1_DstPort}' == '2'"/>
+
+            <step name="Net-Trellis-HAG-Links.Query-227-205-Link-2"
+                  exec="find-link.py ${OC1} link_227_205_2_ device:bmv2:s227 2 device:bmv2:s205 2"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-State" requires="^"
+                  exec="test '${link_227_205_2_State}' == 'ACTIVE'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-Type" requires="^"
+                  exec="test '${link_227_205_2_Type}' == 'DIRECT'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-Src-Device" requires="^"
+                  exec="test '${link_227_205_2_SrcDevice}' == 'device:bmv2:s227'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-Dst-Device" requires="^"
+                  exec="test '${link_227_205_2_DstDevice}' == 'device:bmv2:s205'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-Src-Port" requires="^"
+                  exec="test '${link_227_205_2_SrcPort}' == '2'"/>
+            <step name="Net-Trellis-HAG-Links.Validate-227-205-Link-2-Dst-Port" requires="^"
+                  exec="test '${link_227_205_2_DstPort}' == '2'"/>
+
+        </group>
+
+</scenario>
diff --git a/tools/test/scenarios/net-trellis-p4-smoke.xml b/tools/test/scenarios/net-trellis-p4-smoke.xml
new file mode 100644
index 0000000..6d7a443
--- /dev/null
+++ b/tools/test/scenarios/net-trellis-p4-smoke.xml
@@ -0,0 +1,37 @@
+<!--
+  ~ 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-trellis-p4-smoke" description="Trellis P4 network connectivity test steps">
+
+    <import file="${ONOS_SCENARIOS}/net-setup-trellis-p4.xml"/>
+
+    <step name="Net-Trellis-P4-Smoke.Check-Summary" requires="Trellis-Net-P4-Setup.Wait-For-Mininet" delay="15"
+          exec="onos-check-summary ${OC1} [0-9]* 4 8 0 112"/>
+
+    <import file="${ONOS_SCENARIOS}/net-trellis-p4-devices.xml"/>
+    <dependency name="Net-Trellis-P4-Devices" requires="Net-Trellis-P4-Smoke.Check-Summary"/>
+
+    <import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
+    <dependency name="Net-Teardown" requires="Net-Trellis-P4-Smoke.Check-Summary"/>
+
+    <parallel var="${OC#}">
+        <step name="Net-Trellis-P4-Smoke-Check-Logs-${#}" requires="~Net-Teardown"
+              exec="onos-check-logs ${OC#}"/>
+    </parallel>
+
+</scenario>
\ No newline at end of file