Stratum Support for Segement Rounting Suite

- Add Stratum Bmv2 switch support for SRDhcpRelay and SRRouting tests
- Add Support for 0x1 topology on a Stratum Tofino HW switch
- Support for dockerized mininet with Stratum BMv2 switches
- Update scapy driver to work with newer versions of scapy
- Simple parsing for scapy ping output
- Add support for fetching and installing external onos apps
- Add support for onos-diagnostics profiles
- Move onos log levels to params file
- Add onos cfg settings to SR tests

Change-Id: I7c4a71484c8fd5735da9ef09b96d8990283b199b
(cherry picked from commit bef6d9bd943996483fed32130cb30ad26a06aac0)
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
index 1d057b3..557f03d 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
@@ -32,6 +32,22 @@
         <branch>master</branch>
     </GIT>
 
+    <ONOS_Configuration>
+    </ONOS_Configuration>
+
+    <ONOS_Logging>
+        <org.onosproject.events>TRACE</org.onosproject.events>
+        <org.onosproject.segmentrouting>DEBUG</org.onosproject.segmentrouting>
+        <org.onosproject.driver>DEBUG</org.onosproject.driver>
+        <org.onosproject.net.flowobjective.impl>DEBUG</org.onosproject.net.flowobjective.impl>
+        <org.onosproject.routeservice.impl>DEBUG</org.onosproject.routeservice.impl>
+        <org.onosproject.routeservice.store>DEBUG</org.onosproject.routeservice.store>
+        <org.onosproject.routing.fpm>DEBUG</org.onosproject.routing.fpm>
+        <org.onosproject.fpm>DEBUG</org.onosproject.fpm>
+        <org.onosproject.mcast>DEBUG</org.onosproject.mcast>
+    </ONOS_Logging>
+
+
     <CTRL>
         <port>6653</port>
     </CTRL>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.flex b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.flex
index 7d2bd17..4b26f3b 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.flex
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.flex
@@ -30,6 +30,22 @@
         <branch>master</branch>
     </GIT>
 
+    <ONOS_Configuration>
+    </ONOS_Configuration>
+
+    <ONOS_Logging>
+        <org.onosproject.events>TRACE</org.onosproject.events>
+        <org.onosproject.segmentrouting>DEBUG</org.onosproject.segmentrouting>
+        <org.onosproject.driver>DEBUG</org.onosproject.driver>
+        <org.onosproject.net.flowobjective.impl>DEBUG</org.onosproject.net.flowobjective.impl>
+        <org.onosproject.routeservice.impl>DEBUG</org.onosproject.routeservice.impl>
+        <org.onosproject.routeservice.store>DEBUG</org.onosproject.routeservice.store>
+        <org.onosproject.routing.fpm>DEBUG</org.onosproject.routing.fpm>
+        <org.onosproject.fpm>DEBUG</org.onosproject.fpm>
+        <org.onosproject.mcast>DEBUG</org.onosproject.mcast>
+    </ONOS_Logging>
+
+
     <CTRL>
         <port>6653</port>
     </CTRL>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.stratum b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.stratum
