Link latency test refactoring and database post update
diff --git a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py b/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
index 7097e27..7bc654a 100644
--- a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
+++ b/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
@@ -380,8 +380,15 @@
                 tcpToFeature = int(featureTimestamp) - int(t0Tcp)
                 featureToRole = int(roleTimestamp) - int(featureTimestamp)
                 roleToOfp = float(t0Ofp) - float(roleTimestamp)
-                ofpToDevice = int(deviceTimestamp) - int(t0Ofp)
-                deviceToGraph = float(graphTimestamp) - float(deviceTimestamp)
+                ofpToDevice = float(deviceTimestamp) - float(t0Ofp)
+                # Timestamps gathered from ONOS are millisecond 
+                # precision. They are returned as integers, thus no
+                # need to be more precise than 'int'. However,
+                # the processing seems to be mostly under 1 ms, 
+                # thus this may be a problem point to handle any 
+                # submillisecond output that we are unsure of.
+                # For now, this will be treated as 0 ms if less than 1 ms
+                deviceToGraph = int(graphTimestamp) - int(deviceTimestamp)
                 
                 if endToEnd > thresholdMin and\
                    endToEnd < thresholdMax and i >= iterIgnore:
@@ -439,7 +446,15 @@
                     main.log.info("ONOS "+str(nodeNum)+ " device-to-graph: "+
                             str(deviceToGraph) + " ms")
                 else:
-                    main.log.info("ONOS "+str(nodeNum)+ " device-to-graph "+
+                    if deviceToGraph == 0:
+                        deviceToGraphLatNodeIter[node][i] = 0
+                        main.log.info("ONOS "+str(nodeNum) +
+                            " device-to-graph measurement "+
+                            "was set to 0 ms because of precision "+
+                            "uncertainty")
+                    else:
+                        main.log.info("ONOS "+str(nodeNum)+ 
+                            " device-to-graph "+
                             "measurement ignored due to excess in "+
                             "threshold or premature iteration")
                                 
@@ -841,19 +856,16 @@
                 ip1=ONOS1Ip, port1=defaultSwPort)
         
         time.sleep(15)
-        
-        portUpDeviceToOfpList = []
-        portUpGraphToOfpList = []
-        portDownDeviceToOfpList = []
-        portDownGraphToOfpList = []
-        
-        portUpDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portUpGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portUpLinkLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portDownDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portDownGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portDownLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
-        portUpLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
+     
+        portUpEndToEndNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portUpOfpToDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portUpDevToLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portUpLinkToGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
+
+        portDownEndToEndNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portDownOfpToDevNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portDownDevToLinkNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        portDownLinkToGraphNodeIter = numpy.zeros((clusterCount, int(numIter)))
         
         for i in range(0, int(numIter)):
             main.step('Starting wireshark capture for port status down')
@@ -910,41 +922,53 @@
                     deviceTimestamp = 0
                     linkTimestamp = 0
 
-                ptDownGraphToOfp = int(graphTimestamp) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtDown)
-                ptDownLinkToOfp = int(linkTimestamp) - int(timestampBeginPtDown)
+                ptDownEndToEnd = int(graphTimestamp) - int(timestampBeginPtDown)
+                ptDownOfpToDevice = int(deviceTimestamp) - int(timestampBeginPtDown)
+                ptDownDeviceToLink = int(linkTimestamp) - int(deviceTimestamp)
+                ptDownLinkToGraph = int(graphTimestamp) - int(linkTimestamp)
 
-                if ptDownGraphToOfp > downThresholdMin and\
-                   ptDownGraphToOfp < downThresholdMax and i >= iterIgnore:
-                    portDownGraphNodeIter[node][i] = ptDownGraphToOfp
+                if ptDownEndToEnd > downThresholdMin and\
+                   ptDownEndToEnd < downThresholdMax and i >= iterIgnore:
+                    portDownEndToEndNodeIter[node][i] = ptDownEndToEnd
                     main.log.info("ONOS "+str(nodeNum)+ 
-                            " port down graph-to-ofp: "+
-                            str(ptDownGraphToOfp) + " ms") 
+                            " port down End-to-end: "+
+                            str(ptDownEndToEnd) + " ms") 
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port down graph-to-ofp ignored"+
+                            " port down End-to-end ignored"+
                             " due to excess in threshold or premature iteration")
 
