Fix dependencies in Trellis P4 STC scenario

Add steps to verify driver and pipeconf apps, as well as registered
pipeconfs. Also, start Mininet first, then push Trellis netcfg.

Change-Id: Idf52e268e6f50c7f6b8f17a5ea0390f01a607fea
(cherry picked from commit 4c3364b22ed68511b00e1494a574f29eaf8841d3)
diff --git a/tools/test/bin/onos-check-pipeconfs b/tools/test/bin/onos-check-pipeconfs
new file mode 100755
index 0000000..9af9864
--- /dev/null
+++ b/tools/test/bin/onos-check-pipeconfs
@@ -0,0 +1,33 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Checks whether the given pipeconfs are registered.
+# -----------------------------------------------------------------------------
+
+[ ! -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 $aux.1 $aux.2 2>/dev/null" EXIT
+
+for attempt in {1..30}; do
+    onos ${1:-$OCI} "onos:pipeconfs -s" > $aux
+    cat $aux
+
+    # Normalize the registered pipeconfs
+    cut -d '=' -f2 $aux | sort > $aux.1
+
+    # Expected pipeconfs
+    pipeconfs=${2-org.onosproject.pipelines.basic}
+    (for pipeconf in ${pipeconfs//,/ }; do echo ${pipeconf}; done) | sort > $aux.2
+
+    # Check for differences
+    case ${3:-equals} in
+    equals) diff $aux.1 $aux.2;;
+    includes) [ $(egrep -c -f $aux.2 $aux.1) -ge $(wc -l $aux.2 | sed "s|$aux.2||g") ];;
+    excludes) ! egrep -f $aux.2 $aux.1;;
+    esac
+
+    [ $? -eq 0 ] && exit 0 || sleep 1
+done
+
+exit 1;
diff --git a/tools/test/scenarios/net-setup-trellis-p4.xml b/tools/test/scenarios/net-setup-trellis-p4.xml
index f27263a..fe3112d 100644
--- a/tools/test/scenarios/net-setup-trellis-p4.xml
+++ b/tools/test/scenarios/net-setup-trellis-p4.xml
@@ -17,12 +17,15 @@
 <scenario name="net-setup-trellis-p4" description="Trellis P4 based network setup steps">
 
     <group name="Trellis-Net-P4-Setup">
-        <step name="Trellis-Net-P4-Setup.Push-Topos" exec="onos-push-topos ${OCN}"/>
         <step name="Trellis-Net-P4-Setup.Push-Routing" exec="onos-push-routing ${OCN}"/>
         <step name="Trellis-Net-P4-Setup.Push-Bmv2" exec="onos-push-bmv2 ${OCN}"/>
 
+        <!-- Stop/cleanup mininet -->
         <step name="Trellis-Net-P4-Setup.Stop-Mininet-If-Needed" env="~" exec="onos-mininet stop"/>
         <step name="Trellis-Net-P4-Setup.Clean-Mininet-If-Needed" env="~" exec="onos-mininet cleanup" requires="^"/>
+        <!-- Set up the trellis env on the net machine -->
+        <step name="Trellis-Net-P4-Setup.Set-Up-Trellis" exec="set-up-trellis ${OCN}" requires="^"/>
+
         <step name="Trellis-Net-P4-Setup.Wipe-Out-Data-Before" exec="onos-wipe-out" requires="^"/>
 
         <!-- Make sure that there is no data in the system -->
@@ -70,24 +73,35 @@
                   requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
         </group>
 
-        <!-- set up the trellis environment -->
-        <step name="Trellis-Net-P4-Setup.Set-Up-Trellis" exec="set-up-trellis ${OCN}" requires="Trellis-Net-P4-Setup.Activate-Apps"/>
+        <group name="Trellis-Net-P4-Setup.Verify-Apps" requires="Trellis-Net-P4-Setup.Activate-Apps">
+            <parallel var="${OC#}">
+                <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#} drivers.bmv2,pipelines.fabric,generaldeviceprovider includes"
+                      requires="Trellis-Net-P4-Setup.Activate-Apps"/>
+            </parallel>
+        </group>
 
-        <!-- configure the trellis topology in ONOS -->
-        <step name="Trellis-Net-P4-Setup.Config-Topo"
-              requires="Trellis-Net-P4-Setup.Set-Up-Trellis,Trellis-Net-P4-Setup.Push-Topos,Trellis-Net-P4-Setup.Push-Routing"
-              exec="onos-netcfg ${OC1} ${routing}/trellis/trellisp4.json"/>
+        <group name="Trellis-Net-P4-Setup.Verify-Pipeconfs" requires="Trellis-Net-P4-Setup.Verify-Apps">
+            <parallel var="${OC#}">
+                <step name="Check-Pipeconfs-${#}" exec="onos-check-pipeconfs ${OC#} org.onosproject.pipelines.fabric includes"
+                      requires="Trellis-Net-P4-Setup.Verify-Apps"/>
+            </parallel>
+        </group>
 
         <!-- Bring up mininet -->
         <step name="Trellis-Net-P4-Setup.Start-Mininet"
-              requires="Trellis-Net-P4-Setup.Config-Topo,Trellis-Net-P4-Setup.Push-Topos,Trellis-Net-P4-Setup.Stop-Mininet-If-Needed"
+              requires="Trellis-Net-P4-Setup.Verify-Apps,Trellis-Net-P4-Setup.Verify-Pipeconfs,Trellis-Net-P4-Setup.Set-Up-Trellis"
               exec="mininet-p4-trellis ${ONOS_INSTANCES}"/>
         <step name="Trellis-Net-P4-Setup.Wait-For-Mininet" requires="Trellis-Net-P4-Setup.Start-Mininet"
               exec="onos-mininet wait 10"/>
 
+        <!-- Push the trellis netcfg -->
+        <step name="Trellis-Net-P4-Setup.Config-Topo"
+              requires="Trellis-Net-P4-Setup.Wait-For-Mininet,Trellis-Net-P4-Setup.Push-Routing"
+              exec="onos-netcfg ${OC1} ${routing}/trellis/trellisp4.json"/>
+
         <!-- clean up local routing repo if necessary -->
         <step delay="10" name="Trellis-Net-P4-Setup.Clean-Routing"
-              requires="Trellis-Net-P4-Setup.Start-Mininet"
+              requires="Trellis-Net-P4-Setup.Config-Topo"
               exec="onos-clean-routing ${routing_root}"/>
     </group>
 </scenario>
diff --git a/tools/test/scenarios/net-trellis-p4-smoke.xml b/tools/test/scenarios/net-trellis-p4-smoke.xml
index 6d7a443..0ced6c1 100644
--- a/tools/test/scenarios/net-trellis-p4-smoke.xml
+++ b/tools/test/scenarios/net-trellis-p4-smoke.xml
@@ -34,4 +34,4 @@
               exec="onos-check-logs ${OC#}"/>
     </parallel>
 
-</scenario>
\ No newline at end of file
+</scenario>