Refactored test
    - Add test information
    - Chenge database path
    - Added link down and up driver
    - Added checkIntentSummary driver
    - Modified checkFlowsState driver to be more efficient
    - Refactored pushTestIntents driver
    - Modified sendline driver to handle pexpect timeout
    - Modify CASE20 and delete CASE21. Now Reroute part will in CASE20
    - Modify checkFlowsState drive function, make sure other tests can
      use it
    - Add a param, to control reroute or not
    - Change batch size, min_Intents, Max_Intents, and check_interval in
      params file

Change-Id: Id7fba74e880530a1817f17f576a1180170753143
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 21eb959..35527d4 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -1235,30 +1235,33 @@
 
     def link( self, **linkargs ):
         """
-           Bring link( s ) between two nodes up or down"""
-        args = utilities.parse_args( [ "END1", "END2", "OPTION" ], **linkargs )
-        end1 = args[ "END1" ] if args[ "END1" ] is not None else ""
-        end2 = args[ "END2" ] if args[ "END2" ] is not None else ""
-        option = args[ "OPTION" ] if args[ "OPTION" ] is not None else ""
-        main.log.info(
-            "Bring link between '" +
-            end1 +
-            "' and '" +
-            end2 +
-            "' '" +
-            option +
-            "'" )
-        command = "link " + \
-            str( end1 ) + " " + str( end2 ) + " " + str( option )
+           Bring link( s ) between two nodes up or down
+        """
         try:
-            self.handle.sendline( command )
+            args = utilities.parse_args( [ "END1", "END2", "OPTION" ], **linkargs )
+            end1 = args[ "END1" ] if args[ "END1" ] is not None else ""
+            end2 = args[ "END2" ] if args[ "END2" ] is not None else ""
+            option = args[ "OPTION" ] if args[ "OPTION" ] is not None else ""
+
+            main.log.info( "Bring link between " + str( end1 ) + " and " + str( end2 ) + " " + str( option ) )
+            cmd = "link {} {} {}".format( end1, end2, option )
+            self.handle.sendline( cmd )
             self.handle.expect( "mininet>" )
+            response = self.handle.before
+            main.log.info( response )
+
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return None
         except pexpect.EOF:
-            main.log.error( self.name + ": EOF exception found" )
-            main.log.error( self.name + ":     " + self.handle.before )
+            main.log.exception( self.name + ": connection closed." )
             main.cleanup()
             main.exit()
-        return main.TRUE
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
 
     def switch( self, **switchargs ):
         """
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 5201570..1f74984 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -331,7 +331,7 @@
             main.cleanup()
             main.exit()
 
-    def sendline( self, cmdStr, showResponse=False, debug=False ):
+    def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10 ):
         """
         Send a completely user specified string to
         the onos> prompt. Use this function if you have
@@ -339,25 +339,19 @@
 
         Warning: There are no sanity checking to commands
         sent using this method.
+
         """
         try:
+
+            main.log.info( "Command '" + str( cmdStr ) + "' sent to "
+                           + self.name + "." )
             logStr = "\"Sending CLI command: '" + cmdStr + "'\""
             self.log( logStr )
             self.handle.sendline( cmdStr )
-            i = self.handle.expect( ["onos>", "\$", pexpect.TIMEOUT] )
+            i = self.handle.expect( ["onos>", "\$"], timeout )
             response = self.handle.before
-            if i == 2:
-                self.handle.sendline()
-                self.handle.expect( ["\$", pexpect.TIMEOUT] )
-                response += self.handle.before
-                print response
-                try:
-                    print self.handle.after
-                except TypeError:
-                    pass
             # TODO: do something with i
-            main.log.info( "Command '" + str( cmdStr ) + "' sent to "
-                           + self.name + "." )
+
             if debug:
                 main.log.debug( self.name + ": Raw output" )
                 main.log.debug( self.name + ": " + repr( response ) )
@@ -390,8 +384,13 @@
                     main.log.debug( self.name + ": " + repr( r ) )
             output = output[1].strip()
             if showResponse:
-                main.log.info( "Resonse from ONOS: {}".format( output ) )
+                main.log.info( "Response from ONOS: {}".format( output ) )
             return output
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ":ONOS timeout" )
+            if debug:
+                main.log.debug( self.handle.before )
+            return None
         except IndexError:
             main.log.exception( self.name + ": Object not as expected" )
             return None
@@ -1786,7 +1785,6 @@
             handle = self.sendline( cmdStr )
             jsonResult = json.loads( handle )
             return jsonResult['totalRoutes4']
-
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
             return None
@@ -1925,8 +1923,6 @@
             # Generating a dictionary: intent id as a key and state as value
             returnValue = main.TRUE
             intentsDict = self.getIntentState( intentsId )
-
-            #print "len of intentsDict ", str( len( intentsDict ) )
             if len( intentsId ) != len( intentsDict ):
                 main.log.info( self.name + "There is something wrong " +
                                "getting intents state" )
@@ -1974,7 +1970,48 @@
             main.cleanup()
             main.exit()
 
