"""
    SCPFhostLat
    This test will test the host found latency.
    Host will arping a ip address, tshark will caputure the package time, then compare with the topology event timestamp.
    Test will run with 1 node from start, and scale up to 7 nodes.
    The event timestamp will only greb the latest one, then calculate average and standar dev.

    yunpeng@onlab.us
"""
class SCPFhostLat:

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

    def CASE0( self, main):
        import sys
        import json
        import time
        import os
        import imp

        main.case( "Constructing test variables and building ONOS package" )
        main.step( "Constructing test variables" )
        stepResult = main.FALSE

        # Test variables
        main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
        main.cellName = main.params[ 'ENV' ][ 'cellName' ]
        main.apps = main.params[ 'ENV' ][ 'cellApps' ]
        main.scale = ( main.params[ 'SCALE' ] ).split( "," )
        main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
        main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
        main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
        main.measurementSleep = int( main.params['SLEEP']['measurement'])
        main.timeout = int( main.params['SLEEP']['timeout'] )
        main.dbFileName = main.params['DATABASE']['file']
        main.cellData = {} # for creating cell file

        # Tshark params
        main.tsharkResultPath = main.params['TSHARK']['tsharkPath']
        main.tsharkPacketIn = main.params['TSHARK']['tsharkPacketIn']

        main.numlter = main.params['TEST']['numIter']
        main.iterIgnore = int(main.params['TEST']['iterIgnore'])
        main.hostTimestampKey = main.params['TEST']['hostTimestamp']
        main.thresholdStr = main.params['TEST']['singleSwThreshold']
        main.thresholdObj = main.thresholdStr.split(',')
        main.thresholdMin = int(main.thresholdObj[0])
        main.thresholdMax = int(main.thresholdObj[1])
        main.threadID = 0

        main.CLIs = []
        main.ONOSip = []
        main.maxNumBatch = 0
        main.ONOSip = main.ONOSbench.getOnosIps()
        main.log.info(main.ONOSip)
        main.setupSkipped = False

        gitBranch = main.params[ 'GIT' ][ 'branch' ]
        gitPull = main.params[ 'GIT' ][ 'pull' ]
        nic = main.params['DATABASE']['nic']
        node = main.params['DATABASE']['node']
        nic = main.params['DATABASE']['nic']
        node = main.params['DATABASE']['node']
        stepResult = main.TRUE

        main.log.info("Cresting DB file")
        with open(main.dbFileName, "w+") as dbFile:
            dbFile.write("")

        utilities.assert_equals( expect=main.TRUE,
                                 actual=stepResult,
                                 onpass="environment set up successfull",
                                 onfail="environment set up Failed" )

    def CASE1( self ):
        # main.scale[ 0 ] determines the current number of ONOS controller
        main.CLIs = []
        main.numCtrls = int( main.scale[ 0 ] )
        main.log.info( "Creating list of ONOS cli handles" )
        for i in range(main.numCtrls):
            main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) )

        main.log.info(main.CLIs)
        if not main.CLIs:
            main.log.error( "Failed to create the list of ONOS cli handles" )
            main.cleanup()
            main.exit()

        main.commit = main.ONOSbench.getVersion(report=True)
        main.commit = main.commit.split(" ")[1]

        if gitPull == 'True':
            if not main.startUp.onosBuild( main, gitBranch ):
                main.log.error( "Failed to build ONOS" )
                main.cleanup()
                main.exit()
        else:
            main.log.warn( "Did not pull new code so skipping mvn " +
                           "clean install" )
        with open(main.dbFileName, "a") as dbFile:
            temp = "'" + main.commit + "',"
            temp += "'" + nic + "',"
            dbFile.write(temp)
            dbFile.close()

    def CASE2( self, main ):
        """
        - Uninstall ONOS cluster
        - Verify ONOS start up
        - Install ONOS cluster
        - Connect to cli
        """
        main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls)
        main.log.info( "Safety check, killing all ONOS processes" +
                       " before initiating environment setup" )

        for i in range( main.numCtrls ):
            main.ONOSbench.onosStop( main.ONOSip[ i ] )
            main.ONOSbench.onosKill( main.ONOSip[ i ] )

        main.log.info( "NODE COUNT = %s" % main.numCtrls)

        tempOnosIp = []
        for i in range( main.numCtrls ):
            tempOnosIp.append( main.ONOSip[i] )

        main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
                                       "temp",
                                       main.Mininet1.ip_address,
                                       main.apps,
                                       tempOnosIp )

        main.step( "Apply cell to environment" )
        cellResult = main.ONOSbench.setCell( "temp" )
        verifyResult = main.ONOSbench.verifyCell()
        stepResult = cellResult and verifyResult
        utilities.assert_equals( expect=main.TRUE,
                                 actual=stepResult,
                                 onpass="Successfully applied cell to " + \
                                        "environment",
                                 onfail="Failed to apply cell to environment " )

        main.step( "Creating ONOS package" )
        packageResult = main.ONOSbench.buckBuild()
        stepResult = packageResult
        utilities.assert_equals( expect=main.TRUE,
                                 actual=stepResult,
                                 onpass="Successfully created ONOS package",
                                 onfail="Failed to create ONOS package" )

        main.step( "Uninstall ONOS package on all Nodes" )
        uninstallResult = main.TRUE
        for i in range( int( main.numCtrls ) ):
            main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
            u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
            utilities.assert_equals( expect=main.TRUE, actual=u_result,
                                     onpass="Test step PASS",
                                     onfail="Test step FAIL" )
            uninstallResult = ( uninstallResult and u_result )

        main.step( "Install ONOS package on all Nodes" )
        installResult = main.TRUE
        for i in range( int( main.numCtrls ) ):
            main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
            i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
            utilities.assert_equals( expect=main.TRUE, actual=i_result,
                                     onpass="Test step PASS",
                                     onfail="Test step FAIL" )
            installResult = installResult and i_result
        time.sleep( main.startUpSleep )
        main.step( "Verify ONOS nodes UP status" )
        statusResult = main.TRUE
        for i in range( int( main.numCtrls ) ):
            main.log.info( "ONOS Node " + main.ONOSip[i] + " status:" )
            onos_status = main.ONOSbench.onosStatus( node=main.ONOSip[i] )
            utilities.assert_equals( expect=main.TRUE, actual=onos_status,
                                     onpass="Test step PASS",
                                     onfail="Test step FAIL" )
            statusResult = ( statusResult and onos_status )

        main.step( "Set up ONOS secure SSH" )
        secureSshResult = main.TRUE
        for i in range( int( main.numCtrls ) ):
            secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
        utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
                                 onpass="Test step PASS",
                                 onfail="Test step FAIL" )

        main.step( "Start ONOS CLI on all nodes" )
        cliResult = main.TRUE
        main.step(" Start ONOS cli using thread ")
        time.sleep( main.startUpSleep )
        startCliResult  = main.TRUE
        pool = []

        for i in range( int( main.numCtrls) ):
            t = main.Thread( target=main.CLIs[i].startOnosCli,
                             threadID=main.threadID,
                             name="startOnosCli",
                             args=[ main.ONOSip[i] ],
                             kwargs = {"onosStartTimeout":main.timeout} )
            pool.append(t)
            t.start()
            main.threadID = main.threadID + 1
        for t in pool:
            t.join()
            startCliResult = startCliResult and t.result
        time.sleep( main.startUpSleep )

    def CASE11( self, main ):
        main.log.info( "set and configure Application" )
        import json
        import time
        time.sleep(main.startUpSleep)
        main.step( "Activating org.onosproject.proxyarp" )
        appStatus = utilities.retry( main.ONOSrest1.activateApp,
                                     main.FALSE,
                                     ['org.onosproject.proxyarp'],
                                     sleep=3,
                                     attempts=3 )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=appStatus,
                                 onpass="Successfully activated proxyarp",
                                 onfail="Failed to activated proxyarp")

        main.step( "Set up Default Topology Provider" )
        appStatus = main.TRUE
        configName = 'org.onosproject.net.topology.impl.DefaultTopologyProvider'
        configParam = 'maxEvents'
        appStatus = appStatus and main.CLIs[0].setCfg(  configName, configParam,'1' )
        configParam = 'maxBatchMs'
        appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam, '0')
        configParam = 'maxIdleMs'
        appStatus = appStatus and main.CLIs[0].setCfg( configName, configParam,'0' )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=appStatus,
                                 onpass="Successfully set DefaultTopologyProvider",
                                 onfail="Failed to set DefaultTopologyProvider" )

        time.sleep(main.startUpSleep)
        main.step('Starting mininet topology')
        mnStatus = main.Mininet1.startNet(args='--topo=linear,1')
        utilities.assert_equals( expect=main.TRUE,
                                 actual=mnStatus,
                                 onpass="Successfully started Mininet",
                                 onfail="Failed to activate Mininet" )
        main.step("Assinging masters to switches")
        switches = main.Mininet1.getSwitches()
        swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip[0] )
        utilities.assert_equals( expect=main.TRUE,
                                 actual=swStatus,
                                 onpass="Successfully assigned switches to masters",
                                 onfail="Failed assign switches to masters" )

        time.sleep(main.startUpSleep)

    def CASE20(self, main):
        """
        host1 send arping package and measure latency

        There are only 1 levels of latency measurements to this test:
        1 ) ARPING-to-device measurement: Measurement the time from host1
        send apring package to onos processing the host event

        """
        import time
        import subprocess
        import json
        import requests
        import os
        import numpy

        # Host adding measurement
        assertion = main.TRUE

        main.log.report('Latency of adding one host to ONOS')
        main.log.report('First ' + str(main.iterIgnore) + ' iterations ignored' + ' for jvm warmup time')
        main.log.report('Total iterations of test: ' + str(main.numlter))

        addingHostTime = []
        metricsResultList = []
        for i in range(0, int(main.numlter)):
            main.log.info('Clean up data file')
            with open(main.tsharkResultPath, "w") as dbFile:
                dbFile.write("")

            main.log.info('Starting tshark capture')
            main.ONOSbench.tsharkGrep(main.tsharkPacketIn, main.tsharkResultPath)
            time.sleep(main.measurementSleep)

            main.log.info('host 1 arping...')
            main.Mininet1.arping(srcHost='h1', dstHost='10.0.0.2')

            time.sleep(main.measurementSleep)

            main.log.info('Stopping all Tshark processes')
            main.ONOSbench.tsharkStop()

            time.sleep(main.measurementSleep)

            # Get tshark output
            with open(main.tsharkResultPath, "r") as resultFile:
                resultText = resultFile.readline()
                main.log.info('Capture result:' + resultText)
                resultText = resultText.split(' ')
                if len(resultText) > 1:
                    tsharkResultTime = float(resultText[1]) * 1000.0
                else:
                    main.log.error('Tshark output file for packet_in' + ' returned unexpected results')
                    hostTime = 0
                    caseResult = main.FALSE
                resultFile.close()
            # Compare the timestemps, and get the lowest one.
            temp = 0;
            # Get host event timestamps from each nodes
            for node in range (0, main.numCtrls):
                metricsResult = json.loads(main.CLIs[node].topologyEventsMetrics())
                metricsResult = metricsResult.get(main.hostTimestampKey).get("value")
                main.log.info("ONOS topology event matrics timestemp: {}".format(str(metricsResult)) )

                if temp < metricsResult:
                    temp = metricsResult
                metricsResult = temp

            addingHostTime.append(float(metricsResult) - tsharkResultTime)
            main.log.info("Result of this iteration: {}".format( str( float(metricsResult) - tsharkResultTime) ))
            # gethost to remove
            gethost = main.ONOSrest1.hosts()
            HosttoRemove = []
            HosttoRemove.append( json.loads( gethost[1:len(gethost)-1] ).get('id') )
            main.CLIs[0].removeHost(HosttoRemove)

        main.log.info("Result List: {}".format(addingHostTime))

        # calculate average latency from each nodes
        averageResult = numpy.average(addingHostTime)
        main.log.info("Average Latency: {}".format(averageResult))

        # calculate std
        stdResult = numpy.std(addingHostTime)
        main.log.info("std: {}".format(stdResult))

        # write to DB file
        main.log.info("Writing results to DS file")
        with open(main.dbFileName, "a") as dbFile:
            # Scale number
            temp = str(main.numCtrls)
            temp += ",'" + "baremetal1" + "'"
            # average latency
            temp += "," + str( averageResult )
            # std of latency
            temp += "," + str(stdResult)
            temp += "\n"
            dbFile.write( temp )

        assertion = main.TRUE

        utilities.assert_equals(expect=main.TRUE, actual=assertion,
                onpass='Host latency test successful',
                onfail='Host latency test failed')

        main.Mininet1.stopNet()
        del main.scale[0]
