'''
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/>.
'''

import sys
import os
import re
import time
import json
import itertools


class CHOtest:

    def __init__( self ):
        self.default = ''

    def CASE1( self, main ):
        """
        Startup sequence:
        apply cell <name>
        git pull
        onos-package
        onos-verify-cell
        onos-uninstall
        onos-install
        onos-start-cli
        """
        import time
        import re
        import imp

        global intentState
        try:
            from tests.dependencies.ONOSSetup import ONOSSetup
            main.testSetUp = ONOSSetup()
        except ImportError:
            main.log.error( "ONOSSetup not found exiting the test" )
            main.exit()
        main.testSetUp.envSetupDescription()

        try:
            time1 = time.time()
            main.dependencyPath = main.testOnDirectory + \
                                  main.params[ 'DEPENDENCY' ][ 'path' ]
            wrapperFile = main.params[ 'DEPENDENCY' ][ 'wrapper' ]
            main.numCtrls = int ( main.params[ 'CTRL' ][ 'numCtrl' ] )
            main.maxNodes = main.numCtrls
            karafTimeout = main.params[ 'CTRL' ][ 'karafCliTimeout' ]
            main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
            main.checkIntentsDelay = int( main.params[ 'timers' ][ 'CheckIntentDelay' ] )
            main.pingSleep = int( main.params[ 'timers' ][ 'pingSleep' ] )
            main.topoCheckDelay = int( main.params[ 'timers' ][ 'topoCheckDelay' ] )
            main.pingTimeoutSmallTopo = int( main.params[ 'timers' ][ 'pingTimeoutSmallTopo' ] )
            main.pingTimeoutLargeTopo = int( main.params[ 'timers' ][ 'pingTimeoutLargeTopo' ] )
            main.remHostDelay = int( main.params[ 'timers' ][ 'remHostDelay' ] )
            main.remDevDelay = int( main.params[ 'timers' ][ 'remDevDelay' ] )
            main.failSwitch = main.params[ 'TEST' ][ 'pauseTest' ]
            main.emailOnStop = main.params[ 'TEST' ][ 'email' ]
            main.intentCheck = int( main.params[ 'TEST' ][ 'intentChecks' ] )
            main.linkCheck = int( main.params[ 'TEST' ][ 'linkChecks' ] )
            main.topoCheck = int( main.params[ 'TEST' ][ 'topoChecks' ] )
            main.numPings = int( main.params[ 'TEST' ][ 'numPings' ] )
            main.newTopo = ""

            main.failSwitch = True if main.failSwitch == "on" else False
            main.emailOnStop = True if main.emailOnStop == "on" else False

            main.CHOtestFunctions = imp.load_source( wrapperFile,
                                                     main.dependencyPath +
                                                     wrapperFile +
                                                     ".py" )

            stepResult = main.testSetUp.envSetup()
        except Exception as e:
            main.testSetUp.envSetupException( e )

        main.testSetUp.evnSetupConclusion( stepResult )

        if not main.onoscell :
            main.log.error("Please provide onoscell option at TestON CLI to run CHO tests")
            main.log.error("Example: ~/TestON/bin/cli.py run CHOtest onoscell <cellName>")
            main.cleanup()
            main.exit()

        setupResult = main.testSetUp.ONOSSetUp( Mininet=main.Mininet1, newCell=False, cellName=main.onoscell )

        main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
        time.sleep( 30 )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.proxyarp.ProxyArp", "ipv6NeighborDiscovery", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", "ipv6NeighborDiscovery", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="ipv6NeighborDiscovery cfg is set to true",
                                 onfail="Failed to cfg set ipv6NeighborDiscovery" )

        case1Result = setupResult and cfgResult
        main.log.info( "Time for connecting to CLI: %2f seconds" % ( time.time() - time1 ) )
        utilities.assert_equals( expect=main.TRUE, actual=case1Result,
                                 onpass="Set up test environment PASS",
                                 onfail="Set up test environment FAIL" )

    def CASE20( self, main ):
        """
        This test script Loads a new Topology ( Att ) on CHO setup and balances all switches
        """
        import re
        import time
        import copy

        main.prefix = 0
        main.numMNswitches = int( main.params[ 'TOPO1' ][ 'numSwitches' ] )
        main.numMNlinks = int( main.params[ 'TOPO1' ][ 'numLinks' ] )
        main.numMNhosts = int( main.params[ 'TOPO1' ][ 'numHosts' ] )
        main.pingTimeout = main.pingTimeoutSmallTopo

        main.log.report(
            "Load Att topology and Balance all Mininet switches across controllers" )
        main.log.report(
            "________________________________________________________________________" )
        main.case(
            "Assign and Balance all Mininet switches across controllers" )

        main.step( "Start Mininet with Att topology" )
        main.newTopo = main.params[ 'TOPO1' ][ 'topo' ]
        mininetDir = main.Mininet1.home + "/custom/"
        topoPath = main.dependencyPath + main.newTopo
        main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
        topoPath = mininetDir + main.newTopo
        startStatus = main.Mininet1.startNet( topoFile=topoPath )

        main.step( "Assign switches to controllers" )
        for i in range( 1, ( main.numMNswitches + 1 ) ):  # 1 to ( num of switches +1 )
            main.Mininet1.assignSwController(
                sw="s" + str( i ),
                ip=main.ONOSip )

        switch_mastership = main.TRUE
        for i in range( 1, ( main.numMNswitches + 1 ) ):
            response = main.Mininet1.getSwController( "s" + str( i ) )
            print( "Response is " + str( response ) )
            if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
                switch_mastership = switch_mastership and main.TRUE
            else:
                switch_mastership = main.FALSE

        if switch_mastership == main.TRUE:
            main.log.report( "Controller assignment successfull" )
        else:
            main.log.report( "Controller assignment failed" )

        time.sleep( 30 )  # waiting here to make sure topology converges across all nodes

        main.step( "Balance devices across controllers" )
        balanceResult = main.ONOScli1.balanceMasters()
        # giving some breathing time for ONOS to complete re-balance
        time.sleep( 5 )

        topology_output = main.ONOScli1.topology()
        topology_result = main.ONOScli1.getTopology( topology_output )
        case2Result = ( switch_mastership and startStatus )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=case2Result,
            onpass="Starting new Att topology test PASS",
            onfail="Starting new Att topology test FAIL" )

    def CASE21( self, main ):
        """
        This test script Loads a new Topology ( Chordal ) on CHO setup and balances all switches
        """
        import re
        import time
        import copy

        main.prefix = 1
        main.newTopo = main.params[ 'TOPO2' ][ 'topo' ]
        main.numMNswitches = int( main.params[ 'TOPO2' ][ 'numSwitches' ] )
        main.numMNlinks = int( main.params[ 'TOPO2' ][ 'numLinks' ] )
        main.numMNhosts = int( main.params[ 'TOPO2' ][ 'numHosts' ] )
        main.pingTimeout = main.pingTimeoutSmallTopo

        main.log.report(
            "Load Chordal topology and Balance all Mininet switches across controllers" )
        main.log.report(
            "________________________________________________________________________" )
        main.case(
            "Assign and Balance all Mininet switches across controllers" )

        main.step( "Start Mininet with Chordal topology" )
        mininetDir = main.Mininet1.home + "/custom/"
        topoPath = main.dependencyPath + main.newTopo
        main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
        topoPath = mininetDir + main.newTopo
        startStatus = main.Mininet1.startNet( topoFile=topoPath )

        main.step( "Assign switches to controllers" )

        for i in range( 1, ( main.numMNswitches + 1 ) ):  # 1 to ( num of switches +1 )
            main.Mininet1.assignSwController(
                sw="s" + str( i ),
                ip=main.ONOSip )

        switch_mastership = main.TRUE
        for i in range( 1, ( main.numMNswitches + 1 ) ):
            response = main.Mininet1.getSwController( "s" + str( i ) )
            print( "Response is " + str( response ) )
            if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
                switch_mastership = switch_mastership and main.TRUE
            else:
                switch_mastership = main.FALSE

        if switch_mastership == main.TRUE:
            main.log.report( "Controller assignment successfull" )
        else:
            main.log.report( "Controller assignment failed" )

        main.step( "Balance devices across controllers" )
        balanceResult = main.ONOScli1.balanceMasters()
        # giving some breathing time for ONOS to complete re-balance
        time.sleep( 5 )

        caseResult = switch_mastership
        time.sleep( 30 )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Starting new Chordal topology test PASS",
            onfail="Starting new Chordal topology test FAIL" )

    def CASE22( self, main ):
        """
        This test script Loads a new Topology ( Spine ) on CHO setup and balances all switches
        """
        import re
        import time
        import copy

        main.prefix = 2
        main.newTopo = main.params[ 'TOPO3' ][ 'topo' ]
        main.numMNswitches = int( main.params[ 'TOPO3' ][ 'numSwitches' ] )
        main.numMNlinks = int( main.params[ 'TOPO3' ][ 'numLinks' ] )
        main.numMNhosts = int( main.params[ 'TOPO3' ][ 'numHosts' ] )
        main.pingTimeout = main.pingTimeoutLargeTopo

        main.log.report(
            "Load Spine and Leaf topology and Balance all Mininet switches across controllers" )
        main.log.report(
            "________________________________________________________________________" )
        main.case( "Assign and Balance all Mininet switches across controllers" )

        main.step( "Start Mininet with Spine topology" )
        mininetDir = main.Mininet1.home + "/custom/"
        topoPath = main.dependencyPath + main.newTopo
        main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
        topoPath = mininetDir + main.newTopo
        startStatus = main.Mininet1.startNet( topoFile=topoPath )

        for i in range( 1, ( main.numMNswitches + 1 ) ):  # 1 to ( num of switches +1 )
            main.Mininet1.assignSwController(
                sw="s" + str( i ),
                ip=main.ONOSip )

        switch_mastership = main.TRUE
        for i in range( 1, ( main.numMNswitches + 1 ) ):
            response = main.Mininet1.getSwController( "s" + str( i ) )
            print( "Response is " + str( response ) )
            if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
                switch_mastership = switch_mastership and main.TRUE
            else:
                switch_mastership = main.FALSE

        if switch_mastership == main.TRUE:
            main.log.report( "Controller assignment successfull" )
        else:
            main.log.report( "Controller assignment failed" )
        time.sleep( 5 )

        main.step( "Balance devices across controllers" )
        for i in range( main.numCtrls ):
            balanceResult = main.ONOScli1.balanceMasters()
            # giving some breathing time for ONOS to complete re-balance
            time.sleep( 3 )

        caseResult = switch_mastership
        time.sleep( 60 )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Starting new Spine topology test PASS",
            onfail="Starting new Spine topology test FAIL" )

    def CASE3( self, main ):
        """
        This Test case will be extended to collect and store more data related
        ONOS state.
        """
        import re
        import copy
        main.deviceDPIDs = []
        main.hostMACs = []
        main.deviceLinks = []
        main.deviceActiveLinksCount = []
        main.devicePortsEnabledCount = []

        main.log.report(
            "Collect and Store topology details from ONOS before running any Tests" )
        main.log.report(
            "____________________________________________________________________" )
        main.case( "Collect and Store Topology Details from ONOS" )
        main.step( "Collect and store current number of switches and links" )
        topology_output = main.ONOScli1.topology()
        topology_result = main.ONOScli1.getTopology( topology_output )
        numOnosDevices = topology_result[ 'devices' ]
        numOnosLinks = topology_result[ 'links' ]
        topoResult = main.TRUE

        for check in range( main.topoCheck ):
            if ( ( main.numMNswitches == int( numOnosDevices ) ) and ( main.numMNlinks == int( numOnosLinks ) ) ):
                main.step( "Store Device DPIDs" )
                for i in range( 1, ( main.numMNswitches + 1 ) ):
                    main.deviceDPIDs.append( "of:00000000000000" + format( i, "02x" ) )
                print "Device DPIDs in Store: \n", str( main.deviceDPIDs )

                main.step( "Store Host MACs" )
                for i in range( 1, ( main.numMNhosts + 1 ) ):
                    main.hostMACs.append( "00:00:00:00:00:" + format( i, '02x' ) + "/-1" )
                print "Host MACs in Store: \n", str( main.hostMACs )
                main.MACsDict = {}
                print "Creating dictionary of DPID and HostMacs"
                for i in range( len( main.hostMACs ) ):
                    main.MACsDict[ main.deviceDPIDs[ i ] ] = main.hostMACs[ i ].split( '/' )[ 0 ]
                print main.MACsDict
                main.step( "Collect and store all Devices Links" )
                linksResult = main.ONOScli1.links( jsonFormat=False )
                ansi_escape = re.compile( r'\x1b[^m]*m' )
                linksResult = ansi_escape.sub( '', linksResult )
                linksResult = linksResult.replace( " links", "" ).replace( "\r\r", "" )
                linksResult = linksResult.splitlines()
                main.deviceLinks = copy.copy( linksResult )
                print "Device Links Stored: \n", str( main.deviceLinks )
                # this will be asserted to check with the params provided count of
                # links
                print "Length of Links Store", len( main.deviceLinks )

                main.step( "Collect and store each Device ports enabled Count" )
                time1 = time.time()
                for i in xrange( 1, ( main.numMNswitches + 1 ), main.numCtrls ):
                    pool = []
                    for cli in main.CLIs:
                        if i >= main.numMNswitches + 1:
                            break
                        dpid = "of:00000000000000" + format( i, "02x" )
                        t = main.Thread( target=cli.getDevicePortsEnabledCount, threadID=main.threadID, name="getDevicePortsEnabledCount", args=[ dpid ] )
                        t.start()
                        pool.append( t )
                        i = i + 1
                        main.threadID = main.threadID + 1
                    for thread in pool:
                        thread.join()
                        portResult = thread.result
                        main.devicePortsEnabledCount.append( portResult )
                print "Device Enabled Port Counts Stored: \n", str( main.devicePortsEnabledCount )
                time2 = time.time()
                main.log.info( "Time for counting enabled ports of the switches: %2f seconds" % ( time2 - time1 ) )

                main.step( "Collect and store each Device active links Count" )
                time1 = time.time()

                for i in xrange( 1, ( main.numMNswitches + 1 ), main.numCtrls ):
                    pool = []
                    for cli in main.CLIs:
                        if i >= main.numMNswitches + 1:
                            break
                        dpid = "of:00000000000000" + format( i, "02x" )
                        t = main.Thread( target=cli.getDeviceLinksActiveCount,
                                         threadID=main.threadID,
                                         name="getDevicePortsEnabledCount",
                                         args=[ dpid ] )
                        t.start()
                        pool.append( t )
                        i = i + 1
                        main.threadID = main.threadID + 1
                    for thread in pool:
                        thread.join()
                        linkCountResult = thread.result
                        main.deviceActiveLinksCount.append( linkCountResult )
                print "Device Active Links Count Stored: \n", str( main.deviceActiveLinksCount )
                time2 = time.time()
                main.log.info( "Time for counting all enabled links of the switches: %2f seconds" % ( time2 - time1 ) )

                # Exit out of the topo check loop
                break

            else:
                main.log.info( "Devices (expected): %s, Links (expected): %s" %
                               ( str( main.numMNswitches ), str( main.numMNlinks ) ) )
                main.log.info( "Devices (actual): %s, Links (actual): %s" %
                               ( numOnosDevices, numOnosLinks ) )
                main.log.info( "Topology does not match, trying again..." )
                topoResult = main.FALSE
                time.sleep( main.topoCheckDelay )

        # just returning TRUE for now as this one just collects data
        case3Result = topoResult
        utilities.assert_equals( expect=main.TRUE, actual=case3Result,
                                 onpass="Saving ONOS topology data test PASS",
                                 onfail="Saving ONOS topology data test FAIL" )

    def CASE200( self, main ):

        import time
        try:
            from tests.dependencies.utils import Utils
        except ImportError:
            main.log.error( "Utils not found. exiting the test" )
            main.exit()
        try:
            main.Utils
        except ( NameError, AttributeError ):
            main.Utils = Utils()

        main.log.report( "Clean up ONOS" )
        main.case( "Stop topology and remove hosts and devices" )

        main.Utils.mininetCleanup( False )

        main.log.info( "Constructing host id list" )
        hosts = []
        for i in range( main.numMNhosts ):
            hosts.append( "h" + str( i + 1 ) )

        main.step( "Getting host ids" )
        hostList = main.CLIs[ 0 ].getHostsId( hosts )
        hostIdResult = True if hostList else False
        utilities.assert_equals( expect=True, actual=hostIdResult,
                                 onpass="Successfully obtained the host ids.",
                                 onfail="Failed to obtain the host ids" )

        main.step( "Removing hosts" )
        hostResult = main.CLIs[ 0 ].removeHost( hostList )
        utilities.assert_equals( expect=main.TRUE, actual=hostResult,
                                 onpass="Successfully removed hosts",
                                 onfail="Failed remove hosts" )

        time.sleep( main.remHostDelay )

        main.log.info( "Constructing device uri list" )
        deviceList = []
        for i in range( main.numMNswitches ):
            deviceList.append( "of:00000000000000" + format( i + 1, "02x" ) )

        main.step( "Removing devices" )
        deviceResult = main.CLIs[ 0 ].removeDevice( deviceList )
        utilities.assert_equals( expect=main.TRUE, actual=deviceResult,
                                 onpass="Successfully removed devices",
                                 onfail="Failed remove devices" )

        time.sleep( main.remDevDelay )

        main.log.info( "Summary\n{}".format( main.CLIs[ 0 ].summary( jsonFormat=False ) ) )

    def CASE40( self, main ):
        """
        Verify Reactive forwarding
        """
        import time
        main.log.report( "Verify Reactive forwarding" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify pingall, and disable reactive forwarding" )

        main.step( "Enable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="Reactive Mode IPv4 Pingall test PASS",
                                 onfail="Reactive Mode IPv4 Pingall test FAIL" )

        if not pingResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

        main.step( "Disable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated fwd app",
                                 onfail="Failed to deactivate fwd app" )

    def CASE41( self, main ):
        """
        Verify Reactive forwarding ( Chordal Topology )
        """
        import re
        import copy
        import time
        main.log.report( "Verify Reactive forwarding (Chordal Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding and Verify ping all" )
        main.step( "Enable Reactive forwarding" )
        installResult = main.TRUE
        # Activate fwd app
        appResults = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )

        appCheck = main.TRUE
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()
        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )
        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        time.sleep( 10 )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if not pingResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

        if pingResult == main.TRUE:
            main.log.report( "IPv4 Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "IPv4 Pingall Test in Reactive mode failed" )

        caseResult = appCheck and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Reactive Mode IPv4 Pingall test PASS",
                                 onfail="Reactive Mode IPv4 Pingall test FAIL" )

    def CASE42( self, main ):
        """
        Verify Reactive forwarding ( Spine Topology )
        """
        import re
        import copy
        import time
        main.log.report( "Verify Reactive forwarding (Spine Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding and Verify ping all" )
        main.step( "Enable Reactive forwarding" )
        installResult = main.TRUE
        # Activate fwd app
        appResults = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )

        appCheck = main.TRUE
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()
        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )
        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        time.sleep( 10 )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if not pingResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

        if pingResult == main.TRUE:
            main.log.report( "IPv4 Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "IPv4 Pingall Test in Reactive mode failed" )

        caseResult = appCheck and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Reactive Mode IPv4 Pingall test PASS",
                                 onfail="Reactive Mode IPv4 Pingall test FAIL" )

    def CASE47( self, main ):
        """
        Verify reactive forwarding in ATT topology, use a different ping method than CASE40
        """
        import time
        main.log.report( "Verify Reactive forwarding (ATT Topology) " )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping, and disable reactive forwarding" )

        main.step( "Enable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        numHosts = int( main.params[ 'TOPO1' ][ 'numHosts' ] )

        for i in range( numHosts ):
            src = "h1"
            dest = "h" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )

        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )

        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated fwd app",
                                 onfail="Failed to deactivate fwd app" )

    def CASE48( self, main ):
        """
        Verify reactive forwarding in Chordal topology, use a different ping method than CASE41
        """
        import time
        main.log.report( "Verify Reactive forwarding (Chordal Topology) " )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping, and disable reactive forwarding" )

        main.step( "Enable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        numHosts = int( main.params[ 'TOPO2' ][ 'numHosts' ] )

        for i in range( numHosts ):
            src = "h1"
            dest = "h" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )

        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )

        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated fwd app",
                                 onfail="Failed to deactivate fwd app" )

    def CASE49( self, main ):
        """
        Verify reactive forwarding in Spine-leaf topology, use a different ping method than CASE42
        """
        import time
        main.log.report( "Verify Reactive forwarding (Spine-leaf Topology) " )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping, and disable reactive forwarding" )

        main.step( "Enable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        numHosts = int( main.params[ 'TOPO3' ][ 'numHosts' ] )

        for i in range( 11, numHosts + 10 ):
            src = "h11"
            dest = "h" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )

        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )

        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated fwd app",
                                 onfail="Failed to deactivate fwd app" )

    def CASE140( self, main ):
        """
        Verify IPv6 Reactive forwarding ( Att Topology )
        """
        import re
        import copy
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (Att Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable IPv6 Reactive forwarding and Verify ping all" )
        hostList = [ ( 'h' + str( x + 1 ) ) for x in range( main.numMNhosts ) ]

        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Verify IPv6 Pingall" )
        pingResult = main.FALSE
        time1 = time.time()
        pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        if not pingResult:
            main.log.warn( "First pingall failed. Trying again.." )
            pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for IPv6 Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if pingResult == main.TRUE:
            main.log.report( "IPv6 Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "IPv6 Pingall Test in Reactive mode failed" )

        caseResult = appCheck and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Reactive Mode IPv6 Pingall test PASS",
                                 onfail="Reactive Mode IPv6 Pingall test FAIL" )

    def CASE141( self, main ):
        """
        Verify IPv6 Reactive forwarding ( Chordal Topology )
        """
        import re
        import copy
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (Chordal Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable IPv6 Reactive forwarding and Verify ping all" )
        hostList = [ ( 'h' + str( x + 1 ) ) for x in range( main.numMNhosts ) ]

        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Verify IPv6 Pingall" )
        pingResult = main.FALSE
        time1 = time.time()
        pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        if not pingResult:
            main.log.warn( "First pingall failed. Trying again.." )
            pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for IPv6 Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if pingResult == main.TRUE:
            main.log.report( "IPv6 Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "IPv6 Pingall Test in Reactive mode failed" )

        main.step( "Disable Reactive forwarding" )

        main.log.info( "Uninstall reactive forwarding app" )
        appCheck = main.TRUE
        appResults = appResults and main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()

        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )
        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        # Waiting for reative flows to be cleared.
        time.sleep( 30 )
        caseResult = appCheck and cfgResult and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Reactive Mode IPv6 Pingall test PASS",
                                 onfail="Reactive Mode IPv6 Pingall test FAIL" )

    def CASE142( self, main ):
        """
        Verify IPv6 Reactive forwarding ( Spine Topology )
        """
        import re
        import copy
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (Spine Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable IPv6 Reactive forwarding and Verify ping all" )
        # Spine topology do not have hosts h1-h10
        hostList = [ ( 'h' + str( x + 11 ) ) for x in range( main.numMNhosts ) ]
        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Verify IPv6 Pingall" )
        pingResult = main.FALSE
        time1 = time.time()
        pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        if not pingResult:
            main.log.warn( "First pingall failed. Trying again..." )
            pingResult = main.Mininet1.pingall( protocol="IPv6", timeout=main.pingTimeout )
        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for IPv6 Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if pingResult == main.TRUE:
            main.log.report( "IPv6 Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "IPv6 Pingall Test in Reactive mode failed" )

        main.step( "Disable Reactive forwarding" )

        main.log.info( "Uninstall reactive forwarding app" )
        appCheck = main.TRUE
        appResults = appResults and main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()

        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )
        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        # Waiting for reative flows to be cleared.
        time.sleep( 30 )
        caseResult = appCheck and cfgResult and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Reactive Mode IPv6 Pingall test PASS",
                                 onfail="Reactive Mode IPv6 Pingall test FAIL" )

    def CASE147( self, main ):
        """
        Verify IPv6 reactive forwarding in ATT topology, use a different ping method than CASE140
        """
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (ATT Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping6, and disable reactive forwarding" )

        main.step( "Enable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Discover hosts using ping" )
        numHosts = int( main.params[ 'TOPO1' ][ 'numHosts' ] )
        for i in range( numHosts ):
            src = "h1"
            dest = "1000::" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping6 " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )
        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )
        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        main.log.info( "Uninstall IPv6 reactive forwarding app" )
        appCheck = main.TRUE
        appResults = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()

        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )

        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        # Waiting for reative flows to be cleared.
        time.sleep( 30 )

        main.step( "Disable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated IPv4 fwd app",
                                 onfail="Failed to deactivate IPv4 fwd app" )

    def CASE148( self, main ):
        """
        Verify reactive forwarding in Chordal topology, use a different ping method than CASE141
        """
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (Chordal Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping6, and disable reactive forwarding" )

        main.step( "Enable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Discover hosts using ping" )
        numHosts = int( main.params[ 'TOPO2' ][ 'numHosts' ] )
        for i in range( numHosts ):
            src = "h1"
            dest = "1000::" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping6 " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )
        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )
        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        main.log.info( "Uninstall IPv6 reactive forwarding app" )
        appCheck = main.TRUE
        appResults = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()

        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )

        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        # Waiting for reative flows to be cleared.
        time.sleep( 30 )

        main.step( "Disable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated IPv4 fwd app",
                                 onfail="Failed to deactivate IPv4 fwd app" )

    def CASE149( self, main ):
        """
        Verify reactive forwarding in Spine-leaf topology, use a different ping method than CASE142
        """
        import time
        main.log.report( "Verify IPv6 Reactive forwarding (Spine-leaf Topology)" )
        main.log.report( "______________________________________________" )
        main.case( "Enable Reactive forwarding, verify ping6, and disable reactive forwarding" )

        main.step( "Enable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully install fwd app",
                                 onfail="Failed to install fwd app" )

        main.step( "Set IPv6 cfg parameters for Reactive forwarding" )
        cfgResult1 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
        cfgResult2 = main.CLIs[ 0 ].setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
        cfgResult = cfgResult1 and cfgResult2
        utilities.assert_equals( expect=main.TRUE, actual=cfgResult,
                                 onpass="Reactive mode ipv6Fowarding cfg is set to true",
                                 onfail="Failed to cfg set Reactive mode ipv6Fowarding" )

        main.step( "Discover hosts using ping" )
        numHosts = int( main.params[ 'TOPO3' ][ 'numHosts' ] )
        for i in range( 11, numHosts + 10 ):
            src = "h11"
            dest = "1000::" + str( i + 1 )
            main.Mininet1.handle.sendline( src + " ping6 " + dest + " -c 3 -i 1 -W 1" )
            main.Mininet1.handle.expect( "mininet>" )
            main.log.info( main.Mininet1.handle.before )
        hosts = main.CLIs[ 0 ].hosts( jsonFormat=False )
        main.log.info( hosts )

        main.step( "Disable Reactive forwarding" )
        main.log.info( "Uninstall IPv6 reactive forwarding app" )
        appCheck = main.TRUE
        appResults = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        pool = []
        for cli in main.CLIs:
            t = main.Thread( target=cli.appToIDCheck,
                             name="appToIDCheck-" + str( i ),
                             args=[] )
            pool.append( t )
            t.start()

        for t in pool:
            t.join()
            appCheck = appCheck and t.result
        utilities.assert_equals( expect=main.TRUE, actual=appCheck,
                                 onpass="App Ids seem to be correct",
                                 onfail="Something is wrong with app Ids" )

        if appCheck != main.TRUE:
            main.log.warn( main.CLIs[ 0 ].apps() )
            main.log.warn( main.CLIs[ 0 ].appIDs() )

        # Waiting for reative flows to be cleared.
        time.sleep( 30 )

        main.step( "Disable IPv4 Reactive forwarding" )
        appResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" )
        utilities.assert_equals( expect=main.TRUE, actual=appResult,
                                 onpass="Successfully deactivated IPv4 fwd app",
                                 onfail="Failed to deactivate IPv4 fwd app" )

    def CASE5( self, main ):
        """
        Compare current ONOS topology with reference data
        """
        import re

        devicesDPIDTemp = []
        hostMACsTemp = []
        deviceLinksTemp = []
        deviceActiveLinksCountTemp = []
        devicePortsEnabledCountTemp = []

        main.log.report(
            "Compare ONOS topology with reference data in Stores" )
        main.log.report( "__________________________________________________" )
        main.case( "Compare ONOS topology with reference data" )

        main.step( "Compare current Device ports enabled with reference" )

        for check in range( main.topoCheck ):
            time1 = time.time()
            for i in xrange( 1, ( main.numMNswitches + 1 ), main.numCtrls ):
                pool = []
                for cli in main.CLIs:
                    if i >= main.numMNswitches + 1:
                        break
                    dpid = "of:00000000000000" + format( i, "02x" )
                    t = main.Thread( target=cli.getDevicePortsEnabledCount,
                                     threadID=main.threadID,
                                     name="getDevicePortsEnabledCount",
                                     args=[ dpid ] )
                    t.start()
                    pool.append( t )
                    i = i + 1
                    main.threadID = main.threadID + 1
                for thread in pool:
                    thread.join()
                    portResult = thread.result
                    #portTemp = re.split( r'\t+', portResult )
                    #portCount = portTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
                    devicePortsEnabledCountTemp.append( portResult )

            time2 = time.time()
            main.log.info( "Time for counting enabled ports of the switches: %2f seconds" % ( time2 - time1 ) )
            main.log.info(
                "Device Enabled ports EXPECTED: %s" %
                str( main.devicePortsEnabledCount ) )
            main.log.info(
                "Device Enabled ports ACTUAL: %s" %
                str( devicePortsEnabledCountTemp ) )

            if ( cmp( main.devicePortsEnabledCount,
                      devicePortsEnabledCountTemp ) == 0 ):
                stepResult1 = main.TRUE
            else:
                stepResult1 = main.FALSE

            main.step( "Compare Device active links with reference" )
            time1 = time.time()
            for i in xrange( 1, ( main.numMNswitches + 1 ), main.numCtrls ):
                pool = []
                for cli in main.CLIs:
                    if i >= main.numMNswitches + 1:
                        break
                    dpid = "of:00000000000000" + format( i, "02x" )
                    t = main.Thread( target=cli.getDeviceLinksActiveCount,
                                     threadID=main.threadID,
                                     name="getDeviceLinksActiveCount",
                                     args=[ dpid ] )
                    t.start()
                    pool.append( t )
                    i = i + 1
                    main.threadID = main.threadID + 1
                for thread in pool:
                    thread.join()
                    linkCountResult = thread.result
                    #linkCountTemp = re.split( r'\t+', linkCountResult )
                    #linkCount = linkCountTemp[ 1 ].replace( "\r\r\n\x1b[32m", "" )
                    deviceActiveLinksCountTemp.append( linkCountResult )

                    time2 = time.time()
                    main.log.info( "Time for counting all enabled links of the switches: %2f seconds" % ( time2 - time1 ) )
                    main.log.info(
                        "Device Active links EXPECTED: %s" %
                          str( main.deviceActiveLinksCount ) )
                    main.log.info(
                        "Device Active links ACTUAL: %s" % str( deviceActiveLinksCountTemp ) )
                    if ( cmp( main.deviceActiveLinksCount, deviceActiveLinksCountTemp ) == 0 ):
                        stepResult2 = main.TRUE
                    else:
                        stepResult2 = main.FALSE

            """
            place holder for comparing devices, hosts, paths and intents if required.
            Links and ports data would be incorrect with out devices anyways.
            """
            caseResult = ( stepResult1 and stepResult2 )

            if caseResult:
                break
            else:
                time.sleep( main.topoCheckDelay )
                main.log.warn( "Topology check failed. Trying again..." )

        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Compare Topology test PASS",
                                 onfail="Compare Topology test FAIL" )

    def CASE60( self, main ):
        """
        Install 300 host intents and verify ping all ( Att Topology )
        """
        main.log.report( "Add 300 host intents and verify pingall (Att Topology)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 300 host intents" )

        main.step( "Add host Intents" )
        intentIdList = main.CHOtestFunctions.installHostIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 300 Host Intents and Ping All test PASS",
            onfail="Install 300 Host Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE61( self, main ):
        """
        Install 300 host intents and verify ping all for Chordal Topology
        """
        main.log.report( "Add 300 host intents and verify pingall (Chordal Topo)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 300 host intents" )

        main.step( "Add host Intents" )
        intentIdList = main.CHOtestFunctions.installHostIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=caseResult,
                                 onpass="Install 300 Host Intents and Ping All test PASS",
                                 onfail="Install 300 Host Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE62( self, main ):
        """
        Install 2278 host intents and verify ping all for Spine Topology
        """
        main.log.report( "Add 2278 host intents and verify pingall (Spine Topo)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 2278 host intents" )

        main.step( "Add host Intents" )
        intentIdList = main.CHOtestFunctions.installHostIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=caseResult,
                                 onpass="Install 2278 Host Intents and Ping All test PASS",
                                 onfail="Install 2278 Host Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE160( self, main ):
        """
        Verify IPv6 ping across 300 host intents ( Att Topology )
        """
        main.log.report( "Verify IPv6 ping across 300 host intents (Att Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 300 host intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE161( self, main ):
        """
        Verify IPv6 ping across 300 host intents ( Chordal Topology )
        """
        main.log.report( "Verify IPv6 ping across 300 host intents (Chordal Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 300 host intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE162( self, main ):
        """
        Verify IPv6 ping across 2278 host intents ( Spine Topology )
        """
        main.log.report( "Verify IPv6 ping across 2278 host intents (Spine Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 2278 host intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE, actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 2278 host intents test PASS",
            onfail="IPv6 Ping across 2278 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE70( self, main ):
        """
        Randomly bring some core links down and verify ping all ( Host Intents-Att Topo )
        """
        import random
        main.randomLink1 = []
        main.randomLink2 = []
        main.randomLink3 = []
        link1End1 = main.params[ 'ATTCORELINKS' ][ 'linkS3a' ]
        link1End2 = main.params[ 'ATTCORELINKS' ][ 'linkS3b' ].split( ',' )
        link2End1 = main.params[ 'ATTCORELINKS' ][ 'linkS14a' ]
        link2End2 = main.params[ 'ATTCORELINKS' ][ 'linkS14b' ].split( ',' )
        link3End1 = main.params[ 'ATTCORELINKS' ][ 'linkS18a' ]
        link3End2 = main.params[ 'ATTCORELINKS' ][ 'linkS18b' ].split( ',' )
        switchLinksToToggle = main.params[ 'ATTCORELINKS' ][ 'toggleLinks' ]

        main.log.report( "Randomly bring some core links down and verify ping all (Host Intents-Att Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Host intents - Randomly bring some core links down and verify ping all" )
        main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
        if ( int( switchLinksToToggle ) ==
             0 or int( switchLinksToToggle ) > 5 ):
            main.log.info( "Please check your PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
            #main.cleanup()
            #main.exit()
        else:
            main.log.info( "User provided Core switch links range to toggle is correct, proceeding to run the test" )

        main.step( "Cut links on Core devices using user provided range" )
        main.randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
        main.randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
        main.randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
        for i in range( int( switchLinksToToggle ) ):
            main.Mininet1.link(
                END1=link1End1,
                END2=main.randomLink1[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link2End1,
                END2=main.randomLink2[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link3End1,
                END2=main.randomLink3[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down",
                                                          int( main.numMNlinks ) -
                                                          int( switchLinksToToggle ) * 6 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE,
                                 actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE80( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Host Intents-Att Topo )
        """
        import random
        link1End1 = main.params[ 'ATTCORELINKS' ][ 'linkS3a' ]
        link2End1 = main.params[ 'ATTCORELINKS' ][ 'linkS14a' ]
        link3End1 = main.params[ 'ATTCORELINKS' ][ 'linkS18a' ]
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
        switchLinksToToggle = main.params[ 'ATTCORELINKS' ][ 'toggleLinks' ]

        main.log.report(
            "Bring the core links up that are down and verify ping all (Host Intents-Att Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Host intents - Bring the core links up that are down and verify ping all" )
        main.step( "Bring randomly cut links on Core devices up" )
        for i in range( int( switchLinksToToggle ) ):
            main.Mininet1.link(
                END1=link1End1,
                END2=main.randomLink1[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link2End1,
                END2=main.randomLink2[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link3End1,
                END2=main.randomLink3[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up",
                                                        int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE71( self, main ):
        """
        Randomly bring some core links down and verify ping all ( Point Intents-Att Topo )
        """
        import random
        main.randomLink1 = []
        main.randomLink2 = []
        main.randomLink3 = []
        link1End1 = main.params[ 'ATTCORELINKS' ][ 'linkS3a' ]
        link1End2 = main.params[ 'ATTCORELINKS' ][ 'linkS3b' ].split( ',' )
        link2End1 = main.params[ 'ATTCORELINKS' ][ 'linkS14a' ]
        link2End2 = main.params[ 'ATTCORELINKS' ][ 'linkS14b' ].split( ',' )
        link3End1 = main.params[ 'ATTCORELINKS' ][ 'linkS18a' ]
        link3End2 = main.params[ 'ATTCORELINKS' ][ 'linkS18b' ].split( ',' )
        switchLinksToToggle = main.params[ 'ATTCORELINKS' ][ 'toggleLinks' ]
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report( "Randomly bring some core links down and verify ping all (Point Intents-Att Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Point intents - Randomly bring some core links down and verify ping all" )
        main.step( "Verify number of Switch links to toggle on each Core Switch are between 1 - 5" )
        if ( int( switchLinksToToggle ) ==
             0 or int( switchLinksToToggle ) > 5 ):
            main.log.info( "Please check your PARAMS file. Valid range for number of switch links to toggle is between 1 to 5" )
            #main.cleanup()
            #main.exit()
        else:
            main.log.info( "User provided Core switch links range to toggle is correct, proceeding to run the test" )

        main.step( "Cut links on Core devices using user provided range" )
        main.randomLink1 = random.sample( link1End2, int( switchLinksToToggle ) )
        main.randomLink2 = random.sample( link2End2, int( switchLinksToToggle ) )
        main.randomLink3 = random.sample( link3End2, int( switchLinksToToggle ) )
        for i in range( int( switchLinksToToggle ) ):
            main.Mininet1.link(
                END1=link1End1,
                END2=main.randomLink1[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link2End1,
                END2=main.randomLink2[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link3End1,
                END2=main.randomLink3[ i ],
                OPTION="down" )
            time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down",
                                                          int( main.numMNlinks ) - int( switchLinksToToggle ) * 6 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE81( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Point Intents-Att Topo )
        """
        import random
        link1End1 = main.params[ 'ATTCORELINKS' ][ 'linkS3a' ]
        link2End1 = main.params[ 'ATTCORELINKS' ][ 'linkS14a' ]
        link3End1 = main.params[ 'ATTCORELINKS' ][ 'linkS18a' ]
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
        switchLinksToToggle = main.params[ 'ATTCORELINKS' ][ 'toggleLinks' ]

        main.log.report(
            "Bring the core links up that are down and verify ping all ( Point Intents-Att Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Point intents - Bring the core links up that are down and verify ping all" )
        main.step( "Bring randomly cut links on Core devices up" )
        for i in range( int( switchLinksToToggle ) ):
            main.Mininet1.link(
                END1=link1End1,
                END2=main.randomLink1[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link2End1,
                END2=main.randomLink2[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )
            main.Mininet1.link(
                END1=link3End1,
                END2=main.randomLink3[ i ],
                OPTION="up" )
            time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up", int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE72( self, main ):
        """
        Randomly bring some links down and verify ping all ( Host Intents-Chordal Topo )
        """
        import random
        import itertools
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report( "Randomly bring some core links down and verify ping all (Host Intents-Chordal Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Host intents - Randomly bring some core links down and verify ping all" )
        switches = []
        switchesComb = []
        for i in range( main.numMNswitches ):
            switches.append( 's%d' % ( i + 1 ) )
        switchesLinksComb = list( itertools.combinations( switches, 2 ) )
        main.randomLinks = random.sample( switchesLinksComb, 5 )
        print main.randomLinks
        main.step( "Cut links on random devices" )

        for switch in main.randomLinks:
            main.Mininet1.link(
                END1=switch[ 0 ],
                END2=switch[ 1 ],
                OPTION="down" )
            time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down", int( main.numMNlinks ) - 5 * 2 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE82( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Host Intents Chordal Topo )
        """
        import random
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report(
            "Bring the core links up that are down and verify ping all (Host Intents-Chordal Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Host intents - Bring the core links up that are down and verify ping all" )
        main.step( "Bring randomly cut links on devices up" )

        for switch in main.randomLinks:
            main.Mininet1.link(
                END1=switch[ 0 ],
                END2=switch[ 1 ],
                OPTION="up" )
            time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up", int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE73( self, main ):
        """
        Randomly bring some links down and verify ping all ( Point Intents-Chordal Topo )
        """
        import random
        import itertools
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report( "Randomly bring some core links down and verify ping all ( Point Intents-Chordal Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Point intents - Randomly bring some core links down and verify ping all" )
        switches = []
        switchesComb = []
        for i in range( main.numMNswitches ):
            switches.append( 's%d' % ( i + 1 ) )
        switchesLinksComb = list( itertools.combinations( switches, 2 ) )
        main.randomLinks = random.sample( switchesLinksComb, 5 )
        print main.randomLinks
        main.step( "Cut links on random devices" )

        for switch in main.randomLinks:
            main.Mininet1.link(
                END1=switch[ 0 ],
                END2=switch[ 1 ],
                OPTION="down" )
            time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down", int( main.numMNlinks ) - 5 * 2 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE83( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Point Intents Chordal Topo )
        """
        import random
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report(
            "Bring the core links up that are down and verify ping all ( Point Intents-Chordal Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Point intents - Bring the core links up that are down and verify ping all" )
        main.step( "Bring randomly cut links on devices up" )

        for switch in main.randomLinks:
            main.Mininet1.link(
                END1=switch[ 0 ],
                END2=switch[ 1 ],
                OPTION="up" )
            time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up", int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE74( self, main ):
        """
        Randomly bring some core links down and verify ping all ( Host Intents-Spine Topo )
        """
        import random
        main.randomLink1 = []
        main.randomLink2 = []
        main.randomLink3 = []
        main.randomLink4 = []
        link1End1 = main.params[ 'SPINECORELINKS' ][ 'linkS9' ]
        link1End2top = main.params[ 'SPINECORELINKS' ][ 'linkS9top' ].split( ',' )
        link1End2bot = main.params[ 'SPINECORELINKS' ][ 'linkS9bot' ].split( ',' )
        link2End1 = main.params[ 'SPINECORELINKS' ][ 'linkS10' ]
        link2End2top = main.params[ 'SPINECORELINKS' ][ 'linkS10top' ].split( ',' )
        link2End2bot = main.params[ 'SPINECORELINKS' ][ 'linkS10bot' ].split( ',' )
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report( "Bring some core links down and verify ping all (Host Intents-Spine Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Bring some core links down and verify ping all (Host Intents-Spine Topo)" )

        main.step( "Bring some core links down" )
        linkIndex = range( 4 )
        linkIndexS9 = random.sample( linkIndex, 1 )[ 0 ]
        linkIndex.remove( linkIndexS9 )
        linkIndexS10 = random.sample( linkIndex, 1 )[ 0 ]
        main.randomLink1 = link1End2top[ linkIndexS9 ]
        main.randomLink2 = link2End2top[ linkIndexS10 ]
        main.randomLink3 = random.sample( link1End2bot, 1 )[ 0 ]
        main.randomLink4 = random.sample( link2End2bot, 1 )[ 0 ]

        # Work around for link state propagation delay. Added some sleep time.
        # main.Mininet1.link( END1=link1End1, END2=main.randomLink1, OPTION="down" )
        # main.Mininet1.link( END1=link2End1, END2=main.randomLink2, OPTION="down" )
        main.Mininet1.link( END1=link1End1, END2=main.randomLink3, OPTION="down" )
        time.sleep( main.linkSleep )
        main.Mininet1.link( END1=link2End1, END2=main.randomLink4, OPTION="down" )
        time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down", int( main.numMNlinks ) - 4 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE84( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Host Intents-Spine Topo )
        """
        import random
        link1End1 = main.params[ 'SPINECORELINKS' ][ 'linkS9' ]
        link2End1 = main.params[ 'SPINECORELINKS' ][ 'linkS10' ]
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
        main.log.report(
            "Bring the core links up that are down and verify ping all (Host Intents-Spine Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Host intents - Bring the core links up that are down and verify ping all" )

        main.step( "Bring up the core links that are down" )
        # Work around for link state propagation delay. Added some sleep time.
        # main.Mininet1.link( END1=link1End1, END2=main.randomLink1, OPTION="up" )
        # main.Mininet1.link( END1=link2End1, END2=main.randomLink2, OPTION="up" )
        main.Mininet1.link( END1=link1End1, END2=main.randomLink3, OPTION="up" )
        time.sleep( main.linkSleep )
        main.Mininet1.link( END1=link2End1, END2=main.randomLink4, OPTION="up" )
        time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up", int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE75( self, main ):
        """
        Randomly bring some core links down and verify ping all ( Point Intents-Spine Topo )
        """
        import random
        main.randomLink1 = []
        main.randomLink2 = []
        main.randomLink3 = []
        main.randomLink4 = []
        link1End1 = main.params[ 'SPINECORELINKS' ][ 'linkS9' ]
        link1End2top = main.params[ 'SPINECORELINKS' ][ 'linkS9top' ].split( ',' )
        link1End2bot = main.params[ 'SPINECORELINKS' ][ 'linkS9bot' ].split( ',' )
        link2End1 = main.params[ 'SPINECORELINKS' ][ 'linkS10' ]
        link2End2top = main.params[ 'SPINECORELINKS' ][ 'linkS10top' ].split( ',' )
        link2End2bot = main.params[ 'SPINECORELINKS' ][ 'linkS10bot' ].split( ',' )
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )

        main.log.report( "Bring some core links down and verify ping all (Point Intents-Spine Topo)" )
        main.log.report( "___________________________________________________________________________" )
        main.case( "Bring some core links down and verify ping all (Point Intents-Spine Topo)" )

        main.step( "Bring some core links down" )
        linkIndex = range( 4 )
        linkIndexS9 = random.sample( linkIndex, 1 )[ 0 ]
        linkIndex.remove( linkIndexS9 )
        linkIndexS10 = random.sample( linkIndex, 1 )[ 0 ]
        main.randomLink1 = link1End2top[ linkIndexS9 ]
        main.randomLink2 = link2End2top[ linkIndexS10 ]
        main.randomLink3 = random.sample( link1End2bot, 1 )[ 0 ]
        main.randomLink4 = random.sample( link2End2bot, 1 )[ 0 ]

        # Work around for link state propagation delay. Added some sleep time.
        # main.Mininet1.link( END1=link1End1, END2=main.randomLink1, OPTION="down" )
        # main.Mininet1.link( END1=link2End1, END2=main.randomLink2, OPTION="down" )
        main.Mininet1.link( END1=link1End1, END2=main.randomLink3, OPTION="down" )
        time.sleep( main.linkSleep )
        main.Mininet1.link( END1=link2End1, END2=main.randomLink4, OPTION="down" )
        time.sleep( main.linkSleep )

        main.step( "Verify link down is discoverd by onos" )
        linkDown = main.CHOtestFunctions.checkLinkEvents( "down", int( main.numMNlinks ) - 4 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkDown,
                                 onpass="Link down discovered properly",
                                 onfail="Link down was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkDown and pingResult and intentState
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Random Link cut Test PASS",
                                 onfail="Random Link cut Test FAIL" )

        # Printing what exactly failed
        if not linkDown:
            main.log.debug( "Link down was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE85( self, main ):
        """
        Bring the core links up that are down and verify ping all ( Point Intents-Spine Topo )
        """
        import random
        link1End1 = main.params[ 'SPINECORELINKS' ][ 'linkS9' ]
        link2End1 = main.params[ 'SPINECORELINKS' ][ 'linkS10' ]
        main.linkSleep = int( main.params[ 'timers' ][ 'LinkDiscovery' ] )
        main.log.report(
            "Bring the core links up that are down and verify ping all (Point Intents-Spine Topo" )
        main.log.report(
            "__________________________________________________________________" )
        main.case(
            "Point intents - Bring the core links up that are down and verify ping all" )

        main.step( "Bring up the core links that are down" )
        # Work around for link state propagation delay. Added some sleep time.
        # main.Mininet1.link( END1=link1End1, END2=main.randomLink1, OPTION="up" )
        # main.Mininet1.link( END1=link2End1, END2=main.randomLink2, OPTION="up" )
        main.Mininet1.link( END1=link1End1, END2=main.randomLink3, OPTION="up" )
        time.sleep( main.linkSleep )
        main.Mininet1.link( END1=link2End1, END2=main.randomLink4, OPTION="up" )
        time.sleep( main.linkSleep )

        main.step( "Verify link up is discoverd by onos" )
        linkUp = main.CHOtestFunctions.checkLinkEvents( "up", int( main.numMNlinks ) )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=linkUp,
                                 onpass="Link up discovered properly",
                                 onfail="Link up was not discovered in " +
                                        str( main.linkSleep * main.linkCheck ) +
                                        " seconds" )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = linkUp and pingResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Link Up Test PASS",
                                 onfail="Link Up Test FAIL" )
        # Printing what exactly failed
        if not linkUp:
            main.log.debug( "Link up was not discovered correctly" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not intentState:
            main.log.debug( "Intents are not all installed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE170( self, main ):
        """
        IPv6 ping all with some core links down( Host Intents-Att Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Host Intents-Att Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Host Intents-Att Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE180( self, main ):
        """
        IPv6 ping all with after core links back up( Host Intents-Att Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Host Intents-Att Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Host Intents-Att Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE171( self, main ):
        """
        IPv6 ping all with some core links down( Point Intents-Att Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Point Intents-Att Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Point Intents-Att Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 point intents test PASS",
            onfail="IPv6 Ping across 600 point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE181( self, main ):
        """
        IPv6 ping all with after core links back up( Point Intents-Att Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Point Intents-Att Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Point Intents-Att Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 Point intents test PASS",
            onfail="IPv6 Ping across 600 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE172( self, main ):
        """
        IPv6 ping all with some core links down( Host Intents-Chordal Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Host Intents-Chordal Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Host Intents-Chordal Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

    def CASE182( self, main ):
        """
        IPv6 ping all with after core links back up( Host Intents-Chordal Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Host Intents-Chordal Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Host Intents-Chordal Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 300 host intents test PASS",
            onfail="IPv6 Ping across 300 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE173( self, main ):
        """
        IPv6 ping all with some core links down( Point Intents-Chordal Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Point Intents-Chordal Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Point Intents-Chordal Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 point intents test PASS",
            onfail="IPv6 Ping across 600 point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE183( self, main ):
        """
        IPv6 ping all with after core links back up( Point Intents-Chordal Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Point Intents-Chordal Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Point Intents-Chordal Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 Point intents test PASS",
            onfail="IPv6 Ping across 600 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE174( self, main ):
        """
        IPv6 ping all with some core links down( Host Intents-Spine Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Host Intents-Spine Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Host Intents-Spine Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 2278 host intents test PASS",
            onfail="IPv6 Ping across 2278 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE184( self, main ):
        """
        IPv6 ping all with after core links back up( Host Intents-Spine Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Host Intents-Spine Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Host Intents-Spine Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 2278 host intents test PASS",
            onfail="IPv6 Ping across 2278 host intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE175( self, main ):
        """
        IPv6 ping all with some core links down( Point Intents-Spine Topo )
        """
        main.log.report( "IPv6 ping all with some core links down( Point Intents-Spine Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with some core links down( Point Intents-Spine Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 4556 point intents test PASS",
            onfail="IPv6 Ping across 4556 point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE185( self, main ):
        """
        IPv6 ping all with after core links back up( Point Intents-Spine Topo )
        """
        main.log.report( "IPv6 ping all with after core links back up( Point Intents-Spine Topo )" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all with after core links back up( Point Intents-Spine Topo )" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 4556 Point intents test PASS",
            onfail="IPv6 Ping across 4556 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE90( self, main ):
        """
        Install 600 point intents and verify ping all ( Att Topology )
        """
        main.log.report( "Add 600 point intents and verify pingall (Att Topology)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 600 point intents" )

        main.step( "Add point Intents" )
        intentIdList = main.CHOtestFunctions.installPointIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 600 point Intents and Ping All test PASS",
            onfail="Install 600 point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE91( self, main ):
        """
        Install 600 point intents and verify ping all ( Chordal Topology )
        """
        main.log.report( "Add 600 point intents and verify pingall (Chordal Topology)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 600 point intents" )

        main.step( "Add point Intents" )
        intentIdList = main.CHOtestFunctions.installPointIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 600 point Intents and Ping All test PASS",
            onfail="Install 600 point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE92( self, main ):
        """
        Install 4556 point intents and verify ping all ( Spine Topology )
        """
        main.log.report( "Add 4556 point intents and verify pingall (Spine Topology)" )
        main.log.report( "_______________________________________" )
        main.case( "Install 4556 point intents" )

        main.step( "Add point Intents" )
        intentIdList = main.CHOtestFunctions.installPointIntents()
        main.intentIds = list( intentIdList )

        main.step( "Verify intents are installed" )
        intentState = main.CHOtestFunctions.checkIntents()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall()
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = ( intentState and pingResult )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 4556 point Intents and Ping All test PASS",
            onfail="Install 4556 point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE93( self, main ):
        """
        Install multi-single point intents and verify Ping all works
        for att topology
        """
        import copy
        import time
        from collections import Counter
        main.log.report( "Install multi-single point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install multi-single point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        portIngressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        main.log.info( "MACsDict" + str( main.MACsDict ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                egressDevice = deviceDPIDsCopy[ i ]
                ingressDeviceList = copy.copy( deviceDPIDsCopy )
                ingressDeviceList.remove( egressDevice )
                if i >= len( deviceDPIDsCopy ):
                    break
                t = main.Thread( target=cli.addMultipointToSinglepointIntent,
                                 threadID=main.threadID,
                                 name="addMultipointToSinglepointIntent",
                                 args=[ ingressDeviceList, egressDevice, portIngressList, '1', '', '', main.MACsDict.get( egressDevice ) ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( checkFlowsState and pingResult and intentState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 multi to single point Intents and Ping All test PASS",
            onfail="Install 25 multi to single point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE94( self, main ):
        """
        Install multi-single point intents and verify Ping all works
        for Chordal topology
        """
        import copy
        import time
        main.log.report( "Install multi-single point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install multi-single point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        portIngressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        main.log.info( "MACsDict" + str( main.MACsDict ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                egressDevice = deviceDPIDsCopy[ i ]
                ingressDeviceList = copy.copy( deviceDPIDsCopy )
                ingressDeviceList.remove( egressDevice )
                if i >= len( deviceDPIDsCopy ):
                    break
                t = main.Thread( target=cli.addMultipointToSinglepointIntent,
                                 threadID=main.threadID,
                                 name="addMultipointToSinglepointIntent",
                                 args=[ ingressDeviceList, egressDevice, portIngressList, '1', '', '', main.MACsDict.get( egressDevice ) ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( checkFlowsState and pingResult and intentState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 multi to single point Intents and Ping All test PASS",
            onfail="Install 25 multi to single point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE95( self, main ):
        """
        Install multi-single point intents and verify Ping all works
        for Spine topology
        """
        import copy
        import time
        main.log.report( "Install multi-single point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install multi-single point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        portIngressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        main.log.info( "MACsDict" + str( main.MACsDict ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                egressDevice = deviceDPIDsCopy[ i ]
                ingressDeviceList = copy.copy( deviceDPIDsCopy )
                ingressDeviceList.remove( egressDevice )
                if i >= len( deviceDPIDsCopy ):
                    break
                t = main.Thread( target=cli.addMultipointToSinglepointIntent,
                                 threadID=main.threadID,
                                 name="addMultipointToSinglepointIntent",
                                 args=[ ingressDeviceList, egressDevice, portIngressList, '1', '', '', main.MACsDict.get( egressDevice ) ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( checkFlowsState and pingResult and intentState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 multi to single point Intents and Ping All test PASS",
            onfail="Install 25 multi to single point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE96( self, main ):
        """
        Install single-multi point intents and verify Ping all works
        for att topology
        """
        import copy
        main.log.report( "Install single-multi point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install single-multi point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        portEgressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        main.log.info( "MACsDict" + str( main.MACsDict ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                ingressDevice = deviceDPIDsCopy[ i ]
                egressDeviceList = copy.copy( deviceDPIDsCopy )
                egressDeviceList.remove( ingressDevice )
                if i >= len( deviceDPIDsCopy ):
                    break
                t = main.Thread( target=cli.addSinglepointToMultipointIntent,
                                 threadID=main.threadID,
                                 name="addSinglepointToMultipointIntent",
                                 args=[ ingressDevice, egressDeviceList, '1', portEgressList, '', main.MACsDict.get( ingressDevice ) ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( pingResult and intentState and flowState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 single to multi point Intents and Ping All test PASS",
            onfail="Install 25 single to multi point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE97( self, main ):
        """
        Install single-multi point intents and verify Ping all works
        for Chordal topology
        """
        import copy
        main.log.report( "Install single-multi point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install single-multi point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        portEgressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        main.log.info( "MACsDict" + str( main.MACsDict ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                ingressDevice = deviceDPIDsCopy[ i ]
                egressDeviceList = copy.copy( deviceDPIDsCopy )
                egressDeviceList.remove( ingressDevice )
                if i >= len( deviceDPIDsCopy ):
                    break
                t = main.Thread( target=cli.addSinglepointToMultipointIntent,
                                 threadID=main.threadID,
                                 name="addSinglepointToMultipointIntent",
                                 args=[ ingressDevice, egressDeviceList, '1', portEgressList, '', main.MACsDict.get( ingressDevice ), '' ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( pingResult and intentState and flowState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 single to multi point Intents and Ping All test PASS",
            onfail="Install 25 single to multi point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE98( self, main ):
        """
        Install single-multi point intents and verify Ping all works
        for Spine topology
        """
        import copy
        main.log.report( "Install single-multi point intents and verify Ping all" )
        main.log.report( "___________________________________________" )
        main.case( "Install single-multi point intents and Ping all" )
        deviceDPIDsCopy = copy.copy( main.deviceDPIDs )
        deviceDPIDsCopy = deviceDPIDsCopy[ 10: ]
        portEgressList = [ '1' ] * ( len( deviceDPIDsCopy ) - 1 )
        intentIdList = []
        MACsDictCopy = {}
        for i in range( len( deviceDPIDsCopy ) ):
            MACsDictCopy[ deviceDPIDsCopy[ i ] ] = main.hostMACs[ i ].split( '/' )[ 0 ]

        main.log.info( "deviceDPIDsCopy" + str( deviceDPIDsCopy ) )
        main.log.info( "MACsDictCopy" + str( MACsDictCopy ) )
        time1 = time.time()
        for i in xrange( 0, len( deviceDPIDsCopy ), main.numCtrls ):
            pool = []
            for cli in main.CLIs:
                if i >= len( deviceDPIDsCopy ):
                    break
                ingressDevice = deviceDPIDsCopy[ i ]
                egressDeviceList = copy.copy( deviceDPIDsCopy )
                egressDeviceList.remove( ingressDevice )
                t = main.Thread( target=cli.addSinglepointToMultipointIntent,
                                 threadID=main.threadID,
                                 name="addSinglepointToMultipointIntent",
                                 args=[ ingressDevice, egressDeviceList, '1', portEgressList, '', MACsDictCopy.get( ingressDevice ), '' ] )
                pool.append( t )
                t.start()
                i = i + 1
                main.threadID = main.threadID + 1
            for thread in pool:
                thread.join()
                intentIdList.append( thread.result )
        time2 = time.time()
        main.log.info( "Time for adding point intents: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify intents are installed" )
        # Giving onos multiple chances to install intents
        for i in range( main.intentCheck ):
            if i != 0:
                main.log.warn( "Verification failed. Retrying..." )
            main.log.info( "Waiting for onos to install intents..." )
            time.sleep( main.checkIntentsDelay )

            intentState = main.TRUE
            for e in range( main.numCtrls ):
                main.log.info( "Checking intents on CLI %s" % ( e + 1 ) )
                IntentStateIndividual = main.CLIs[ e ].checkIntentState( intentsId=intentIdList )
                if not IntentStateIndividual:
                    main.log.warn( "Not all intents installed on ONOS%s" % ( e + 1 ) )
                intentState = intentState and IntentStateIndividual
            if intentState:
                break
        if not intentState:
            #Dumping intent summary
            main.log.info( "**** Intent Summary ****\n" + str( main.ONOScli1.intents( jsonFormat=False, summary=True ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=intentState,
                                 onpass="INTENTS INSTALLED",
                                 onfail="SOME INTENTS NOT INSTALLED" )

        main.step( "Verify flows are all added" )

        for i in range( main.flowCheck ):
            if i != 0:
                main.log.warn( "verification failed. Retrying..." )
            main.log.info( "Waiting for onos to add flows..." )
            time.sleep( main.checkFlowsDelay )

            flowState = main.TRUE
            for cli in main.CLIs:
                flowState = cli.checkFlowState()
                if not flowState:
                    main.log.warn( "Not all flows added" )
            if flowState:
                break
        else:
            #Dumping summary
            main.log.info( "Summary:\n" + str( main.ONOScli1.summary( jsonFormat=False ) ) )

        utilities.assert_equals( expect=main.TRUE, actual=flowState,
                                 onpass="FLOWS INSTALLED",
                                 onfail="SOME FLOWS NOT ADDED" )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        caseResult = ( pingResult and intentState and flowState )
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="Install 25 single to multi point Intents and Ping All test PASS",
            onfail="Install 25 single to multi point Intents and Ping All test FAIL" )

        if not intentState:
            main.log.debug( "Intents failed to install completely" )
        if not pingResult:
            main.log.debug( "Pingall failed" )
        if not checkFlowsState:
            main.log.debug( "Flows failed to add completely" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE190( self, main ):
        """
        Verify IPv6 ping across 600 Point intents ( Att Topology )
        """
        main.log.report( "Verify IPv6 ping across 600 Point intents (Att Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 600 Point intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 Point intents test PASS",
            onfail="IPv6 Ping across 600 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE191( self, main ):
        """
        Verify IPv6 ping across 600 Point intents ( Chordal Topology )
        """
        main.log.report( "Verify IPv6 ping across 600 Point intents (Chordal Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 600 Point intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 600 Point intents test PASS",
            onfail="IPv6 Ping across 600 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE192( self, main ):
        """
        Verify IPv6 ping across 4556 Point intents ( Spine Topology )
        """
        main.log.report( "Verify IPv6 ping across 4556 Point intents (Spine Topology)" )
        main.log.report( "_________________________________________________" )
        main.case( "IPv6 ping all 4556 Point intents" )

        main.step( "Verify IPv6 Ping across all hosts" )
        pingResult = main.CHOtestFunctions.checkPingall( protocol="IPv6" )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=pingResult,
                                 onpass="PING ALL PASS",
                                 onfail="PING ALL FAIL" )

        caseResult = pingResult
        utilities.assert_equals(
            expect=main.TRUE,
            actual=caseResult,
            onpass="IPv6 Ping across 4556 Point intents test PASS",
            onfail="IPv6 Ping across 4556 Point intents test FAIL" )

        if not caseResult and main.failSwitch:
            main.log.report( "Stopping test" )
            main.stop( email=main.emailOnStop )

    def CASE10( self, main ):
        import time
        import re
        """
         Remove all Intents
        """
        main.log.report( "Remove all intents that were installed previously" )
        main.log.report( "______________________________________________" )
        main.log.info( "Remove all intents" )
        main.case( "Removing intents" )
        purgeDelay = int( main.params[ "timers" ][ "IntentPurgeDelay" ] )
        main.step( "Obtain the intent id's first" )
        intentsList = main.ONOScli1.getAllIntentIds()
        ansi_escape = re.compile( r'\x1b[^m]*m' )
        intentsList = ansi_escape.sub( '', intentsList )
        intentsList = intentsList.replace(
            " onos:intents | grep id=",
            "" ).replace(
            "id=",
            "" ).replace(
            "\r\r",
             "" )
        intentsList = intentsList.splitlines()
        intentIdList = []
        step1Result = main.TRUE
        moreIntents = main.TRUE
        removeIntentCount = 0
        intentsCount = len( intentsList )
        main.log.info( "Current number of intents:  " + str( intentsCount ) )

        main.step( "Remove all installed intents" )
        if ( len( intentsList ) > 1 ):
            results = main.TRUE
            main.log.info( "Removing intent..." )
            while moreIntents:
                # This is a work around only: cycle through intents removal for up to 5 times.
                if removeIntentCount == 5:
                    break
                removeIntentCount = removeIntentCount + 1
                intentsList1 = main.ONOScli1.getAllIntentIds()
                if len( intentsList1 ) == 0:
                    break
                ansi_escape = re.compile( r'\x1b[^m]*m' )
                intentsList1 = ansi_escape.sub( '', intentsList1 )
                intentsList1 = intentsList1.replace(
                    " onos:intents | grep id=",
                    "" ).replace(
                    " state=",
                    "" ).replace(
                    "\r\r",
                    "" )
                intentsList1 = intentsList1.splitlines()
                main.log.info( "Round %d intents to remove: " % ( removeIntentCount ) )
                print intentsList1
                intentIdList1 = []
                if ( len( intentsList1 ) > 0 ):
                    moreIntents = main.TRUE
                    for i in range( len( intentsList1 ) ):
                        intentsTemp1 = intentsList1[ i ].split( ',' )
                        intentIdList1.append( intentsTemp1[ 0 ].split( '=' )[ 1 ] )
                    main.log.info( "Leftover Intent IDs: " + str( intentIdList1 ) )
                    main.log.info( "Length of Leftover Intents list: " + str( len( intentIdList1 ) ) )
                    time1 = time.time()
                    for i in xrange( 0, len( intentIdList1 ), main.numCtrls ):
                        pool = []
                        for cli in main.CLIs:
                            if i >= len( intentIdList1 ):
                                break
                            t = main.Thread( target=cli.removeIntent,
                                             threadID=main.threadID,
                                             name="removeIntent",
                                             args=[ intentIdList1[ i ], 'org.onosproject.cli', False, False ] )
                            pool.append( t )
                            t.start()
                            i = i + 1
                            main.threadID = main.threadID + 1
                        for thread in pool:
                            thread.join()
                            intentIdList.append( thread.result )
                        #time.sleep( 2 )
                    time2 = time.time()
                    main.log.info( "Time for removing host intents: %2f seconds" % ( time2 - time1 ) )
                    time.sleep( purgeDelay )
                    main.log.info( "Purging WITHDRAWN Intents" )
                    purgeResult = main.ONOScli1.purgeWithdrawnIntents()
                else:
                    time.sleep( 10 )
                    if len( main.ONOScli1.intents() ):
                        continue
                    break
                time.sleep( purgeDelay )
            else:
                print "Removed %d intents" % ( intentsCount )
                step1Result = main.TRUE
        else:
            print "No Intent IDs found in Intents list: ", intentsList
            step1Result = main.FALSE

        print main.ONOScli1.intents()

        main.log.info( main.ONOScli1.summary( jsonFormat=False ) )
        caseResult = step1Result
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Intent removal test successful",
                                 onfail="Intent removal test failed" )

    def CASE12( self, main ):
        """
        Enable onos-app-ifwd, Verify Intent based Reactive forwarding through ping all and Disable it
        """
        import re
        import copy
        import time

        threadID = 0

        main.log.report( "Enable Intent based Reactive forwarding and Verify ping all" )
        main.log.report( "_____________________________________________________" )
        main.case( "Enable Intent based Reactive forwarding and Verify ping all" )
        main.step( "Enable intent based Reactive forwarding" )
        installResult = main.FALSE
        feature = "onos-app-ifwd"

        pool = []
        time1 = time.time()
        for cli, feature in main.CLIs:
            t = main.Thread( target=cli, threadID=threadID,
                             name="featureInstall", args=[ feature ] )
            pool.append( t )
            t.start()
            threadID = threadID + 1

        results = []
        for thread in pool:
            thread.join()
            results.append( thread.result )
        time2 = time.time()

        if( all( result == main.TRUE for result in results ) == False ):
            main.log.info( "Did not install onos-app-ifwd feature properly" )
            #main.cleanup()
            #main.exit()
        else:
            main.log.info( "Successful feature:install onos-app-ifwd" )
            installResult = main.TRUE
        main.log.info( "Time for feature:install onos-app-ifwd: %2f seconds" % ( time2 - time1 ) )

        main.step( "Verify Ping across all hosts" )
        for i in range( main.numPings ):
            time1 = time.time()
            pingResult = main.Mininet1.pingall( timeout=main.pingTimeout )
            if not pingResult:
                main.log.warn( "First pingall failed. Retrying..." )
                time.sleep( main.pingSleep )
            else:
                break

        time2 = time.time()
        timeDiff = round( ( time2 - time1 ), 2 )
        main.log.report(
            "Time taken for Ping All: " +
            str( timeDiff ) +
            " seconds" )

        if pingResult == main.TRUE:
            main.log.report( "Pingall Test in Reactive mode successful" )
        else:
            main.log.report( "Pingall Test in Reactive mode failed" )

        main.step( "Disable Intent based Reactive forwarding" )
        uninstallResult = main.FALSE

        pool = []
        time1 = time.time()
        for cli, feature in main.CLIs:
            t = main.Thread( target=cli, threadID=threadID,
                             name="featureUninstall", args=[ feature ] )
            pool.append( t )
            t.start()
            threadID = threadID + 1

        results = []
        for thread in pool:
            thread.join()
            results.append( thread.result )
        time2 = time.time()

        if( all( result == main.TRUE for result in results ) == False ):
            main.log.info( "Did not uninstall onos-app-ifwd feature properly" )
            uninstallResult = main.FALSE
            #main.cleanup()
            #main.exit()
        else:
            main.log.info( "Successful feature:uninstall onos-app-ifwd" )
            uninstallResult = main.TRUE
        main.log.info( "Time for feature:uninstall onos-app-ifwd: %2f seconds" % ( time2 - time1 ) )

        # Waiting for reative flows to be cleared.
        time.sleep( 10 )

        caseResult = installResult and pingResult and uninstallResult
        utilities.assert_equals( expect=main.TRUE, actual=caseResult,
                                 onpass="Intent based Reactive forwarding Pingall test PASS",
                                 onfail="Intent based Reactive forwarding Pingall test FAIL" )
