Scale-out case refactoring and minor bug fixes
diff --git a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.params b/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.params
deleted file mode 100644
index 24588e0..0000000
--- a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.params
+++ /dev/null
@@ -1,95 +0,0 @@
-<PARAMS>
-    <testcases>1,2,3,4,2,3,4,2,3,4,2,3</testcases>
-
-    <ENV>
-        <cellName>topo_perf_test</cellName>
-        <cellFeatures>"webconsole,onos-core,onos-api,onos-cli,onos-app-metrics,onos-app-gui,onos-openflow"</cellFeatures>
-    </ENV>
-
-    <GIT>
-        #autoPull 'on' or 'off'
-        <autoPull>off</autoPull>
-        <checkout>master</checkout>
-    </GIT>
-
-    <CTRL>
-        <user>sdn</user>
-        <ip1>10.254.1.201</ip1>
-        <port1>6633</port1>
-        <ip2>10.254.1.202</ip2>
-        <port2>6633</port2>
-        <ip3>10.254.1.203</ip3>
-        <port3>6633</port3>
-        <ip4>10.254.1.204</ip4>
-        
-        <ip5>10.254.1.205</ip5>
-        <ip6>10.254.1.206</ip6>
-        <ip7>10.254.1.207</ip7>
-    </CTRL>
-
-    <MN>
-        <ip1>10.254.1.200</ip1>
-        <ip2>10.254.1.200</ip2>
-    </MN>
-
-    <BENCH>
-        <ip>10.254.1.200</ip>
-    </BENCH>
-
-    <TSHARK>
-        <ofpPortStatus>OF 1.3 146</ofpPortStatus>
-        <ofpRoleReply>OF 1.3 90 of_role_reply</ofpRoleReply>
-        <featureReply>OF 1.3 98 of_features_reply</featureReply>
-        <roleRequest>OF 1.3 90 of_role_request</roleRequest>
-        <tcpSynAck>TCP 74 6633</tcpSynAck>
-    </TSHARK>
-
-    <TEST>
-        #'on' or 'off' debug mode.
-        #If on, logging will be more verbose and
-        #tshark pcap will be enabled
-        #pcap file located at /tmp/'capture_name'
-        <debugMode>on</debugMode>
-        <onosLogFile>/opt/onos/log/karaf*</onosLogFile>
-        <mci>off</mci>
-
-        <topoConfigFile>
-        single_topo_event_accumulator.cfg
-        </topoConfigFile>
-        <topoConfigName>
-        org.onlab.onos.net.topology.impl.DefaultTopologyProvider.cfg
-        </topoConfigName>
-
-        #Number of times to iterate each case
-        <numIter>35</numIter>
-        <numSwitch>2</numSwitch>
-        #Number of iterations to ignore initially
-        <iterIgnore>2</iterIgnore>
-
-        <singleSwThreshold>0,1000</singleSwThreshold>
-        <portUpThreshold>0,1000</portUpThreshold>
-        <portDownThreshold>0,1000</portDownThreshold>
-        <linkUpThreshold>0,10000</linkUpThreshold>
-        <linkDownThreshold>0,10000</linkDownThreshold>
-        <swDisc100Threshold>0,10000</swDisc100Threshold>
-    
-        <tabletFile>tablets_3node.json</tabletFile>
-   </TEST>
-
-    <DB>
-        <postToDB>on</postToDB>
-        <portEventResultPath>
-        /home/admin/ONLabTest/TestON/tests/TopoPerfNextBM/portEventResultDb.log
-        </portEventResultPath>
-        <switchEventResultPath>
-        /home/admin/ONLabTest/TestON/tests/TopoPerfNextBM/switchEventResultDb.log
-        </switchEventResultPath>
-    </DB>
-
-    <JSON>
-        <deviceTimestamp>topologyDeviceEventTimestamp</deviceTimestamp>
-        <hostTimestamp>topologyHostEventTimestamp</hostTimestamp>
-        <linkTimestamp>topologyLinkEventTimestamp</linkTimestamp>
-        <graphTimestamp>topologyGraphEventTimestamp</graphTimestamp>
-    </JSON>
-</PARAMS>
diff --git a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py b/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
index e89491a..e73c588 100644
--- a/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
+++ b/TestON/tests/TopoPerfNextBM/TopoPerfNextBM.py
@@ -119,26 +119,15 @@
         CLIs[0].activateApp( 'org.onosproject.openflow' )
 
         main.step( 'Configuring application parameters' )
-        # TODO: Check driver for this functionality
-        main.ONOSbench.handle.sendline(
-                'onos '+nodeIpList[0]+
-                ' cfg set org.onosproject.net.'+
-                'topology.impl.DefaultTopologyProvider'+
-                ' maxEvents 1')
-        main.ONOSbench.handle.expect(":~")
-        main.ONOSbench.handle.sendline(
-                'onos '+nodeIpList[0]+
-                ' cfg set org.onosproject.net.'+
-                'topology.impl.DefaultTopologyProvider'+
-                ' maxBatchMs 0')
-        main.ONOSbench.handle.expect(":~")
-        main.ONOSbench.handle.sendline(
-                'onos '+nodeIpList[0]+
-                ' cfg set org.onosproject.net.'+
-                'topology.impl.DefaultTopologyProvider'+
-                ' maxIdleMs 0')
-        main.ONOSbench.handle.expect(":~")
-
+        
+        configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
+        configParam = 'maxEvents 1'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+        configParam = 'maxBatchMs 0'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+        configParam = 'maxIdleMs 0'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+        
         utilities.assert_equals(expect=main.TRUE,
                 actual=cellFileResult and cellApplyResult and\
                         verifyCellResult and checkoutResult and\
@@ -194,11 +183,40 @@
         tsharkFeatureReply = main.params[ 'TSHARK' ][ 'featureReply' ]
         tsharkRoleRequest = main.params[ 'TSHARK' ][ 'roleRequest' ]
         tsharkOfString = main.params[ 'TSHARK' ][ 'ofpRoleReply' ]
+        tsharkFinAckSequence = main.params[ 'TSHARK' ][ 'finAckSequence' ]
 
         tsharkOfOutput = '/tmp/tshark_of_topo.txt'
         tsharkTcpOutput = '/tmp/tshark_tcp_topo.txt'
         tsharkRoleOutput = '/tmp/tshark_role_request.txt'
         tsharkFeatureOutput = '/tmp/tshark_feature_reply.txt'
+        tsharkFinAckOutput = '/tmp/tshark_fin_ack.txt'
+
+        # Switch connect measurement list
+        # TCP Syn/Ack -> Feature Reply latency collection for each node
+        tcpToFeatureLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
+        # Feature Reply -> Role Request latency collection for each node
+        featureToRoleRequestLatNodeIter = numpy.zeros((clusterCount, 
+            int(numIter)))
+        # Role Request -> Role Reply latency collection for each node
+        roleRequestToRoleReplyLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
+        # Role Reply -> Device Update latency collection for each node
+        roleReplyToDeviceLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
+        # Device Update -> Graph Update latency collection for each node
+        deviceToGraphLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
+        
+        # Switch disconnect measurement lists
+        # Mininet Fin / Ack -> Mininet Ack
+        finAckTransactionLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
+        # Mininet Ack -> Device Event
+        ackToDeviceLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
+        # Device event -> Graph event
+        deviceToGraphDiscLatNodeIter = numpy.zeros((clusterCount,
+            int(numIter)))
 
         # TCP Syn/Ack -> Feature Reply latency collection for each node
         tcpToFeatureLatNodeIter = numpy.zeros((clusterCount, int(numIter)))
@@ -423,7 +441,7 @@
                     main.log.info("ONOS "+str(nodeNum)+ " device-to-graph: "+
                             str(deviceToGraph) + " ms")
                 else:
-                    main.log.info("ONOS "+str(nodeNum)+ " device=to-graph "+
+                    main.log.info("ONOS "+str(nodeNum)+ " device-to-graph "+
                             "measurement ignored due to excess in "+
                             "threshold or premature iteration")
                                 
@@ -440,22 +458,128 @@
             for device in deviceId:
                 deviceList.append(device['id'])
            
-            # TODO: Measure switch down metrics 
+            # Measure switch down metrics 
             # TCP FIN/ACK -> TCP FIN
             # TCP FIN -> Device Event
             # Device Event -> Graph Event
+            # Capture switch down FIN / ACK packets
+
+            main.ONOS1.tsharkGrep( tsharkFinAckSequence, tsharkFinAckOutput, 
+                    grepOptions = '-A 1' )
+           
+            time.sleep( 5 )
+
+            removeJsonList = []
 
             main.step('Remove switch from controller')
             main.Mininet1.deleteSwController('s3')
-            
-            #firstDevice = deviceList[0] 
-            firstDevice = "of:0000000000000003"
+            firstDevice = deviceList[0] 
             main.log.info( "Removing device " +str(firstDevice)+
                     " from ONOS" )
+            
+            time.sleep( 5 )
+           
+            # We need to get metrics before removing
+            # device from the store below.
+            for node in range(0, clusterCount):
+                metricsSwDown = CLIs[node].topologyEventsMetrics
+                jsonStr = metricsSwDown()
+                removeJsonList.append( json.loads(jsonStr) ) 
+            
             #if deviceId:
             main.ONOS1cli.deviceRemove(firstDevice)
+           
+            main.ONOS1.tsharkStop()
+
+            main.log.info('Copying over tshark files')
+            os.system('scp ' + ONOSUser + '@' + nodeIpList[0] +
+                    ':' + tsharkFinAckOutput + ' /tmp/')
+           
+            time.sleep( 10 )
+            finAckOutputList = []
+            with open(tsharkFinAckOutput, 'r') as f:
+                tempLine = f.readlines()
+                main.log.info('Object read in from FinAck capture: ' +
+                    str(tempLine))
+                
+                index = 1
+                for line in tempLine:
+                    obj = line.split(' ')
             
+                    if len(obj) > 1:
+                        if index == 1:
+                            tFinAck = float(obj[1]) * 1000.0
+                        elif index == 3:
+                            tAck = float(obj[1]) * 1000.0
+                    else:
+                        main.log.error('Tshark output file for OFP' +
+                            ' returned unexpected results')
+                        tFinAck = 0
+                        tAck = 0
+                        assertion = main.FALSE
+                    
+                    index = index+1
+
+            # with open() as f takes care of closing file
+
             time.sleep(5)
+            
+            for node in range(0, clusterCount):
+                nodeNum = node+1
+                jsonObj = removeJsonList[node]
+                if jsonObj:
+                    graphTimestamp = jsonObj[graphTimestampKey]['value']
+                    deviceTimestamp = jsonObj[deviceTimestampKey]['value']
+                    main.log.info("Graph timestamp: "+str(graphTimestamp))
+                    main.log.info("Device timestamp: "+str(deviceTimestamp))
+                else:
+                    main.log.error( "Unexpected JSON object" )
+                    # If we could not obtain the JSON object, 
+                    # set the timestamps to 0, which will be
+                    # excluded from the measurement later on
+                    # (realized as invalid)
+                    graphTimestamp = 0
+                    deviceTimestamp = 0
+               
+                finAckTransaction = int(tAck) - int(tFinAck)
+                ackToDevice = int(deviceTimestamp) - int(tAck)
+                deviceToGraph = int(graphTimestamp) - int(deviceTimestamp)
+                
+                if finAckTransaction > thresholdMin and\
+                   finAckTransaction < thresholdMax and i >= iterIgnore:
+                    finAckTransactionLatNodeIter[node][i] = finAckTransaction 
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " fin/ack transaction: "+
+                            str(finAckTransaction) + " ms")
+                else:
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " fin/ack transaction "+
+                            "measurement ignored due to excess in "+
+                            "threshold or premature iteration")
+                
+                if ackToDevice > thresholdMin and\
+                   ackToDevice < thresholdMax and i >= iterIgnore:
+                    ackToDeviceLatNodeIter[node][i] = ackToDevice
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " ack-to-device: "+
+                            str(ackToDevice) + " ms")
+                else:
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " ack-to-device "+
+                            "measurement ignored due to excess in "+
+                            "threshold or premature iteration")
+                
+                if deviceToGraph > thresholdMin and\
+                   deviceToGraph < thresholdMax and i >= iterIgnore:
+                    deviceToGraphDiscLatNodeIter[node][i] = deviceToGraph
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " device-to-graph disconnect: "+
+                            str(deviceToGraph) + " ms")
+                else:
+                    main.log.info("ONOS "+str(nodeNum)+
+                            " device-to-graph disconnect "+
+                            "measurement ignored due to excess in "+
+                            "threshold or premature iteration")
 
         endToEndAvg = 0
         ofpToGraphAvg = 0
@@ -469,12 +593,16 @@
             roleToOfpList = []
             ofpToDeviceList = []
             deviceToGraphList = []
+            
+            finAckTransactionList = []
+            ackToDeviceList = []
+            deviceToGraphDiscList = []
 
             # LatNodeIter 2d arrays contain all iteration latency
             # for each node of the current scale cluster size
-            
-            # TODO: Use the new breakdown latency lists
-
+            # Switch connection measurements
+            # Set further acceptance criteria for measurements
+            # here if you would like to filter reporting results
             for item in endToEndLatNodeIter[node]:
                 if item > 0.0:
                     endToEndList.append(item)
@@ -493,12 +621,29 @@
 
             for item in roleReplyToDeviceLatNodeIter[node]:
                 if item > 0.0:
-                    ofpToDeviceList.append(item)
+                    tcpToFeatureList.append(item)
+
+            for item in featureToRoleRequestLatNodeIter[node]:
+                if item > 0.0:
+                    featureToRoleList.append(item)
 
             for item in deviceToGraphLatNodeIter[node]:
                 if item > 0.0:
                     deviceToGraphList.append(item)
 
+            # Switch disconnect measurements
+            for item in finAckTransactionLatNodeIter[node]:
+                if item > 0.0:
+                    finAckTransactionList.append(item)
+
+            for item in ackToDeviceLatNodeIter[node]:
+                if item > 0.0:
+                    ackToDeviceList.append(item)
+
+            for item in deviceToGraphDiscLatNodeIter[node]:
+                if item > 0.0:
+                    deviceToGraphDiscList.append(item)
+            
             endToEndAvg = round(numpy.mean(endToEndList), 2)
             endToEndStdDev = round(numpy.std(endToEndList), 2)
 
@@ -517,7 +662,18 @@
             deviceToGraphAvg = round(numpy.mean(deviceToGraphList), 2)
             deviceToGraphStdDev = round(numpy.std(deviceToGraphList), 2)
 
+            finAckAvg = round(numpy.mean(finAckTransactionList), 2)
+            finAckStdDev = round(numpy.std(finAckTransactionList), 2)
+            
+            ackToDeviceAvg = round(numpy.mean(ackToDeviceList), 2)
+            ackToDeviceStdDev = round(numpy.std(ackToDeviceList), 2)
+            
+            deviceToGraphDiscAvg = round(numpy.mean(deviceToGraphDiscList), 2)
+            deviceToGraphDiscStdDev = round(numpy.std(deviceToGraphDiscList), 2)
+
             main.log.report(' - Node ' + str(node + 1) + ' Summary - ')
+            main.log.report(' - Switch Connection Statistics - ')
+            
             main.log.report(' End-to-end Avg: ' + str(endToEndAvg) +
                     ' ms' + ' End-to-end Std dev: ' +
                     str(endToEndStdDev) + ' ms')
@@ -547,12 +703,27 @@
             main.log.report( 'Device-to-graph Std dev: ' +
                     str(deviceToGraphStdDev) + ' ms')
             
+            main.log.report(' - Switch Disconnection Statistics - ')
+            main.log.report(' Fin/Ack-to-Ack Avg: ' + str(finAckAvg) + ' ms')
+            main.log.report(' Fin/Ack-to-Ack Std dev: ' +
+                    str(finAckStdDev) + ' ms')
+            
+            main.log.report(' Ack-to-device Avg: ' + str(ackToDeviceAvg) + 
+                    ' ms')
+            main.log.report(' Ack-to-device Std dev: ' + str(ackToDeviceStdDev) +
+                    ' ms')
+
+            main.log.report(' Device-to-graph (disconnect) Avg: ' +
+                    str(deviceToGraphDiscAvg) + ' ms')
+            main.log.report(' Device-to-graph (disconnect) Std dev: ' +
+                    str(deviceToGraphDiscStdDev) + ' ms')
+
             dbCmdList.append(
                     "INSERT INTO switch_latency_tests VALUES('" +
                     timeToPost + "','switch_latency_results'," +
                     runNum + ',' + str(clusterCount) + ",'baremetal" + 
                     str(node + 1) + "'," + str(endToEndAvg) + ',' +
-                    str(endToEndStd) + ',0,0);')
+                    str(endToEndStdDev) + ',0,0);')
 
         if debugMode == 'on':
             main.ONOS1.cpLogsToDir('/opt/onos/log/karaf.log',
@@ -592,9 +763,10 @@
         assertion = main.TRUE
         numIter = main.params['TEST']['numIter']
         iterIgnore = int(main.params['TEST']['iterIgnore'])
-        deviceTimestamp = main.params['JSON']['deviceTimestamp']
-        graphTimestamp = main.params['JSON']['graphTimestamp']
-        linkTimestamp = main.params['JSON']['linkTimestamp']
+        
+        deviceTimestampKey = main.params['JSON']['deviceTimestamp']
+        graphTimestampKey = main.params['JSON']['graphTimestamp']
+        linkTimestampKey = main.params['JSON']['linkTimestamp']
         
         tsharkPortUp = '/tmp/tshark_port_up.txt'
         tsharkPortDown = '/tmp/tshark_port_down.txt'
@@ -650,22 +822,34 @@
         for i in range(0, int(numIter)):
             main.step('Starting wireshark capture for port status down')
             main.ONOS1.tsharkGrep(tsharkPortStatus, tsharkPortDown)
+            
             time.sleep(5)
+            
             main.step('Disable port: ' + interfaceConfig)
             main.Mininet1.handle.sendline('sh ifconfig ' +
                     interfaceConfig + ' down')
             main.Mininet1.handle.expect('mininet>')
+            
             time.sleep(3)
+            
             main.ONOS1.tsharkStop()
+            
             os.system('scp ' + ONOSUser + '@' + ONOS1Ip + ':' +
                     tsharkPortDown + ' /tmp/')
+            
             fPortDown = open(tsharkPortDown, 'r')
             fLine = fPortDown.readline()
             objDown = fLine.split(' ')
             if len(fLine) > 0:
                 timestampBeginPtDown = int(float(objDown[1]) * 1000)
+                # At times, tshark reports timestamp at the 3rd 
+                # index of the array. If initial readings were 
+                # unlike the epoch timestamp, then check the 3rd
+                # index and set that as a timestamp
                 if timestampBeginPtDown < 1400000000000:
                     timestampBeginPtDown = int(float(objDown[2]) * 1000)
+                # If there are any suspicion of invalid results
+                # check this reported value
                 main.log.info('Port down begin timestamp: ' +
                         str(timestampBeginPtDown))
             else:
@@ -674,25 +858,28 @@
                 timestampBeginPtDown = 0
             fPortDown.close()
           
-            """
-            # TODO: Refactor in progress
-
             for node in range(0, clusterCount):
                 nodeNum = node+1
-                exec "metricsDown = main.ONOS%scli.topologyEventsMetrics"%str(nodeNum) 
+                metricsDown = CLIs[node].topologyEventsMetrics
                 jsonStrDown = metricsDown()
                 jsonObj = json.loads(jsonStrDown)
                 
-                graphTimestamp = jsonObj[graphTimestamp]['value']
-                deviceTimestamp = jsonObj[deviceTimestamp]['value']
-                linkTimestamp = jsonObj[linkTimestamp]['value']
-                
+                if jsonObj:
+                    graphTimestamp = jsonObj[graphTimestampKey]['value']
+                    deviceTimestamp = jsonObj[deviceTimestampKey]['value']
+                    linkTimestamp = jsonObj[linkTimestampKey]['value']
+                else:
+                    main.log.error( "Unexpected json object" )
+                    graphTimestamp = 0
+                    deviceTimestamp = 0
+                    linkTimestamp = 0
+
                 ptDownGraphToOfp = int(graphTimestamp) - int(timestampBeginPtDown)
                 ptDownDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtDown)
                 ptDownLinkToOfp = int(linkTimestamp) - int(timestampBeginPtDown)
 
                 if ptDownGraphToOfp > downThresholdMin and\
-                   ptDownGraphToOfp < downThresholdMax and i > iterIgnore:
+                   ptDownGraphToOfp < downThresholdMax and i >= iterIgnore:
                     portDownGraphNodeIter[node][i] = ptDownGraphToOfp
                     main.log.info("ONOS "+str(nodeNum)+ 
                             " port down graph-to-ofp: "+
@@ -703,8 +890,8 @@
                             " due to excess in threshold or premature iteration")
 
                 if ptDownDeviceToOfp > downThresholdMin and\
-                   ptDownDeviceToOfp < downThresholdMax and i > iterIgnore:
-                    portDownDeviceNodeIter[node][i] = ptDownDeviceToOfp
+                   ptDownDeviceToOfp < downThresholdMax and i >= iterIgnore:
+                    portDownDevNodeIter[node][i] = ptDownDeviceToOfp
                     main.log.info("ONOS "+str(nodeNum)+ 
                             " port down device-to-ofp: "+
                             str(ptDownDeviceToOfp) + " ms") 
@@ -714,7 +901,7 @@
                             " due to excess in threshold or premature iteration")
 
                 if ptDownLinkToOfp > downThresholdMin and\
-                   ptDownLinkToOfp < downThresholdMax and i > iterIgnore:
+                   ptDownLinkToOfp < downThresholdMax and i >= iterIgnore:
                     portDownLinkNodeIter[node][i] = ptDownLinkToOfp
                     main.log.info("ONOS "+str(nodeNum)+
                             " port down link-to-ofp: "+
@@ -723,199 +910,6 @@
                     main.log.info("ONOS "+str(nodeNum)+
                             " port down link-to-ofp ignored"+
                             " due to excess in threshold or premature iteration")
-            """
-            # *************************
-
-            main.step('Obtain t1 by metrics call')
-            
-            jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
-            jsonObj1 = json.loads(jsonStrUp1)
-            graphTimestamp1 = jsonObj1[graphTimestamp]['value']
-            deviceTimestamp1 = jsonObj1[deviceTimestamp]['value']
-            linkTimestamp1 = jsonObj1[linkTimestamp]['value']
-            ptDownGraphToOfp1 = int(graphTimestamp1) - int(timestampBeginPtDown)
-            ptDownDeviceToOfp1 = int(deviceTimestamp1) - int(timestampBeginPtDown)
-            ptDownLinkToOfp1 = int(linkTimestamp1) - int(timestampBeginPtDown)
-           
-            if ptDownGraphToOfp1 > downThresholdMin and\
-               ptDownGraphToOfp1 < downThresholdMax and i > iterIgnore:
-                portDownGraphNodeIter[0][i] = ptDownGraphToOfp1
-                main.log.info('ONOS1 iter' + str(i) +
-                        ' port down graph-to-ofp: ' +
-                        str(ptDownGraphToOfp1) + ' ms')
-            
-            if ptDownDeviceToOfp1 > downThresholdMin and \
-               ptDownDeviceToOfp1 < downThresholdMax and i > iterIgnore:
-                portDownDevNodeIter[0][i] = ptDownDeviceToOfp1
-                main.log.info('ONOS1 iter' + str(i) + 
-                        ' port down device-to-ofp: ' +
-                        str(ptDownDeviceToOfp1) + ' ms')
-            if ptDownLinkToOfp1 > downThresholdMin and\
-               ptDownLinkToOfp1 < downThresholdMax and i > iterIgnore:
-                portDownLinkNodeIter[0][i] = ptDownLinkToOfp1
-                main.log.info('ONOS1 iter' + str(i) +
-                        ' port down link-to-ofp: ' +
-                        str(ptDownLinkToOfp1) + ' ms')
-            
-            if clusterCount >= 3:
-                jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
-                jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
-                jsonObj2 = json.loads(jsonStrUp2)
-                jsonObj3 = json.loads(jsonStrUp3)
-                graphTimestamp2 = jsonObj2[graphTimestamp]['value']
-                graphTimestamp3 = jsonObj3[graphTimestamp]['value']
-                deviceTimestamp2 = jsonObj2[deviceTimestamp]['value']
-                deviceTimestamp3 = jsonObj3[deviceTimestamp]['value']
-                linkTimestamp2 = jsonObj2[linkTimestamp]['value']
-                linkTimestamp3 = jsonObj3[linkTimestamp]['value']
-                ptDownGraphToOfp2 = int(graphTimestamp2) - int(timestampBeginPtDown)
-                ptDownGraphToOfp3 = int(graphTimestamp3) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp2 = int(deviceTimestamp2) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp3 = int(deviceTimestamp3) - int(timestampBeginPtDown)
-                ptDownLinkToOfp2 = int(linkTimestamp2) - int(timestampBeginPtDown)
-                ptDownLinkToOfp3 = int(linkTimestamp3) - int(timestampBeginPtDown)
-                if ptDownGraphToOfp2 > downThresholdMin and\
-                   ptDownGraphToOfp2 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[1][i] = ptDownGraphToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp2) + ' ms')
-                if ptDownDeviceToOfp2 > downThresholdMin and \
-                   ptDownDeviceToOfp2 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[1][i] = ptDownDeviceToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' device-to-ofp: ' +
-                            str(ptDownDeviceToOfp2) + ' ms')
-                if ptDownLinkToOfp2 > downThresholdMin and\
-                   ptDownLinkToOfp2 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[1][i] = ptDownLinkToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp2) + ' ms')
-                if ptDownGraphToOfp3 > downThresholdMin and\
-                   ptDownGraphToOfp3 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[2][i] = ptDownGraphToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp3) + ' ms')
-                if ptDownDeviceToOfp3 > downThresholdMin and\
-                   ptDownDeviceToOfp3 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[2][i] = ptDownDeviceToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' device-to-ofp: ' +
-                            str(ptDownDeviceToOfp3) + ' ms')
-                if ptDownLinkToOfp3 > downThresholdMin and\
-                   ptDownLinkToOfp3 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[2][i] = ptDownLinkToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp3) + ' ms')
-            if clusterCount >= 5:
-                jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
-                jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
-                jsonObj4 = json.loads(jsonStrUp4)
-                jsonObj5 = json.loads(jsonStrUp5)
-                graphTimestamp4 = jsonObj4[graphTimestamp]['value']
-                graphTimestamp5 = jsonObj5[graphTimestamp]['value']
-                deviceTimestamp4 = jsonObj4[deviceTimestamp]['value']
-                deviceTimestamp5 = jsonObj5[deviceTimestamp]['value']
-                linkTimestamp4 = jsonObj4[linkTimestamp]['value']
-                linkTimestamp5 = jsonObj5[linkTimestamp]['value']
-                ptDownGraphToOfp4 = int(graphTimestamp4) - int(timestampBeginPtDown)
-                ptDownGraphToOfp5 = int(graphTimestamp5) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp4 = int(deviceTimestamp4) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp5 = int(deviceTimestamp5) - int(timestampBeginPtDown)
-                ptDownLinkToOfp4 = int(linkTimestamp4) - int(timestampBeginPtDown)
-                ptDownLinkToOfp5 = int(linkTimestamp5) - int(timestampBeginPtDown)
-                if ptDownGraphToOfp4 > downThresholdMin and \
-                   ptDownGraphToOfp4 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[3][i] = ptDownGraphToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp4) + ' ms')
-                if ptDownDeviceToOfp4 > downThresholdMin and\
-                   ptDownDeviceToOfp4 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[3][i] = ptDownDeviceToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' device-to-ofp: ' +
-                            str(ptDownDeviceToOfp4) + ' ms')
-                if ptDownLinkToOfp4 > downThresholdMin and\
-                   ptDownLinkToOfp4 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[3][i] = ptDownLinkToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp4) + ' ms')
-                if ptDownGraphToOfp5 > downThresholdMin and\
-                   ptDownGraphToOfp5 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[4][i] = ptDownGraphToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp5) + ' ms')
-                if ptDownDeviceToOfp5 > downThresholdMin and\
-                   ptDownDeviceToOfp5 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[4][i] = ptDownDeviceToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' device-to-ofp: ' +
-                            str(ptDownDeviceToOfp5) + ' ms')
-                if ptDownLinkToOfp5 > downThresholdMin and\
-                   ptDownLinkToOfp5 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[4][i] = ptDownLinkToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp5) + ' ms')
-            if clusterCount >= 7:
-                jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
-                jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
-                jsonObj6 = json.loads(jsonStrUp6)
-                jsonObj7 = json.loads(jsonStrUp7)
-                graphTimestamp6 = jsonObj6[graphTimestamp]['value']
-                graphTimestamp7 = jsonObj7[graphTimestamp]['value']
-                deviceTimestamp6 = jsonObj6[deviceTimestamp]['value']
-                deviceTimestamp7 = jsonObj7[deviceTimestamp]['value']
-                linkTimestamp6 = jsonObj6[linkTimestamp]['value']
-                linkTimestamp7 = jsonObj7[linkTimestamp]['value']
-                ptDownGraphToOfp6 = int(graphTimestamp6) - int(timestampBeginPtDown)
-                ptDownGraphToOfp7 = int(graphTimestamp7) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp6 = int(deviceTimestamp6) - int(timestampBeginPtDown)
-                ptDownDeviceToOfp7 = int(deviceTimestamp7) - int(timestampBeginPtDown)
-                ptDownLinkToOfp6 = int(linkTimestamp6) - int(timestampBeginPtDown)
-                ptDownLinkToOfp7 = int(linkTimestamp7) - int(timestampBeginPtDown)
-                if ptDownGraphToOfp6 > downThresholdMin and\
-                   ptDownGraphToOfp6 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[5][i] = ptDownGraphToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp6) + ' ms')
-                if ptDownDeviceToOfp6 > downThresholdMin and\
-                   ptDownDeviceToOfp6 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[5][i] = ptDownDeviceToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' device-to-ofp: ' +
-                            str(ptDownDeviceToOfp6) + ' ms')
-                if ptDownLinkToOfp6 > downThresholdMin and\
-                   ptDownLinkToOfp6 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[5][i] = ptDownLinkToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp6) + ' ms')
-                if ptDownGraphToOfp7 > downThresholdMin and\
-                   ptDownGraphToOfp7 < downThresholdMax and i > iterIgnore:
-                    portDownGraphNodeIter[6][i] = ptDownGraphToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' graph-to-ofp: ' +
-                            str(ptDownGraphToOfp7) + ' ms')
-                if ptDownDeviceToOfp7 > downThresholdMin and\
-                   ptDownDeviceToOfp7 < downThresholdMax and i > iterIgnore:
-                    portDownDevNodeIter[6][i] = ptDownDeviceToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' device-to-ofp: ' + 
-                            str(ptDownDeviceToOfp7) + ' ms')
-                if ptDownLinkToOfp7 > downThresholdMin and\
-                   ptDownLinkToOfp7 < downThresholdMax and i > iterIgnore:
-                    portDownLinkNodeIter[6][i] = ptDownLinkToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' link-to-ofp: ' +
-                            str(ptDownLinkToOfp7) + ' ms')
 
             time.sleep(3)
             
@@ -946,21 +940,23 @@
                 main.log.info('Tshark output file returned unexpected' + ' results.')
                 timestampBeginPtUp = 0
             fPortUp.close()
-            """ 
-            # TODO: Refactoring in progress
             
             for node in range(0, clusterCount):
                 nodeNum = node+1
-                exec "metricsUp = main.ONOS%scli.topologyEventsMetrics"%str(nodeNum) 
+                metricsUp = CLIs[node].topologyEventsMetrics
                 jsonStrUp = metricsUp()
                 jsonObj = json.loads(jsonStrUp)
-                
-                print jsonObj
+               
+                if jsonObj:
+                    graphTimestamp = jsonObj[graphTimestampKey]['value']
+                    deviceTimestamp = jsonObj[deviceTimestampKey]['value']
+                    linkTimestamp = jsonObj[linkTimestampKey]['value']
+                else:
+                    main.log.error( "Unexpected json object" )
+                    graphTimestamp = 0
+                    deviceTimestamp = 0
+                    linkTimestamp = 0
 
-                graphTimestamp = jsonObj[graphTimestamp]['value']
-                deviceTimestamp = jsonObj[deviceTimestamp]['value']
-                linkTimestamp = jsonObj[linkTimestamp]['value']
-                
                 ptUpGraphToOfp = int(graphTimestamp) - int(timestampBeginPtUp)
                 ptUpDeviceToOfp = int(deviceTimestamp) - int(timestampBeginPtUp)
                 ptUpLinkToOfp = int(linkTimestamp) - int(timestampBeginPtUp)
@@ -978,7 +974,7 @@
 
                 if ptUpDeviceToOfp > upThresholdMin and\
                    ptUpDeviceToOfp < upThresholdMax and i > iterIgnore:
-                    portUpDeviceNodeIter[node][i] = ptUpDeviceToOfp
+                    portUpDevNodeIter[node][i] = ptUpDeviceToOfp
                     main.log.info("ONOS "+str(nodeNum)+ 
                             " port up device-to-ofp: "+
                             str(ptUpDeviceToOfp) + " ms") 
@@ -998,198 +994,6 @@
                             " port up link-to-ofp ignored"+
                             " due to excess in threshold or premature iteration")
 
-            """
-
-            # *****************************
-            
-            main.step('Obtain t1 by REST call')
-            jsonStrUp1 = main.ONOS1cli.topologyEventsMetrics()
-            jsonObj1 = json.loads(jsonStrUp1)
-            graphTimestamp1 = jsonObj1[graphTimestamp]['value']
-            deviceTimestamp1 = jsonObj1[deviceTimestamp]['value']
-            linkTimestamp1 = jsonObj1[linkTimestamp]['value']
-            ptUpGraphToOfp1 = int(graphTimestamp1) - int(timestampBeginPtUp)
-            ptUpDeviceToOfp1 = int(deviceTimestamp1) - int(timestampBeginPtUp)
-            ptUpLinkToOfp1 = int(linkTimestamp1) - int(timestampBeginPtUp)
-            if ptUpGraphToOfp1 > upThresholdMin and\
-               ptUpGraphToOfp1 < upThresholdMax and i > iterIgnore:
-                portUpGraphNodeIter[0][i] = ptUpGraphToOfp1
-                main.log.info('ONOS1 iter' + str(i) +
-                        ' port up graph-to-ofp: ' +
-                        str(ptUpGraphToOfp1) + ' ms')
-            if ptUpDeviceToOfp1 > upThresholdMin and \
-               ptUpDeviceToOfp1 < upThresholdMax and i > iterIgnore:
-                portUpDevNodeIter[0][i] = ptUpDeviceToOfp1
-                main.log.info('ONOS1 iter' + str(i) +
-                        ' port up device-to-ofp: ' +
-                        str(ptUpDeviceToOfp1) + ' ms')
-            if ptUpLinkToOfp1 > downThresholdMin and\
-               ptUpLinkToOfp1 < downThresholdMax and i > iterIgnore:
-                portUpLinkNodeIter[0][i] = ptUpLinkToOfp1
-                main.log.info('ONOS1 iter' + str(i) +
-                        ' link-to-ofp: ' +
-                        str(ptUpLinkToOfp1) + ' ms')
-            if clusterCount >= 3:
-                jsonStrUp2 = main.ONOS2cli.topologyEventsMetrics()
-                jsonStrUp3 = main.ONOS3cli.topologyEventsMetrics()
-                jsonObj2 = json.loads(jsonStrUp2)
-                jsonObj3 = json.loads(jsonStrUp3)
-                graphTimestamp2 = jsonObj2[graphTimestamp]['value']
-                graphTimestamp3 = jsonObj3[graphTimestamp]['value']
-                deviceTimestamp2 = jsonObj2[deviceTimestamp]['value']
-                deviceTimestamp3 = jsonObj3[deviceTimestamp]['value']
-                linkTimestamp2 = jsonObj2[linkTimestamp]['value']
-                linkTimestamp3 = jsonObj3[linkTimestamp]['value']
-                ptUpGraphToOfp2 = int(graphTimestamp2) - int(timestampBeginPtUp)
-                ptUpGraphToOfp3 = int(graphTimestamp3) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp2 = int(deviceTimestamp2) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp3 = int(deviceTimestamp3) - int(timestampBeginPtUp)
-                ptUpLinkToOfp2 = int(linkTimestamp2) - int(timestampBeginPtUp)
-                ptUpLinkToOfp3 = int(linkTimestamp3) - int(timestampBeginPtUp)
-                if ptUpGraphToOfp2 > upThresholdMin and\
-                   ptUpGraphToOfp2 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[1][i] = ptUpGraphToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' port up graph-to-ofp: ' +
-                            str(ptUpGraphToOfp2) + ' ms')
-                if ptUpDeviceToOfp2 > upThresholdMin and\
-                   ptUpDeviceToOfp2 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[1][i] = ptUpDeviceToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' port up device-to-ofp: ' +
-                            str(ptUpDeviceToOfp2) + ' ms')
-                if ptUpLinkToOfp2 > downThresholdMin and\
-                   ptUpLinkToOfp2 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[1][i] = ptUpLinkToOfp2
-                    main.log.info('ONOS2 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp2) + ' ms')
-                if ptUpGraphToOfp3 > upThresholdMin and\
-                   ptUpGraphToOfp3 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[2][i] = ptUpGraphToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' port up graph-to-ofp: ' +
-                            str(ptUpGraphToOfp3) + ' ms')
-                if ptUpDeviceToOfp3 > upThresholdMin and\
-                   ptUpDeviceToOfp3 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[2][i] = ptUpDeviceToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' port up device-to-ofp: ' +
-                            str(ptUpDeviceToOfp3) + ' ms')
-                if ptUpLinkToOfp3 > downThresholdMin and\
-                   ptUpLinkToOfp3 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[2][i] = ptUpLinkToOfp3
-                    main.log.info('ONOS3 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp3) + ' ms')
-            if clusterCount >= 5:
-                jsonStrUp4 = main.ONOS4cli.topologyEventsMetrics()
-                jsonStrUp5 = main.ONOS5cli.topologyEventsMetrics()
-                jsonObj4 = json.loads(jsonStrUp4)
-                jsonObj5 = json.loads(jsonStrUp5)
-                graphTimestamp4 = jsonObj4[graphTimestamp]['value']
-                graphTimestamp5 = jsonObj5[graphTimestamp]['value']
-                deviceTimestamp4 = jsonObj4[deviceTimestamp]['value']
-                deviceTimestamp5 = jsonObj5[deviceTimestamp]['value']
-                linkTimestamp4 = jsonObj4[linkTimestamp]['value']
-                linkTimestamp5 = jsonObj5[linkTimestamp]['value']
-                ptUpGraphToOfp4 = int(graphTimestamp4) - int(timestampBeginPtUp)
-                ptUpGraphToOfp5 = int(graphTimestamp5) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp4 = int(deviceTimestamp4) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp5 = int(deviceTimestamp5) - int(timestampBeginPtUp)
-                ptUpLinkToOfp4 = int(linkTimestamp4) - int(timestampBeginPtUp)
-                ptUpLinkToOfp5 = int(linkTimestamp5) - int(timestampBeginPtUp)
-                if ptUpGraphToOfp4 > upThresholdMin and\
-                   ptUpGraphToOfp4 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[3][i] = ptUpGraphToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' port up graph-to-ofp: ' +
-                            str(ptUpGraphToOfp4) + ' ms')
-                if ptUpDeviceToOfp4 > upThresholdMin and\
-                   ptUpDeviceToOfp4 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[3][i] = ptUpDeviceToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' port up device-to-ofp: ' +
-                            str(ptUpDeviceToOfp4) + ' ms')
-                if ptUpLinkToOfp4 > downThresholdMin and\
-                   ptUpLinkToOfp4 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[3][i] = ptUpLinkToOfp4
-                    main.log.info('ONOS4 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp4) + ' ms')
-                if ptUpGraphToOfp5 > upThresholdMin and\
-                    ptUpGraphToOfp5 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[4][i] = ptUpGraphToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' port up graph-to-ofp: ' +
-                            str(ptUpGraphToOfp5) + ' ms')
-                if ptUpDeviceToOfp5 > upThresholdMin and \
-                   ptUpDeviceToOfp5 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[4][i] = ptUpDeviceToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' port up device-to-ofp: ' +
-                            str(ptUpDeviceToOfp5) + ' ms')
-                if ptUpLinkToOfp5 > downThresholdMin and\
-                   ptUpLinkToOfp5 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[4][i] = ptUpLinkToOfp5
-                    main.log.info('ONOS5 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp5) + ' ms')
-            
-            if clusterCount >= 7:
-                jsonStrUp6 = main.ONOS6cli.topologyEventsMetrics()
-                jsonStrUp7 = main.ONOS7cli.topologyEventsMetrics()
-                jsonObj6 = json.loads(jsonStrUp6)
-                jsonObj7 = json.loads(jsonStrUp7)
-                graphTimestamp6 = jsonObj6[graphTimestamp]['value']
-                graphTimestamp7 = jsonObj7[graphTimestamp]['value']
-                deviceTimestamp6 = jsonObj6[deviceTimestamp]['value']
-                deviceTimestamp7 = jsonObj7[deviceTimestamp]['value']
-                linkTimestamp6 = jsonObj6[linkTimestamp]['value']
-                linkTimestamp7 = jsonObj7[linkTimestamp]['value']
-                ptUpGraphToOfp6 = int(graphTimestamp6) - int(timestampBeginPtUp)
-                ptUpGraphToOfp7 = int(graphTimestamp7) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp6 = int(deviceTimestamp6) - int(timestampBeginPtUp)
-                ptUpDeviceToOfp7 = int(deviceTimestamp7) - int(timestampBeginPtUp)
-                ptUpLinkToOfp6 = int(linkTimestamp6) - int(timestampBeginPtUp)
-                ptUpLinkToOfp7 = int(linkTimestamp7) - int(timestampBeginPtUp)
-                if ptUpGraphToOfp6 > upThresholdMin and\
-                   ptUpGraphToOfp6 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[5][i] = ptUpGraphToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' port up graph-to-ofp: ' +
-                            str(ptUpGraphToOfp6) + ' ms')
-                if ptUpDeviceToOfp6 > upThresholdMin and\
-                   ptUpDeviceToOfp6 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[5][i] = ptUpDeviceToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' port up device-to-ofp: ' + 
-                            str(ptUpDeviceToOfp6) + ' ms')
-                if ptUpLinkToOfp6 > downThresholdMin and\
-                   ptUpLinkToOfp6 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[5][i] = ptUpLinkToOfp6
-                    main.log.info('ONOS6 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp6) + ' ms')
-                if ptUpGraphToOfp7 > upThresholdMin and \
-                   ptUpGraphToOfp7 < upThresholdMax and i > iterIgnore:
-                    portUpGraphNodeIter[6][i] = ptUpGraphToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' port up graph-to-ofp: ' + 
-                            str(ptUpGraphToOfp7) + ' ms')
-                if ptUpDeviceToOfp7 > upThresholdMin and\
-                   ptUpDeviceToOfp7 < upThresholdMax and i > iterIgnore:
-                    portUpDevNodeIter[6][i] = ptUpDeviceToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' port up device-to-ofp: ' +
-                            str(ptUpDeviceToOfp7) + ' ms')
-                if ptUpLinkToOfp7 > downThresholdMin and\
-                   ptUpLinkToOfp7 < downThresholdMax and i > iterIgnore:
-                    portUpLinkNodeIter[6][i] = ptUpLinkToOfp7
-                    main.log.info('ONOS7 iter' + str(i) +
-                            ' port up link-to-ofp: ' +
-                            str(ptUpLinkToOfp7) + ' ms')
-
         dbCmdList = []
         for node in range(0, clusterCount):
             portUpDevList = []
@@ -1268,6 +1072,9 @@
                 fResult.write(line + '\n')
 
         fResult.close()
+
+        # Delete switches from controller to prepare for next
+        # set of tests
         main.Mininet1.deleteSwController('s1')
         main.Mininet1.deleteSwController('s2')
         utilities.assert_equals(expect=main.TRUE,
@@ -1340,7 +1147,18 @@
             if not isup:
                 main.log.error( "ONOS "+str(node) + " did not start" )
 
-        for node in range( 1, clusterCount + 1):
-            exec "a = main.ONOS%scli.startOnosCli" %str(node)
-            a(main.params[ 'CTRL' ][ 'ip'+str(node) ])
+        for node in range( 0, clusterCount ):
+            CLIs[node].startOnosCli( cellIp[node] )
+       
+        main.step( 'Setting configurations for metrics' )
+        configParam = 'maxEvents 1'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+        configParam = 'maxBatchMs 0'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+        configParam = 'maxIdleMs 0'
+        main.ONOSbench.onosCfgSet( nodeIpList[0], configName, configParam )
+       
+        main.step( 'Activating essential applications' )
+        CLIs[0].activateApp( 'org.onosproject.metrics' )
+        CLIs[0].activateApp( 'org.onosproject.openflow' )