-                if ptDownDeviceToOfp > downThresholdMin and\
-                   ptDownDeviceToOfp < downThresholdMax and i >= iterIgnore:
-                    portDownDevNodeIter[node][i] = ptDownDeviceToOfp
+                if ptDownOfpToDevice > downThresholdMin and\
+                   ptDownOfpToDevice < downThresholdMax and i >= iterIgnore:
+                    portDownOfpToDevNodeIter[node][i] = ptDownOfpToDevice
                     main.log.info("ONOS "+str(nodeNum)+ 
-                            " port down device-to-ofp: "+
-                            str(ptDownDeviceToOfp) + " ms") 
+                            " port down Ofp-to-device: "+
+                            str(ptDownOfpToDevice) + " ms") 
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port down device-to-ofp ignored"+
+                            " port down Ofp-to-device ignored"+
                             " due to excess in threshold or premature iteration")
 
-                if ptDownLinkToOfp > downThresholdMin and\
-                   ptDownLinkToOfp < downThresholdMax and i >= iterIgnore:
-                    portDownLinkNodeIter[node][i] = ptDownLinkToOfp
+                if ptDownDeviceToLink > downThresholdMin and\
+                   ptDownDeviceToLink < downThresholdMax and i >= iterIgnore:
+                    portDownDevToLinkNodeIter[node][i] = ptDownDeviceToLink
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port down link-to-ofp: "+
-                            str(ptDownLinkToOfp) + " ms")
+                            " port down Device-to-link "+
+                            str(ptDownDeviceToLink) + " ms")
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port down link-to-ofp ignored"+
+                            " port down Device-to-link ignored"+
+                            " due to excess in threshold or premature iteration")
+
+                if ptDownLinkToGraph > downThresholdMin and\
+                   ptDownLinkToGraph < downThresholdMax and i >= iterIgnore:
+                    portDownLinkToGraphNodeIter[node][i] = ptDownLinkToGraph
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " port down Link-to-graph "+
+                            str(ptDownLinkToGraph) + " ms")
+                else:
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " port down Link-to-graph ignored"+
                             " due to excess in threshold or premature iteration")
 
             time.sleep(3)
@@ -993,118 +1017,158 @@
                     deviceTimestamp = 0
                     linkTimestamp = 0
 
-                ptUpGraphToOfp = int(graphTimestamp) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtUp)
-                ptUpLinkToOfp = int(linkTimestamp) - int(timestampBeginPtUp)
+                ptUpEndToEnd = int(graphTimestamp) - int(timestampBeginPtUp)
+                ptUpOfpToDevice = int(deviceTimestamp) - int(timestampBeginPtUp)
+                ptUpDeviceToLink = int(linkTimestamp) - int(deviceTimestamp)
+                ptUpLinkToGraph = int(graphTimestamp) - int(linkTimestamp)
 
-                if ptUpGraphToOfp > upThresholdMin and\
-                   ptUpGraphToOfp < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[node][i] = ptUpGraphToOfp
+                if ptUpEndToEnd > upThresholdMin and\
+                   ptUpEndToEnd < upThresholdMax and i > iterIgnore:
+                    portUpEndToEndNodeIter[node][i] = ptUpEndToEnd
                     main.log.info("ONOS "+str(nodeNum)+ 
-                            " port up graph-to-ofp: "+
-                            str(ptUpGraphToOfp) + " ms") 
+                            " port up End-to-end: "+
+                            str(ptUpEndToEnd) + " ms") 
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port up graph-to-ofp ignored"+
+                            " port up End-to-end ignored"+
                             " due to excess in threshold or premature iteration")
 
-                if ptUpDeviceToOfp > upThresholdMin and\
-                   ptUpDeviceToOfp < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[node][i] = ptUpDeviceToOfp
+                if ptUpOfpToDevice > upThresholdMin and\
+                   ptUpOfpToDevice < upThresholdMax and i > iterIgnore:
+                    portUpOfpToDevNodeIter[node][i] = ptUpOfpToDevice
                     main.log.info("ONOS "+str(nodeNum)+ 
-                            " port up device-to-ofp: "+
-                            str(ptUpDeviceToOfp) + " ms") 
+                            " port up Ofp-to-device: "+
+                            str(ptUpOfpToDevice) + " ms") 
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port up device-to-ofp ignored"+
+                            " port up Ofp-to-device ignored"+
                             " due to excess in threshold or premature iteration")
 
-                if ptUpLinkToOfp > upThresholdMin and\
-                   ptUpLinkToOfp < upThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[node][i] = ptUpLinkToOfp
+                if ptUpDeviceToLink > upThresholdMin and\
+                   ptUpDeviceToLink < upThresholdMax and i > iterIgnore:
+                    portUpDevToLinkNodeIter[node][i] = ptUpDeviceToLink
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port up link-to-ofp: "+
-                            str(ptUpLinkToOfp) + " ms")
+                            " port up Device-to-link: "+
+                            str(ptUpDeviceToLink) + " ms")
                 else:
                     main.log.info("ONOS "+str(nodeNum)+
-                            " port up link-to-ofp ignored"+
+                            " port up Device-to-link ignored"+
+                            " due to excess in threshold or premature iteration")
+                
+                if ptUpLinkToGraph > upThresholdMin and\
+                   ptUpLinkToGraph < upThresholdMax and i > iterIgnore:
+                    portUpLinkToGraphNodeIter[node][i] = ptUpLinkToGraph
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " port up Link-to-graph: "+
+                            str(ptUpLinkToGraph) + " ms")
+                else:
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " port up Link-to-graph ignored"+
                             " due to excess in threshold or premature iteration")
 
         dbCmdList = []
         for node in range(0, clusterCount):
-            portUpDevList = []
-            portUpGraphList = []
-            portUpLinkList = []
-            portDownDevList = []
-            portDownGraphList = []
-            portDownLinkList = []
+            portUpEndToEndList = []
+            portUpOfpToDevList = []
+            portUpDevToLinkList = []
+            portUpLinkToGraphList = []
 
-            portUpDevAvg = 0
-            portUpGraphAvg = 0
-            portUpLinkAvg = 0
-            portDownDevAvg = 0
-            portDownGraphAvg = 0
-            portDownLinkAvg = 0
+            portDownEndToEndList = []
+            portDownOfpToDevList = []
+            portDownDevToLinkList = []
+            portDownLinkToGraphList = []
+
+            portUpEndToEndAvg = 0
+            portUpOfpToDevAvg = 0
+            portUpDevToLinkAvg = 0
+            portUpLinkToGraphAvg = 0
+            
+            portDownEndToEndAvg = 0
+            portDownOfpToDevAvg = 0
+            portDownDevToLinkAvg = 0
+            portDownLinkToGraphAvg = 0
 
             # TODO: Update for more pythonic way to get list
             # portUpDevList = [item for item in portUpDevNodeIter[node] 
             #        if item > 0.0] 
-
-            for item in portUpDevNodeIter[node]:
+            for item in portUpEndToEndNodeIter[node]:
                 if item > 0.0:
-                    portUpDevList.append(item)
+                    portUpEndToEndList.append(item)
 
-            for item in portUpGraphNodeIter[node]:
+            for item in portUpOfpToDevNodeIter[node]:
                 if item > 0.0:
-                    portUpGraphList.append(item)
-
-            for item in portUpLinkNodeIter[node]:
+                    portUpOfpToDevList.append(item)
+                
+            for item in portUpDevToLinkNodeIter[node]:
                 if item > 0.0:
-                    portUpLinkList.append(item)
+                    portUpDevToLinkList.append(item)
 
-            for item in portDownDevNodeIter[node]:
+            for item in portUpLinkToGraphNodeIter[node]:
                 if item > 0.0:
-                    portDownDevList.append(item)
+                    portUpLinkToGraphList.append(item)
 
-            for item in portDownGraphNodeIter[node]:
+
+            for item in portDownEndToEndNodeIter[node]:
                 if item > 0.0:
-                    portDownGraphList.append(item)
+                    portDownEndToEndList.append(item)
 
-            for item in portDownLinkNodeIter[node]:
+            for item in portDownOfpToDevNodeIter[node]:
                 if item > 0.0:
-                    portDownLinkList.append(item)
+                    portDownOfpToDevList.append(item)
 
-            portUpDevAvg = round(numpy.mean(portUpDevList), 2)
-            portUpGraphAvg = round(numpy.mean(portUpGraphList), 2)
-            portUpLinkAvg = round(numpy.mean(portUpLinkList), 2)
+            for item in portDownDevToLinkNodeIter[node]:
+                if item > 0.0:
+                    portDownDevToLinkList.append(item)
 
-            portDownDevAvg = round(numpy.mean(portDownDevList), 2)
-            portDownGraphAvg = round(numpy.mean(portDownGraphList), 2)
-            portDownLinkAvg = round(numpy.mean(portDownLinkList), 2)
+            for item in portDownLinkToGraphNodeIter[node]:
+                if item > 0.0:
+                    portDownLinkToGraphList.append(item)
+
+            portUpEndToEndAvg = round(numpy.mean(portUpEndToEndList), 2)
+            portUpOfpToDevAvg = round(numpy.mean(portUpOfpToDevList), 2)
+            portUpDevToLinkAvg = round(numpy.mean(portUpDevToLinkList), 2)
+            portUpLinkToGraphAvg = round(numpy.mean(portUpLinkToGraphList), 2)
+
+            portDownEndToEndAvg = round(numpy.mean(portDownEndToEndList), 2)
+            portDownOfpToDevAvg = round(numpy.mean(portDownOfpToDevList), 2)
+            portDownDevToLinkAvg = round(numpy.mean(portDownDevToLinkList), 2)
+            portDownLinkToGraphAvg = round(numpy.mean(portDownLinkToGraphList), 2)
             
-            portUpStdDev = round(numpy.std(portUpGraphList), 2)
-            portDownStdDev = round(numpy.std(portDownGraphList), 2)
+            portUpStdDev = round(numpy.std(portUpEndToEndList), 2)
+            portDownStdDev = round(numpy.std(portDownEndToEndList), 2)
            
             main.log.report(' - Node ' + str(node + 1) + ' Summary - ')
-            main.log.report(' Port up ofp-to-device ' +
-                    str(portUpDevAvg) + ' ms')
-            main.log.report(' Port up ofp-to-graph ' +
-                    str(portUpGraphAvg) + ' ms')
-            main.log.report(' Port up ofp-to-link ' +
-                    str(portUpLinkAvg) + ' ms')
+            main.log.report(' Port up End-to-end ' +
+                    str(portUpEndToEndAvg) + ' ms')
+            main.log.report(' Port up Ofp-to-device ' +
+                    str(portUpOfpToDevAvg) + ' ms')
+            main.log.report(' Port up Device-to-link ' +
+                    str(portUpDevToLinkAvg) + ' ms')
+            main.log.report(' Port up Link-to-graph ' +
+                    str(portUpLinkToGraphAvg) + ' ms')
             
-            main.log.report(' Port down ofp-to-device ' +
-                    str(round(portDownDevAvg, 2)) + ' ms')
-            main.log.report(' Port down ofp-to-graph ' +
-                    str(portDownGraphAvg) + ' ms')
-            main.log.report(' Port down ofp-to-link ' +
-                    str(portDownLinkAvg) + ' ms')
+            main.log.report(' Port down End-to-end ' +
+                    str(round(portDownEndToEndAvg, 2)) + ' ms')
+            main.log.report(' Port down Ofp-to-device ' +
+                    str(portDownOfpToDevAvg) + ' ms')
+            main.log.report(' Port down Device-to-link' +
+                    str(portDownDevToLinkAvg) + ' ms')
+            main.log.report(' Port down Link-to-graph' +
+                    str(portDownLinkToGraphAvg) + ' ms')
 
-            dbCmdList.append("INSERT INTO port_latency_tests VALUES('" + 
+            dbCmdList.append("INSERT INTO port_latency_details VALUES('" + 
                     timeToPost + "','port_latency_results'," + jenkinsBuildNumber +
                     ',' + str(clusterCount) + ",'baremetal" + str(node + 1) +
-                    "'," + str(portUpGraphAvg) + ',' + str(portUpStdDev) +
-                    '' + str(portDownGraphAvg) + ',' + str(portDownStdDev) + ');')
+                    "'," +
+                    str(portUpEndToEndAvg) +',' +
+                    str(portUpOfpToDevAvg) + ',' +
+                    str(portUpDevToLinkAvg) + ',' +
+                    str(portUpLinkToGraphAvg) + ',' + 
+                    str(portDownEndToEndAvg) + ',' +
+                    str(portDownOfpToDevAvg) + ',' +
+                    str(portDownDevToLinkAvg) + ',' +
+                    str(portDownLinkToGraphAvg) +
+                    ');')
 
         fResult = open(resultPath, 'a')
         for line in dbCmdList: