Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONLabTest
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.py b/TestON/tests/IntentPerfNext/IntentPerfNext.py
index c965612..8fd8089 100644
--- a/TestON/tests/IntentPerfNext/IntentPerfNext.py
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.py
@@ -23,22 +23,10 @@
         gitPull = main.params[ 'GIT' ][ 'autoPull' ]
         checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
 
-        ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
-        ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
-        ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
-        ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
-        ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
-        ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
-        ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
-
-        main.ONOSbench.onosUninstall( nodeIp=ONOS1Ip )
-        main.ONOSbench.onosUninstall( nodeIp=ONOS2Ip )
-        main.ONOSbench.onosUninstall( nodeIp=ONOS3Ip )
-        main.ONOSbench.onosUninstall( nodeIp=ONOS4Ip )
-        main.ONOSbench.onosUninstall( nodeIp=ONOS5Ip )
-        main.ONOSbench.onosUninstall( nodeIp=ONOS6Ip )
-        #TODO: Investigate why node 7 uninstall fails
-        #main.ONOSbench.onosUninstall( nodeIp=ONOS7Ip )
+        ONOSIp = []
+        for i in range(1, 8):
+            ONOSIp.append(main.params[ 'CTRL' ][ 'ip'+str(i) ]) 
+            main.ONOSbench.onosUninstall( nodeIp = ONOSIp[i-1] )
 
         MN1Ip = main.params[ 'MN' ][ 'ip1' ]
         BENCHIp = main.params[ 'BENCH' ][ 'ip' ]
@@ -52,7 +40,7 @@
         cellFileResult = main.ONOSbench.createCellFile(
             BENCHIp, cellName, MN1Ip,
             "onos-core,onos-app-metrics,onos-gui",
-            ONOS1Ip )
+            ONOSIp[0] )
 
         main.step( "Applying cell file to environment" )
         cellApplyResult = main.ONOSbench.setCell( cellName )
@@ -83,21 +71,15 @@
         packageResult = main.ONOSbench.onosPackage()
 
         main.step( "Installing ONOS package" )
-        install1Result = main.ONOSbench.onosInstall( node=ONOS1Ip )
-        #install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip )
-        #install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip )
+        install1Result = main.ONOSbench.onosInstall( node=ONOSIp[0] )
 
         main.step( "Set cell for ONOScli env" )
         main.ONOS1cli.setCell( cellName )
-        # main.ONOS2cli.setCell( cellName )
-        # main.ONOS3cli.setCell( cellName )
 
         time.sleep( 5 )
 
         main.step( "Start onos cli" )
-        cli1 = main.ONOS1cli.startOnosCli( ONOS1Ip )
-        #cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip )
-        #cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip )
+        cli1 = main.ONOS1cli.startOnosCli( ONOSIp[0] )
 
         utilities.assert_equals( expect=main.TRUE,
                                 actual=cellFileResult and cellApplyResult and
@@ -560,6 +542,9 @@
     def CASE4( self, main ):
         """
         Batch intent install
+        
+        Supports scale-out scenarios and increasing
+        number of intents within each iteration
         """
         import time
         import json
diff --git a/TestON/tests/TopoPerfNext/TopoPerfNext.params b/TestON/tests/TopoPerfNext/TopoPerfNext.params
index e17d6bd..c653090 100644
--- a/TestON/tests/TopoPerfNext/TopoPerfNext.params
+++ b/TestON/tests/TopoPerfNext/TopoPerfNext.params
@@ -67,6 +67,13 @@
         <tabletFile>tablets_3node.json</tabletFile>
    </TEST>
 
+    <DB>
+        <postToDB>on</postToDB>
+        <portEventResultPath>
+        /home/admin/ONLabTest/TestON/tests/TopoPerfNext/portEventResultDb.log
+        </portEventResultPath>
+    </DB>
+
     <JSON>
         <deviceTimestamp>topologyDeviceEventTimestamp</deviceTimestamp>
         <hostTimestamp>topologyHostEventTimestamp</hostTimestamp>
diff --git a/TestON/tests/TopoPerfNext/TopoPerfNext.py b/TestON/tests/TopoPerfNext/TopoPerfNext.py
index 24e3c9f..0d2a596 100644
--- a/TestON/tests/TopoPerfNext/TopoPerfNext.py
+++ b/TestON/tests/TopoPerfNext/TopoPerfNext.py
@@ -27,10 +27,14 @@
 
         # Global cluster count for scale-out purposes
         global clusterCount
+        #TODO: fix run number implementation
+        global runNum 
         # Set initial cluster count
         clusterCount = 1
         ##
 
+        runNum = time.strftime("%d%H%M%S")
+
         cellName = main.params[ 'ENV' ][ 'cellName' ]
 
         gitPull = main.params[ 'GIT' ][ 'autoPull' ]
@@ -611,6 +615,7 @@
         import json
         import numpy
         global clusterCount
+        global runNum
 
         ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
         ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
@@ -630,6 +635,9 @@
         graphTimestamp = main.params[ 'JSON' ][ 'graphTimestamp' ]
 
         debugMode = main.params[ 'TEST' ][ 'debugMode' ]
+        postToDB = main.params[ 'DB' ][ 'postToDB' ]
+        resultPath = main.params[ 'DB' ][ 'portEventResultPath' ]
+        timeToPost = time.strftime("%Y-%m-%d %H:%M:%S")
 
         localTime = time.strftime( '%x %X' )
         localTime = localTime.replace( "/", "" )
@@ -1131,6 +1139,8 @@
         portDownDevAvg = 0
         portDownGraphAvg = 0
 
+        dbCmdList = []
+
         for node in range( 0, clusterCount ):
 
             # NOTE: 
@@ -1150,20 +1160,34 @@
                 if item > 0.0:
                     portDownGraphList.append(item)
        
-            portUpDevAvg = numpy.mean(portUpDevList)
-            portUpGraphAvg = numpy.mean(portUpGraphList)
-            portDownDevAvg = numpy.mean(portDownDevList)
-            portDownGraphAvg = numpy.mean(portDownGraphList)
+            portUpDevAvg = round(numpy.mean(portUpDevList), 2)
+            portUpGraphAvg = round(numpy.mean(portUpGraphList), 2)
+            portDownDevAvg = round(numpy.mean(portDownDevList), 2)
+            portDownGraphAvg = round(numpy.mean(portDownGraphList), 2)
 
             main.log.report( " - Node "+str(node+1)+" Summary - " )
             #main.log.report( " Port up ofp-to-device "+
             #                 str(round(portUpDevAvg, 2))+" ms")
             main.log.report( " Port up ofp-to-graph "+
-                             str(round(portUpGraphAvg, 2))+" ms")
+                             str(portUpGraphAvg)+" ms")
             #main.log.report( " Port down ofp-to-device "+
             #                 str(round(portDownDevAvg, 2))+" ms")
             main.log.report( " Port down ofp-to-graph "+
-                             str(round(portDownGraphAvg, 2))+" ms")
+                             str(portDownGraphAvg)+" ms")
+       
+            dbCmdList.append(
+                "INSERT INTO port_latency_tests VALUES("
+                   "'"+timeToPost+"','port_latency_results',"
+                   ""+runNum+","+str(clusterCount)+",'baremetal"+str(node+1)+"',"
+                   ""+str(portUpGraphAvg)+",0,"+str(portDownGraphAvg)+",0);"
+            )
+        
+        #Write to file for posting to DB
+        fResult = open(resultPath, 'a')
+        for line in dbCmdList:
+            if line:
+                fResult.write(line+"\n")
+        fResult.close()
 
         # Remove switches from controller for next test
         main.Mininet1.deleteSwController( "s1" )