# ScaleOutTemplate
#
# CASE1 starts number of nodes specified in param file
#
# cameron@onlab.us

import sys
import os.path


class IntentInstallWithdrawLat:

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

    def CASE1( self, main ):           
                                        
        import time                     
        global init       
        try: 
            if type(init) is not bool: 
                init = False  
        except NameError: 
            init = False 
       
        #Load values from params file
        checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
        gitPull = main.params[ 'GIT' ][ 'autopull' ]
        cellName = main.params[ 'ENV' ][ 'cellName' ]
        Apps = main.params[ 'ENV' ][ 'cellApps' ]
        BENCHIp = main.params[ 'BENCH' ][ 'ip1' ]
        BENCHUser = main.params[ 'BENCH' ][ 'user' ]
        MN1Ip = main.params[ 'MN' ][ 'ip1' ]
        maxNodes = int(main.params[ 'availableNodes' ])
        skipMvn = main.params[ 'TEST' ][ 'skipCleanInstall' ]
        cellName = main.params[ 'ENV' ][ 'cellName' ]        
        switchCount = main.params[ 'TEST' ][ 'switchCount' ]

        # -- INIT SECTION, ONLY RUNS ONCE -- # 
        if init == False: 
            init = True
            global clusterCount             #number of nodes running
            global ONOSIp                   #list of ONOS IP addresses
            global scale 
            global commit            
    
            clusterCount = 0
            ONOSIp = [ 0 ]
            scale = (main.params[ 'SCALE' ]).split(",")            
            clusterCount = int(scale[0])

            #Populate ONOSIp with ips from params 
            for i in range(1, maxNodes + 1): 
                ipString = 'ip' + str(i) 
                ONOSIp.append(main.params[ 'CTRL' ][ ipString ])   
            
            #mvn clean install, for debugging set param 'skipCleanInstall' to yes to speed up test
            if skipMvn != "yes":
                mvnResult = main.ONOSbench.cleanInstall()

            #git
            main.step( "Git checkout and pull " + checkoutBranch )
            if gitPull == 'on':
                checkoutResult = main.ONOSbench.gitCheckout( checkoutBranch )
                pullResult = main.ONOSbench.gitPull()

            else:
                checkoutResult = main.TRUE
                pullResult = main.TRUE
                main.log.info( "Skipped git checkout and pull" )
       
            commit = main.ONOSbench.getVersion()
            commit = (commit.split(" "))[1]

            resultsDB = open("IntentInstallWithdrawLatDB", "w+")
            resultsDB.close()

        # -- END OF INIT SECTION --#
         
        clusterCount = int(scale[0])
        scale.remove(scale[0])       
        
        #kill off all onos processes 
        main.log.step("Safety check, killing all ONOS processes")
        main.log.step("before initiating enviornment setup")
        for node in range(1, maxNodes + 1):
            main.ONOSbench.onosDie(ONOSIp[node])
        
        #Uninstall everywhere
        main.log.step( "Cleaning Enviornment..." )
        for i in range(1, maxNodes + 1):
            main.log.info(" Uninstalling ONOS " + str(i) )
            main.ONOSbench.onosUninstall( ONOSIp[i] )
       
        #construct the cell file
        main.log.info("Creating cell file")
        cellIp = []
        for node in range (1, clusterCount + 1):
            cellIp.append(ONOSIp[node])

        main.ONOSbench.createCellFile(BENCHIp,cellName,MN1Ip,str(Apps), *cellIp)

        main.step( "Set Cell" )
        main.ONOSbench.setCell(cellName)
        
        main.step( "Creating ONOS package" )
        packageResult = main.ONOSbench.onosPackage()  

        main.step( "verify cells" )
        verifyCellResult = main.ONOSbench.verifyCell()
      
        main.log.report( "Initializeing " + str( clusterCount ) + " node cluster." )
        for node in range(1, clusterCount + 1):
            main.log.info("Starting ONOS " + str(node) + " at IP: " + ONOSIp[node])
            main.ONOSbench.onosInstall( ONOSIp[node])

        for node in range(1, clusterCount + 1):
            for i in range( 2 ):
                isup = main.ONOSbench.isup( ONOSIp[node] )
                if isup:
                    main.log.info("ONOS " + str(node) + " is up\n")
                    break
            if not isup:
                main.log.report( "ONOS " + str(node) + " didn't start!" )

        main.ONOS1cli.startOnosCli( ONOSIp[1] )
        main.log.info("Startup sequence complete")
        
        time.sleep(30)

        main.ONOSbench.handle.sendline("""onos $OC1 "cfg set org.onosproject.provider.nil.NullProviders deviceCount """ + str(switchCount) + """ " """)
        main.ONOSbench.handle.expect(":~")
        print main.ONOSbench.handle.before
        time.sleep(3)
        main.ONOSbench.handle.sendline("""onos $OC1 "cfg set org.onosproject.provider.nil.NullProviders topoShape linear" """)
        main.ONOSbench.handle.expect(":~")
        print main.ONOSbench.handle.before
        time.sleep(3)
        main.ONOSbench.handle.sendline("""onos $OC1 "null-simulation start" """)
        main.ONOSbench.handle.expect(":~")
        print main.ONOSbench.handle.before
        time.sleep(3)
        main.ONOSbench.handle.sendline("""onos $OC1 "balance-masters" """)
        main.ONOSbench.handle.expect(":~")
        print main.ONOSbench.handle.before
        time.sleep(3)

        for i in range(0,5):
            main.ONOSbench.handle.sendline("onos $OC1 summary")
            main.ONOSbench.handle.expect(":~")
            check = main.ONOSbench.handle.before
            if "devices=7," in check: 
                main.log.info("startup successful")
                break 
            else:
                main.log.error(check)
                main.ONOSbench.handle.sendline("""onos $OC1 "null-simulation stop" """)
                main.ONOSbench.handle.expect(":~")
                time.sleep(6)
                main.ONOSbench.handle.sendline("""onos $OC1 "null-simulation start" """)
                main.ONOSbench.handle.expect(":~")
                time.sleep(2)

    def CASE2( self, main ):
         
        import time
        import numpy

        sampleSize = int(main.params[ 'TEST' ][ 'sampleSize' ])
        warmUp = int(main.params[ 'TEST' ][ 'warmUp' ])
        intentsList = (main.params[ 'TEST' ][ 'intents' ]).split(",")
        switchCount = int(main.params[ 'TEST' ][ 'switchCount' ])
        debug = main.params[ 'TEST' ][ 'switchCount' ]
        print("0")

        for i in range(0,len(intentsList)):
            intentsList[i] = int(intentsList[i])
        main.log.info("Intents list: " + str(intentsList))

        print("1")
        if debug == "True":
            debug = True
        else:
            debug = False
        
        linkCount = 0
        for i in range(0,10):
            main.ONOSbench.handle.sendline("onos $OC1 links|wc -l")
            main.ONOSbench.handle.expect(":~")
            linkCount = main.ONOSbench.handle.before
            if debug: main.log.info("Link Count check: " + linkCount)
            if str((switchCount*2)-2) in linkCount:
                break
            time.sleep(2)
        links = "--"
        x = 0
        print("2")
        while "=null:" not in links:
            if x >= 20:
                main.log.error("link check failure")
                break
            if debug: main.log.info("top of loop")
            main.ONOSbench.handle.sendline("onos $OC1 links")
            main.ONOSbench.handle.expect(":~")
            links = main.ONOSbench.handle.before
            if debug: main.log.info(str(links))
            time.sleep(1)
            x += 1
        links = links.splitlines()
        templinks = links
        tempDevices = []
        for line in links:
            temp = line.split(" ")
            temp[0].replace("src=","")
            temp[0] = (temp[0].split("/"))[0]
            tempDevices.append(temp[0])

        print("3")

        tempDevices.sort()
        devices = []
        for i in tempDevices:
            if "src=null" in i:
                devices.append(i.replace("src=", ""))
        if debug: main.log.info(str(devices))

        print("4")

        ingress = devices[0]
        egress = devices.pop()
        if debug: main.log.info(ingress)
        if debug: main.log.info(egress)

        print("5")

        for intentSize in intentsList:
            cmd = "onos $OC1 push-test-intents "
            cmd += ingress + "/6 "
            cmd += egress + "/5 "
            cmd += str(intentSize) + " 1"
            main.log.info("COMMAND: " + cmd)
            installed = []
            withdrawn = []
            for run in range(0, (warmUp + sampleSize)):
                if run > warmUp:
                    time.sleep(5)
                myRawResult = "--"
                while "ms" not in myRawResult:
                    main.ONOSbench.handle.sendline(cmd)
                    main.ONOSbench.handle.expect(":~")
                    myRawResult = main.ONOSbench.handle.before
                    main.log.info(myRawResult)

                if debug: main.log.info(myRawResult)
                if run >= warmUp:
                    myRawResult = myRawResult.splitlines()
                    for line in myRawResult:
                        if "install" in line:
                            print(line)
                            installed.append(int(line.split(" ")[5]))

                    for line in myRawResult:
                        if "withdraw" in line:
                            withdrawn.append(int(line.split(" ")[5]))
                    print("installed: " + str(installed))
                    print("withraw: " + str(withdrawn) + "\n")

            main.log.report("----------------------------------------------------")
            main.log.report("Scale: " + str(clusterCount) + "\tIntent batch size: " + str(intentSize))
            main.log.report("Data samples: " + str(sampleSize) + "\tWarm up tests: " + str(warmUp))
            main.log.report("Installed average: " + str(numpy.mean(installed)))
            main.log.report("Installed standard deviation: " + str(numpy.std(installed)))
            main.log.report("Withdraw average: " + str(numpy.mean(withdrawn)))
            main.log.report("Withdraw standard deviation: " + str(numpy.std(withdrawn)))
            main.log.report("     ")

            resultString = "'" + commit + "',"
            resultString += str(clusterCount) + ","
            resultString += str(intentSize) + ","
            resultString += str(numpy.mean(installed)) + ","
            resultString += str(numpy.std(installed)) + ","
            resultString += str(numpy.mean(withdrawn)) + ","
            resultString += str(numpy.std(withdrawn)) + "\n"
            resultsDB = open("IntentInstallWithdrawLatDB", "a")
            resultsDB.write(resultString)
            resultsDB.close()