new file mode 100644
index 0000000..f01fbf2
--- /dev/null
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params.stratum
@@ -0,0 +1,98 @@
+<PARAMS>
+    <testcases>101,102,103,104,105,106,107,108,109,201,202,203,204,205,206,207,208,209,301,302,303,304,305,306,307,308,309,601,602,603,604,605,606,620,621,622,630,640,641,642,643,651,652,653,660,661,662,663,664,665</testcases>
+
+    <GRAPH>
+        <nodeCluster>Fabric</nodeCluster>
+        <builds>20</builds>
+    </GRAPH>
+
+    <SCALE>
+        <size>7</size>
+        <max>7</max>
+    </SCALE>
+
+    <DEPENDENCY>
+        <useCommonConf>False</useCommonConf>
+        <useCommonTopo>True</useCommonTopo>
+        <useBmv2>True</useBmv2>
+        <bmv2SwitchType>stratum</bmv2SwitchType>
+        <stratumRoot>~/stratum</stratumRoot>
+        <topology>hagg_fabric.py</topology>
+        <lib>routinglib.py,trellislib.py,trellis_fabric.py</lib>
+        <conf>bgpdbgp1.conf,bgpdbgp2.conf,bgpdr1.conf,bgpdr2.conf,dhcpd6.conf,dhcpd.conf,zebradbgp1.conf,zebradbgp2.conf</conf>
+    </DEPENDENCY>
+
+    <MN_DOCKER>
+        <args>--privileged --net host --rm -v topo:/topo -v ~/mininet/custom:/home/root/mininet/custom -v /var/run/openvswitch/:/var/run/openvswitch/ -v /tmp/mn-stratum:/tmp -v /tmp/mn_conf/:/home/root --hostname mn-stratum -v /etc/network/interfaces:/etc/network/interfaces -v /lib/modules:/lib/modules -it -d</args>
+        <name>trellis_mininet</name>
+        <home>/home/root/</home>
+    </MN_DOCKER>
+
+    <ENV>
+        <cellName>productionCell</cellName>
+        <cellApps>drivers,openflow,segmentrouting,fpm,dhcprelay,netcfghostprovider,routeradvertisement,t3,hostprobingprovider,drivers.bmv2,pipelines.fabric</cellApps>
+    </ENV>
+
+    <GIT>
+        <pull>False</pull>
+        <branch>master</branch>
+    </GIT>
+
+    <ONOS_Configuration>
+        <org.onosproject.grpc.ctl.GrpcChannelControllerImpl>
+            <enableMessageLog>true</enableMessageLog>
+        </org.onosproject.grpc.ctl.GrpcChannelControllerImpl>
+    </ONOS_Configuration>
+
+    <ONOS_Logging>
+        <org.onosproject.events>TRACE</org.onosproject.events>
+        <org.onosproject.segmentrouting>DEBUG</org.onosproject.segmentrouting>
+        <org.onosproject.driver>DEBUG</org.onosproject.driver>
+        <org.onosproject.net.flowobjective.impl>DEBUG</org.onosproject.net.flowobjective.impl>
+        <org.onosproject.routeservice.impl>DEBUG</org.onosproject.routeservice.impl>
+        <org.onosproject.routeservice.store>DEBUG</org.onosproject.routeservice.store>
+        <org.onosproject.routing.fpm>DEBUG</org.onosproject.routing.fpm>
+        <org.onosproject.fpm>DEBUG</org.onosproject.fpm>
+        <org.onosproject.mcast>DEBUG</org.onosproject.mcast>
+        <org.onosproject.p4runtime>DEBUG</org.onosproject.p4runtime>
+        <org.onosproject.protocols.p4runtime>DEBUG</org.onosproject.protocols.p4runtime>
+        <org.onosproject.drivers.p4runtime>DEBUG</org.onosproject.drivers.p4runtime>
+        <org.onosproject.protocols.grpc>DEBUG</org.onosproject.protocols.grpc>
+        <org.onosproject.protocols.gnmi>DEBUG</org.onosproject.protocols.gnmi>
+        <org.onosproject.protocols.gnoi>DEBUG</org.onosproject.protocols.gnoi>
+        <org.onosproject.drivers.gnoi>DEBUG</org.onosproject.drivers.gnoi>
+        <org.onosproject.drivers.gmni>DEBUG</org.onosproject.drivers.gmni>
+        <org.onosproject.drivers.stratum>DEBUG</org.onosproject.drivers.stratum>
+        <org.onosproject.bmv2>DEBUG</org.onosproject.bmv2>
+    </ONOS_Logging>
+
+
+    <CTRL>
+        <port>6653</port>
+    </CTRL>
+
+    <timers>
+        <LinkDiscovery>30</LinkDiscovery>
+        <SwitchDiscovery>45</SwitchDiscovery>
+        <OnosDiscovery>45</OnosDiscovery>
+        <loadNetcfgSleep>5</loadNetcfgSleep>
+        <startMininetSleep>25</startMininetSleep>
+        <dhcpSleep>150</dhcpSleep>
+        <balanceMasterSleep>10</balanceMasterSleep>
+    </timers>
+
+    <TOPO>
+        <internalIpv4Hosts>h1v4,h2v4,h3v4,h4v4,h5v4,h6v4,h7v4,h8v4,h9v4,h10v4,h11v4,h12v4,h13v4</internalIpv4Hosts>
+        <internalIpv6Hosts>h1v6,h2v6,h3v6,h4v6,h5v6,h6v6,h7v6,h8v6,h9v6,h10v6,h11v6,h12v6,h13v6</internalIpv6Hosts>
+        <externalIpv4Hosts>rh1v4,rh2v4</externalIpv4Hosts>
+        <externalIpv6Hosts>rh1v6,rh11v6,rh2v6,rh22v6</externalIpv6Hosts>
+        <staticIpv4Hosts>rh5v4</staticIpv4Hosts>
+        <staticIpv6Hosts>rh5v6</staticIpv6Hosts>
+        <switchNum>10</switchNum>
+        <linkNum>48</linkNum>
+    </TOPO>
+
+    <ALARM>
+        <minPassPercent>80</minPassPercent>
+    </ALARM>
+</PARAMS>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.py b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.py
index f379896..5ca5f40 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.py
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.py
@@ -508,6 +508,7 @@
         main.case( "Bring down all switches then recover" )
         setupTest( main, test_idx=601, external=False )
         main.Cluster.next().CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         main.Network.discoverHosts( hostList=main.internalIpv4Hosts + main.internalIpv6Hosts )
         totalSwitches = int( main.params[ 'TOPO' ][ 'switchNum' ] )
