Merge "Fixed hardcoded variable and Added logging"
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 0a1d25f..b65b887 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -1159,11 +1159,11 @@
             main.exit()
         return response
 
-    def links( self ):
+    def links( self, timeout=20 ):
         main.log.info( self.name + ": List network links" )
         try:
             response = self.execute( cmd='links', prompt='mininet>',
-                                     timeout=20 )
+                                     timeout=timeout )
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":     " + self.handle.before )
@@ -1984,7 +1984,7 @@
             response = main.FALSE
         return response
 
-    def arping( self, srcHost="", dstHost="10.128.20.211", ethDevice="" ):
+    def arping( self, srcHost="", dstHost="10.128.20.211", ethDevice="", output=main.TRUE ):
         """
         Description:
             Sends arp message from mininet host for hosts discovery
@@ -1998,7 +1998,8 @@
             ethDevice = '-I ' + ethDevice + ' '
         cmd = srcHost + " arping -c1 " + ethDevice + dstHost
         try:
-            main.log.info( "Sending: " + cmd )
+            if output:
+                main.log.info( "Sending: " + cmd )
             self.handle.sendline( cmd )
             i = self.handle.expect( [ "mininet>", "arping: " ] )
             if i == 0:
@@ -2507,7 +2508,7 @@
                 hosts[ name ] = { "interfaces": interfaces }
         return hosts
 
-    def getLinks( self ):
+    def getLinks( self, timeout=20 ):
         """
         Gathers information about current Mininet links. These links may not
         be up if one of the ports is down.
@@ -2524,7 +2525,7 @@
               hosts, this is just the eth#.
         """
         self.update()
-        response = self.links().split( '\n' )
+        response = self.links(timeout=timeout).split( '\n' )
 
         # Examples:
         # s1-eth3<->s2-eth1 (OK OK)
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index c5ac77e..a333be5 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -4028,14 +4028,13 @@
             main.cleanup()
             main.exit()
 
-    def counterTestAddAndGet( self, counter, delta=1, inMemory=False ):
+    def counterTestAddAndGet( self, counter, delta=1 ):
         """
         CLI command to add a delta to then get a distributed counter.
         Required arguments:
             counter - The name of the counter to increment.
         Optional arguments:
             delta - The long to add to the counter
-            inMemory - use in memory map for the counter
         returns:
             integer value of the counter or
             None on Error
@@ -4044,8 +4043,6 @@
             counter = str( counter )
             delta = int( delta )
             cmdStr = "counter-test-increment "
-            if inMemory:
-                cmdStr += "-i "
             cmdStr += counter
             if delta != 1:
                 cmdStr += " " + str( delta )
@@ -4093,14 +4090,13 @@
             main.cleanup()
             main.exit()
 
-    def counterTestGetAndAdd( self, counter, delta=1, inMemory=False ):
+    def counterTestGetAndAdd( self, counter, delta=1 ):
         """
         CLI command to get a distributed counter then add a delta to it.
         Required arguments:
             counter - The name of the counter to increment.
         Optional arguments:
             delta - The long to add to the counter
-            inMemory - use in memory map for the counter
         returns:
             integer value of the counter or
             None on Error
@@ -4109,8 +4105,6 @@
             counter = str( counter )
             delta = int( delta )
             cmdStr = "counter-test-increment -g "
-            if inMemory:
-                cmdStr += "-i "
             cmdStr += counter
             if delta != 1:
                 cmdStr += " " + str( delta )
@@ -4193,15 +4187,13 @@
             main.cleanup()
             main.exit()
 
-    def transactionalMapGet( self, keyName, inMemory=False ):
+    def transactionalMapGet( self, keyName ):
         """
         CLI command to get the value of a key in a consistent map using
         transactions. This a test function and can only get keys from the
         test map hard coded into the cli command
         Required arguments:
             keyName - The name of the key to get
-        Optional arguments:
-            inMemory - use in memory map for the counter
         returns:
             The string value of the key or
             None on Error
@@ -4209,8 +4201,6 @@
         try:
             keyName = str( keyName )
             cmdStr = "transactional-map-test-get "
-            if inMemory:
-                cmdStr += "-i "
             cmdStr += keyName
             output = self.sendline( cmdStr )
             assert "Command not found:" not in output, output
@@ -4253,7 +4243,7 @@
             main.cleanup()
             main.exit()
 