-    def flows( self, jsonFormat=True ):
+    def checkIntentSummary( self, timeout=60 ):
+        """
+        Description:
+            Check the number of installed intents.
+        Optional:
+            timeout - the timeout for pexcept
+        Return:
+            Returns main.TRUE only if the number of all installed intents are the same as total intents number
+            , otherwise, returns main.FALSE.
+        """
+
+        try:
+            cmd = "intents -s -j"
+
+            # Check response if something wrong
+            response = self.sendline( cmd, timeout=timeout )
+            if response == None:
+                return main.False
+            response = json.loads( response )
+
+            # get total and installed number, see if they are match
+            allState = response.get( 'all' )
+            if allState.get('total') == allState.get('installed'):
+                main.log.info( 'successful verified Intents' )
+                return main.TRUE
+            main.log.info( 'Verified Intents failed Excepte intetnes: {} installed intents: {}'.format(allState.get('total'), allState.get('installed')))
+            return main.FALSE
+
+        except TypeError:
+            main.log.exception( self.name + ": Object not as expected" )
+            return None
+        except pexpect.EOF:
+            main.log.error( self.name + ": EOF exception found" )
+            main.log.error( self.name + ":    " + self.handle.before )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def flows( self, state="", jsonFormat=True, timeout=60 ):
         """
         Optional:
             * jsonFormat: enable output formatting in json
@@ -1984,12 +2021,16 @@
         try:
             cmdStr = "flows"
             if jsonFormat:
-                cmdStr += " -j"
-            handle = self.sendline( cmdStr )
-            if re.search( "Error:", handle ):
-                main.log.error( self.name + ": flows() response: " +
-                                str( handle ) )
-            return handle
+                cmdStr += " -j "
+            cmdStr += state
+
+            response = self.sendline( cmdStr, timeout = timeout )
+
+            return response
+
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": ONOS timeout" )
+            return None
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
             return None
@@ -2003,46 +2044,43 @@
             main.cleanup()
             main.exit()
 
-    def checkFlowsState( self, isPENDING_ADD = True ):
+
+    def checkFlowsState( self, isPENDING = True, timeout=60 ):
         """
         Description:
-            Check the if all the current flows are in ADDED state or
-            PENDING_ADD state
+            Check the if all the current flows are in ADDED state
+            We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, if the count of those states is 0,
+            which means all current flows are in ADDED state, and return main.TRUE
+            otherwise return main.FALSE
         Optional:
-            * isPENDING_ADD: whether the PENDING_ADD is also a correct status
+            * isPENDING:  whether the PENDING_ADD is also a correct status
         Return:
             returnValue - Returns main.TRUE only if all flows are in
-                          ADDED state or PENDING_ADD if the PENDING_ADD
+                          ADDED state or PENDING_ADD if the isPENDING_ADD
                           parameter is set true, return main.FALSE otherwise.
         """
         try:
-            tempFlows = json.loads( self.flows() )
-            #print tempFlows[0]
-            returnValue = main.TRUE
+            states = ["PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED"]
+            checkedStates = []
+            statesCount = [0, 0, 0, 0]
+            for s in states:
+                checkedStates.append( json.loads( self.flows( state=s, timeout = timeout ) ) )
 
-            if isPENDING_ADD:
-                for device in tempFlows:
-                    for flow in device.get( 'flows' ):
-                        if flow.get( 'state' ) != 'ADDED' and \
-                            flow.get( 'state' ) != 'PENDING_ADD':
+            for i in range (len( states )):
+                for c in checkedStates[i]:
+                    statesCount[i] += int( c.get("flowCount"))
+                main.log.info(states[i] + " flows: "+ str( statesCount[i] ) )
 
-                            main.log.info( self.name + ": flow Id: " +
-                                           str( flow.get( 'groupId' ) ) +
-                                           " | state:" +
-                                           str( flow.get( 'state' ) ) )
-                            returnValue = main.FALSE
+            # We want to count PENDING_ADD if isPENDING is true
+            if isPENDING:
+                if statesCount[1] + statesCount[2] + statesCount[3] > 0:
+                    return main.FALSE
             else:
-                for device in tempFlows:
-                    for flow in device.get( 'flows' ):
-                        if flow.get( 'state' ) != 'ADDED':
+                if statesCount[0] + statesCount[1] + statesCount[2] + statesCount[3] > 0:
+                    return main.FALSE
 
-                            main.log.info( self.name + ": flow Id: " +
-                                           str( flow.get( 'groupId' ) ) +
-                                           " | state:" +
-                                           str( flow.get( 'state' ) ) )
-                            returnValue = main.FALSE
+            return main.TRUE
 
-            return returnValue
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
             return None
@@ -2056,58 +2094,55 @@
             main.cleanup()
             main.exit()
 
-    def pushTestIntents( self, dpidSrc, dpidDst, numIntents,
-                         numMult="", appId="", report=True ):
+    def pushTestIntents( self, ingress, egress, batchSize, offset="",
+                         options="", timeout=10, background = False ):
         """
         Description:
             Push a number of intents in a batch format to
             a specific point-to-point intent definition
         Required:
-            * dpidSrc: specify source dpid
-            * dpidDst: specify destination dpid
-            * numIntents: specify number of intents to push
+            * ingress: specify source dpid
+            * egress: specify destination dpid
+            * batchSize: specify number of intents to push
         Optional:
-            * numMult: number multiplier for multiplying
-              the number of intents specified
-            * appId: specify the application id init to further
-              modularize the intents
-            * report: default True, returns latency information
+            * offset: the keyOffset is where the next batch of intents
+                      will be installed
+        Returns: If failed to push test intents, it will returen None,
+                 if successful, return true.
+                 Timeout expection will return None,
+                 TypeError will return false
+                 other expections will exit()
         """
         try:
-            cmd = "push-test-intents " +\
-                  str( dpidSrc ) + " " + str( dpidDst ) + " " +\
-                  str( numIntents )
-            if numMult:
-                cmd += " " + str( numMult )
-                # If app id is specified, then numMult
-                # must exist because of the way this command
-                if appId:
-                    cmd += " " + str( appId )
-            handle = self.sendline( cmd )
-            if report:
-                latResult = []
-                main.log.info( handle )
-                # Split result by newline
-                newline = handle.split( "\r\r\n" )
-                # Ignore the first object of list, which is empty
-                newline = newline[ 1: ]
-                # Some sloppy parsing method to get the latency
-                for result in newline:
-                    result = result.split( ": " )
-                    # Append the first result of second parse
-                    latResult.append( result[ 1 ].split( " " )[ 0 ] )
-                main.log.info( latResult )
-                return latResult
+            if background:
+                back = "&"
             else:
-                return main.TRUE
-        except TypeError:
-            main.log.exception( self.name + ": Object not as expected" )
+                back = ""
+            cmd = "push-test-intents {} {} {} {} {} {}".format( options,
+                                                             ingress,
+                                                             egress,
+                                                             batchSize,
+                                                             offset,
+                                                             back )
+            response = self.sendline( cmd, timeout=timeout )
+            main.log.info( response )
+            if response == None:
+                return None
+
+            # TODO: We should handle if there is failure in installation
+            return main.TRUE
+
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": ONOS timeout" )
             return None
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":    " + self.handle.before )
             main.cleanup()
             main.exit()
+        except TypeError:
+            main.log.exception( self.name + ": Object not as expected" )
+            return main.FALSE
         except Exception:
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanup()
@@ -4220,3 +4255,37 @@
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanup()
             main.exit()
+
+    def link( self, begin, end, state):
+        '''
+        Description:
+            Bring link down or up in the null-provider.
+        params:
+            begin - (string) One end of a device or switch.
+            end - (string) the other end of the device or switch
+        returns:
+            main.TRUE if no exceptions were thrown and no Errors are
+            present in the resoponse. Otherwise, returns main.FALSE
+        '''
+        try:
+            cmd =  "null-link null:{} null:{} {}".format(begin, end, state)
+            response = self.sendline( cmd, showResponse=True )
+
+            if "Error" in response or "Failure" in response:
+                main.log.error( response )
+                return main.FALSE
+
+            return main.TRUE
+        except TypeError:
+            main.log.exception( self.name + ": Object not as expected" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.error( self.name + ": EOF exception found" )
+            main.log.error( self.name + ":    " + self.handle.before )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
index 7a08c48..2324185 100755
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
@@ -1,13 +1,14 @@
 <PARAMS>
 
-    # 0-init
-    # 1-setup
+    # 1-init
+    # 2-setup
     # 10-null provider setup
     # 11-mininet setup
-    # 20-pushing intents,
-    # 21-rerouting intents
-    # 0,1,11,20,1,11,21,1,10,20,1,10,21,100
-    <testcases>0,1,11,20,1,11,21,1,10,20,1,10,21,100</testcases>
+    # 20-pushing intents, and rerouting intents if reroute is true
+    # 1,2,10,20,2,11,20,100
+    <testcases>1,2,10,20</testcases>
+
+    <reroute>False</reroute>
 
     <SCALE>
         <size>1</size>
@@ -37,24 +38,66 @@
 
     <SLEEP>
         <startup>3</startup>
-        <install>0</install>
-        <verify>0</verify>
+        <install>1</install>
+        <verify>5</verify>
         <reroute>3</reroute>
         # timeout for pexpect
         <timeout>120</timeout>
     </SLEEP>
 
+    <ATTEMPTS>
+        <verify>3</verify>
+        <push>3</push>
+    </ATTEMPTS>
+
     <DATABASE>
-        <file>MaxIntentDB</file>
+        <file>/tmp/MaxIntentDB</file>
         <nic>1gig</nic>
         <node>baremetal</node>
     </DATABASE>
 
-    <TEST>
-        <batch_size>10000</batch_size>
-        <min_intents>800000</min_intents>
-        <max_intents>1000000</max_intents>
-        <check_interval>20000</check_interval>
-    </TEST>
+    <LINK>
+        <ingress>0000000000000001/9</ingress>
+        <egress>0000000000000002/9</egress>
+    </LINK>
+
+    # CASE10
+    <NULL>
+        # CASE20
+        <PUSH>
+            <batch_size>1000</batch_size>
+            <min_intents>10000</min_intents>
+            <max_intents>1000000</max_intents>
+            <check_interval>10000</check_interval>
+        </PUSH>
+
+        # if reroute is true
+        <REROUTE>
+            <batch_size>1000</batch_size>
+            <min_intents>10000</min_intents>
+            <max_intents>1000000</max_intents>
+            <check_interval>100000</check_interval>
+        </REROUTE>
+    </NULL>
+
+    # CASE11
+    <OVS>
+        # CASE20
+        <PUSH>
+            <batch_size>1000</batch_size>
+            <min_intents>10000</min_intents>
+            <max_intents>500000</max_intents>
+            <check_interval>10000</check_interval>
+        </PUSH>
+
+        # if reroute is true
+        <REROUTE>
+            <batch_size>1000</batch_size>
+            <min_intents>10000</min_intents>
+            <max_intents>500000</max_intents>
+            <check_interval>10000</check_interval>
+        </REROUTE>
+    </OVS>
+
 
 </PARAMS>
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
index 011b275..4c92d74 100644
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
@@ -1,13 +1,27 @@
 
 # This is a performance scale intent that test onos to see how many intents can
 # be installed and rerouted using the null provider and mininet.
+'''
+This test will not test on reroute and OVS!!!
+If you need test on reroute or OVS, change the params file
+
+Test information:
+    - BatchSize: 1000
+    - Minimum intents: 10,000
+    - Maximum Intents: 1,000,000
+    - Check Interval: 10,000
+    - Link:
+        - ingress: 0000000000000001/9
+        - egress: 0000000000000002/9
+    - Timeout: 120 Seconds
+'''
 
 class SCPFmaxIntents:
 
     def __init__( self ):
         self.default = ''
 
-    def CASE0( self, main ):
+    def CASE1( self, main ):
         import time
         import os
         import imp
@@ -42,16 +56,20 @@
         main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
         main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
         main.timeout = int(main.params['SLEEP']['timeout'])
-        main.minIntents = int(main.params['TEST']['min_intents'])
-        main.maxIntents = int(main.params['TEST']['max_intents'])
-        main.checkInterval = int(main.params['TEST']['check_interval'])
         main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
         main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
         main.verifySleep = int( main.params[ 'SLEEP' ][ 'verify' ] )
         main.rerouteSleep = int ( main.params['SLEEP']['reroute'] )
-        main.batchSize = int(main.params['TEST']['batch_size'])
+        main.verifyAttempts = int( main.params['ATTEMPTS']['verify'] )
+        main.ingress = main.params['LINK']['ingress']
+        main.egress = main.params['LINK']['egress']
         main.dbFileName = main.params['DATABASE']['file']
         main.cellData = {} # for creating cell file
+        main.reroute = main.params['reroute']
+        if main.reroute == "True":
+            main.reroute = True
+        else:
+            main.reroute = False
         main.CLIs = []
         main.ONOSip = []
         main.maxNumBatch = 0
@@ -127,19 +145,23 @@
                                        main.apps,
                                        tempOnosIp )
 
-        main.log.info( "Applying cell to environment" )
-        cell = main.ONOSbench.setCell( "temp" )
-        verify = main.ONOSbench.verifyCell()
-        if not cell or not verify:
-            main.log.error("Failed to apply cell to environment")
-            main.cleanup()
-            main.exit()
+        main.step( "Apply cell to environment" )
+        cellResult = main.ONOSbench.setCell( "temp" )
+        verifyResult = main.ONOSbench.verifyCell()
+        stepResult = cellResult and verifyResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully applied cell to " + \
+                                        "environment",
+                                 onfail="Failed to apply cell to environment " )
 
-        main.log.info( "Creating ONOS package" )
-        if not main.ONOSbench.onosPackage():
-            main.log.error("Failed to create ONOS package")
-            main.cleanup()
-            main.exit()
+        main.step( "Creating ONOS package" )
+        packageResult = main.ONOSbench.onosPackage()
+        stepResult = packageResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully created ONOS package",
+                                 onfail="Failed to create ONOS package" )
 
         main.log.info("Creating DB file")
         with open(main.dbFileName, "w+") as dbFile:
@@ -149,7 +171,7 @@
             temp += "'" + node + "1" + "'"
             dbFile.write(temp)
 
-    def CASE1( self, main ):
+    def CASE2( self, main ):
         """
         - Uninstall ONOS cluster
         - Verify ONOS start up
@@ -157,52 +179,48 @@
         - Connect to cli
         """
 
-        main.log.info( "Uninstalling ONOS package" )
-        main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[i] )
-        for i in range( main.maxNodes ):
-            if not main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[i] ):
-                main.log.error("Failed to uninstall onos on node %s" % (i+1))
-                main.cleanup()
-                main.exit()
-
-        main.log.info( "Installing ONOS package" )
+        main.step( "Installing ONOS with -f" )
+        onosInstallResult = main.TRUE
         for i in range( main.numCtrls ):
-            if not main.ONOSbench.onosInstall( node=main.ONOSip[i] ):
-                main.log.error("Failed to install onos on node %s" % (i+1))
-                main.cleanup()
-                main.exit()
+            onosInstallResult = onosInstallResult and \
+                    main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
+        stepResult = onosInstallResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully installed ONOS package",
+                                 onfail="Failed to install ONOS package" )
 
-        main.log.info( "Starting ONOS service" )
-        for i in range( main.numCtrls ):
-            start = main.ONOSbench.onosStart( main.ONOSip[i] )
-            isup = main.ONOSbench.isup( main.ONOSip[i] )
-            if not start or not isup:
-                main.log.error("Failed to start onos service on node %s" % (i+1))
-                main.cleanup()
-                main.exit()
+        time.sleep( main.startUpSleep )
 
-        main.log.info( "Starting ONOS cli" )
+        main.step( "Start ONOS cli" )
+        cliResult = main.TRUE
         for i in range( main.numCtrls ):
-            if not main.CLIs[i].startOnosCli( main.ONOSip[i] ):
-                main.log.error("Failed to start onos cli on node %s" % (i+1))
-                main.cleanup()
-                main.exit()
+            cliResult = cliResult and \
+                        main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
+        stepResult = cliResult
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully start ONOS cli",
+                                 onfail="Failed to start ONOS cli" )
+
+        time.sleep( main.startUpSleep )
 
     def CASE10( self, main ):
         """
             Setting up null-provider
         """
         import json
-        import pexpect
 
         # Activate apps
-        main.log.info("Activating null-provider")
+        main.step("Activating null-provider")
         appStatus = main.CLIs[0].activateApp('org.onosproject.null')
-        if not appStatus:
-            main.log.error("Failed to activate null-provider")
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=appStatus,
+                                 onpass="Successfully activated null-provider",
+                                 onfail="Failed activate null-provider" )
 
         # Setup the null-provider
-        main.log.info("Configuring null-provider")
+        main.step("Configuring null-provider")
         cfgStatus = main.ONOSbench.onosCfgSet( main.ONOSip[0],
                 'org.onosproject.provider.nil.NullProviders', 'deviceCount 3' )
         cfgStatus = cfgStatus and main.ONOSbench.onosCfgSet( main.ONOSip[0],
@@ -210,20 +228,30 @@
         cfgStatus = cfgStatus and main.ONOSbench.onosCfgSet( main.ONOSip[0],
                 'org.onosproject.provider.nil.NullProviders', 'enabled true' )
 
-        if not cfgStatus:
-            main.log.error("Failed to configure null-provider")
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=cfgStatus,
+                                 onpass="Successfully configured null-provider",
+                                 onfail="Failed to configure null-provider" )
 
         # give onos some time to settle
         time.sleep(main.startUpSleep)
 
+        main.log.info("Setting default flows to zero")
         main.defaultFlows = 0
-        main.ingress =  ":0000000000000001/3"
-        main.egress = ":0000000000000003/2"
-        main.switch = "null"
-        main.linkUpCmd = "null-link null:0000000000000001/3 null:0000000000000003/1 up"
-        main.linkDownCmd = "null-link null:0000000000000001/3 null:0000000000000003/1 down"
 
-        if not appStatus or not cfgStatus:
+        main.step("Check status of null-provider setup")
+        caseResult = appStatus and cfgStatus
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=caseResult,
+                                 onpass="Setting up null-provider was successfull",
+                                 onfail="Failed to setup null-provider" )
+
+        # This tells the following cases if we are using the null-provider or ovs
+        main.switchType = "null:"
+
+        # If the null-provider setup was unsuccessfull, then there is no point to
+        # run the subsequent cases
+        if not caseResult:
             main.setupSkipped = True
 
     def CASE11( self, main ):
@@ -233,239 +261,214 @@
         import json
         import time
 
-        main.log.step("Activating openflow")
+        time.sleep(main.startUpSleep)
+
+        main.step("Activating openflow")
         appStatus = main.CLIs[0].activateApp('org.onosproject.openflow')
-        if appStatus:
-            main.log.error("Failed to activate openflow")
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=appStatus,
+                                 onpass="Successfully activated openflow",
+                                 onfail="Failed activate openflow" )
 
         time.sleep(main.startUpSleep)
 
-        main.log.info('Starting mininet topology')
+        main.step('Starting mininet topology')
         mnStatus = main.Mininet1.startNet(topoFile='~/mininet/custom/rerouteTopo.py')
-        if mnStatus:
-            main.log.error("Failed to start mininet")
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=mnStatus,
+                                 onpass="Successfully started Mininet",
+                                 onfail="Failed to activate Mininet" )
 
-        main.log.info("Assinging masters to switches")
-        swStatus =  main.Mininet1.assignSwController(sw='s1', ip=main.ONOSip[0])
-        swStatus = swStatus and  main.Mininet1.assignSwController(sw='s2', ip=main.ONOSip[0])
-        swStatus = swStatus and main.Mininet1.assignSwController(sw='s3', ip=main.ONOSip[0])
-        if not swStatus:
-            main.log.info("Failed to assign masters to switches")
+        main.step("Assinging masters to switches")
+        switches = main.Mininet1.getSwitches()
+        swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=swStatus,
+                                 onpass="Successfully assigned switches to masters",
+                                 onfail="Failed assign switches to masters" )
 
         time.sleep(main.startUpSleep)
 
+        main.log.info("Getting default flows")
         jsonSum = json.loads(main.CLIs[0].summary())
-        sumStatus = (jsonSum['devices'] == 3 and jsonSum['SCC(s)'] == 1)
-
-        main.log.step("Getting default flows")
-        jsonSum = json.loads(main.CLIs[0].summary())
-
         main.defaultFlows = jsonSum["flows"]
-        main.ingress =  ":0000000000000001/3"
-        main.egress = ":0000000000000003/2"
-        main.switch = "of"
-        main.linkDownCmd = 'link s1 s3 down'
-        main.linkUpCmd = 'link s1 s3 up'
 
-        if not appStatus or not mnStatus or not swStatus or not sumStatus:
+        main.step("Check status of Mininet setup")
+        caseResult = appStatus and mnStatus and swStatus
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=caseResult,
+                                 onpass="Successfully setup Mininet",
+                                 onfail="Failed setup Mininet" )
+
+        # This tells the following cases if we are using the null-provider or ovs
+        main.switchType = "of:"
+
+        if not caseResult:
             main.setupSkipped = True
 
     def CASE20( self, main ):
-        import pexpect
         '''
             Pushing intents
         '''
 
-        # check if the setup case has been skipped
+        if main.reroute:
+            if main.switchType == "of:":
+                main.minIntents = int(main.params['OVS']['REROUTE']['min_intents'])
+                main.maxIntents = int(main.params['OVS']['REROUTE']['max_intents'])
+                main.checkInterval = int(main.params['OVS']['REROUTE']['check_interval'])
+                main.batchSize = int(main.params['OVS']['REROUTE']['batch_size'])
+            else:
+                main.minIntents = int(main.params['NULL']['REROUTE']['min_intents'])
+                main.maxIntents = int(main.params['NULL']['REROUTE']['max_intents'])
+                main.checkInterval = int(main.params['NULL']['REROUTE']['check_interval'])
+                main.batchSize = int(main.params['NULL']['REROUTE']['batch_size'])
+        else:
+            if main.switchType == "of:":
+                main.minIntents = int(main.params['OVS']['PUSH']['min_intents'])
+                main.maxIntents = int(main.params['OVS']['PUSH']['max_intents'])
+                main.checkInterval = int(main.params['OVS']['PUSH']['check_interval'])
+                main.batchSize = int(main.params['OVS']['PUSH']['batch_size'])
+            else:
+                main.minIntents = int(main.params['NULL']['PUSH']['min_intents'])
+                main.maxIntents = int(main.params['NULL']['PUSH']['max_intents'])
+                main.checkInterval = int(main.params['NULL']['PUSH']['check_interval'])
+                main.batchSize = int(main.params['NULL']['PUSH']['batch_size'])
+
+        # check if the case needs to be skipped
         if main.setupSkipped:
             main.setupSkipped = False
             main.skipCase()
 
         # the index where the next intents will be installed
         offset = 0
-        # the number of intents we expect to be in the installed state
-        expectedIntents = 0
         # keeps track of how many intents have been installed
-        maxIntents = 0
-        # the number of flows we expect to be in the added state
-        expectedFlows = main.defaultFlows
+        currIntents = 0
         # keeps track of how many flows have been installed
-        maxFlows = main.defaultFlows
+        currFlows = main.defaultFlows
         # limit for the number of intents that can be installed
         limit = main.maxIntents / main.batchSize
 
+        main.step( "Pushing intents" )
         for i in range(limit):
-            # Push intents
-            main.log.info("Pushing intents")
-            main.intentFunctions.pushIntents( main,
-                                              main.switch,
-                                              main.ingress,
-                                              main.egress,
-                                              main.batchSize,
-                                              offset,
-                                              sleep=main.installSleep,
-                                              timeout=main.timeout,
-                                              options="-i" )
+            pushResult = main.ONOScli1.pushTestIntents( main.switchType +  main.ingress,
+                                                        main.switchType +  main.egress,
+                                                        main.batchSize,
+                                                        offset = offset,
+                                                        options = "-i",
+                                                        timeout = main.timeout )
+            if pushResult == None:
+                main.log.info( "Timeout!" )
+                main.skipCase()
+            time.sleep(1)
 
+            # Update offset
             offset += main.batchSize
-            expectedIntents = offset
-            expectedFlows += main.batchSize*2
 
-            main.log.info("Grabbing number of installed intents and flows")
-            maxIntents = main.intentFunctions.getIntents( main )
-            maxFlows = main.intentFunctions.getFlows( main )
+            if offset >= main.minIntents and offset % main.checkInterval == 0:
+                intentVerify = utilities.retry( main.ONOScli1.checkIntentSummary,
+                                                main.FALSE,
+                                                [main.timeout],
+                                                sleep=main.verifySleep,
+                                                attempts=main.verifyAttempts )
 
-            if offset >= main.minIntents and offset % main.checkInterval == 0 or expectedIntents == main.maxIntents:
-                # Verifying intents
-                main.log.info("Verifying intents\nExpected intents: " + str(expectedIntents))
-                intentStatus = main.intentFunctions.verifyIntents( main,
-                                                                   expectedIntents,
-                                                                   sleep=main.verifySleep,
-                                                                   timeout=main.timeout)
-                # Verfying flows
-                main.log.info("Verifying flows\nExpected Flows: " + str(expectedFlows))
-                flowStatus = main.intentFunctions.verifyFlows( main,
-                                                               expectedFlows,
-                                                               sleep=main.verifySleep,
-                                                               timeout=main.timeout)
+                flowVerify = utilities.retry( main.ONOScli1.checkFlowsState,
+                                              main.FALSE,
+                                              [False,main.timeout],
+                                              sleep=main.verifySleep,
+                                              attempts=main.verifyAttempts )
 
-                if not flowStatus or not intentsStataus:
-                    main.log.error("Failed to verify")
+                if not intentVerify:
+                    main.log.error( "Failed to install intents" )
                     break
 
-        main.log.info("Summary: Intents=" + str(expectedIntents) + " Flows=" + str(expectedFlows))
-        main.log.info("Installed intents: " + str(maxIntents) +
-                      " Added flows: " + str(maxFlows))
+                if main.reroute:
+                    main.step( "Reroute" )
+                    # tear down a link
+                    main.log.info("Tearing down link")
+                    if main.switchType == "of:":
+                        downlink = main.Mininet1.link( END1 = "s1", END2 = "s3", OPTION = "down" )
+                    else:
+                        downlink = main.ONOScli1.link( main.ingress, main.egress, "down")
+
+                    if downlink:
+                        main.log.info( "Successfully tear down link" )
+                    else:
+                        main.log.warn( "Failed to tear down link" )
+
+                    time.sleep(main.rerouteSleep)
+
+                    # Verifying intents
+                    main.step( "Checking intents and flows" )
+                    intentVerify = utilities.retry( main.ONOScli1.checkIntentSummary,
+                                                    main.FALSE,
+                                                    [main.timeout],
+                                                    sleep=main.verifySleep,
+                                                    attempts=main.verifyAttempts )
+                    # Verfying flows
+                    flowVerify = utilities.retry( main.ONOScli1.checkFlowsState,
+                                                  main.FALSE,
+                                                  [False, main.timeout],
+                                                  sleep = main.verifySleep,
+                                                  attempts = main.verifyAttempts )
+
+                    if not intentVerify:
+                        main.log.error( "Failed to install intents" )
+                    # Bring link back up
+                    main.log.info("Bringing link back up")
+                    if main.switchType == "of:":
+                        uplink = main.Mininet1.link( END1 = "s1", END2 = "s3", OPTION = "up" )
+                    else:
+                        uplink = main.ONOScli1.link( main.ingress, main.egress, "up" )
+
+                    if uplink:
+                        main.log.info( "Successfully bring link back up" )
+                    else:
+                        main.log.warn( "Failed to bring link back up" )
+
+                    time.sleep(main.rerouteSleep)
+
+                    # Verifying intents
+                    main.step( "Checking intents and flows" )
+                    intentVerify = utilities.retry( main.ONOScli1.checkIntentSummary,
+                                                    main.FALSE,
+                                                    [main.timeout],
+                                                    sleep=main.verifySleep,
+                                                    attempts=main.verifyAttempts )
+                    # Verfying flows
+                    flowVerify = utilities.retry( main.ONOScli1.checkFlowsState,
+                                                  main.FALSE,
+                                                  [False, main.timeout],
+                                                  sleep = main.verifySleep,
+                                                  attempts = main.verifyAttempts )
+
+                    if not intentVerify:
+                        main.log.error( "Failed to install intents" )
+
+                    rerouteResult = downlink and uplink
+                    utilities.assert_equals( expect = main.TRUE,
+                                             actual = rerouteResult,
+                                             onpass = "Successfully reroute",
+                                             onfail = "Failed to reroute" )
+
+        utilities.assert_equals( expect = main.TRUE,
+                                 actual = intentVerify,
+                                 onpass = "Successfully pushed and verified intents",
+                                 onfail = "Failed to push and verify intents" )
 
         main.log.info("Writing results to DB file")
-        with open(dbFileName, "a") as dbFile:
-            temp = "," + str(maxIntents)
-            temp += "," + str(maxFlows)
-            dbFile.write(temp)
-
-        # Stopping mininet
-        if main.switch == "of":
-            main.log.info("Stopping mininet")
-            main.Mininet1.stopNet()
-
-    def CASE21( self, main ):
-        import pexpect
-        import time
-        '''
-            Reroute
-        '''
-
-        # check if the setup case has been skipped
-        if main.setupSkipped:
-            main.setupSkipped = False
-            main.skipCase()
-
-        # the index where the next intents will be installed
-        offset = 0
-        # the number of intents we expect to be in the installed state
-        expectedIntents = 0
-        # keeps track of how many intents have been installed
-        maxIntents = 0
-        # the number of flows we expect to be in the added state
-        expectedFlows = main.defaultFlows
-        # keeps track of how many flows have been installed
-        maxFlows = main.defaultFlows
-        # limit for the number of intents that can be installed
-        limit = main.maxIntents / main.batchSize
-
-        for i in range(limit):
-            # Push intents
-            main.log.info("Pushing intents")
-            main.intentFunctions.pushIntents( main,
-                                              main.switch,
-                                              main.ingress,
-                                              main.egress,
-                                              main.batchSize,
-                                              offset,
-                                              sleep=main.installSleep,
-                                              timeout=main.timeout,
-                                              options="-i" )
-
-            offset += main.batchSize
-            expectedIntents = offset
-            expectedFlows += main.batchSize*2
-
-            main.log.info("Grabbing number of installed intents and flows")
-            maxIntents = main.intentFunctions.getIntents( main )
-            maxFlows = main.intentFunctions.getFlows( main )
-
-            # Verifying intents
-            main.log.info("Verifying intents\n\tExpected intents: " + str(expectedIntents))
-            intentStatus = main.intentFunctions.verifyIntents( main,
-                                                               expectedIntents,
-                                                               sleep=main.verifySleep,
-                                                               timeout=main.timeout)
-            # Verfying flows
-            main.log.info("Verifying flows\n\tExpected Flows: " + str(expectedFlows))
-            flowStatus = main.intentFunctions.verifyFlows( main,
-                                                           expectedFlows,
-                                                           sleep=main.verifySleep,
-                                                           timeout=main.timeout)
-
-            if not flowStatus or not intentsStataus:
-                main.log.error("Failed to verify\n\tSkipping case")
-                main.log.skipCase()
-
-            # tear down a link
-            main.log.step("Tearing down link")
-            if main.switch == "of":
-                main.log.info("Sending: " + main.linkDownCmd)
-                main.Mininet1.handle.sendline(main.linkDownCmd)
-                main.Mininet1.handle.expect('mininet>')
-            else:
-                main.log.info("Sending: " + main.linkDownCmd)
-                main.CLIs[0].handle.sendline(main.linkDownCmd)
-                main.CLIs[0].handle.expect('onos>')
-
-            time.sleep(main.rerouteSleep)
-
-            # rerouting adds a 1000 flows
-            expectedFlows += 1000
-
-            main.log.info("Grabbing number of added flows")
-            maxFlows = main.intentFunctions.getFlows( main )
-
-            # Verfying flows
-            main.log.info("Verifying flows\n\tExpected Flows: " + str(expectedFlows))
-            flowStatus = main.intentFunctions.verifyFlows( main,
-                                                           expectedFlows,
-                                                           sleep=main.verifySleep,
-                                                           timeout=main.timeout)
-            if not flowStatus:
-                main.log.error("Failed to verify flows\n\tSkipping case")
-                main.skipCase()
-
-            # Bring link back up
-            main.log.step("Bringing link back up")
-            if main.switch == "of":
-                main.log.info("Sending: " + main.linkUpCmd)
-                main.Mininet1.handle.sendline(main.linkUpCmd)
-                main.Mininet1.handle.expect('mininet>')
-            else:
-                main.log.info("Sending: " + main.linkUpCmd)
-                main.CLIs[0].handle.sendline(main.linkUpCmd)
-                main.CLIs[0].handle.expect('onos>')
-
-            time.sleep(main.rerouteSleep)
-
-        main.log.info("Summary: Intents=" + str(expectedIntents) + " Flows=" + str(expectedFlows))
-        main.log.info("Installed intents: " + str(maxIntents) +
-                      " Added flows: " + str(maxFlows))
-
         with open(main.dbFileName, "a") as dbFile:
-            temp = "," + str(maxIntents)
-            temp += "," + str(maxFlows)
+            temp = "," + str(currIntents)
+            temp += "," + str(currFlows)
             dbFile.write(temp)
 
-        # Stopping mininet
-        if main.switch == "of":
-            main.log.info("Stopping mininet")
-            main.Mininet1.stopNet()
+        if main.switchType == "of:":
+            main.step( "Stopping mininet" )
+            stepResult = main.Mininet1.stopNet()
+            utilities.assert_equals( expect = main.TRUE,
+                                     actual = stepResult,
+                                     oppass = "Successfully stop Mininet",
+                                     opfail = "Failed stop Mininet" )
+
 
     def CASE100( self, main ):
         '''
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
index be3236a..f34ed12 100755
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
@@ -20,7 +20,7 @@
             <COMPONENTS>
             </COMPONENTS>
         </ONOScli1>
- 
+
         <Mininet1>
             <host>localhost</host>
             <user>admin</user>
diff --git a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
index fde3b1b..dd987c8 100644
--- a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
+++ b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
@@ -410,7 +410,6 @@
             stepResult = main.CLIs[controller].balanceMasters()
         else:
             main.log.error( "List of active nodes is empty" )
-        main.step( "Balancing Masters" )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
                                  onpass="Balance masters was successfull",