@@ -527,6 +528,7 @@
                                      onpass="All switches stopped",
                                      onfail="Failed to stop all switches" )
 
+            main.log.debug( "sleeping %i seconds" % float( 60 ) )
             time.sleep( 60 )
             lib.verifyTopology( main, 0, 0, main.Cluster.numCtrls )
             # Bring up all switches
@@ -542,8 +544,10 @@
             main.Network.discoverHosts( hostList=main.internalIpv4Hosts + main.internalIpv6Hosts )
             lib.verifyTopology( main, totalSwitches, totalLinks, main.Cluster.numCtrls )
             main.log.debug( main.Cluster.next().summary() )
+            main.log.debug( "sleeping %i seconds" % float( 60 ) )
             time.sleep( 60 )
             main.log.debug( main.Cluster.next().summary() )
+            main.log.debug( "sleeping %i seconds" % float( 60 ) )
             time.sleep( 60 )
             main.log.debug( main.Cluster.next().summary() )
             verifyPing( main )
@@ -935,6 +939,7 @@
             lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
             lib.enablePortBatch( main, portsToDisable, 10, 48 )
             main.Network.discoverHosts( hostList=main.disconnectedIpv4Hosts + main.disconnectedIpv6Hosts )
+            main.log.debug( "sleeping %i seconds" % float( 10 ) )
             time.sleep( 10 )
             main.disconnectedIpv4Hosts = []
             main.disconnectedIpv6Hosts = []
@@ -1054,6 +1059,7 @@
                                                                                          switches ) )
             setupTest( main, test_idx=640 )
             main.Cluster.next().CLI.balanceMasters()
+            main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
             time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
             main.Network.discoverHosts( hostList=main.internalIpv4Hosts + main.internalIpv6Hosts )
             instance = main.Cluster.controllers[ nodeIndex ]
