Updating test for TOST QA Pod

Add more robust topology check to Segment routing tests
Fix Typos
Include minimum flow count # in the comparision (>= vs > )
Add option for username and password in onos-app function
Don't add app prefix if it looks like it is already the full name

Change-Id: Ib4af0f72df8e7dcc5c179fafea1fd9c61d931246
(cherry picked from commit cda0902ee85041b22da8ad7638a8518914d07322)
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
index 95f1173..fc89308 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
@@ -21,25 +21,34 @@
         <stratumRoot>~/stratum</stratumRoot>
         <topology>trellis_fabric.py</topology>
         <lib>routinglib.py,trellislib.py,stratum.py</lib>
-        <trellisOar>/home/sdn/segmentrouting-app-3.0.1-SNAPSHOT.oar</trellisOar>
-        <t3Oar>/home/sdn/t3-app-4.0.0-SNAPSHOT.oar</t3Oar>
     </DEPENDENCY>
 
     <jsonFileSuffix>.hw</jsonFileSuffix>
 
     <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 -it -d</args>
+        <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/config --hostname mn-stratum -v /etc/network/interfaces:/etc/network/interfaces -it -d</args>
         <name>trellis_mininet</name>
         <home>/home/root/</home>
     </MN_DOCKER>
+    <CLUSTER>
+        # Params for onos docker
+        <dockerSkipBuild>True</dockerSkipBuild>
+        <dockerBuildCmd>make ONOS_VERSION=onos-2.2 DOCKER_TAG=TestON-onos-2.2 onos-build trellis-control-build trellis-t3-build tost-build</dockerBuildCmd> # If using another cmd like make
+        <dockerBuildTimeout>1200</dockerBuildTimeout>
+        <dockerFilePath>~/tost-onos</dockerFilePath>
+        <dockerImageTag>registry.aetherproject.org/tost/tost:master</dockerImageTag>
+        <dockerOptions>-d --rm --network host -v ~/.ssh/authorized_keys:/root/.ssh/authorized_keys -v /tmp/cluster.json:/root/onos/config/cluster.json </dockerOptions> # We start the container detached, so the docker component can connect to cli instead of logs
+        <atomixImageTag>atomix/atomix:3.1.5</atomixImageTag>
+        <atomixOptions>-d --rm --network host -v ~/.ssh/authorized_keys:/root/.ssh/authorized_keys -v /tmp/atomix.json:/opt/atomix/conf/atomix.json </atomixOptions>
+    </CLUSTER>
+
 
     <ENV>
         <cellName>productionCell</cellName>
-        <cellApps>drivers,openflow,fpm,netcfghostprovider,drivers.bmv2,pipelines.fabric,drivers.barefoot</cellApps>
+        <cellApps>drivers,fpm,lldpprovider,hostprovider,netcfghostprovider,drivers.bmv2,org.opencord.fabric-tofino,pipelines.fabric,org.stratumproject.fabric-tna,drivers.barefoot,segmentrouting,t3</cellApps>
     </ENV>
 
     <EXTERNAL_APPS>
-        <fabric-tofino>https://oss.sonatype.org/content/groups/public/org/opencord/fabric-tofino/1.1.0/fabric-tofino-1.1.0.oar</fabric-tofino>
     </EXTERNAL_APPS>
 
     <ONOS_Configuration>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.0x1.physical b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.0x1.physical
index 111380e..d7a2bad 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.0x1.physical
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.0x1.physical
@@ -24,7 +24,7 @@
         </ONOScell>
 
         <SwitchLeaf1>
-            <host>10.128.13.232</host>
+            <host>10.128.13.211</host>
             <user>root</user>
             <password>onl</password>
             <type>StratumOSSwitchDriver</type>
@@ -47,13 +47,13 @@
             <type>HostDriver</type>
             <connect_order>6</connect_order>
             <COMPONENTS>
-                <mac>3c:fd:fe:a8:ea:31</mac>
+                <mac>3c:fd:fe:a8:ea:30</mac>
                 <inband>false</inband>
                 <ip>10.0.2.1</ip>
                 <shortName>h1</shortName>
                 <port1>0</port1>
                 <link1>SwitchLeaf1</link1>
-                <interfaceName>ens6f1</interfaceName>
+                <interfaceName>ens6f0</interfaceName>
                 <routes>
                     <route1>
                         <network>10.0.2.0</network>
@@ -72,13 +72,13 @@
             <type>HostDriver</type>
             <connect_order>7</connect_order>
             <COMPONENTS>
-                <mac>3c:fd:fe:a8:ea:30</mac>
+                <mac>3c:fd:fe:a8:ea:31</mac>
                 <inband>false</inband>
                 <ip>10.0.2.2</ip>
                 <shortName>h2</shortName>
                 <port1>0</port1>
                 <link1>SwitchLeaf1</link1>
-                <interfaceName>ens6f0</interfaceName>
+                <interfaceName>ens6f1</interfaceName>
                 <routes>
                     <route1>
                         <network>10.0.2.0</network>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
index 56d44ec..f88c85a 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
@@ -29,7 +29,7 @@
         self.topo = dict()
         # TODO: Check minFlowCount of leaf for BMv2 switch
         # (number of spine switch, number of leaf switch, dual-homed, description, minFlowCount - leaf (OvS), minFlowCount - leaf (BMv2))
-        self.topo[ '0x1' ] = ( 0, 1, False, 'single ToR', 28, 28 )
+        self.topo[ '0x1' ] = ( 0, 1, False, 'single ToR', 28, 20 )
         self.topo[ '0x2' ] = ( 0, 2, True, 'dual-homed ToR', 37, 37 )
         self.topo[ '2x2' ] = ( 2, 2, False, '2x2 leaf-spine topology', 37, 32 )
         # TODO: Implement 2x3 topology
@@ -53,6 +53,13 @@
 
             main.case( '%s, with %s, %s switches and %d ONOS instance%s' %
                        ( description, self.topo[ topology ][ 3 ], main.switchType, onosNodes, 's' if onosNodes > 1 else '' ) )
+            spines = self.topo[ topology ][ 0 ]
+            leaves = self.topo[ topology ][ 1 ]
+            switches = spines + leaves
+            links = ( spines * leaves ) * 2
+            if self.topo[ topology ][ 2 ]:
+                links += links
+                links += ( leaves - 1 ) * 2
 
             main.cfgName = 'CASE%01d%01d' % ( test_idx / 10, ( ( test_idx - 1 ) % 10 ) % 4 + 1 )
             main.Cluster.setRunningNode( onosNodes )
@@ -91,11 +98,16 @@
 
             run.checkFlows( main, minFlowCount=self.topo[ topology ][ 5 if main.useBmv2 else 4 ] * self.topo[ topology ][ 1 ], sleep=5 )
             if main.useBmv2:
-                leaf_dpid = [ "device:bmv2:leaf%d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ]) ]
+                switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix' )
+                if switchPrefix == "tofino":
+                    leaf_dpid = [ "device:tofino:leaf%d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ]) ]
+                else:
+                    leaf_dpid = [ "device:bmv2:leaf%d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ]) ]
             else:
                 leaf_dpid = [ "of:%016d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ] ) ]
             for dpid in leaf_dpid:
                 run.checkFlowsByDpid( main, dpid, self.topo[ topology ][ 5 if main.useBmv2 else 4 ], sleep=5 )
+            run.verifyTopology( main, switches, links, onosNodes )
             run.pingAll( main )
         except Exception as e:
             main.log.exception( "Error in runTest" )
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json
index ac9c2ca..b6699f0 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json
@@ -1,9 +1,7 @@
 {
     "devices":{
-        "of:0000000000000001":{
-            "basic":{
-                "driver":"ofdpa-ovs"
-            },
+        "device:tofino:leaf1":{
+            "basic":{},
             "segmentrouting":{
                 "adjacencySids":[],
                 "ipv4Loopback":"192.168.0.1",
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json.hw b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json.hw
index 31c166a..b2eb1e6 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json.hw
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/CASE01.json.hw
@@ -1,17 +1,17 @@
 {
     "devices":{
-        "of:0000000000000001":{
+        "device:tofino:leaf1":{
             "segmentrouting":{
                 "adjacencySids":[],
-                "ipv4Loopback":"10.128.13.232",
+                "ipv4Loopback":"10.128.13.211",
                 "ipv4NodeSid":201,
                 "isEdgeRouter":true,
-                "routerMac":"00:90:fb:64:cc:9e"
+                "routerMac":"00:00:00:00:00:01"
             }
         }
     },
     "ports":{
-        "of:0000000000000001/160":{
+        "device:tofino:leaf1/128":{
             "interfaces":[
                 {
                     "ips":[
@@ -21,7 +21,7 @@
                 }
             ]
         },
-        "of:0000000000000001/168":{
+        "device:tofino:leaf1/136":{
             "interfaces":[
                 {
                     "ips":[
@@ -32,4 +32,4 @@
             ]
         }
     }
-}
\ No newline at end of file
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/tofino-onos-netcfg.json b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/tofino-onos-netcfg.json
index 5cc17ed..8c8995a 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/tofino-onos-netcfg.json
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/json/tofino-onos-netcfg.json
@@ -3,7 +3,7 @@
     "device:tofino:leaf1": {
       "basic": {
         "name": "leaf1",
-        "managementAddress": "grpc://10.128.13.232:28000?device_id=1",
+        "managementAddress": "grpc://10.128.13.211:28000?device_id=1",
         "driver": "stratum-tofino",
         "pipeconf": "org.opencord.fabric.tofino.montara_sde_9_0_0"
       }