Merge "[ONOS-7125] add/fix the SCPFintent related sanity check"
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index f7f488d..f6f57bb 100755
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -1956,6 +1956,30 @@
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanAndExit()
 
+    def wipeout( self ):
+        """
+        Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS.
+        """
+        try:
+            cmdStr = "wipe-out please"
+            handle = self.sendline( cmdStr, timeout=60 )
+            assert handle is not None, "Error in sendline"
+            assert "Command not found:" not in handle, handle
+            return main.TRUE
+        except AssertionError:
+            main.log.exception( "" )
+            return None
+        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.cleanAndExit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanAndExit()
+
     def routes( self, jsonFormat=False ):
         """
         NOTE: This method should be used after installing application:
@@ -5709,4 +5733,5 @@
             main.cleanAndExit()
         except Exception:
             main.log.exception( self.name + ": Uncaught exception!" )
-            main.cleanAndExit()
\ No newline at end of file
+            main.cleanAndExit()
+
diff --git a/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.params b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.params
index 081ebdb..9d8fd6e 100644
--- a/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.params
+++ b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.params
@@ -13,6 +13,7 @@
     <TEST>
         <warmUp>5</warmUp>
         <sampleSize>20</sampleSize>
+        <deviceCount>7</deviceCount>
         <intents>1,100,1000</intents>                       #list format, will be split on ','
         <ingress>null:0000000000000001/6</ingress>
         <egress>null:0000000000000007/5</egress>
@@ -24,19 +25,24 @@
         <pull>False</pull>
         <branch>master</branch>
     </GIT>
-
+    <DEPENDENCY>
+        <FILE1>intentInstallLatFuncs</FILE1>
+        <PATH>/tests/SCPF/SCPFintentInstallWithdrawLat/dependencies/</PATH>
+    </DEPENDENCY>
     <DATABASE>
         <dbName>/tmp/IntentInstallWithdrawLatDB</dbName>
         <dbFlowObj>/tmp/IntentInstallWithdrawLatDBWFO</dbFlowObj>
     </DATABASE>
     <ATTEMPTS>
-        <verify>3</verify>
+        <verify>6</verify>
+        <maxInvalidRun>5</maxInvalidRun>
+        <cfg>5</cfg>
     </ATTEMPTS>
 
     <SLEEP>
         <startup>10</startup>
         <install>10</install>
-        <verify>3</verify>
+        <verify>5</verify>
         <reroute>3</reroute>
         # timeout for pexpect
         <timeout>300</timeout>
diff --git a/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.py b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.py
index 44e0b6e..9232a73 100644
--- a/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.py
+++ b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/SCPFintentInstallWithdrawLat.py
@@ -34,6 +34,8 @@
         self.default = ''
 
     def CASE0( self, main ):
+        import imp
+        import os
         """
         - GIT
         - BUILDING ONOS
@@ -69,9 +71,12 @@
             main.nullProviderCfg = main.params[ 'CFG' ][ 'nullProvider' ]
             main.linkCollectionIntentCfg = main.params[ 'CFG' ][ 'linkCollectionIntent' ]
             main.verifyAttempts = int( main.params[ 'ATTEMPTS' ][ 'verify' ] )
+            main.cfgRetry = int( main.params[ 'ATTEMPTS' ][ 'cfg' ] )
+            main.maxInvalidRun = int( main.params[ 'ATTEMPTS' ][ 'maxInvalidRun' ] )
             main.sampleSize = int( main.params[ 'TEST' ][ 'sampleSize' ] )
             main.warmUp = int( main.params[ 'TEST' ][ 'warmUp' ] )
             main.intentsList = ( main.params[ 'TEST' ][ 'intents' ] ).split( "," )
+            main.deviceCount = int( main.params[ 'TEST' ][ 'deviceCount' ] )
             main.ingress = main.params[ 'TEST' ][ 'ingress' ]
             main.egress = main.params[ 'TEST' ][ 'egress' ]
             main.debug = main.params[ 'TEST' ][ 'debug' ]
@@ -92,6 +97,9 @@
             main.log.info( "Create Database file " + main.dbFileName )
             resultsDB = open( main.dbFileName, "w+" )
             resultsDB.close()
+            file1 = main.params[ "DEPENDENCY" ][ "FILE1" ]
+            main.dependencyPath = os.path.dirname( os.getcwd() ) + main.params[ "DEPENDENCY" ][ "PATH" ]
+            main.intentFuncs = imp.load_source( file1, main.dependencyPath + file1 + ".py" )
         except Exception as e:
             main.testSetUp.envSetupException( e )
         main.testSetUp.evnSetupConclusion( stepResult )
@@ -104,149 +112,191 @@
         main.maxNumBatch = 0
         main.testSetUp.ONOSSetUp( main.MN1Ip, main.Cluster, True,
                                   cellName=main.cellName, killRemoveMax=False )
+        configRetry = 0
+        main.cfgCheck = False
+        while configRetry < main.cfgRetry:
+            # configure apps
+            stepResult = main.TRUE
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "deviceCount", value=main.deviceCount )
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "topoShape", value="linear" )
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "enabled", value="true" )
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg,
+                                                              "skipReleaseResourcesOnWithdrawal",
+                                                              value="true" )
+            if main.flowObj:
+                stepResult = stepResult and \
+                             main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                                                  "useFlowObjectives", value="true" )
+                stepResult = stepResult and \
+                             main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                                                  "defaultFlowObjectiveCompiler",
+                                                                  value=main.linkCollectionIntentCfg )
+            time.sleep( main.startUpSleep )
 
-        # configure apps
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
-                                             "deviceCount", value=7 )
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
-                                             "topoShape", value="linear" )
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
-                                             "enabled", value="true" )
-        main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg,
-                                             "skipReleaseResourcesOnWithdrawal",
-                                             value="true" )
-        if main.flowObj:
-            main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
-                                                 "useFlowObjectives", value="true" )
-            main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
-                                                 "defaultFlowObjectiveCompiler",
-                                                 value=main.linkCollectionIntentCfg )
-        time.sleep( main.startUpSleep )
+            # balanceMasters
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.balanceMasters()
+            if stepResult:
+                main.cfgCheck = True
+                break
+            configRetry += 1
+            time.sleep( main.verifySleep )
 
-        # balanceMasters
-        main.Cluster.active( 0 ).CLI.balanceMasters()
         time.sleep( main.startUpSleep )
+        if not main.cfgCheck:
+            main.log.error( "Setting configuration to the ONOS failed. Skip the rest of the steps" )
 
     def CASE2( self, main ):
         import time
         import numpy
         import json
-        print( main.intentsList )
-        for batchSize in main.intentsList:
-            main.log.report( "Intent Batch size: {}".format( batchSize ) )
-            main.installLatList = []
-            main.withdrawLatList = []
-            validrun = 0
-            invalidrun = 0
-            # we use two variables to control the iteration
-            while validrun <= main.warmUp + main.sampleSize and invalidrun < 20:
-                if validrun >= main.warmUp:
-                    main.log.info( "================================================" )
-                    main.log.info( "Starting test iteration " + str( validrun - main.warmUp ) )
-                    main.log.info( "Total test iteration: " + str( invalidrun + validrun ) )
-                    main.log.info( "================================================" )
-                else:
-                    main.log.info( "====================Warm Up=====================" )
+        testResult = main.TRUE
+        main.case( "Installing/Withdrawing intents start" )
+        main.step( "Checking starts" )
+        if main.cfgCheck:
+            print( main.intentsList )
+            for batchSize in main.intentsList:
+                main.log.report( "Intent Batch size: {}".format( batchSize ) )
+                main.batchSize = batchSize
+                main.installLatList = []
+                main.withdrawLatList = []
+                main.validrun = 0
+                main.invalidrun = 0
+                # we use two variables to control the iteration
+                while main.validrun <= main.warmUp + main.sampleSize and main.invalidrun <= main.maxInvalidRun:
+                    if main.validrun >= main.warmUp:
+                        main.log.info( "================================================" )
+                        main.log.info( "Starting test iteration " + str( main.validrun - main.warmUp ) )
+                        main.log.info( "Total test iteration: " + str( main.invalidrun + main.validrun ) )
+                        main.log.info( "================================================" )
+                    else:
+                        main.log.info( "====================Warm Up=====================" )
 
-                # push intents
-                installResult = main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
-                                                                              main.egress,
-                                                                              batchSize,
-                                                                              offset=1,
-                                                                              options="-i",
-                                                                              timeout=main.timeout,
-                                                                              getResponse=True )
-                if isinstance( installResult, str ):
-                    if "Failure" in installResult:
-                        main.log.error( "Install Intents failure, ignore this iteration." )
-                        if validrun < main.warmUp:
-                            validrun += 1
-                            continue
-                        else:
-                            invalidrun += 1
-                            continue
+                    # push intents
+                    installResult = main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
+                                                                                  main.egress,
+                                                                                  batchSize,
+                                                                                  offset=1,
+                                                                                  options="-i",
+                                                                                  timeout=main.timeout,
+                                                                                  getResponse=True )
 
-                    try:
-                        latency = int( installResult.split()[ 5 ] )
-                        main.log.info( installResult )
-                    except:
-                        main.log.error( "Failed to get latency, ignore this iteration." )
-                        main.log.error( "Response from ONOS:" )
-                        print( installResult )
-                        if validrun < main.warmUp:
-                            validrun += 1
-                            continue
-                        else:
-                            invalidrun += 1
-                            continue
+                    time.sleep( 2 )
+                    main.intentFuncs.sanityCheck( main,
+                                                  ( main.deviceCount - 1 ) * 2,
+                                                  batchSize * main.deviceCount,
+                                                  main.batchSize )
+                    if not main.verify:
+                        main.log.warn( "Sanity check failed, skipping this iteration..." )
+                        continue
+                    if isinstance( installResult, str ):
+                        if "Failure" in installResult:
+                            main.log.error( "Install Intents failure, ignore this iteration." )
+                            if main.validrun < main.warmUp:
+                                main.validrun += 1
+                                continue
+                            else:
+                                main.invalidrun += 1
+                                continue
 
-                    if validrun >= main.warmUp:
-                        main.installLatList.append( latency )
-                else:
-                    invalidrun += 1
-                    continue
-                time.sleep( 2 )
-                # Withdraw Intents
-                withdrawResult = main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
-                                                                               main.egress,
-                                                                               batchSize,
-                                                                               offset=1,
-                                                                               options="-w",
-                                                                               timeout=main.timeout,
-                                                                               getResponse=True )
+                        try:
+                            latency = int( installResult.split()[ 5 ] )
+                            main.log.info( installResult )
+                        except:
+                            main.log.error( "Failed to get latency, ignore this iteration." )
+                            main.log.error( "Response from ONOS:" )
+                            print( installResult )
+                            if main.validrun < main.warmUp:
+                                main.validrun += 1
+                                continue
+                            else:
+                                main.invalidrun += 1
+                                continue
 