-    def transactionalMapPut( self, numKeys, value, inMemory=False ):
+    def transactionalMapPut( self, numKeys, value ):
         """
         CLI command to put a value into 'numKeys' number of keys in a
         consistent map using transactions. This a test function and can only
@@ -4261,8 +4251,6 @@
         Required arguments:
             numKeys - Number of keys to add the value to
             value - The string value to put into the keys
-        Optional arguments:
-            inMemory - use in memory map for the counter
         returns:
             A dictionary whose keys are the name of the keys put into the map
             and the values of the keys are dictionaries whose key-values are
@@ -4278,8 +4266,6 @@
             numKeys = str( numKeys )
             value = str( value )
             cmdStr = "transactional-map-test-put "
-            if inMemory:
-                cmdStr += "-i "
             cmdStr += numKeys + " " + value
             output = self.sendline( cmdStr )
             assert "Command not found:" not in output, output
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.params b/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.params
index 986145e..b44a3c0 100755
--- a/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.params
+++ b/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.params
@@ -11,7 +11,7 @@
     <testcases>1,2,[10,300,11,100,300,11,200,300,11,1000]*3</testcases>
 
     <DEPENDENCY>
-        <path>/tests/SCPFscaleTopo/dependencies/</path>
+        <path>/tests/SCPF/SCPFscaleTopo/dependencies/</path>
         <wrapper1>startUp</wrapper1>
         <wrapper2>scaleTopoFunction</wrapper2>
         <wrapper3>topo</wrapper3>
@@ -37,7 +37,7 @@
         <balance>10</balance>
         <nodeSleep>10</nodeSleep>
         <pingall>15</pingall>
-        <MNsleep>5</MNsleep>
+        <MNsleep>120</MNsleep>
     </SLEEP>
 
     <TIMEOUT>
@@ -52,7 +52,7 @@
 
     <TOPOLOGY>
         <topology>torus</topology>
-        <scale>5,10,15</scale>
+        <scale>10,15,20</scale>
     </TOPOLOGY>
 
 </PARAMS>
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.py b/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.py
index 830fbf2..96ac405 100644
--- a/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.py
+++ b/TestON/tests/SCPF/SCPFscaleTopo/SCPFscaleTopo.py
@@ -64,17 +64,14 @@
                                         main.dependencyPath +
                                         wrapperFile1 +
                                         ".py" )
-
         main.scaleTopoFunction = imp.load_source( wrapperFile2,
                                                   main.dependencyPath +
                                                   wrapperFile2 +
                                                   ".py" )
-
         main.topo = imp.load_source( wrapperFile3,
                                      main.dependencyPath +
                                      wrapperFile3 +
                                      ".py" )
-
         main.ONOSbench.scp( main.Mininet1,
                             main.dependencyPath +
                             main.multiovs,
@@ -247,6 +244,13 @@
             main.currScale = main.topoScale.pop(0)
         else: main.log.error( "topology scale is empty" )
 
+        # remove device before setup topology
+        devices = main.topo.getAllDevices( main )
+        if( devices[0] != '[]' ): # because devices is a list witch contain 3 string, not contain list!
+            temp = json.loads( devices[0] )
+            devicesIdList = []
+            for d in temp:
+                main.CLIs[0].deviceRemove( d.get('id').encode() )
 
         main.step( "Starting up TORUS %sx%s topology" % (main.currScale, main.currScale) )
 
@@ -279,58 +283,66 @@
         main.caseExplanation = "Pinging all hosts and comparing topology " +\
                 "elements between Mininet and ONOS"
 
-        main.log.info( "Pinging all hosts" )
-
-        # the pingall timeout is depend on the number of total host
-        pingTimeout = int( main.pingTimeout * float( int(main.currScale) * int(main.currScale ) ) )
-        pingResult = main.Mininet1.pingall( pingTimeout )
-
         main.log.info( "Gathering topology information" )
-
         time.sleep( main.MNSleep )
 
         devicesResults = main.TRUE
         linksResults = main.TRUE
         hostsResults = main.TRUE
         stepResult = main.TRUE
-        devices = main.topo.getAllDevices( main )
-        hosts = main.topo.getAllHosts( main )
-        ports = main.topo.getAllPorts( main )
-        links = main.topo.getAllLinks( main )
-        clusters = main.topo.getAllClusters( main )
-        mnSwitches = main.Mininet1.getSwitches()
-        mnLinks = main.Mininet1.getLinks()
-        mnHosts = main.Mininet1.getHosts()
-
         main.step( "Comparing MN topology to ONOS topology" )
-        for controller in range(len(main.activeNodes)):
-            controllerStr = str( main.activeNodes[controller] + 1 )
-            if devices[ controller ] and ports[ controller ] and\
-                "Error" not in devices[ controller ] and\
-                "Error" not in ports[ controller ]:
 
-                currentDevicesResult = main.Mininet1.compareSwitches(
-                        mnSwitches,
-                        json.loads( devices[ controller ] ),
-                        json.loads( ports[ controller ] ) )
-            else:
-                currentDevicesResult = main.FALSE
- 
-            if links[ controller ] and "Error" not in links[ controller ]:
-                currentLinksResult = main.Mininet1.compareLinks(
-                        mnSwitches, mnLinks,
-                        json.loads( links[ controller ] ) )
-            else:
-                currentLinksResult = main.FALSE
+        compareRetry=0
+        while compareRetry <3:
+            #While loop for retry
+            devices = main.topo.getAllDevices( main )
+            ports = main.topo.getAllPorts( main )
+            links = main.topo.getAllLinks( main)
+            clusters = main.topo.getAllClusters( main )
+            mnSwitches = main.Mininet1.getSwitches()
+            mnLinks = main.Mininet1.getLinks(timeout=180)
+            mnHosts = main.Mininet1.getHosts()
 
-            if hosts[ controller ] or "Error" not in hosts[ controller ]:
-                currentHostsResult = main.Mininet1.compareHosts(
-                        mnHosts,
-                        json.loads( hosts[ controller ] ) )
-            else:
-                currentHostsResult = main.FALSE
+            for controller in range(len(main.activeNodes)):
+                controllerStr = str( main.activeNodes[controller] + 1 )
+                if devices[ controller ] and ports[ controller ] and\
+                    "Error" not in devices[ controller ] and\
+                    "Error" not in ports[ controller ]:
 
-            stepResult = stepResult and currentDevicesResult and currentLinksResult and currentHostsResult
+                    currentDevicesResult = main.Mininet1.compareSwitches(
+                            mnSwitches,
+                            json.loads( devices[ controller ] ),
+                            json.loads( ports[ controller ] ) )
+                else:
+                    currentDevicesResult = main.FALSE
+
+                if links[ controller ] and "Error" not in links[ controller ]:
+                    currentLinksResult = main.Mininet1.compareLinks(
+                            mnSwitches, mnLinks,
+                            json.loads( links[ controller ] ) )
+                else:
+                    currentLinksResult = main.FALSE
+
+                stepResult = currentDevicesResult and currentLinksResult
+            if stepResult:
+                break
+            compareRetry += 1
+
+        # host discover
+        hostList=[]
+        for i in range( 1, int(main.currScale)+1 ):
+            for j in range( 1, int(main.currScale)+1 ):
+                hoststr = "h" + str(i)+ "x" + str(j)
+                hostList.append(hoststr)
+        totalNum = main.topo.sendArpPackage(main, hostList)
+        # check host number
+        main.log.info("{} hosts has been discovered".format( totalNum ))
+        if int(totalNum) == ( int(main.currScale) * int(main.currScale) ):
+            main.log.info("All hosts has been discovered")
+            stepResult = stepResult and main.TRUE
+        else:
+            main.log.warn("Hosts number is not correct!")
+            stepResult = stepResult and main.FALSE
 
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
@@ -341,7 +353,7 @@
 
     def CASE100( self, main ):
         '''
-           Bring Down node 3 
+           Bring Down node 3
         '''
 
         main.case("Balancing Masters and bring ONOS node 3 down: TORUS %sx%s" % (main.currScale, main.currScale))
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/multiovs.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/multiovs.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/multiovs.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/multiovs.py
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/newFuncTopo.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/newFuncTopo.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/newFuncTopo.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/newFuncTopo.py
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/scaleTopoFunction.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/scaleTopoFunction.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/scaleTopoFunction.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/scaleTopoFunction.py
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/spine.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/spine.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/spine.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/spine.py
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/startUp.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/startUp.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/startUp.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/startUp.py
diff --git a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/topo.py b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/topo.py
similarity index 81%
rename from TestON/tests/SCPF/SCPFscaleTopo/Dependency/topo.py
rename to TestON/tests/SCPF/SCPFscaleTopo/dependencies/topo.py
index 0dbb02d..7a8c0c6 100644
--- a/TestON/tests/SCPF/SCPFscaleTopo/Dependency/topo.py
+++ b/TestON/tests/SCPF/SCPFscaleTopo/dependencies/topo.py
@@ -97,4 +97,19 @@
         clusters.append( t.result )
     return clusters
 
-
+def sendArpPackage( main, hostList ):
+    import json
+    """
+        send arping package from host
+        return the total hosts number from Onos
+    """
+    main.log.info("Sending Arping package...")
+    if isinstance(hostList, list):
+        threads = []
+        for h in hostList:
+            main.Mininet1.arping( srcHost=h, dstHost="10.0.0.1", output=main.FALSE )
+    else:
+        main.Mininet1.arping(srcHost=hostList)
+    summaryStr = json.loads( main.CLIs[0].summary().encode() )
+    hostNum = summaryStr.get('hosts')
+    return hostNum
diff --git a/TestON/tests/SCPF/SCPFswitchLat/Dependency/topo-perf-1sw.py b/TestON/tests/SCPF/SCPFswitchLat/dependencies/topo-perf-1sw.py
similarity index 100%
rename from TestON/tests/SCPF/SCPFswitchLat/Dependency/topo-perf-1sw.py
rename to TestON/tests/SCPF/SCPFswitchLat/dependencies/topo-perf-1sw.py
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.params b/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.params
index 6f4e47b..3570fd0 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.params
+++ b/TestON/tests/USECASE/USECASE_SdnipFunction/USECASE_SdnipFunction.params
@@ -15,7 +15,7 @@
     </CTRL>
 
     <DEPENDENCY>
-        <path>/USECASE_SdnipFunction/dependencies/</path>
+        <path>/USECASE/USECASE_SdnipFunction/dependencies/</path>
         <topology>USECASE_SdnipI2MN.py</topology>
         <wrapper1>Functions</wrapper1>
     </DEPENDENCY>
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.params b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.params
index c266402..7f93976 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.params
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.params
@@ -16,7 +16,7 @@
     </CTRL>
 
     <DEPENDENCY>
-        <path>/USECASE_SdnipFunctionCluster/dependencies/</path>
+        <path>/USECASE/USECASE_SdnipFunctionCluster/dependencies/</path>
         <topology>USECASE_SdnipI2MN_Cluster.py</topology>
         <wrapper1>Functions</wrapper1>
         <wrapper2>USECASE_SdnipI2MN_Cluster</wrapper2>
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster_fsfw/USECASE_SdnipFunctionCluster_fsfw.params b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster_fsfw/USECASE_SdnipFunctionCluster_fsfw.params
index fa41d0d..54c42be 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster_fsfw/USECASE_SdnipFunctionCluster_fsfw.params
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster_fsfw/USECASE_SdnipFunctionCluster_fsfw.params
@@ -21,7 +21,7 @@
     </CTRL>
 
     <DEPENDENCY>
-        <path>/USECASE_SdnipFunctionCluster_fsfw/dependencies/</path>
+        <path>/USECASE/USECASE_SdnipFunctionCluster_fsfw/dependencies/</path>
         <topology>USECASE_SdnipI2MN_Cluster.py</topology>
         <wrapper1>Functions</wrapper1>
         <wrapper2>USECASE_SdnipI2MN_Cluster_fsfw</wrapper2>
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunction_fsfw/USECASE_SdnipFunction_fsfw.params b/TestON/tests/USECASE/USECASE_SdnipFunction_fsfw/USECASE_SdnipFunction_fsfw.params
index ae028d0..b1c2f8f 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunction_fsfw/USECASE_SdnipFunction_fsfw.params
+++ b/TestON/tests/USECASE/USECASE_SdnipFunction_fsfw/USECASE_SdnipFunction_fsfw.params
@@ -19,7 +19,7 @@
     </CTRL>
 
     <DEPENDENCY>
-        <path>/USECASE_SdnipFunction_fsfw/dependencies/</path>
+        <path>/USECASE/USECASE_SdnipFunction_fsfw/dependencies/</path>
         <topology>USECASE_SdnipI2MN.py</topology>
         <wrapper1>Functions</wrapper1>
     </DEPENDENCY>