Adding an STC scenario for fabric.p4

Change-Id: I3457ab67c2c97eab73623500ba3f6a75b9ed33a3
diff --git a/tools/dev/mininet/bmv2.py b/tools/dev/mininet/bmv2.py
index 0430ee3..e161ced 100644
--- a/tools/dev/mininet/bmv2.py
+++ b/tools/dev/mininet/bmv2.py
@@ -11,12 +11,7 @@
 from mininet.log import info, warn, error
 from mininet.node import Switch, Host
 
-if 'ONOS_ROOT' not in os.environ:
-    error("ERROR: environment var $ONOS_ROOT not set")
-    exit()
-
 SIMPLE_SWITCH_GRPC = 'simple_switch_grpc'
-ONOS_ROOT = os.environ["ONOS_ROOT"]
 PKT_BYTES_TO_DUMP = 80
 VALGRIND_PREFIX = 'valgrind --leak-check=yes'
 SWITCH_START_TIMEOUT = 5  # seconds
diff --git a/tools/dev/p4vm/user-bootstrap.sh b/tools/dev/p4vm/user-bootstrap.sh
index e068727..e1696a5 100755
--- a/tools/dev/p4vm/user-bootstrap.sh
+++ b/tools/dev/p4vm/user-bootstrap.sh
@@ -21,3 +21,9 @@
 # Mininet
 git clone git://github.com/mininet/mininet ~/mininet
 sudo ~/mininet/util/install.sh -nv
+
+# Trellis routing repo
+git clone https://github.com/opennetworkinglab/routing.git
+
+# Set Python path for bmv2 in fabric.p4
+echo 'export PYTHONPATH=$PYTHONPATH:~/onos/tools/dev/mininet/bmv2.py' >> ~/.bashrc
diff --git a/tools/test/bin/onos-push-bmv2 b/tools/test/bin/onos-push-bmv2
new file mode 100755
index 0000000..271c31d
--- /dev/null
+++ b/tools/test/bin/onos-push-bmv2
@@ -0,0 +1,18 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Remotely pushes bmv2 custom mininet script to a remote mininet test machine.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+node=${1:-$OCN}
+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
diff --git a/tools/test/scenarios/bin/mininet-p4-trellis b/tools/test/scenarios/bin/mininet-p4-trellis
new file mode 100755
index 0000000..889fb77
--- /dev/null
+++ b/tools/test/scenarios/bin/mininet-p4-trellis
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+remote=$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'"
+chmod +x /tmp/invoke_trellis_p4
+scp /tmp/invoke_trellis_p4 [$remote]:
+
+ssh $remote "rm -f $log; echo logfile flush 1 > ~/.screenrc"
+    (
+    $mininet ./invoke_trellis_p4
+    scp [$remote]:$log /tmp/mininet.log
+    ssh $remote rm -f $log
+    ) &
+
+
+
+
+
diff --git a/tools/test/scenarios/bin/set-up-trellis-hag b/tools/test/scenarios/bin/set-up-trellis
similarity index 99%
rename from tools/test/scenarios/bin/set-up-trellis-hag
rename to tools/test/scenarios/bin/set-up-trellis
index 5e947ec..03dc23d 100755
--- a/tools/test/scenarios/bin/set-up-trellis-hag
+++ b/tools/test/scenarios/bin/set-up-trellis
@@ -16,4 +16,4 @@
     echo isc-dhcp-relay isc-dhcp-relay/interfaces string "" | sudo debconf-set-selections
     echo isc-dhcp-relay isc-dhcp-relay/options string "" | sudo debconf-set-selections
     echo isc-dhcp-relay isc-dhcp-relay/servers string "" | sudo debconf-set-selections
-"
+"
\ No newline at end of file
diff --git a/tools/test/scenarios/net-setup-trellis-hag.xml b/tools/test/scenarios/net-setup-trellis-hag.xml
index c7a5c7a..bccca73 100644
--- a/tools/test/scenarios/net-setup-trellis-hag.xml
+++ b/tools/test/scenarios/net-setup-trellis-hag.xml
@@ -70,7 +70,7 @@
         </group>
 
         <!-- set up the trellis environment -->
-        <step name="Trellis-Net-HAG-Setup.Set-Up-Trellis" exec="set-up-trellis-hag ${OCN}" requires="Trellis-Net-HAG-Setup.Activate-Apps"/>
+        <step name="Trellis-Net-HAG-Setup.Set-Up-Trellis" exec="set-up-trellis ${OCN}" requires="Trellis-Net-HAG-Setup.Activate-Apps"/>
 
         <!-- configure the trellis topology in ONOS -->
         <step name="Trellis-Net-HAG-Setup.Config-Topo"
diff --git a/tools/test/scenarios/net-setup-trellis-p4.xml b/tools/test/scenarios/net-setup-trellis-p4.xml
new file mode 100644
index 0000000..e4bc2ee
--- /dev/null
+++ b/tools/test/scenarios/net-setup-trellis-p4.xml
@@ -0,0 +1,93 @@
+<!--
+  ~ Copyright 2015-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-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}"/>
+
+        <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="^"/>
+        <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 -->
+        <step name="Trellis-Net-P4-Setup.Initial-Summary-Check" requires="~Trellis-Net-P4-Setup.Wipe-Out-Data-Before"
+              exec="onos-check-summary ${OC1} [0-9]* 0 0 0"/>
+
+        <!-- Deactivate unneeded apps -->
+        <group name="Trellis-Net-P4-Setup.Deactivate-Apps" requires="Trellis-Net-P4-Setup.Initial-Summary-Check">
+            <step name="App-Deactivate-PathPainter"
+                  exec="onos ${OCI} app deactivate org.onosproject.pathpainter"
+                  requires="Trellis-Net-P4-Setup.Initial-Summary-Check"/>
+            <step name="App-Deactivate-Mobility"
+                  exec="onos ${OCI} app deactivate org.onosproject.mobility"
+                  requires="Trellis-Net-P4-Setup.Initial-Summary-Check"/>
+            <step name="App-Deactivate-RouteService"
+                  exec="onos ${OCI} app deactivate org.onosproject.route-service"
+                  requires="Trellis-Net-P4-Setup.Initial-Summary-Check"/>
+        </group>
+
+        <!-- Active required apps -->
+        <group name="Trellis-Net-P4-Setup.Activate-Apps" requires="Trellis-Net-P4-Setup.Deactivate-Apps">
+            <step name="App-Activate-Drivers-Bmv2"
+                  exec="onos ${OCI} app activate org.onosproject.drivers.bmv2"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-Pipelines-Fabric"
+                  exec="onos ${OCI} app activate org.onosproject.pipelines.fabric"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-SegmentRouting"
+                  exec="onos ${OCI} app activate org.onosproject.segmentrouting"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-Fpm"
+                  exec="onos ${OCI} app activate org.onosproject.fpm"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-DhcpRelay"
+                  exec="onos ${OCI} app activate org.onosproject.dhcprelay"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-NetCfgHostProvider"
+                  exec="onos ${OCI} app activate org.onosproject.netcfghostprovider"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-RouterAdvertisement"
+                  exec="onos ${OCI} app activate org.onosproject.routeradvertisement"
+                  requires="Trellis-Net-P4-Setup.Deactivate-Apps"/>
+            <step name="App-Activate-Mcast"
+                  exec="onos ${OCI} app activate org.onosproject.mcast"
+                  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"/>
+
+        <!-- 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"/>
+
+        <!-- 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"
+              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"/>
+
+        <!-- clean up local routing repo if necessary -->
+        <step name="Trellis-Net-P4-Setup.Clean-Routing"
+              requires="Trellis-Net-P4-Setup.Start-Mininet"
+              exec="onos-clean-routing ${routing_root}"/>
+    </group>
+</scenario>