-                if isinstance( withdrawResult, str ):
-                    if "Failure" in withdrawResult:
-                        main.log.error( "withdraw Intents failure, ignore this iteration." )
-                        if validrun < main.warmUp:
-                            validrun += 1
-                            continue
-                        else:
-                            invalidrun += 1
-                            continue
+                        if main.validrun >= main.warmUp:
+                            main.installLatList.append( latency )
+                    else:
+                        main.invalidrun += 1
+                        continue
+                    # Withdraw Intents
+                    withdrawResult = main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
+                                                                                   main.egress,
+                                                                                   batchSize,
+                                                                                   offset=1,
+                                                                                   options="-w",
+                                                                                   timeout=main.timeout,
+                                                                                   getResponse=True )
+                    time.sleep( 5 )
+                    main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
+                    main.intentFuncs.sanityCheck( main, ( main.deviceCount - 1 ) * 2, 0, 0 )
+                    if not main.verify:
+                        main.log.warn( "Sanity check failed, skipping this iteration..." )
+                        continue
+                    if isinstance( withdrawResult, str ):
+                        if "Failure" in withdrawResult:
+                            main.log.error( "withdraw Intents failure, ignore this iteration." )
+                            if main.validrun < main.warmUp:
+                                main.validrun += 1
+                                continue
+                            else:
+                                main.invalidrun += 1
+                                continue
 
-                    try:
-                        latency = int( withdrawResult.split()[ 5 ] )
-                        main.log.info( withdrawResult )
-                    except:
-                        main.log.error( "Failed to get latency, ignore this iteration." )
-                        main.log.error( "Response from ONOS:" )
-                        print( withdrawResult )
-                        if validrun < main.warmUp:
-                            validrun += 1
-                            continue
-                        else:
-                            invalidrun += 1
-                            continue
+                        try:
+                            latency = int( withdrawResult.split()[ 5 ] )
+                            main.log.info( withdrawResult )
+                        except:
+                            main.log.error( "Failed to get latency, ignore this iteration." )
+                            main.log.error( "Response from ONOS:" )
+                            print( withdrawResult )
+                            if main.validrun < main.warmUp:
+                                main.validrun += 1
+                                continue
+                            else:
+                                main.invalidrun += 1
+                                continue
 