@@ -1154,6 +1160,7 @@
                                                                                                  switches ) )
             setupTest( main, test_idx=641 )
             main.Cluster.next().CLI.balanceMasters()
+            main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
             time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
             main.Network.discoverHosts( hostList=main.internalIpv4Hosts + main.internalIpv6Hosts )
             instance = main.Cluster.controllers[ nodeIndex ]
@@ -1208,6 +1215,7 @@
         main.case( "Drop ONOS instance and links at the same time" )
         setupTest( main, test_idx=642, onosNodes=3 )
         main.Cluster.active( 0 ).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         verify( main )
         portsToDisable = [ [ "of:0000000000000001", 1 ], [ "of:0000000000000103", 1 ],
@@ -1255,6 +1263,7 @@
         main.case( "Drop ONOS instances and bring up links at the same time" )
         setupTest( main, test_idx=643, onosNodes=3 )
         main.Cluster.active( 0 ).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         verify( main )
         portsToDisable = [ [ "of:0000000000000001", 1 ], [ "of:0000000000000103", 1 ],
@@ -1296,6 +1305,7 @@
         main.case( "Move a single-homed host to another port in the same DAAS" )
         setupTest( main, test_idx=651, onosNodes=3 )
         main.Cluster.active( 0 ).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         verify( main )
         # Move an untagged IPv4 host on DAAS-1
@@ -1353,6 +1363,7 @@
         main.case( "Move a dual-homed host from porst 1A and 1B to ports 2A and 2B with the same MAC and IP" )
         setupTest( main, test_idx=652, onosNodes=3 )
         main.Cluster.active( 0 ).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         verify( main )
 
@@ -1406,6 +1417,7 @@
         main.case( "Move a dual-homed host from porst 1A and 1B to ports 2A and 2B with the same IP and different MAC" )
         setupTest( main, test_idx=653, onosNodes=3 )
         main.Cluster.active( 0 ).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
         verify( main )
 
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py b/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
index 0b13a61..2868b57 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/dependencies/SRRoutingTest.py
@@ -64,10 +64,13 @@
         main.cfgName = main.params[ "DEPENDENCY" ][ "confName" ]
     if main.useBmv2:
         # Translate configuration file from OVS-OFDPA to BMv2 driver
-        translator.ofdpaToBmv2( main )
+        translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types
+        switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', "bmv2" )
+        translator.ofdpaToBmv2( main, switchPrefix=switchPrefix )
     else:
         translator.bmv2ToOfdpa( main )
     lib.loadJson( main )
+    main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
     time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
     lib.loadHost( main )
 
@@ -84,19 +87,22 @@
         lib.loadCount( main )
 
     if hasattr( main, 'Mininet1' ):
+        lib.mnDockerSetup( main )
         # Run the test with Mininet
         mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
                                                                            1 if ipv4 else 0 )
         if main.useBmv2:
-            mininet_args += ' --switch bmv2'
-            main.log.info( "Using BMv2 switch" )
+            mininet_args += ' --switch %s' % main.switchType
+            main.log.info( "Using %s switch"  % main.switchType )
         lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
+        main.log.debug( "Waiting %i seconds for ONOS to discover dataplane" % float( main.params[ "timers" ][ "startMininetSleep" ] ))
         time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
     else:
         # Run the test with physical devices
         lib.connectToPhysicalNetwork( main )
 
     # wait some time for onos to install the rules!
+    main.log.info( "Waiting %i seconds for ONOS to program the dataplane" % float( main.params[ "timers" ][ "dhcpSleep" ] ))
     time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
 
 def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
@@ -240,11 +246,13 @@
         # Kill node
         lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
         main.Cluster.active(0).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % mastershipSleep )
         time.sleep( mastershipSleep )
         verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
         # Recover node
         lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
         main.Cluster.active(0).CLI.balanceMasters()
+        main.log.debug( "sleeping %i seconds" % mastershipSleep )
         time.sleep( mastershipSleep )
         verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )