Merge branch 'ONOS-Next' of https://github.com/OPENNETWORKINGLAB/ONLabTest into ONOS-Next
diff --git a/TestON/dependencies/topo-100sw.py b/TestON/dependencies/topo-100sw.py
new file mode 100644
index 0000000..308a3f1
--- /dev/null
+++ b/TestON/dependencies/topo-100sw.py
@@ -0,0 +1,31 @@
+
+from mininet.topo import Topo
+
+class MyTopo( Topo ):
+        "100 'floating' switch topology"
+
+        def __init__( self ):
+                # Initialize topology
+                Topo.__init__( self )
+
+                sw_list = []
+
+                for i in range(1, 101):
+                        sw_list.append(
+                                self.addSwitch(
+                                        's'+str(i),
+                                        dpid = str(i).zfill(16)))
+
+
+                #Below connections are used for test cases
+                #that need to test link and port events
+                #Add link between switch 1 and switch 2
+                self.addLink(sw_list[0],sw_list[1])
+                
+                #Create hosts and attach to sw 1 and sw 2
+                h1 = self.addHost('h1')
+                h2 = self.addHost('h2')
+                self.addLink(sw_list[0],h1)
+                self.addLink(sw_list[1],h2)
+        
+topos = { 'mytopo': ( lambda: MyTopo() ) }
diff --git a/TestON/dependencies/topo-intentFlower.py b/TestON/dependencies/topo-intentFlower.py
new file mode 100644
index 0000000..138c291
--- /dev/null
+++ b/TestON/dependencies/topo-intentFlower.py
@@ -0,0 +1,80 @@
+'''
+Topology with 3 core switches connected linearly.
+
+Each 'core' switch has a 'flower' of 10 switches
+for a total of 33 switches.
+
+Used in conjunction with 'IntentPerfNext' test
+'''
+
+from mininet.topo import Topo
+
+class MyTopo( Topo ):
+
+    def __init__( self ):
+        Topo.__init__( self )
+       
+        #Switches are listed out here for better view
+        #of the topology from this code
+        core_sw_list = ['s1','s2','s3']
+       
+        #Flower switches for core switch 1
+        flower_sw_list_s1 =\
+                ['s10', 's11', 's12', 's13', 's14',
+                 's15', 's16', 's17', 's18', 's19']
+        #Flower switches for core switch 2
+        flower_sw_list_s2 =\
+                ['s20', 's21', 's22', 's23', 's24',
+                 's25', 's26', 's27', 's28', 's29']
+        #Flower switches for core switch 3
+        flower_sw_list_s3 =\
+                ['s30', 's31', 's32', 's33', 's34',
+                 's35', 's36', 's37', 's38', 's39']
+
+        #Store switch objects in these variables
+        core_switches = []
+        flower_switches_1 = []
+        flower_switches_2 = []
+        flower_switches_3 = []
+       
+        #Add switches
+        for sw in core_sw_list:
+            core_switches.append(
+                    self.addSwitch(
+                        sw, 
+                        dpid = sw.replace('s','').zfill(16)
+                    )
+            )
+        for sw in flower_sw_list_s1:
+            flower_switches_1.append(
+                    self.addSwitch(
+                        sw,
+                        dpid = sw.replace('s','').zfill(16)
+                    )
+            )
+        for sw in flower_sw_list_s2:
+            flower_switches_2.append(
+                    self.addSwitch(
+                        sw,
+                        dpid = sw.replace('s','').zfill(16)
+                    )
+            )
+        for sw in flower_sw_list_s3:
+            flower_switches_3.append(
+                    self.addSwitch(
+                        sw,
+                        dpid = sw.replace('s','').zfill(16)
+                    )
+            )
+
+        self.addLink(core_switches[0], core_switches[1])
+        self.addLink(core_switches[1], core_switches[2])
+
+        for x in range(0, len(flower_sw_list_s1)):
+            self.addLink(core_switches[0], flower_switches_1[x]) 
+        for x in range(0, len(flower_sw_list_s2)):
+            self.addLink(core_switches[1], flower_switches_2[x])
+        for x in range(0, len(flower_sw_list_s3)):
+            self.addLink(core_switches[2], flower_switches_3[x])
+
+topos = { 'mytopo': ( lambda: MyTopo() ) }
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 2404a0d..90514d0 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -950,7 +950,7 @@
 
     def add_point_intent(self, ingress_device, port_ingress,
             egress_device, port_egress, ethType="", ethSrc="",
-            ethDst=""):
+            ethDst="", bandwidth="", lambda_alloc=False):
         '''
         Required:
             * ingress_device: device id of ingress device
@@ -959,6 +959,9 @@
             * ethType: specify ethType
             * ethSrc: specify ethSrc (i.e. src mac addr)
             * ethDst: specify ethDst (i.e. dst mac addr)
+            * bandwidth: specify bandwidth capacity of link
+            * lambda_alloc: if True, intent will allocate lambda 
+              for the specified intent
         Description:
             Adds a point-to-point intent (uni-directional) by
             specifying device id's and optional fields
@@ -971,7 +974,8 @@
             cmd = ""
 
             #If there are no optional arguments
-            if not ethType and not ethSrc and not ethDst:
+            if not ethType and not ethSrc and not ethDst\
+                    and not bandwidth and not lambda_alloc:
                 cmd = "add-point-intent "+\
                         str(ingress_device) + "/" + str(port_ingress) + " " +\
                         str(egress_device) + "/" + str(port_egress)
@@ -985,13 +989,14 @@
                     cmd += " --ethSrc " + str(ethSrc) 
                 if ethDst:    
                     cmd += " --ethDst " + str(ethDst) 
-                        
-                cmd += " "+str(ingress_device) + "/" + str(port_ingress) + " " +\
-                str(egress_device) + "/" + str(port_egress) 
+                if bandwidth:
+                    cmd += " --bandwidth " + str(bandwidth)
+                if lambda_alloc:
+                    cmd += " --lambda " 
 
-            #print "cmd = ", cmd
-            #self.handle.sendline("")
-            #self.handle.expect("onos>")
+                cmd += " "+str(ingress_device) +\
+                    "/" + str(port_ingress) + " " +\
+                    str(egress_device) + "/" + str(port_egress) 
 
             self.handle.sendline(cmd)
             i = self.handle.expect([
@@ -1001,12 +1006,6 @@
             self.handle.sendline("intents")
             self.handle.expect("onos>")
             Intenthandle = self.handle.before
-            #print "Intenthandle = ", Intenthandle
-
-            #self.handle.sendline("flows")
-            #self.handle.expect("onos>")
-            #Flowhandle = self.handle.before
-            #print "Flowhandle = ", Flowhandle
 
             if i == 0:
                 main.log.error("Error in adding point-to-point intent")
@@ -1072,7 +1071,9 @@
                 self.handle.expect("intents -j")
                 self.handle.expect("onos>")
                 handle = self.handle.before
-
+                
+                ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
+                handle = ansi_escape.sub('', handle)
             else:
                 self.handle.sendline("")
                 self.handle.expect("onos>")
@@ -1130,7 +1131,44 @@
             main.cleanup()
             main.exit()
 
+    def intents_events_metrics(self, json_format=True):
+        '''
+        Description:Returns topology metrics 
+        Optional:
+            * json_format: enable json formatting of output
+        '''
+        try:
+            if json_format:
+                self.handle.sendline("intents-events-metrics -j")
+                self.handle.expect("intents-events-metrics -j")
+                self.handle.expect("onos>")
+                
+                handle = self.handle.before
+              
+                #Some color thing that we want to escape
+                ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
+                handle = ansi_escape.sub('', handle)
+            
+            else:
+                self.handle.sendline("intents-events-metrics")
+                self.handle.expect("intents-events-metrics")
+                self.handle.expect("onos>")
+                
+                handle = self.handle.before
 
+            return handle
+        
+        except pexpect.EOF:
+            main.log.error(self.name + ": EOF exception found")
+            main.log.error(self.name + ":    " + self.handle.before)
+            main.cleanup()
+            main.exit()
+        except:
+            main.log.info(self.name+" ::::::")
+            main.log.error( traceback.print_exc())
+            main.log.info(self.name+" ::::::")
+            main.cleanup()
+            main.exit()
 
     def topology_events_metrics(self, json_format=True):
         '''
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index 03f49be..cb42a8d 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -120,6 +120,36 @@
             main.cleanup()
             main.exit()
 
+    def onos_build(self):
+        '''
+        Use the pre defined script to build onos via mvn
+        '''
+        
+        try:
+            self.handle.sendline("onos-build")
+            self.handle.expect("onos-build")
+            i = self.handle.expect([
+                "BUILD SUCCESS",
+                "ERROR",
+                "BUILD FAILED"], timeout=120)
+            handle = str(self.handle.before)
+
+            main.log.info("onos-build command returned: "+
+                    handle)
+
+            if i == 0:
+                return main.TRUE
+            else:
+                return handle
+
+        except pexpect.EOF:
+            main.log.error(self.name + ": EOF exception found")
+            main.log.error(self.name + ":    " + self.handle.before)
+        except:
+            main.log.error("Failed to build ONOS")
+            main.cleanup()
+            main.exit()
+
     def clean_install(self):
         '''
         Runs mvn clean install in the root of the ONOS directory. 
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.params b/TestON/tests/IntentPerfNext/IntentPerfNext.params
new file mode 100644
index 0000000..7e1de77
--- /dev/null
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.params
@@ -0,0 +1,44 @@
+<PARAMS>
+    <testcases>1,2</testcases>
+
+    <ENV>
+        <cellName>intent_perf_test</cellName>
+    </ENV>
+
+    <GIT>
+        #autoPull 'on' or 'off'
+        <autoPull>off</autoPull>
+        <checkout>master</checkout>
+    </GIT>
+
+    <CTRL>
+        <user>admin</user>
+        <ip1>10.128.174.1</ip1>
+        <port1>6633</port1>
+        <ip2>10.128.174.2</ip2>
+        <port2>6633</port2>
+        <ip3>10.128.174.3</ip3>
+        <port3>6633</port3>
+    </CTRL>
+
+    <MN>
+        <ip1>10.128.10.90</ip1>
+        <ip2>10.128.10.91</ip2>
+    </MN>
+
+    <BENCH>
+        <ip>10.128.174.10</ip>
+    </BENCH>
+
+    <TEST>
+        #Number of times to iterate each case
+        <numIter>5</numIter>
+    </TEST>
+
+    <JSON>
+        <submittedTime>intentSubmittedTimestamp</submittedTime>
+        <installedTime>intentInstalledTimestamp</installedTime>
+        <wdRequestTime>intentWithdrawRequestedTimestamp</wdRequestTime>
+        <withdrawnTime>intentWithdrawnTimestamp</withdrawnTime>
+    </JSON>
+</PARAMS>
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.py b/TestON/tests/IntentPerfNext/IntentPerfNext.py
new file mode 100644
index 0000000..2fb22dc
--- /dev/null
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.py
@@ -0,0 +1,218 @@
+#Intent Performance Test for ONOS-next
+#
+#andrew@onlab.us
+#
+#November 5, 2014
+
+class IntentPerfNext:
+    def __init__(self):
+        self.default = ""
+
+    def CASE1(self, main):
+        '''
+        ONOS startup sequence
+        '''
+
+        import time
+
+        cell_name = main.params['ENV']['cellName']
+
+        git_pull = main.params['GIT']['autoPull']
+        checkout_branch = main.params['GIT']['checkout']
+
+        ONOS1_ip = main.params['CTRL']['ip1']
+        ONOS2_ip = main.params['CTRL']['ip2']
+        ONOS3_ip = main.params['CTRL']['ip3']
+        
+        MN1_ip = main.params['MN']['ip1']
+        BENCH_ip = main.params['BENCH']['ip']
+    
+        main.case("Setting up test environment")
+
+        main.step("Creating cell file")
+        cell_file_result = main.ONOSbench.create_cell_file(
+                BENCH_ip, cell_name, MN1_ip, "onos-core",
+                ONOS1_ip, ONOS2_ip, ONOS3_ip)
+
+        main.step("Applying cell file to environment")
+        cell_apply_result = main.ONOSbench.set_cell(cell_name)
+        verify_cell_result = main.ONOSbench.verify_cell()
+
+        main.step("Git checkout and pull "+checkout_branch)
+        if git_pull == 'on':
+            checkout_result = \
+                main.ONOSbench.git_checkout(checkout_branch)
+            pull_result = main.ONOSbench.git_pull()
+           
+            #If you used git pull, auto compile
+            main.step("Using onos-build to compile ONOS")
+            build_result = main.ONOSbench.onos_build()
+        else:
+            checkout_result = main.TRUE
+            pull_result = main.TRUE
+            build_result = main.TRUE
+            main.log.info("Git pull skipped by configuration")
+
+        main.step("Creating ONOS package")
+        package_result = main.ONOSbench.onos_package()
+
+        main.step("Installing ONOS package")
+        install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
+        install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
+        install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
+
+        main.step("Set cell for ONOScli env")
+        main.ONOS1cli.set_cell(cell_name)
+        main.ONOS2cli.set_cell(cell_name)
+        main.ONOS3cli.set_cell(cell_name)
+
+        time.sleep(5)
+
+        main.step("Start onos cli")
+        cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
+        cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
+        cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
+
+        main.step("Enable metrics feature")
+        main.ONOS1cli.feature_install("onos-app-metrics")
+        main.ONOS2cli.feature_install("onos-app-metrics")
+        main.ONOS3cli.feature_install("onos-app-metrics")
+
+        utilities.assert_equals(expect=main.TRUE,
+                actual = cell_file_result and cell_apply_result and\
+                         verify_cell_result and checkout_result and\
+                         pull_result and build_result and\
+                         install1_result and install2_result and\
+                         install3_result,
+                onpass="ONOS started successfully",
+                onfail="Failed to start ONOS")
+
+    def CASE2(self, main):
+        '''
+        Single intent add latency
+
+        '''
+        import time
+        import json
+        import requests
+        import os
+
+        ONOS1_ip = main.params['CTRL']['ip1']
+        ONOS2_ip = main.params['CTRL']['ip2']
+        ONOS3_ip = main.params['CTRL']['ip3']
+        ONOS_user = main.params['CTRL']['user']
+
+        default_sw_port = main.params['CTRL']['port1']
+
+        #number of iterations of case
+        num_iter = main.params['TEST']['numIter']
+
+        #Timestamp keys for json metrics output
+        submit_time = main.params['JSON']['submittedTime']
+        install_time = main.params['JSON']['installedTime']
+        wdRequest_time = main.params['JSON']['wdRequestTime']
+        withdrawn_time = main.params['JSON']['withdrawnTime']
+
+        devices_json_str = main.ONOS1cli.devices()
+        devices_json_obj = json.loads(devices_json_str)
+
+        device_id_list = []
+
+        #Obtain device id list in ONOS format.
+        #They should already be in order (1,2,3,10,11,12,13, etc)
+        for device in devices_json_obj:
+            device_id_list.append(device['id'])
+
+        intent_add_lat_list = []
+
+        for i in range(0, int(num_iter)):
+            #add_point_intent(ingr_device, ingr_port, 
+            #                 egr_device, egr_port)
+            main.ONOS1cli.add_point_intent(
+                device_id_list[0], 2,
+                device_id_list[2], 1)
+        
+            #Allow some time for intents to propagate
+            time.sleep(5)
+
+            #Obtain metrics from ONOS 1, 2, 3
+            intents_json_str_1 = main.ONOS1cli.intents_events_metrics()
+            intents_json_str_2 = main.ONOS2cli.intents_events_metrics()
+            intents_json_str_3 = main.ONOS3cli.intents_events_metrics()
+
+            intents_json_obj_1 = json.loads(intents_json_str_1)
+            intents_json_obj_2 = json.loads(intents_json_str_2)
+            intents_json_obj_3 = json.loads(intents_json_str_3)
+
+            #Parse values from the json object
+            intent_submit_1 = \
+                    intents_json_obj_1[submit_time]['value']
+            intent_submit_2 = \
+                    intents_json_obj_2[submit_time]['value']
+            intent_submit_3 = \
+                    intents_json_obj_3[submit_time]['value']
+
+            intent_install_1 = \
+                    intents_json_obj_1[install_time]['value']
+            intent_install_2 = \
+                    intents_json_obj_2[install_time]['value']
+            intent_install_3 = \
+                    intents_json_obj_3[install_time]['value']
+
+            intent_install_lat_1 = \
+                    int(intent_install_1) - int(intent_submit_1)
+            intent_install_lat_2 = \
+                    int(intent_install_2) - int(intent_submit_2)
+            intent_install_lat_3 = \
+                    int(intent_install_3) - int(intent_submit_3)
+            
+            intent_install_lat_avg = \
+                    (intent_install_lat_1 + 
+                     intent_install_lat_2 +
+                     intent_install_lat_3 ) / 3
+
+            main.log.info("Intent add latency avg for iteration "+str(i)+
+                    ": "+str(intent_install_lat_avg))
+
+            if intent_install_lat_avg > 0.0 and \
+               intent_install_lat_avg < 1000:
+                intent_add_lat_list.append(intent_install_lat_avg)
+            else:
+                main.log.info("Intent add latency exceeded "+
+                        "threshold. Skipping iteration "+str(i))
+
+            time.sleep(3)
+            
+            #TODO: Possibly put this in the driver function
+            main.log.info("Removing intents for next iteration")
+            json_temp = \
+                    main.ONOS1cli.intents(json_format=True)
+            json_obj_intents = json.loads(json_temp)
+            if json_obj_intents:
+                for intents in json_obj_intents:
+                    temp_id = intents['id']
+                    main.ONOS1cli.remove_intent(temp_id)
+                    main.log.info("Removing intent id: "+
+                        str(temp_id))
+                    main.ONOS1cli.remove_intent(temp_id)
+            else:
+                main.log.info("Intents were not installed correctly")
+
+            time.sleep(5)
+
+        intent_add_lat_min = min(intent_add_lat_list)
+        intent_add_lat_max = max(intent_add_lat_list)
+        intent_add_lat_avg = sum(intent_add_lat_list) /\
+                             len(intent_add_lat_list)
+        #END ITERATION FOR LOOP
+        main.log.report("Single intent add latency - \n"+
+                "Min: "+str(intent_add_lat_min)+" ms\n"+
+                "Max: "+str(intent_add_lat_max)+" ms\n"+
+                "Avg: "+str(intent_add_lat_avg)+" ms\n")
+
+
+    def CASE3(self, main):
+        '''
+        CASE3 coming soon
+        '''
+
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.topo b/TestON/tests/IntentPerfNext/IntentPerfNext.topo
new file mode 100644
index 0000000..fbde0e1
--- /dev/null
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.topo
@@ -0,0 +1,73 @@
+<TOPOLOGY>
+    <COMPONENT>
+        
+        <ONOSbench>
+            <host>10.128.174.10</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>OnosDriver</type>
+            <connect_order>1</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </ONOSbench>
+
+        <ONOS1cli>
+            <host>10.128.174.10</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>OnosCliDriver</type>
+            <connect_order>2</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </ONOS1cli>
+
+        <ONOS2cli>
+            <host>10.128.174.10</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>OnosCliDriver</type>
+            <connect_order>2</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </ONOS2cli>
+        
+        <ONOS3cli>
+            <host>10.128.174.10</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>OnosCliDriver</type>
+            <connect_order>2</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </ONOS3cli>
+
+        <ONOS1>
+            <host>10.128.174.1</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>OnosDriver</type>
+            <connect_order>3</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </ONOS1>
+
+        <Mininet1>
+            <host>10.128.10.90</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>MininetCliDriver</type>
+            <connect_order>4</connect_order>
+            <COMPONENTS>
+                <arg1> --custom topo-intentFlower.py </arg1>
+                <arg2> --arp --mac --topo mytopo</arg2>
+                <arg3> </arg3>
+                <controller> remote,ip=10.128.174.1 </controller>
+            </COMPONENTS>
+        </Mininet1>
+
+        <Mininet2>
+            <host>10.128.10.90</host>
+            <user>admin</user>
+            <password>onos_test</password>
+            <type>RemoteMininetDriver</type>
+            <connect_order>5</connect_order>
+            <COMPONENTS> </COMPONENTS>
+        </Mininet2>
+
+    </COMPONENT>
+</TOPOLOGY>
diff --git a/TestON/tests/MininetSlicing/MininetSlicing.py b/TestON/tests/MininetSlicing/MininetSlicing.py
index ac723fb..86b3ddc 100644
--- a/TestON/tests/MininetSlicing/MininetSlicing.py
+++ b/TestON/tests/MininetSlicing/MininetSlicing.py
@@ -1,17 +1,4 @@
-'''
-	
- *   TestON is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 2 of the License, or
- *   (at your option) any later version.
 
- *   TestON is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
-
-
-'''
 class MininetSlicing :
 
     def __init__(self) :
@@ -81,5 +68,4 @@
     
     
     
-    
-    
+    
\ No newline at end of file
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.params b/TestON/tests/ONOSNextTest/ONOSNextTest.params
index 019b746..d600eae 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.params
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.params
@@ -8,7 +8,7 @@
     </ENV>
 
     <CTRL>
-        <ip1>10.128.20.11</ip1>
+        <ip1>10.128.174.1</ip1>
         <port1>6633</port1>
     </CTRL>
 
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.py b/TestON/tests/ONOSNextTest/ONOSNextTest.py
index de441ba..3496771 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.py
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.py
@@ -30,7 +30,7 @@
         ONOS1_port = main.params['CTRL']['port1']
         
         git_pull_trigger = main.params['GIT']['autoPull']
-        git_checkout_branch = main.params['GIT']['branch']
+        git_checkout_branch = main.params['GIT']['checkout']
 
         main.case("Setting up test environment")
         
@@ -39,7 +39,7 @@
         cell_file_result = main.ONOSbench.create_cell_file(
                 "10.128.20.10", "temp_cell_2", "10.128.10.90",
                 "onos-core-trivial,onos-app-fwd",
-                "10.128.20.11")
+                "10.128.174.1")
 
         main.step("Applying cell variable to environment")
         #cell_result = main.ONOSbench.set_cell(cell_name)
@@ -180,7 +180,8 @@
         main.case("Testing the ONOS-cli")
         
         main.step("Set cell for ONOS-cli environment")
-        main.ONOScli.set_cell(cell_name)
+        #main.ONOScli.set_cell(cell_name)
+        main.ONOScli.set_cell("temp_cell_2")
 
         main.step("Start ONOS-cli")
         main.ONOScli.start_onos_cli(ONOS1_ip)
@@ -198,12 +199,12 @@
             main.log.info("Node successfully added")
 
         main.step("Add a correct node")
-        node_result = main.ONOScli.add_node("111", "10.128.20.12")
+        node_result = main.ONOScli.add_node("111", "10.128.174.2")
 
         main.step("Assign switches and list devices")
         for i in range(1,8):
             main.Mininet2.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+
-                    " tcp:10.128.20.11")
+                    " tcp:10.128.174.1")
             main.Mininet2.handle.expect("mininet>")
         #Need to sleep to allow switch add processing
         time.sleep(5)
@@ -315,6 +316,19 @@
             main.log.info(get_intent_result)
         #*******************************************
 
+        main.step("Print intents in json format")
+        intents = main.ONOScli.intents(json_format = True)
+        main.log.info(intents)
+
+        main.step("Add eth options in point-to-point intent")
+        ptp_eth = main.ONOScli.add_point_intent(
+                devices_id_list[2], 1, devices_id_list[3], 2,
+                ethSrc = "00:02", ethDst = "00:03")
+        main.log.info(ptp_eth)
+
+        main.step("Print intents with eth options")
+        intents = main.ONOScli.intents()
+        main.log.info(intents)
 ######
 #jhall@onlab.us
 #andrew@onlab.us
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.topo b/TestON/tests/ONOSNextTest/ONOSNextTest.topo
index 118e57c..0c84cc7 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.topo
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.topo
@@ -20,7 +20,7 @@
         </ONOScli>
 
         <ONOS1>
-            <host>10.128.20.11</host>
+            <host>10.128.174.1</host>
             <user>sdn</user>
             <password>rocks</password>
             <type>OnosDriver</type>
diff --git a/TestON/tests/TopoPerfNext/TopoPerfNext.params b/TestON/tests/TopoPerfNext/TopoPerfNext.params
index 4a8de48..82d492c 100644
--- a/TestON/tests/TopoPerfNext/TopoPerfNext.params
+++ b/TestON/tests/TopoPerfNext/TopoPerfNext.params
@@ -1,5 +1,5 @@
 <PARAMS>
-    <testcases>1,5</testcases>
+    <testcases>1,2,3,4</testcases>
 
     <ENV>
         <cellName>topo_perf_test</cellName>
@@ -32,8 +32,8 @@
 
     <TEST>
         #Number of times to iterate each case
-        <numIter>2</numIter>
-        <numSwitch>10</numSwitch>         
+        <numIter>10</numIter>
+        <numSwitch>100</numSwitch>         
     </TEST>
 
     <JSON>
diff --git a/TestON/tests/TopoPerfNext/TopoPerfNext.py b/TestON/tests/TopoPerfNext/TopoPerfNext.py
index c8291e8..1e4b4c0 100644
--- a/TestON/tests/TopoPerfNext/TopoPerfNext.py
+++ b/TestON/tests/TopoPerfNext/TopoPerfNext.py
@@ -326,14 +326,11 @@
             
             #NOTE: ofp - delta measurements are occasionally negative
             #      due to system time misalignment.
-            #TODO: Implement ptp across all clusters
-            #Just add the calculation to list for now
             latency_ofp_to_device_list.append(avg_delta_ofp_device)
 
             #TODO:
             #Fetch logs upon threshold excess
 
-            
             main.log.info("ONOS1 delta end-to-end: "+
                     str(delta_graph_1) + " ms")
             main.log.info("ONOS2 delta end-to-end: "+
@@ -355,12 +352,12 @@
             main.log.info("ONOS3 delta device - t0: "+
                     str(delta_device_3) + " ms")
           
-            main.log.info("ONOS1 delta OFP - device: "+
-                    str(delta_ofp_device_1) + " ms")
-            main.log.info("ONOS2 delta OFP - device: "+
-                    str(delta_ofp_device_2) + " ms")
-            main.log.info("ONOS3 delta OFP - device: "+
-                    str(delta_ofp_device_3) + " ms")
+            #main.log.info("ONOS1 delta OFP - device: "+
+            #        str(delta_ofp_device_1) + " ms")
+            #main.log.info("ONOS2 delta OFP - device: "+
+            #        str(delta_ofp_device_2) + " ms")
+            #main.log.info("ONOS3 delta OFP - device: "+
+            #        str(delta_ofp_device_3) + " ms")
 
             main.step("Remove switch from controller")
             main.Mininet1.delete_sw_controller("s1")
@@ -433,10 +430,6 @@
                 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
                 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
                 "Avg: "+str(latency_ofp_to_graph_avg))
-        main.log.report("Switch add - OFP-to-Device latency: \n"+\
-                "Min: "+str(latency_ofp_to_device_min)+"\n"+\
-                "Max: "+str(latency_ofp_to_device_max)+"\n"+\
-                "Avg: "+str(latency_ofp_to_device_avg))
         main.log.report("Switch add - t0-to-Device latency: \n"+\
                 "Min: "+str(latency_t0_to_device_min)+"\n"+\
                 "Max: "+str(latency_t0_to_device_max)+"\n"+\
@@ -467,7 +460,8 @@
         ONOS_user = main.params['CTRL']['user']
 
         default_sw_port = main.params['CTRL']['port1']
-       
+      
+        assertion = main.TRUE
         #Number of iterations of case
         num_iter = main.params['TEST']['numIter']
        
@@ -493,6 +487,11 @@
         main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
                 port1=default_sw_port)
 
+        #Give enough time for metrics to propagate the 
+        #assign controller event. Otherwise, these events may
+        #carry over to our measurements
+        time.sleep(10)
+
         main.step("Verify switch is assigned correctly")
         result_s1 = main.Mininet1.get_sw_controller(sw="s1")
         result_s2 = main.Mininet1.get_sw_controller(sw="s2")
@@ -519,7 +518,7 @@
             main.Mininet2.handle.sendline("sudo ifconfig "+
                     interface_config+" down")
             main.Mininet2.handle.expect("\$")
-            time.sleep(20)
+            time.sleep(10)
 
             main.ONOS1.tshark_stop()
             time.sleep(5)
@@ -544,11 +543,15 @@
             
             f_port_down.close()
 
+            main.log.info("TEST tshark obj: "+str(obj_down))
+
             main.step("Obtain t1 by REST call")
             json_str_1 = main.ONOS1cli.topology_events_metrics()
             json_str_2 = main.ONOS2cli.topology_events_metrics()
             json_str_3 = main.ONOS3cli.topology_events_metrics()
 
+            main.log.info("TEST json_str 1: "+str(json_str_1))
+
             json_obj_1 = json.loads(json_str_1)
             json_obj_2 = json.loads(json_str_2)
             json_obj_3 = json.loads(json_str_3)
@@ -564,11 +567,6 @@
             graph_timestamp_3 = \
                     json_obj_3[graphTimestamp]['value']
 
-            #TODO: Test purposes, remove later
-            main.log.info("json_timestamp graph: "+str(graph_timestamp_1))
-            main.log.info("json_timestamp graph: "+str(graph_timestamp_2))
-            main.log.info("json_timestamp graph: "+str(graph_timestamp_3))
-
             #Obtain device timestamp. This timestamp captures
             #the epoch time at which the device event happened
             device_timestamp_1 = \
@@ -577,11 +575,6 @@
                     json_obj_2[deviceTimestamp]['value'] 
             device_timestamp_3 = \
                     json_obj_3[deviceTimestamp]['value'] 
-            
-            #TODO: Test purposes, remove later
-            main.log.info("json_timestamp device: "+str(device_timestamp_1))
-            main.log.info("json_timestamp device: "+str(device_timestamp_2))
-            main.log.info("json_timestamp device: "+str(device_timestamp_3))
 
             #Get delta between graph event and OFP 
             pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
@@ -603,16 +596,18 @@
             pt_down_graph_to_ofp_avg =\
                     (int(pt_down_graph_to_ofp_1) +
                      int(pt_down_graph_to_ofp_2) + 
-                     int(pt_down_graph_to_ofp_3)) / 3
+                     int(pt_down_graph_to_ofp_3)) / 3.0
             pt_down_device_to_ofp_avg = \
                     (int(pt_down_device_to_ofp_1) + 
                      int(pt_down_device_to_ofp_2) +
-                     int(pt_down_device_to_ofp_3)) / 3
+                     int(pt_down_device_to_ofp_3)) / 3.0
 
-            if pt_down_graph_to_ofp_avg > 0 and \
+            if pt_down_graph_to_ofp_avg > 0.0 and \
                     pt_down_graph_to_ofp_avg < 1000:
                 port_down_graph_to_ofp_list.append(
-                        pt_down_graph_to_ofp_avg)
+                    pt_down_graph_to_ofp_avg)
+                main.log.info("Port down: graph to ofp avg: "+
+                    str(pt_down_graph_to_ofp_avg) + " ms")
             else:
                 main.log.info("Average port down graph-to-ofp result" +
                         " exceeded the threshold: "+
@@ -621,34 +616,26 @@
             if pt_down_device_to_ofp_avg > 0 and \
                     pt_down_device_to_ofp_avg < 1000:
                 port_down_device_to_ofp_list.append(
-                        pt_down_device_to_ofp_avg)
+                    pt_down_device_to_ofp_avg)
+                main.log.info("Port down: device to ofp avg: "+
+                    str(pt_down_device_to_ofp_avg) + " ms")
             else:
                 main.log.info("Average port down device-to-ofp result" +
                         " exceeded the threshold: "+
                         str(pt_down_device_to_ofp_avg))
 
-            #TODO: Remove these logs. For test purposes only
-            main.log.info("Delta1 down graph: "+str(pt_down_graph_to_ofp_1))
-            main.log.info("Delta2 down graph: "+str(pt_down_graph_to_ofp_2))
-            main.log.info("Delta3 down graph: "+str(pt_down_graph_to_ofp_3))
-            
-            main.log.info("Delta1 down device: "+
-                    str(pt_down_device_to_ofp_1))
-            main.log.info("Delta2 down device: "+
-                    str(pt_down_device_to_ofp_2))
-            main.log.info("Delta3 down device: "+
-                    str(pt_down_device_to_ofp_3))
-        
             #Port up events 
             main.step("Enable port and obtain timestamp")
             main.step("Starting wireshark capture for port status up")
             main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
-            time.sleep(10)
+            time.sleep(5)
 
             main.Mininet2.handle.sendline("sudo ifconfig "+
                     interface_config+" up")
             main.Mininet2.handle.expect("\$")
-            time.sleep(20)
+            time.sleep(10)
+            
+            main.ONOS1.tshark_stop()
 
             os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
                     tshark_port_up+" /tmp/")
@@ -668,7 +655,6 @@
             f_port_up.close()
 
             main.step("Obtain t1 by REST call")
-            #TODO: Implement json object parsing here
             json_str_1 = main.ONOS1cli.topology_events_metrics()
             json_str_2 = main.ONOS2cli.topology_events_metrics()
             json_str_3 = main.ONOS3cli.topology_events_metrics()
@@ -725,6 +711,8 @@
                     pt_up_graph_to_ofp_avg < 1000:
                 port_up_graph_to_ofp_list.append(
                         pt_up_graph_to_ofp_avg)
+                main.log.info("Port down: graph to ofp avg: "+
+                    str(pt_up_graph_to_ofp_avg) + " ms")
             else:
                 main.log.info("Average port up graph-to-ofp result"+
                         " exceeded the threshold: "+
@@ -734,38 +722,77 @@
                     pt_up_device_to_ofp_avg < 1000:
                 port_up_device_to_ofp_list.append(
                         pt_up_device_to_ofp_avg)
+                main.log.info("Port up: device to ofp avg: "+
+                    str(pt_up_device_to_ofp_avg) + " ms")
             else:
-                main.log.info("Average port up graph-to-ofp result"+
+                main.log.info("Average port up device-to-ofp result"+
                         " exceeded the threshold: "+
                         str(pt_up_device_to_ofp_avg))
-
-            #TODO: Remove these logs. For test purposes only
-            main.log.info("Delta1 up graph: "+str(pt_up_graph_to_ofp_1))
-            main.log.info("Delta2 up graph: "+str(pt_up_graph_to_ofp_2))
-            main.log.info("Delta3 up graph: "+str(pt_up_graph_to_ofp_3))
-             
-            main.log.info("Delta1 down device: "+
-                    str(pt_up_device_to_ofp_1))
-            main.log.info("Delta2 down device: "+
-                    str(pt_up_device_to_ofp_2))
-            main.log.info("Delta3 down device: "+
-                    str(pt_up_device_to_ofp_3))
             
             #END ITERATION FOR LOOP
         
+        #Check all list for latency existence and set assertion
+        if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\
+           and port_up_graph_to_ofp_list and port_up_device_to_ofp_list):
+            assertion = main.TRUE
+
+        #Calculate and report latency measurements
         port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
         port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
         port_down_graph_to_ofp_avg = \
                 (sum(port_down_graph_to_ofp_list) / 
                  len(port_down_graph_to_ofp_list))
         
-        main.log.report("Port up graph-to-ofp Min: ")
-        main.log.report("Port up graph-to-ofp Max: ")
-        main.log.report("Port up graph-to-ofp Avg: ")
-            
+        main.log.report("Port down graph-to-ofp Min: "+
+                str(port_down_graph_to_ofp_min)+" ms  Max: "+
+                str(port_down_graph_to_ofp_max)+" ms  Avg: "+
+                str(port_down_graph_to_ofp_avg))
+        
+        port_down_device_to_ofp_min = min(port_down_device_to_ofp_list)
+        port_down_device_to_ofp_max = max(port_down_device_to_ofp_list)
+        port_down_device_to_ofp_avg = \
+                (sum(port_down_device_to_ofp_list) /\
+                 len(port_down_device_to_ofp_list))
+        
+        main.log.report("Port down device-to-ofp Min: "+
+                str(port_down_device_to_ofp_min)+" ms  Max: "+
+                str(port_down_device_to_ofp_max)+" ms  Avg: "+
+                str(port_down_device_to_ofp_avg))
+        
+        port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list)
+        port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list)
+        port_up_graph_to_ofp_avg = \
+                (sum(port_up_graph_to_ofp_list) /\
+                 len(port_up_graph_to_ofp_list))
+        
+        main.log.report("Port up graph-to-ofp Min: "+
+                str(port_up_graph_to_ofp_min)+" ms  Max: "+
+                str(port_up_graph_to_ofp_max)+" ms  Avg: "+
+                str(port_up_graph_to_ofp_avg))
+          
+        port_up_device_to_ofp_min = min(port_up_device_to_ofp_list)
+        port_up_device_to_ofp_max = max(port_up_device_to_ofp_list)
+        port_up_device_to_ofp_avg = \
+                (sum(port_up_device_to_ofp_list) /\
+                 len(port_up_device_to_ofp_list))
+        
+        main.log.report("Port up device-to-ofp Min: "+
+                str(port_up_device_to_ofp_min)+" ms  Max: "+
+                str(port_up_device_to_ofp_max)+" ms  Avg: "+
+                str(port_up_device_to_ofp_avg))
+
+        utilities.assert_equals(expect=main.TRUE, actual=assertion,
+                onpass="Port discovery latency calculation successful",
+                onfail="Port discovery test failed")
+
     def CASE4(self, main):
         '''
         Link down event using loss rate 100%
+        
+        Important:
+            Use a simple 2 switch topology with 1 link between
+            the two switches. Ensure that mac addresses of the 
+            switches are 1 / 2 respectively
         '''
         import time
         import subprocess
@@ -787,7 +814,8 @@
         #These are subject to change, hence moved into params
         deviceTimestamp = main.params['JSON']['deviceTimestamp']
         linkTimestamp = main.params['JSON']['linkTimestamp'] 
-           
+        graphTimestamp = main.params['JSON']['graphTimestamp']
+
         assertion = main.TRUE
         #Link event timestamp to system time list
         link_down_link_to_system_list = []
@@ -808,16 +836,13 @@
         main.step("Verifying switch assignment")
         result_s1 = main.Mininet1.get_sw_controller(sw="s1")
         result_s2 = main.Mininet1.get_sw_controller(sw="s2")
-
-        if result_s1 == main.TRUE and result_s2 == main.TRUE:
-            main.log.report("Switches s1, s2 assigned successfully")
-        else:
-            main.log.error("Error assigning switches s1 and s2")
-            assertion = main.FALSE
           
         #Allow time for events to finish before taking measurements
         time.sleep(10)
 
+        link_down1 = False
+        link_down2 = False
+        link_down3 = False
         #Start iteration of link event test
         for i in range(0, int(num_iter)):
             main.step("Getting initial system time as t0")
@@ -828,23 +853,357 @@
             main.Mininet1.handle.sendline(
                     "sh tc qdisc add dev s1-eth1 root netem loss 100%")
 
-            #TODO: Iterate through topology count to detect 
-            #      link down discovery. Take timestamp and
-            #      gather list for num_iter
-         
+            #TODO: Iterate through 'links' command to verify that
+            #      link s1 -> s2 went down (loop timeout 30 seconds) 
+            #      on all 3 ONOS instances
+            main.log.info("Checking ONOS for link update")
+            loop_count = 0
+            while( not (link_down1 and link_down2 and link_down3)\
+                    and loop_count < 30 ):
+                json_str1 = main.ONOS1cli.links()
+                json_str2 = main.ONOS2cli.links()
+                json_str3 = main.ONOS3cli.links()
+                
+                if not (json_str1 and json_str2 and json_str3):
+                    main.log.error("CLI command returned error ")
+                    break
+                else:
+                    json_obj1 = json.loads(json_str1)
+                    json_obj2 = json.loads(json_str2)
+                    json_obj3 = json.loads(json_str3)
+                for obj1 in json_obj1:
+                    if '01' not in obj1['src']['device']:
+                        link_down1 = True
+                        main.log.report("Link down from "+
+                                "s1 -> s2 on ONOS1 detected")
+                for obj2 in json_obj2:
+                    if '01' not in obj2['src']['device']:
+                        link_down2 = True
+                        main.log.report("Link down from "+
+                                "s1 -> s2 on ONOS2 detected")
+                for obj3 in json_obj3:
+                    if '01' not in obj3['src']['device']:
+                        link_down3 = True
+                        main.log.report("Link down from "+
+                                "s1 -> s2 on ONOS3 detected")
+                
+                loop_count += 1
+                #If CLI doesn't like the continuous requests
+                #and exits in this loop, increase the sleep here.
+                #Consequently, while loop timeout will increase
+                time.sleep(1)
+    
+            #Give time for metrics measurement to catch up
+            #NOTE: May need to be configured more accurately
+            time.sleep(10)
+            #If we exited the while loop and link down 1,2,3 are still 
+            #false, then ONOS has failed to discover link down event
+            if not (link_down1 and link_down2 and link_down3):
+                main.log.info("Link down discovery failed")
+                
+                link_down_lat_graph1 = 0
+                link_down_lat_graph2 = 0
+                link_down_lat_graph3 = 0
+                link_down_lat_device1 = 0
+                link_down_lat_device2 = 0
+                link_down_lat_device3 = 0
+                
+                assertion = main.FALSE
+            else:
+                json_topo_metrics_1 =\
+                        main.ONOS1cli.topology_events_metrics()
+                json_topo_metrics_2 =\
+                        main.ONOS2cli.topology_events_metrics()
+                json_topo_metrics_3 =\
+                        main.ONOS3cli.topology_events_metrics()
+                json_topo_metrics_1 = json.loads(json_topo_metrics_1)
+                json_topo_metrics_2 = json.loads(json_topo_metrics_2)
+                json_topo_metrics_3 = json.loads(json_topo_metrics_3)
+
+                main.log.info("Obtaining graph and device timestamp")
+                graph_timestamp_1 = \
+                    json_topo_metrics_1[graphTimestamp]['value']
+                graph_timestamp_2 = \
+                    json_topo_metrics_2[graphTimestamp]['value']
+                graph_timestamp_3 = \
+                    json_topo_metrics_3[graphTimestamp]['value']
+
+                link_timestamp_1 = \
+                    json_topo_metrics_1[linkTimestamp]['value']
+                link_timestamp_2 = \
+                    json_topo_metrics_2[linkTimestamp]['value']
+                link_timestamp_3 = \
+                    json_topo_metrics_3[linkTimestamp]['value']
+
+                if graph_timestamp_1 and graph_timestamp_2 and\
+                        graph_timestamp_3 and link_timestamp_1 and\
+                        link_timestamp_2 and link_timestamp_3:
+                    link_down_lat_graph1 = int(graph_timestamp_1) -\
+                            timestamp_link_down_t0
+                    link_down_lat_graph2 = int(graph_timestamp_2) -\
+                            timestamp_link_down_t0
+                    link_down_lat_graph3 = int(graph_timestamp_3) -\
+                            timestamp_link_down_t0
+                
+                    link_down_lat_link1 = int(link_timestamp_1) -\
+                            timestamp_link_down_t0
+                    link_down_lat_link2 = int(link_timestamp_2) -\
+                            timestamp_link_down_t0
+                    link_down_lat_link3 = int(link_timestamp_3) -\
+                            timestamp_link_down_t0
+                else:
+                    main.log.error("There was an error calculating"+
+                        " the delta for link down event")
+                    link_down_lat_graph1 = 0
+                    link_down_lat_graph2 = 0
+                    link_down_lat_graph3 = 0
+                    
+                    link_down_lat_device1 = 0
+                    link_down_lat_device2 = 0
+                    link_down_lat_device3 = 0
+        
+            main.log.report("Link down latency ONOS1 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_down_lat_graph1)+" ms")
+            main.log.report("Link down latency ONOS2 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_down_lat_graph2)+" ms")
+            main.log.report("Link down latency ONOS3 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_down_lat_graph3)+" ms")
+            
+            main.log.report("Link down latency ONOS1 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_down_lat_link1)+" ms")
+            main.log.report("Link down latency ONOS2 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_down_lat_link2)+" ms")
+            main.log.report("Link down latency ONOS3 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_down_lat_link3))
+      
+            #Calculate avg of node calculations
+            link_down_lat_graph_avg =\
+                    (link_down_lat_graph1 +
+                     link_down_lat_graph2 +
+                     link_down_lat_graph3) / 3.0
+            link_down_lat_link_avg =\
+                    (link_down_lat_link1 +
+                     link_down_lat_link2 +
+                     link_down_lat_link3) / 3.0
+
+            #Set threshold and append latency to list
+            if link_down_lat_graph_avg > 0.0 and\
+               link_down_lat_graph_avg < 30000:
+                link_down_graph_to_system_list.append(
+                        link_down_lat_graph_avg)
+            else:
+                main.log.info("Link down latency exceeded threshold")
+                main.log.info("Results for iteration "+str(i)+
+                        "have been omitted")
+            if link_down_lat_link_avg > 0.0 and\
+               link_down_lat_link_avg < 30000:
+                link_down_link_to_system_list.append(
+                        link_down_lat_link_avg)
+            else:
+                main.log.info("Link down latency exceeded threshold")
+                main.log.info("Results for iteration "+str(i)+
+                        "have been omitted")
+
+            #NOTE: To remove loss rate and measure latency:
+            #       'sh tc qdisc del dev s1-eth1 root'
+            timestamp_link_up_t0 = time.time() * 1000
+            main.Mininet1.handle.sendline("sh tc qdisc del dev "+
+                    "s1-eth1 root")
+            main.Mininet1.handle.expect("mininet>")
+            
+            main.log.info("Checking ONOS for link update")
+            
+            link_down1 = True
+            link_down2 = True
+            link_down3 = True
+            loop_count = 0
+            while( (link_down1 and link_down2 and link_down3)\
+                    and loop_count < 30 ):
+                json_str1 = main.ONOS1cli.links()
+                json_str2 = main.ONOS2cli.links()
+                json_str3 = main.ONOS3cli.links()
+                if not (json_str1 and json_str2 and json_str3):
+                    main.log.error("CLI command returned error ")
+                    break
+                else:
+                    json_obj1 = json.loads(json_str1)
+                    json_obj2 = json.loads(json_str2)
+                    json_obj3 = json.loads(json_str3)
+                
+                for obj1 in json_obj1:
+                    if '01' in obj1['src']['device']:
+                        link_down1 = False 
+                        main.log.report("Link up from "+
+                            "s1 -> s2 on ONOS1 detected")
+                for obj2 in json_obj2:
+                    if '01' in obj2['src']['device']:
+                        link_down2 = False 
+                        main.log.report("Link up from "+
+                            "s1 -> s2 on ONOS2 detected")
+                for obj3 in json_obj3:
+                    if '01' in obj3['src']['device']:
+                        link_down3 = False 
+                        main.log.report("Link up from "+
+                            "s1 -> s2 on ONOS3 detected")
+                
+                loop_count += 1
+                time.sleep(1)
+            
+            if (link_down1 and link_down2 and link_down3):
+                main.log.info("Link up discovery failed")
+                
+                link_up_lat_graph1 = 0
+                link_up_lat_graph2 = 0
+                link_up_lat_graph3 = 0
+                link_up_lat_device1 = 0
+                link_up_lat_device2 = 0
+                link_up_lat_device3 = 0
+                
+                assertion = main.FALSE
+            else:
+                json_topo_metrics_1 =\
+                        main.ONOS1cli.topology_events_metrics()
+                json_topo_metrics_2 =\
+                        main.ONOS2cli.topology_events_metrics()
+                json_topo_metrics_3 =\
+                        main.ONOS3cli.topology_events_metrics()
+                json_topo_metrics_1 = json.loads(json_topo_metrics_1)
+                json_topo_metrics_2 = json.loads(json_topo_metrics_2)
+                json_topo_metrics_3 = json.loads(json_topo_metrics_3)
+
+                main.log.info("Obtaining graph and device timestamp")
+                graph_timestamp_1 = \
+                    json_topo_metrics_1[graphTimestamp]['value']
+                graph_timestamp_2 = \
+                    json_topo_metrics_2[graphTimestamp]['value']
+                graph_timestamp_3 = \
+                    json_topo_metrics_3[graphTimestamp]['value']
+
+                link_timestamp_1 = \
+                    json_topo_metrics_1[linkTimestamp]['value']
+                link_timestamp_2 = \
+                    json_topo_metrics_2[linkTimestamp]['value']
+                link_timestamp_3 = \
+                    json_topo_metrics_3[linkTimestamp]['value']
+
+                if graph_timestamp_1 and graph_timestamp_2 and\
+                        graph_timestamp_3 and link_timestamp_1 and\
+                        link_timestamp_2 and link_timestamp_3:
+                    link_up_lat_graph1 = int(graph_timestamp_1) -\
+                            timestamp_link_up_t0
+                    link_up_lat_graph2 = int(graph_timestamp_2) -\
+                            timestamp_link_up_t0
+                    link_up_lat_graph3 = int(graph_timestamp_3) -\
+                            timestamp_link_up_t0
+                
+                    link_up_lat_link1 = int(link_timestamp_1) -\
+                            timestamp_link_up_t0
+                    link_up_lat_link2 = int(link_timestamp_2) -\
+                            timestamp_link_up_t0
+                    link_up_lat_link3 = int(link_timestamp_3) -\
+                            timestamp_link_up_t0
+                else:
+                    main.log.error("There was an error calculating"+
+                        " the delta for link down event")
+                    link_up_lat_graph1 = 0
+                    link_up_lat_graph2 = 0
+                    link_up_lat_graph3 = 0
+                    
+                    link_up_lat_device1 = 0
+                    link_up_lat_device2 = 0
+                    link_up_lat_device3 = 0
+        
+            main.log.info("Link up latency ONOS1 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_up_lat_graph1)+" ms")
+            main.log.info("Link up latency ONOS2 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_up_lat_graph2)+" ms")
+            main.log.info("Link up latency ONOS3 iteration "+
+                    str(i)+" (end-to-end): "+
+                    str(link_up_lat_graph3)+" ms")
+            
+            main.log.info("Link up latency ONOS1 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_up_lat_link1)+" ms")
+            main.log.info("Link up latency ONOS2 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_up_lat_link2)+" ms")
+            main.log.info("Link up latency ONOS3 iteration "+
+                    str(i)+" (link-event-to-system-timestamp): "+
+                    str(link_up_lat_link3))
+      
+            #Calculate avg of node calculations
+            link_up_lat_graph_avg =\
+                    (link_up_lat_graph1 +
+                     link_up_lat_graph2 +
+                     link_up_lat_graph3) / 3.0
+            link_up_lat_link_avg =\
+                    (link_up_lat_link1 +
+                     link_up_lat_link2 +
+                     link_up_lat_link3) / 3.0
+
+            #Set threshold and append latency to list
+            if link_up_lat_graph_avg > 0.0 and\
+               link_up_lat_graph_avg < 30000:
+                link_up_graph_to_system_list.append(
+                        link_up_lat_graph_avg)
+            else:
+                main.log.info("Link up latency exceeded threshold")
+                main.log.info("Results for iteration "+str(i)+
+                        "have been omitted")
+            if link_up_lat_link_avg > 0.0 and\
+               link_up_lat_link_avg < 30000:
+                link_up_link_to_system_list.append(
+                        link_up_lat_link_avg)
+            else:
+                main.log.info("Link up latency exceeded threshold")
+                main.log.info("Results for iteration "+str(i)+
+                        "have been omitted")
+
+        #Calculate min, max, avg of list and report
+        link_down_min = min(link_down_graph_to_system_list)
+        link_down_max = max(link_down_graph_to_system_list)
+        link_down_avg = sum(link_down_graph_to_system_list) / \
+                        len(link_down_graph_to_system_list)
+        link_up_min = min(link_up_graph_to_system_list)
+        link_up_max = max(link_up_graph_to_system_list)
+        link_up_avg = sum(link_up_graph_to_system_list) / \
+                        len(link_up_graph_to_system_list)
+
+        main.log.report("Link down latency - Min: "+
+                str(link_down_min)+"ms  Max: "+
+                str(link_down_max)+"ms  Avg: "+
+                str(link_down_avg)+"ms")
+        main.log.report("Link up latency - Min: "+
+                str(link_up_min)+"ms  Max: "+
+                str(link_up_max)+"ms  Avg: "+
+                str(link_up_avg)+"ms")
+
+        utilities.assert_equals(expect=main.TRUE, actual=assertion,
+                onpass="Link discovery latency calculation successful",
+                onfail="Link discovery latency case failed")
+
     def CASE5(self, main):
         '''
         100 Switch discovery latency
 
         Important:
-            If a simple topology was used in previous cases,
-            you will need to change the topology file in the
-            params for this case to proceed
-        
             This test case can be potentially dangerous if 
             your machine has previously set iptables rules.
             One of the steps of the test case will flush
             all existing iptables rules.
+        Note:
+            You can specify the number of switches in the 
+            params file to adjust the switch discovery size
+            (and specify the corresponding topology in Mininet1 
+            .topo file)
         '''
         import time
         import subprocess
@@ -869,7 +1228,11 @@
         deviceTimestamp = main.params['JSON']['deviceTimestamp']
         graphTimestamp = main.params['JSON']['graphTimestamp']
    
-        tshark_ofp_output = "/tmp/tshark_ofp_100sw.txt"
+        tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
+        tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
+
+        tshark_ofp_result_list = []
+        tshark_tcp_result_list = []
 
         main.case(num_sw+" Switch discovery latency")
         main.step("Assigning all switches to ONOS1")
@@ -889,11 +1252,28 @@
             
             main.step("Set iptables rule to block incoming sw connections")
             #Set iptables rule to block incoming switch connections
+            #The rule description is as follows:
+            #   Append to INPUT rule,
+            #   behavior DROP that matches following:
+            #       * packet type: tcp
+            #       * source IP: MN1_ip
+            #       * destination PORT: 6633
             main.ONOS1.handle.sendline(
                     "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
                     " --dport "+default_sw_port+" -j DROP")
             main.ONOS1.handle.expect("\$") 
+            #   Append to OUTPUT rule, 
+            #   behavior DROP that matches following:
+            #       * packet type: tcp
+            #       * source IP: MN1_ip
+            #       * destination PORT: 6633
+            main.ONOS1.handle.sendline(
+                    "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
+                    " --dport "+default_sw_port+" -j DROP")
+            main.ONOS1.handle.expect("\$")
             #Give time to allow rule to take effect
+            #NOTE: Sleep period may need to be configured 
+            #      based on the number of switches in the topology
             main.log.info("Please wait for switch connection to "+
                     "time out")
             time.sleep(60)
@@ -901,6 +1281,8 @@
             #Gather vendor OFP with tshark
             main.ONOS1.tshark_grep("OFP 86 Vendor", 
                     tshark_ofp_output)
+            main.ONOS1.tshark_grep("TCP 74 ",
+                    tshark_tcp_output)
 
             #NOTE: Remove all iptables rule quickly (flush)
             #      Before removal, obtain TestON timestamp at which 
@@ -970,7 +1352,8 @@
                         main.ONOS2cli.topology_events_metrics()
                     json_str_topology_metrics_3 =\
                         main.ONOS3cli.topology_events_metrics()
-                    
+                   
+                    #Exit while loop if all devices discovered
                     break 
                 
                 counter_loop += 1
@@ -982,14 +1365,27 @@
             
             os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
                     tshark_ofp_output+" /tmp/") 
+            os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
+                    tshark_tcp_output+" /tmp/")
             ofp_file = open(tshark_ofp_output, 'r')
 
             #The following is for information purpose only.
             #TODO: Automate OFP output analysis
             main.log.info("Tshark OFP Vendor output: ")
             for line in ofp_file:
+                tshark_ofp_result_list.append(line)
                 main.log.info(line)
 
+            ofp_file.close()
+
+            tcp_file = open(tshark_tcp_output, 'r')
+            main.log.info("Tshark TCP 74 output: ")
+            for line in tcp_file:
+                tshark_tcp_result_list.append(line)
+                main.log.info(line)
+
+            tcp_file.close()
+
             json_obj_1 = json.loads(json_str_topology_metrics_1)
             json_obj_2 = json.loads(json_str_topology_metrics_2)
             json_obj_3 = json.loads(json_str_topology_metrics_3)
diff --git a/TestON/tests/TopoPerfNext/TopoPerfNext.topo b/TestON/tests/TopoPerfNext/TopoPerfNext.topo
index 5b06d5d..5010fcc 100644
--- a/TestON/tests/TopoPerfNext/TopoPerfNext.topo
+++ b/TestON/tests/TopoPerfNext/TopoPerfNext.topo
@@ -71,7 +71,7 @@
             <type>MininetCliDriver</type>
             <connect_order>4</connect_order>
             <COMPONENTS>
-                <arg1> --custom topo-10sw.py </arg1>
+                <arg1> --custom topo-100sw.py </arg1>
                 <arg2> --arp --mac --topo mytopo</arg2>
                 <arg3> </arg3>
                 <controller> remote </controller>