-                    if validrun >= main.warmUp:
-                        main.withdrawLatList.append( latency )
-                else:
-                    invalidrun += 1
-                    continue
-                time.sleep( 2 )
-                main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
-                validrun += 1
-            installave = numpy.average( main.installLatList )
-            installstd = numpy.std( main.installLatList )
-            withdrawave = numpy.average( main.withdrawLatList )
-            withdrawstd = numpy.std( main.withdrawLatList )
-            # log report
-            main.log.report( "----------------------------------------------------" )
-            main.log.report( "Scale: " + str( main.Cluster.numCtrls ) )
-            main.log.report( "Intent batch: " + str( batchSize ) )
-            main.log.report( "Install average: {}    std: {}".format( installave, installstd ) )
-            main.log.report( "Withdraw average: {}   std: {}".format( withdrawave, withdrawstd ) )
-            # write result to database file
-            if not ( numpy.isnan( installave ) or numpy.isnan( installstd ) or
-                     numpy.isnan( withdrawstd ) or numpy.isnan( withdrawave ) ):
-                databaseString = "'" + main.commit + "',"
-                databaseString += str( main.Cluster.numCtrls ) + ","
-                databaseString += str( batchSize ) + ","
-                databaseString += str( installave ) + ","
-                databaseString += str( installstd ) + ","
-                databaseString += str( withdrawave ) + ","
-                databaseString += str( withdrawstd ) + "\n"
-                resultsDB = open( main.dbFileName, "a" )
-                resultsDB.write( databaseString )
-                resultsDB.close()
+                        if main.validrun >= main.warmUp:
+                            main.withdrawLatList.append( latency )
+                    else:
+                        main.invalidrun += 1
+                        continue
+                    main.validrun += 1
+                result = ( main.TRUE if main.invalidrun <= main.maxInvalidRun else main.FALSE )
+                installave = numpy.average( main.installLatList ) if main.installLatList and result else 0
+                installstd = numpy.std( main.installLatList ) if main.installLatList and result else 0
+                withdrawave = numpy.average( main.withdrawLatList ) if main.withdrawLatList and result else 0
+                withdrawstd = numpy.std( main.withdrawLatList ) if main.withdrawLatList and result else 0
+                testResult = testResult and result
+                # log report
+                main.log.report( "----------------------------------------------------" )
+                main.log.report( "Scale: " + str( main.Cluster.numCtrls ) )
+                main.log.report( "Intent batch: " + str( batchSize ) )
+                main.log.report( "Install average: {}    std: {}".format( installave, installstd ) )
+                main.log.report( "Withdraw average: {}   std: {}".format( withdrawave, withdrawstd ) )
+                # write result to database file
+                if not ( numpy.isnan( installave ) or numpy.isnan( installstd ) or
+                         numpy.isnan( withdrawstd ) or numpy.isnan( withdrawave ) ):
+                    databaseString = "'" + main.commit + "',"
+                    databaseString += str( main.Cluster.numCtrls ) + ","
+                    databaseString += str( batchSize ) + ","
+                    databaseString += str( installave ) + ","
+                    databaseString += str( installstd ) + ","
+                    databaseString += str( withdrawave ) + ","
+                    databaseString += str( withdrawstd ) + "\n"
+                    resultsDB = open( main.dbFileName, "a" )
+                    resultsDB.write( databaseString )
+                    resultsDB.close()
+        else:
+            testResult = main.FALSE
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass="Installing and withdrawing intents properly",
+                                 onfail="There was something wrong installing and withdrawing intents" )
diff --git a/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/dependencies/intentInstallLatFuncs.py b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/dependencies/intentInstallLatFuncs.py
new file mode 100644
index 0000000..032fed4
--- /dev/null
+++ b/TestON/tests/SCPF/SCPFintentInstallWithdrawLat/dependencies/intentInstallLatFuncs.py
@@ -0,0 +1,83 @@
+"""
+The functions for intentInstallWithdrawLat
+
+"""
+import numpy
+import time
+import json
+
+
+def _init_( self ):
+    self.default = ''
+
+
+def sanityCheck( main, linkNumExpected, flowNumExpected, intentNumExpected ):
+    """
+    Sanity check on numbers of links, flows and intents in ONOS
+    """
+    attemps = 0
+    main.verify = main.FALSE
+    linkNum = 0
+    flowNum = 0
+    intentNum = 0
+    while attemps <= main.verifyAttempts:
+        time.sleep( main.verifySleep )
+        summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) )
+        linkNum = summary.get( "links" )
+        flowNum = main.Cluster.active( 0 ).CLI.getTotalFlowsNum( timeout=600, noExit=True )
+        intentNum = summary.get( "intents" )
+        if linkNum == linkNumExpected and flowNum == flowNumExpected and intentNum == intentNumExpected:
+            main.log.info( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
+            main.verify = main.TRUE
+            break
+        attemps += 1
+    if not main.verify:
+        main.log.warn( "Links or flows or intents number not as expected" )
+        main.log.warn( "[Expected] links: {}, flows: {}, intents: {}".format( linkNumExpected, flowNumExpected, intentNumExpected ) )
+        main.log.warn( "[Actual]   links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
+        # bring back topology
+        bringBackTopology( main )
+        if main.validrun >= main.warmUp:
+            main.invalidrun += 1
+        else:
+            main.validrun += 1
+
+def bringBackTopology( main ):
+    main.log.info( "Bring back topology " )
+
+    main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
+                                                  main.egress,
+                                                  main.batchSize,
+                                                  offset=1,
+                                                  options="-w",
+                                                  timeout=main.timeout )
+    main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
+    # configure apps
+    main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                         "deviceCount", value=0 )
+    main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                         "enabled", value="false" )
+    main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg,
+                                         "skipReleaseResourcesOnWithdrawal",
+                                         value="false" )
+    if main.flowObj:
+        main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                             "useFlowObjectives", value="false" )
+    time.sleep( main.startUpSleep )
+    main.Cluster.active( 0 ).CLI.wipeout()
+    time.sleep( main.startUpSleep )
+    main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                         "deviceCount", value=main.deviceCount )
+    main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                         "enabled", value="true" )
+    main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg,
+                                         "skipReleaseResourcesOnWithdrawal",
+                                         value="true" )
+    if main.flowObj:
+        main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                             "useFlowObjectives", value="true" )
+    time.sleep( main.startUpSleep )
+
+    # balanceMasters
+    main.Cluster.active( 0 ).CLI.balanceMasters()
+    time.sleep( main.startUpSleep )
diff --git a/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.params b/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.params
index 3dfbb97..d1aec26 100644
--- a/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.params
+++ b/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.params
@@ -51,15 +51,16 @@
     </GIT>
 
     <ATTEMPTS>
-        <verify>5</verify>
-        <maxInvalidRun>10</maxInvalidRun>
+        <verify>6</verify>
+        <maxInvalidRun>5</maxInvalidRun>
+        <cfg>5</cfg>
     </ATTEMPTS>
 
     <SLEEP>
         <startup>5</startup>
         <setmaster>5</setmaster>
         <install>10</install>
-        <verify>10</verify>
+        <verify>5</verify>
         # timeout for pexpect
         <timeout>300</timeout>
     </SLEEP>
diff --git a/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.py b/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.py
index 41a3408..71bf1aa 100644
--- a/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.py
+++ b/TestON/tests/SCPF/SCPFintentRerouteLat/SCPFintentRerouteLat.py
@@ -72,6 +72,7 @@
             main.setMasterSleep = int( main.params[ 'SLEEP' ][ 'setmaster' ] )
             main.verifyAttempts = int( main.params[ 'ATTEMPTS' ][ 'verify' ] )
             main.maxInvalidRun = int( main.params[ 'ATTEMPTS' ][ 'maxInvalidRun' ] )
+            main.cfgRetry = int( main.params[ 'ATTEMPTS' ][ 'cfg' ] )
             main.sampleSize = int( main.params[ 'TEST' ][ 'sampleSize' ] )
             main.intentManagerCfg = main.params[ 'CFG' ][ 'intentManager' ]
             main.intentConfigRegiCfg = main.params[ 'CFG' ][ 'intentConfigRegi' ]
@@ -122,18 +123,44 @@
         main.maxNumBatch = 0
         main.testSetUp.ONOSSetUp( main.MN1Ip, main.Cluster, True,
                                   cellName=main.cellName, killRemoveMax=False )
-        # configure apps
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, "deviceCount", value=main.deviceCount )
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, "topoShape", value="reroute" )
-        main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg, "enabled", value="true" )
-        main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg, "skipReleaseResourcesOnWithdrawal",
-                                             value="true" )
-        if main.flowObj:
-            main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
-                                                 "useFlowObjectives", value="true" )
-            main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
-                                                 "defaultFlowObjectiveCompiler",
-                                                 value=main.linkCollectionIntentCfg )
+        configRetry = 0
+        main.cfgCheck = False
+        while configRetry < main.cfgRetry:
+            # configure apps
+            stepResult = main.TRUE
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "deviceCount",
+                                                              value=main.deviceCount )
+
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "topoShape",
+                                                              value="reroute" )
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
+                                                              "enabled",
+                                                              value="true" )
+
+            stepResult = stepResult and \
+                         main.Cluster.active( 0 ).CLI.setCfg( main.intentManagerCfg,
+                                                              "skipReleaseResourcesOnWithdrawal",
+                                                              value="true" )
+            if main.flowObj:
+                stepResult = stepResult and \
+                             main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                                                  "useFlowObjectives",
+                                                                  value="true" )
+                stepResult = stepResult and \
+                             main.Cluster.active( 0 ).CLI.setCfg( main.intentConfigRegiCfg,
+                                                                  "defaultFlowObjectiveCompiler",
+                                                                  value=main.linkCollectionIntentCfg )
+            if stepResult:
+                main.cfgCheck = True
+                break
+            configRetry += 1
+            time.sleep( main.verifySleep )
+
         time.sleep( main.startUpSleep )
         for ctrl in main.Cluster.active():
             ctrl.CLI.logSet( "DEBUG", "org.onosproject.metrics.topology" )
@@ -145,6 +172,8 @@
             main.Cluster.active( 0 ).CLI.deviceRole( main.end1[ 'name' ], main.Cluster.active( 0 ).ipAddress )
             main.Cluster.active( 0 ).CLI.deviceRole( main.end2[ 'name' ], main.Cluster.active( 0 ).ipAddress )
         time.sleep( main.setMasterSleep )
+        if not main.cfgCheck:
+            main.log.error( "Setting configuration to the ONOS failed. Skip the rest of the steps" )
 
     def CASE2( self, main ):
         import time
@@ -152,162 +181,174 @@
         import datetime
         import json
         # from scipy import stats
+        testResult = main.TRUE
+        main.case( "Intent Reroute starts" )
+        main.step( "Checking intent reroute" )
+        if main.cfgCheck:
+            print( main.intentsList )
+            for batchSize in main.intentsList:
+                main.batchSize = batchSize
+                main.log.report( "Intent Batch size: " + str( batchSize ) + "\n      " )
+                firstLocalLatencies = []
+                lastLocalLatencies = []
+                firstGlobalLatencies = []
+                lastGlobalLatencies = []
+                main.startLine = {}
+                main.validRun = 0
+                main.invalidRun = 0
+                while main.validRun <= main.warmUp + main.sampleSize and main.invalidRun <= main.maxInvalidRun:
+                    if main.validRun >= main.warmUp:
+                        main.log.info( "================================================" )
+                        main.log.info( "Valid iteration: {} ".format( main.validRun - main.warmUp ) )
+                        main.log.info( "Total iteration: {}".format( main.validRun + main.invalidRun ) )
+                        main.log.info( "================================================" )
+                    else:
+                        main.log.info( "====================Warm Up=====================" )
 
-        print( main.intentsList )
-        for batchSize in main.intentsList:
-            main.batchSize = batchSize
-            main.log.report( "Intent Batch size: " + str( batchSize ) + "\n      " )
-            firstLocalLatencies = []
-            lastLocalLatencies = []
-            firstGlobalLatencies = []
-            lastGlobalLatencies = []
-            main.startLine = {}
-            main.validRun = 0
-            main.invalidRun = 0
-            while main.validRun <= main.warmUp + main.sampleSize and main.invalidRun <= main.maxInvalidRun:
-                if main.validRun >= main.warmUp:
-                    main.log.info( "================================================" )
-                    main.log.info( "Valid iteration: {} ".format( main.validRun - main.warmUp ) )
-                    main.log.info( "Total iteration: {}".format( main.validRun + main.invalidRun ) )
-                    main.log.info( "================================================" )
-                else:
-                    main.log.info( "====================Warm Up=====================" )
+                    # push intents
+                    main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
+                                                                  main.egress,
+                                                                  main.batchSize,
+                                                                  offset=1,
+                                                                  options="-i",
+                                                                  timeout=main.timeout )
 
-                # push intents
-                main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
-                                                              main.egress,
-                                                              main.batchSize,
-                                                              offset=1,
-                                                              options="-i",
-                                                              timeout=main.timeout )
+                    # check links, flows and intents
+                    main.intentRerouteLatFuncs.sanityCheck( main,
+                                                            main.deviceCount * 2,
+                                                            batchSize * ( main.deviceCount - 1 ),
+                                                            main.batchSize )
+                    if not main.verify:
+                        main.log.warn( "Sanity check failed, skipping this iteration..." )
+                        continue
 
-                # check links, flows and intents
-                main.intentRerouteLatFuncs.sanityCheck( main,
-                                                        main.deviceCount * 2,
-                                                        batchSize * ( main.deviceCount - 1 ),
-                                                        main.batchSize )
-                if not main.verify:
-                    main.log.warn( "Sanity check failed, skipping this iteration..." )
-                    continue
+                    # Insert one line in karaf.log before link down
+                    main.Cluster.command( "log",
+                                          args=[ "\'Scale: {}, Batch:{}, Iteration: {}\'".format(
+                                              main.Cluster.numCtrls, batchSize, main.validRun + main.invalidRun ) ],
+                                          returnBool=True, specificDriver=2 )
+                    # bring link down
+                    main.Cluster.active( 0 ).CLI.link( main.end1[ 'port' ], main.end2[ 'port' ], "down",
+                                                       timeout=main.timeout, showResponse=False )
 
-                # Insert one line in karaf.log before link down
-                main.Cluster.command( "log",
-                                      args=[ "\'Scale: {}, Batch:{}, Iteration: {}\'".format(
-                                          main.Cluster.numCtrls, batchSize, main.validRun + main.invalidRun ) ],
-                                      returnBool=True, specificDriver=2 )
-                # bring link down
-                main.Cluster.active( 0 ).CLI.link( main.end1[ 'port' ], main.end2[ 'port' ], "down",
-                                                   timeout=main.timeout, showResponse=False )
+                    # check links, flows and intents
+                    main.intentRerouteLatFuncs.sanityCheck( main,
+                                                            ( main.deviceCount - 1 ) * 2,
+                                                            batchSize * main.deviceCount,
+                                                            main.batchSize )
+                    if not main.verify:
+                        main.log.warn( "Sanity check failed, skipping this iteration..." )
+                        continue
 
-                # check links, flows and intents
-                main.intentRerouteLatFuncs.sanityCheck( main,
-                                                        ( main.deviceCount - 1 ) * 2,
-                                                        batchSize * main.deviceCount,
-                                                        main.batchSize )
-                if not main.verify:
-                    main.log.warn( "Sanity check failed, skipping this iteration..." )
-                    continue
-
-                # Get timestamp of last LINK_REMOVED event as separator between iterations
-                skip = False
-                for i in range( main.Cluster.numCtrls ):
-                    logNum = main.intentRerouteLatFuncs.getLogNum( main, i )
-                    timestamp = str( main.Cluster.active( i ).CLI.getTimeStampFromLog( "last",
-                                                                                       "LINK_REMOVED",
-                                                                                       "time = ", " ",
-                                                                                       logNum=logNum ) )
-                    if timestamp == main.ERROR:
-                        # Try again in case that the log number just increased
+                    # Get timestamp of last LINK_REMOVED event as separator between iterations
+                    skip = False
+                    for i in range( main.Cluster.numCtrls ):
                         logNum = main.intentRerouteLatFuncs.getLogNum( main, i )
                         timestamp = str( main.Cluster.active( i ).CLI.getTimeStampFromLog( "last",
                                                                                            "LINK_REMOVED",
                                                                                            "time = ", " ",
                                                                                            logNum=logNum ) )
-                    if timestamp == main.ERROR:
-                        main.log.warn( "Cannot find the event we want in the log, skipping this iteration..." )
+                        if timestamp == main.ERROR:
+                            # Try again in case that the log number just increased
+                            logNum = main.intentRerouteLatFuncs.getLogNum( main, i )
+                            timestamp = str( main.Cluster.active( i ).CLI.getTimeStampFromLog( "last",
+                                                                                               "LINK_REMOVED",
+                                                                                               "time = ", " ",
+                                                                                               logNum=logNum ) )
+                        if timestamp == main.ERROR:
+                            main.log.warn( "Cannot find the event we want in the log, skipping this iteration..." )
+                            main.intentRerouteLatFuncs.bringBackTopology( main )
+                            if main.validRun >= main.warmUp:
+                                main.invalidRun += 1
+                            else:
+                                main.validRun += 1
+                            skip = True
+                            break
+                        else:
+                            main.startLine[ i ] = timestamp
+                            main.log.info( "Timestamp of last LINK_REMOVED event on node {} is {}".format( i + 1,
+                                                                                                           main.startLine[ i ] ) )
+                    if skip:
+                        continue
+
+                    # calculate values
+                    topologyTimestamps = main.intentRerouteLatFuncs.getTopologyTimestamps( main )
+                    intentTimestamps = main.intentRerouteLatFuncs.getIntentTimestamps( main )
+                    if intentTimestamps == main.ERROR or topologyTimestamps == main.ERROR:
+                        main.log.info( "Got invalid timestamp, skipping this iteration..." )
                         main.intentRerouteLatFuncs.bringBackTopology( main )
                         if main.validRun >= main.warmUp:
                             main.invalidRun += 1
                         else:
                             main.validRun += 1
-                        skip = True
-                        break
+                        continue
                     else:
-                        main.startLine[ i ] = timestamp
-                        main.log.info( "Timestamp of last LINK_REMOVED event on node {} is {}".format( i + 1,
-                                                                                                       main.startLine[ i ] ) )
-                if skip:
-                    continue
+                        main.log.info( "Got valid timestamps" )
 
-                # calculate values
-                topologyTimestamps = main.intentRerouteLatFuncs.getTopologyTimestamps( main )
-                intentTimestamps = main.intentRerouteLatFuncs.getIntentTimestamps( main )
-                if intentTimestamps == main.ERROR or topologyTimestamps == main.ERROR:
-                    main.log.info( "Got invalid timestamp, skipping this iteration..." )
-                    main.intentRerouteLatFuncs.bringBackTopology( main )
-                    if main.validRun >= main.warmUp:
-                        main.invalidRun += 1
+                    firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy \
+                        = main.intentRerouteLatFuncs.calculateLatency( main, topologyTimestamps, intentTimestamps )
+                    if firstLocalLatnecy < 0:
+                        main.log.info( "Got negative latency, skipping this iteration..." )
+                        main.intentRerouteLatFuncs.bringBackTopology( main )
+                        if main.validRun >= main.warmUp:
+                            main.invalidRun += 1
+                        else:
+                            main.validRun += 1
+                        continue
                     else:
+                        main.log.info( "Got valid latencies" )
                         main.validRun += 1
-                    continue
-                else:
-                    main.log.info( "Got valid timestamps" )
 
-                firstLocalLatnecy, lastLocalLatnecy, firstGlobalLatency, lastGlobalLatnecy \
-                    = main.intentRerouteLatFuncs.calculateLatency( main, topologyTimestamps, intentTimestamps )
-                if firstLocalLatnecy < 0:
-                    main.log.info( "Got negative latency, skipping this iteration..." )
-                    main.intentRerouteLatFuncs.bringBackTopology( main )
                     if main.validRun >= main.warmUp:
-                        main.invalidRun += 1
-                    else:
-                        main.validRun += 1
-                    continue
-                else:
-                    main.log.info( "Got valid latencies" )
-                    main.validRun += 1
+                        firstLocalLatencies.append( firstLocalLatnecy )
+                        lastLocalLatencies.append( lastLocalLatnecy )
+                        firstGlobalLatencies.append( firstGlobalLatency )
+                        lastGlobalLatencies.append( lastGlobalLatnecy )
 
-                firstLocalLatencies.append( firstLocalLatnecy )
-                lastLocalLatencies.append( lastLocalLatnecy )
-                firstGlobalLatencies.append( firstGlobalLatency )
-                lastGlobalLatencies.append( lastGlobalLatnecy )
+                    # bring up link and withdraw intents
+                    main.Cluster.active( 0 ).CLI.link( main.end1[ 'port' ],
+                                                       main.end2[ 'port' ],
+                                                       "up",
+                                                       timeout=main.timeout )
+                    main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
+                                                                  main.egress,
+                                                                  batchSize,
+                                                                  offset=1,
+                                                                  options="-w",
+                                                                  timeout=main.timeout )
+                    main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
 
-                # bring up link and withdraw intents
-                main.Cluster.active( 0 ).CLI.link( main.end1[ 'port' ],
-                                                   main.end2[ 'port' ],
-                                                   "up",
-                                                   timeout=main.timeout )
-                main.Cluster.active( 0 ).CLI.pushTestIntents( main.ingress,
-                                                              main.egress,
-                                                              batchSize,
-                                                              offset=1,
-                                                              options="-w",
-                                                              timeout=main.timeout )
-                main.Cluster.active( 0 ).CLI.purgeWithdrawnIntents()
+                    # check links, flows and intents
+                    main.intentRerouteLatFuncs.sanityCheck( main, main.deviceCount * 2, 0, 0 )
+                    if not main.verify:
+                        main.log.warn( "Sanity check failed, skipping this iteration..." )
+                        continue
+                result = ( main.TRUE if main.invalidRun <= main.maxInvalidRun else main.FALSE )
+                aveLocalLatency = numpy.average( lastLocalLatencies ) if lastLocalLatencies and result else 0
+                aveGlobalLatency = numpy.average( lastGlobalLatencies ) if lastGlobalLatencies and result else 0
+                stdLocalLatency = numpy.std( lastLocalLatencies ) if lastLocalLatencies and result else 0
+                stdGlobalLatency = numpy.std( lastGlobalLatencies ) if lastGlobalLatencies and result else 0
+                testResult = testResult and result
 
-                # check links, flows and intents
-                main.intentRerouteLatFuncs.sanityCheck( main, main.deviceCount * 2, 0, 0 )
-                if not main.verify:
-                    continue
+                main.log.report( "Scale: " + str( main.Cluster.numCtrls ) + "  \tIntent batch: " + str( batchSize ) )
+                main.log.report( "Local latency average:................" + str( aveLocalLatency ) )
+                main.log.report( "Global latency average:................" + str( aveGlobalLatency ) )
+                main.log.report( "Local latency std:................" + str( stdLocalLatency ) )
+                main.log.report( "Global latency std:................" + str( stdGlobalLatency ) )
+                main.log.report( "________________________________________________________" )
 
-            aveLocalLatency = numpy.average( lastLocalLatencies )
-            aveGlobalLatency = numpy.average( lastGlobalLatencies )
-            stdLocalLatency = numpy.std( lastLocalLatencies )
-            stdGlobalLatency = numpy.std( lastGlobalLatencies )
-
-            main.log.report( "Scale: " + str( main.Cluster.numCtrls ) + "  \tIntent batch: " + str( batchSize ) )
-            main.log.report( "Local latency average:................" + str( aveLocalLatency ) )
-            main.log.report( "Global latency average:................" + str( aveGlobalLatency ) )
-            main.log.report( "Local latency std:................" + str( stdLocalLatency ) )
-            main.log.report( "Global latency std:................" + str( stdGlobalLatency ) )
-            main.log.report( "________________________________________________________" )
-
-            if not ( numpy.isnan( aveLocalLatency ) or numpy.isnan( aveGlobalLatency ) ):
-                # check if got NaN for result
-                resultsDB = open( main.dbFileName, "a" )
-                resultsDB.write( "'" + main.commit + "'," )
-                resultsDB.write( str( main.Cluster.numCtrls ) + "," )
-                resultsDB.write( str( batchSize ) + "," )
-                resultsDB.write( str( aveLocalLatency ) + "," )
-                resultsDB.write( str( stdLocalLatency ) + "\n" )
-                resultsDB.close()
+                if not ( numpy.isnan( aveLocalLatency ) or numpy.isnan( aveGlobalLatency ) ):
+                    # check if got NaN for result
+                    resultsDB = open( main.dbFileName, "a" )
+                    resultsDB.write( "'" + main.commit + "'," )
+                    resultsDB.write( str( main.Cluster.numCtrls ) + "," )
+                    resultsDB.write( str( batchSize ) + "," )
+                    resultsDB.write( str( aveLocalLatency ) + "," )
+                    resultsDB.write( str( stdLocalLatency ) + "\n" )
+                    resultsDB.close()
+        else:
+            testResult = main.FALSE
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass="Installing and withdrawing intents reroute properly",
+                                 onfail="There was something wrong installing and withdrawing intents reroute" )
diff --git a/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/intentRerouteLatFuncs.py b/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/intentRerouteLatFuncs.py
index d91f09e..947917b 100644
--- a/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/intentRerouteLatFuncs.py
+++ b/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/intentRerouteLatFuncs.py
@@ -24,7 +24,7 @@
         time.sleep( main.verifySleep )
         summary = json.loads( main.Cluster.active( 0 ).CLI.summary( timeout=main.timeout ) )
         linkNum = summary.get( "links" )
-        flowNum = summary.get( "flows" )
+        flowNum = main.Cluster.active( 0 ).CLI.getTotalFlowsNum( timeout=600, noExit=True )
         intentNum = summary.get( "intents" )
         if linkNum == linkNumExpected and flowNum == flowNumExpected and intentNum == intentNumExpected:
             main.log.info( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
@@ -33,7 +33,8 @@
         attemps += 1
     if not main.verify:
         main.log.warn( "Links or flows or intents number not as expected" )
-        main.log.warn( "links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
+        main.log.warn( "[Expected] links: {}, flows: {}, intents: {}".format( linkNumExpected, flowNumExpected, intentNumExpected ) )
+        main.log.warn( "[Actual]   links: {}, flows: {}, intents: {}".format( linkNum, flowNum, intentNum ) )
         # bring back topology
         bringBackTopology( main )
         if main.validRun >= main.warmUp:
@@ -57,6 +58,9 @@
     main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
                                          "enabled",
                                          value="false" )
+    time.sleep( main.startUpSleep )
+    main.Cluster.active( 0 ).CLI.wipeout()
+    time.sleep( main.startUpSleep )
     main.Cluster.active( 0 ).CLI.setCfg( main.nullProviderCfg,
                                          "deviceCount",
                                          value=main.deviceCount )
diff --git a/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/rerouteTopo.py b/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/rerouteTopo.py
new file mode 100644
index 0000000..62850e7
--- /dev/null
+++ b/TestON/tests/SCPF/SCPFintentRerouteLat/dependencies/rerouteTopo.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+
+"""
+Copyright 2015 Open Networking Foundation ( ONF )
+
+Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
+the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
+or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
+
+    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.
+
+    You should have received a copy of the GNU General Public License
+    along with TestON.  If not, see <http://www.gnu.org/licenses/>.
+"""
+"""
+Custom topology for Mininet
+"""
+from mininet.topo import Topo
+from mininet.net import Mininet
+from mininet.node import Host, RemoteController
+from mininet.node import Node
+from mininet.link import TCLink
+from mininet.cli import CLI
+from mininet.log import setLogLevel
+from mininet.util import dumpNodeConnections
+from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
+
+
+class MyTopo( Topo ):
+
+    def __init__( self ):
+        # Initialize topology
+        Topo.__init__( self )
+
+        host1 = self.addHost( 'h1', ip='10.1.0.1/24' )
+        host2 = self.addHost( 'h2', ip='10.1.0.2/24' )
+        host3 = self.addHost( 'h3', ip='10.1.0.3/24' )
+        host4 = self.addHost( 'h4', ip='10.1.0.4/24' )
+        host5 = self.addHost( 'h5', ip='10.1.0.5/24' )
+        host6 = self.addHost( 'h6', ip='10.1.0.6/24' )
+        host7 = self.addHost( 'h7', ip='10.1.0.7/24' )
+        host8 = self.addHost( 'h8', ip='10.1.0.8/24' )
+
+        s1 = self.addSwitch( 's1' )
+        s2 = self.addSwitch( 's2' )
+        s3 = self.addSwitch( 's3' )
+        s4 = self.addSwitch( 's4' )
+        s5 = self.addSwitch( 's5' )
+        s6 = self.addSwitch( 's6' )
+        s7 = self.addSwitch( 's7' )
+        s8 = self.addSwitch( 's8' )
+
+        self.addLink( s1, host1 )
+        self.addLink( s2, host2 )
+        self.addLink( s3, host3 )
+        self.addLink( s4, host4 )
+        self.addLink( s5, host5 )
+        self.addLink( s6, host6 )
+        self.addLink( s7, host7 )
+        self.addLink( s8, host8 )
+
+        self.addLink( s1, s2 )
+        self.addLink( s2, s3 )
+        self.addLink( s3, s4 )
+        self.addLink( s4, s5 )
+        self.addLink( s5, s6 )
+        self.addLink( s6, s7 )
+        self.addLink( s3, s8 )
+        self.addLink( s8, s4 )
+
+topos = { 'mytopo': ( lambda: MyTopo() ) }
+
+# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
+
+
+def setupNetwork():
+    "Create network"
+    topo = MyTopo()
+    network = Mininet( topo=topo, autoSetMacs=True, controller=None )
+    network.start()
+    CLI( network )
+    network.stop()
+
+if __name__ == '__main__':
+    setLogLevel( 'info' )
+    # setLogLevel( 'debug' )
+    setupNetwork()