def usage(): print 'Usage: test.py [-options]s' print '\t\tto run this script.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--avrora-network-file=<file> \n\tdefault: ' + str( optAvroraNetworkFile ) + '\n\tif not provided freespace radio model won\'t be used by Avrora' print '--simulation-Duration=sec\n\tdefault: ' + str(optSimulationDuration) print '\nScenarios to be tested:' print '--measurement-name=String\n\tUse either measurement-name or test-list' print '--measurement-Dir=String' print 'Ways to do tests:' print '--nesc-input-directory=<Dir>"\n\tdefault: Use current directory\n\tParent directory of the Mote0..MoteN directories' print '--report-led-states=True|False\n\tdefualt:' + str( optReportLedStates) print '--report-led-durations=True|False\n\tdefualt:' + str( optReportLedDurations) AvroraLib.usage() RandomSeeder.usage() SneeqlLib.usage()
def addtoEnergyGraphs(yValue,xValue,inputfile): global totalGraph, averageGraph, maxGraph, lifetimeGraph, radioGraph, cpu_cycleGraph, packetGraph, energyGraph, logger print'************ Adding '+str(xValue) #Get the nergy used totalEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy = AvroraLib.computeEnergyConsumed(inputfile) packetCount = AvroraLib.getPacketCount() workingEnergy = AvroraLib.getWorkingEnergy() #add point to the graphs totalGraph.addPoint(yValue,xValue,str(totalEnergy),logger) logger.info('yValue= '+str(yValue)+' xValue= '+str(xValue) +' total energy= '+str(totalEnergy)) maxGraph.addPoint(yValue,xValue,str(maxEnergy),logger) averageGraph.addPoint(yValue, xValue, str(averageEnergy),logger) radioGraph.addPoint(yValue,xValue,str(radioEnergy),logger) cpu_cycleGraph.addPoint(yValue,xValue,str(cpu_cycleEnergy),logger) workingGraph.addPoint(yValue,xValue,str(workingEnergy),logger) secondLifetime = Globals.batteryEnergy / (maxEnergy/(Globals.simulationDuration)) dayLifetime = secondLifetime / (24*60*60) lifetimeGraph.addPoint(yValue, xValue, str(dayLifetime),logger) packetGraph.addPoint(yValue, xValue, packetCount,logger) energyGraph.addPoint("Sensor",str(xValue)+str(yValue),str(sensorEnergy),logger) #print str(xValue)+str(yValue)+"sensorEnergy "+str(sensorEnergy) energyGraph.addPoint("CPU",str(xValue)+str(yValue),str(cpu_cycleEnergy),logger) #print str(xValue)+str(yValue)+"cpu_cyclePower "+str(cpu_cycleEnergy) energyGraph.addPoint("Radio",str(xValue)+str(yValue),str(radioEnergy),logger) #print str(xValue)+str(yValue)+"radioPower "+str(radioEnergy) energyGraph.addPoint("Other",str(xValue)+str(yValue),str(otherEnergy),logger)
def testAvroraCandidate(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, deliveryTime, actualBFactor): #Compile the nesC exitVal = AvroraLib.compileNesCCode(nescDir) if (exitVal != 0): return AvroraLib.generateODs(nescDir) for i in range(0, optNumAvroraRuns): if optNumAvroraRuns > 1: report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath)) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(nescDir, outputPath, query, numNodes, simulationDuration=duration, networkFilePath=None) #check all tuples present queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % ( outputPath, query) checkTupleCount.checkResults(query, traceFilePath, schemaPath, aqRate, actualBFactor, duration) #add points to graph here #TODO: exp dependent - deliveryTime if (optXValType == 'acq'): addtoEnergyGraphs(query, aqRate, outputPath, duration, query) elif (optXValType == 'del'): addtoEnergyGraphs(query, deliveryTime, outputPath, duration, query)
def usage(): print 'Usage: python runExperiments.py [-options]s' print '\t\tto run the experiment.\n' print 'where options include:' print '-h, --help\n\tdisplay this message' AvroraLib.usage()
def dotest(query, bufferingFactor, measurementsActiveAgendaLoops, measurementsIgnoreIn, measurementsRemoveOperators, measurementsThinOperators, measurementsMultiAcquire, removeUnrequiredOperators): global outputPath testName = runDir(bufferingFactor, measurementsActiveAgendaLoops, measurementsIgnoreIn, measurementsRemoveOperators, measurementsThinOperators, measurementsMultiAcquire, removeUnrequiredOperators) outputPath = optOutputRoot + testName + "/" report("DoTest to: " + outputPath) if optCompileQuery: queryDir = outputPath + "/" + str(query) report("Running: " + queryDir) if os.path.isdir(queryDir): if not (SneeqlLib.optDeleteOldFiles): report("Reusing " + queryDir) copyFiles(queryDir, measurementsActiveAgendaLoops) return outputPath = compileInput( outputPath, query, bufferingFactor, measurementsActiveAgendaLoops, measurementsIgnoreIn, measurementsRemoveOperators, measurementsThinOperators, measurementsMultiAcquire, removeUnrequiredOperators) else: copyInput(outputPath) report("Outpath = " + outputPath) if (optCompileNesc): exitVal = AvroraLib.compileNesCCode(outputPath) if (exitVal != 0): return AvroraLib.generateODs(outputPath) print "complied" else: print 'reusing existing Nesc and od files' numNodes = getMaxMote(outputPath) desc = "test" #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation( outputPath, outputPath, desc, numNodes, simulationDuration=optSimulationDuration, networkFilePath=optAvroraNetworkFile) getLedTimes(avroraOutputFile, numNodes) getLedStates(avroraOutputFile, numNodes) Energy.getEnergy(outputPath) copyFiles(queryDir, measurementsActiveAgendaLoops)
def usage(): print 'Usage: exp-rt-score.py [-options]' print '\t\tto run the experiment.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--short\tdo a short run of the regTests' print '\nFor all tests:' print '--sneeql-root=<dir> \n\tdefault: ' + optSneeqlRoot print '--num-epochs=<sec> \n\tdefault: ' + str(optNumEpochs) print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--do-tossim \n\tdefault: ' + str(optDoTossim) print '--do-avrora \n\tdefault: ' + str(optDoAvrora) print '--num-avrora-runs \n\tdefault: ' + str(optNumAvroraRuns) print '--tossim-sync-time \n\tdefault: ' + str(optTossimSyncTime) print '--do-avrora-individual-queries \n\tdefault: ' + str( optDoAvroraIndividualQueries) print '--do-tossim-individual-queries \n\tdefault: ' + str( optDoTossimIndividualQueries) print '--generate-random-network=[True|False] \n\tdefault: ' + str( optGenerateRandomNet) print '\nIf a pre-existing network is to be used:' print '--sneeql-network-file=<file> \n\tdefault: ' + str(optSneeqlNetFile) print '--avrora-network-file=<file> \n\tdefault: ' + str( optAvroraNetFile ) + '\n\tif not provided freespace radio model won\'t be used by Avrora' print '\nIf a network is to be generated :' print '--net-num-nodes=<n> \n\tdefault: ' + str(optNetNumNodes) print '--net-x-dim=<n> \n\tdefault: ' + str(optNetXDim) print '--net-y-dim=<n> \n\tdefault: ' + str(optNetYDim) print '\nPhysical schema options:' print '--generate-random-schemas=[True|False] \n\tdefault: ' + str( optGenerateRandomSchemas) print '--num-schemas=<num> \n\tdefault: ' + str( optNumSchemas) + "\n\tonly applies if generate-random-schemas=True" print '--schema-file=<file> \n\tdefault: ' + str( optSchemaFile) + "\n\tonly applies if generate-random-schemas=False" print '\nScenarios to be tested:' print '--query-set=[Q1,Q2,..Qn] \n\tdefault: ' + str(optQuerySet) print '--sinks=[N1,N2,..Nn] \n\tdefault: ' + str(optSinks) print '--acq-rates=[a1,..,an] \n\t default: ' + str(optAcqRates) print '--max-buffering-factors=[b1..bn] \n\t default: ' + str( optMaxBufferingFactors) print '--max-delivery-time=[D1..Dn] \n\t default: ' + str( optMaxDeliveryTime) SneeqlLib.usage() TossimLib.usage() AvroraLib.usage() RandomSeeder.usage()
def main(): #parse the command-line arguments parseArgs(sys.argv[1:]) #AvroraLib.compileNesCCode("/cygdrive/c/dias-mc/work2/SNEEql-test/output/Q3test/nesc"); #AvroraLib.generateODs("/cygdrive/c/dias-mc/work2/SNEEql-test/output/Q3test/nesc") #AvroraLib.runSimulation("/cygdrive/c/dias-mc/work2/SNEEql-test/output/Q3test/nesc", "/cygdrive/c/tmp/output", "Q0test", 10, simulationDuration=20); print AvroraLib.computeEnergyConsumed("/cygdrive/c/tmp/output")
def usage(): print 'Usage: regTests.py [-options]' print '\t\tto run the experiment.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--short\tdo a short run of the regTests' print '\nFor all tests:' print '--sneeql-root=<dir> \n\tdefault: '+ optSneeqlRoot print '--num-agenda-evals=<n> \n\tdefault: ' + str(optNumAgendaEvals) print '--query-duration=<secs>' + str(optQueryDuration) print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--do-tossim \n\tdefault: ' + str(optDoTossim) print '--do-avrora \n\tdefault: ' + str(optDoAvrora) print '--num-avrora-runs \n\tdefault: ' + str(optNumAvroraRuns) print '--tossim-sync-time \n\tdefault: ' + str(optTossimSyncTime) print '--do-avrora-candidates \n\tdefault: ' + str(optDoAvroraCandidates) print '--do-tossim-candidates \n\tdefault: ' + str(optDoTossimCandidates) print '--do-model: ' + str(optDoModel) print '--generate-random-network=[True|False] \n\tdefault: '+str(optGenerateRandomNet) print '\nIf a pre-existing network is to be used:' print '--sneeql-network-file=<file> \n\tdefault: '+ str(optSneeqlNetFile) print '--avrora-network-file=<file> \n\tdefault: '+ str(optAvroraNetFile) + '\n\tif not provided freespace radio model won\'t be used by Avrora' print '\nIf a network is to be generated :' print '--net-num-nodes=<n> \n\tdefault: ' + str(optNetNumNodes) print '--net-x-dim=<n> \n\tdefault: ' + str(optNetXDim) print '--net-y-dim=<n> \n\tdefault: ' + str(optNetYDim) print '\nPhysical schema options:' print '--generate-random-schemas=[True|False] \n\tdefault: '+ str(optGenerateRandomSchemas) print '--num-schemas=<num> \n\tdefault: ' + str(optNumSchemas) + "\n\tonly applies if generate-random-schemas=True" print '--schema-file=<file> \n\tdefault: ' + str(optSchemaFile) + "\n\tonly applies if generate-random-schemas=False" print '\nScenarios to be tested:' print '--queries=[Q1..Qn] \n\tdefault: '+ str(optQueries) print '--acq-rates=[a1,..,an] \n\t default: ' + str(optAcqRates) print '--max-buffering-factors=[b1..bn] \n\t default: ' + str(optMaxBufferingFactors) print '--qos-aware-routing=[True|False] \n\tdefault:' + str(optQoSAwareRouting) #Move to sneeqlLib print '--routing-trees-to-generate=<n> \n\tdefault: ' + str(optRoutingTreesToGenerate) #Move to sneeqlLib print '--routing-trees-to-keep=<n> \n\tdefault: ' + str(optRoutingTreesToKeep) #Move to sneeqlLib print '--qos-aware-where-scheduling=[True|False] \n\tdefault:' + str(optQoSAwareWhereScheduling) #Move to sneeqlLib print '--qos-aware-when-scheduling=[True|False] \n\tdefault:' + str(optQoSAwareWhenScheduling) #Move to sneeqlLib SneeqlLib.usage() TossimLib.usage() AvroraLib.usage() RandomSeeder.usage()
def doExperiment1(): #set up the logger startLogger(currentExperimentRoot) if not os.path.isdir(currentExperimentRoot): os.makedirs(currentExperimentRoot) Globals.recordParameters(currentExperimentRoot,logger) setupEnergyGraphs('Acquisition interval (ms)',Globals.exp1AqRates, Globals.queries,'Max buffering factor: '+str(Globals.exp1MaxBufferingFactor)) for aqRate in Globals.exp1AqRates: for query in Globals.queries: queryInstanceRoot, queryPlanDir, nescDir, outputDir, desc = getExpDescAndDirs(currentExperimentRoot, query, 'aqRate', aqRate) #run the SNEEql query compiler SNEEqlParams = generateSNEEqlParams(Globals.queryDir+query, queryInstanceRoot, aqRate, Globals.exp1MaxBufferingFactor, sys.maxint, Globals.simulationDuration, True) exitVal = ExperimentLib.compileQuery(SNEEqlParams, desc, logger) if (exitVal != 0): continue #compile the nesC code if not os.path.exists(outputDir): os.makedirs(outputDir) print "made "+outputDir else: print "Exists "+outputDir ExperimentLib.compileNesC(nescDir, desc, logger) AvroraLib.runSimulation(nescDir, outputDir, desc, logger) if (os.path.exists(outputDir+'/avrora.txt')): addtoEnergyGraphs(query,aqRate,outputDir+'/avrora.txt') else: print 'Did not find '+outputDir+'/avrora.txt' #generate the graphs #generateEnergyGraphs('linespoints',1,True) energyGraph.generatePlotFile(currentExperimentRoot+'Exp1energy.txt',False, logger) os.chdir(currentExperimentRoot) energyGraph.plotFig14(Globals.gnuPlotExe, logger) lifetimeGraph.generatePlotFile(currentExperimentRoot+'Exp1lifetime.txt',True, logger) os.chdir(currentExperimentRoot) lifetimeGraph.plotFig15(Globals.gnuPlotExe, logger)
def evaluateAvroraQueryPlan(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, avroraNetFile, energyGraph): #Compile the nesC exitVal = AvroraLib.compileNesCCode(nescDir) if (exitVal != 0): return AvroraLib.generateODs(nescDir) for i in range(0, optNumAvroraRuns): if optNumAvroraRuns > 1: report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath)) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation( nescDir, outputPath + '/' + query + '/avrora', query, numNodes, simulationDuration=duration, networkFilePath=avroraNetFile) #check all tuples present #TODO: We can't do this for now because MQE branch doesn't produce query plan/candidate summary #queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (outputPath, query) #actualBFactor = SneeqlLib.getBufferingFactor(queryPlanSummaryFile) #checkTupleCount.checkResults(query, traceFilePath, schemaPath, aqRate, actualBFactor, duration) #Report total energy consumption siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir (sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues( nescDir, duration, inputFile="avrora-out.txt", ignoreLedEnergy=True, siteLifetimeRankFile=siteLifetimeRankFile) report("The total energy consumption is %f" % (sumEnergy)) report("The lifetime for this network is %f" % (networkLifetime)) #candidateInfo = getCandidateSummaryInformation(nescDir, query, outputPath) #print candidateInfo energyGraph.addPoint("Sensor", query, str(sensorEnergy)) energyGraph.addPoint("CPU", query, str(cpu_cycleEnergy)) energyGraph.addPoint("Radio", query, str(radioEnergy)) energyGraph.addPoint("Other", query, str(otherEnergy))
def doTest(): mainPath = optOutputRoot + "/" + optMeasurementDir + "/" if SneeqlLib.optQuery != None: SneeqlLib.compileQuery("AvroraSim", targets="Avrora1", outputRootDir=mainPath) queryParts = SneeqlLib.optQuery.split("/") query = queryParts[len(queryParts) - 1] codePath = mainPath + "/" + query + "/avrora1/" else: copyInput(mainPath) codePath = mainPath + "/avrora1/" #Use this to get many durations in one run. #multiplyNCFiles(codePath, range(0, 1)) report("codePath = " + codePath) exitVal = AvroraLib.compileNesCCode(codePath) if (exitVal != 0): return AvroraLib.generateODs(codePath) print "complied" numNodes = getMaxMote(codePath) desc = "test" #Multiple loops of same code openSummarises() for i in range(0, 2): outputDir = mainPath + "/run" + str(i) if not os.path.isdir(outputDir): os.makedirs(outputDir) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation( codePath, outputDir, desc, numNodes, simulationDuration=optSimulationDuration, networkFilePath=optAvroraNetworkFile) getLedTimes(avroraOutputFile, numNodes) getLedStates(avroraOutputFile, numNodes) Energy.getEnergy(outputDir) copyFiles(outputDir, i) closeFiles()
def parseArgs(args): global optOutputRoot, optTimeStampOutput global optAvroraNetworkFile, optSimulationDuration global optNescInputDirectory global optMeasurementName, optMeasurementDir global optReportLedStates, optReportLedDurations report("running with: " + str(args)) try: optNames = ['ouput-root=', 'timestamp-output='] optNames += ['avrora-network-file=', 'simulation-Duration='] optNames += ['nesc-input-directory='] optNames += ['measurement-name=', 'measurement-dir='] optNames += ['report-led-states=', 'report-led-durations='] #append the result of getOpNames to all the libraries optNames += AvroraLib.getOptNames() optNames += RandomSeeder.getOptNames() optNames += SneeqlLib.getOptNames() opts, args = getopt.getopt(args, "h", optNames) except getopt.GetoptError, err: print str(err) usage() sys.exit(2)
def main(): timeStamp = UtilLib.getTimeStamp() startLogger(timeStamp) if (not os.getcwd().endswith("avrora1")): print "This script should be run from the avrora directory" sys.exit(-1) parseArgs(sys.argv[1:]) nescDir = os.getcwd() if not optSkipODs: AvroraLib.compileNesCCode(nescDir) AvroraLib.generateODs(nescDir) runSimulation(nescDir)
def parseArgs(args): global optSneeqlRoot, optNumEpochs, optOutputRoot, optTimeStampOutput, optDoTossim, optDoAvrora, optNumAvroraRuns, optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates, optGenerateRandomNet, optSneeqlNetFile, optAvroraNetFile, optNetNumNodes, optNetXDim, optNetYDim, optGenerateRandomSchemas, optNumSchemas, optSchemaFile, optQueries, optAcqRates, optMaxBufferingFactors try: optNames = [ "help", "short", "sneeql-root=", "num-epochs=", "output-root=", "timestamp-output=", "do-tossim=", "do-avrora=", "num-avrora-runs=", "tossim-sync-time=", "do-avrora-candidates=", "do-tossim-candidates=" ] optNames += [ "generate-random-network=", "sneeql-network-file=", "avrora-network-file=", "net-num-nodes=", "net-x-dim=", "net-y-dim=" ] optNames += [ "generate-random-schemas=", "num-schemas=", "schema-file=" ] optNames += ["queries=", "acq-rates=", "max-buffering-factors="] #append the result of getOpNames to all the libraries optNames += SneeqlLib.getOptNames() optNames += TossimLib.getOptNames() optNames += AvroraLib.getOptNames() optNames += RandomSeeder.getOptNames() optNames = UtilLib.removeDuplicates(optNames) opts, args = getopt.getopt(args, "h", optNames) except getopt.GetoptError, err: print str(err) usage() sys.exit(2)
def testAvroraCandidate(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, avroraNetFile, rtscore_lifetime): #Compile the nesC exitVal = AvroraLib.compileNesCCode(nescDir) if (exitVal != 0): return AvroraLib.generateODs(nescDir) for i in range(0, optNumAvroraRuns): if optNumAvroraRuns > 1: report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath)) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation( nescDir, outputPath, query, numNodes, simulationDuration=duration, networkFilePath=avroraNetFile) #check all tuples present queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % ( outputPath, query) actualBFactor = SneeqlLib.getBufferingFactor(queryPlanSummaryFile) checkTupleCount.checkResults(query, traceFilePath, schemaPath, aqRate, actualBFactor, duration) #Report total energy consumption siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir (sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues( nescDir, duration, inputFile="avrora-out.txt", ignoreLedEnergy=True, siteLifetimeRankFile=siteLifetimeRankFile) report("The total energy consumption is %f" % (sumEnergy)) report("The lifetime for this network is %f" % (networkLifetime)) (agendaName, rtName, score) = getRTScore(nescDir, query, outputPath) agendaID = agendaName.split("-")[2] rtscore_lifetime.add(1, sumEnergy, agendaID)
def usage(): print 'Usage: regTests.py [-options]' print '\t\tto run the experiment.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--short\tdo a short run of the regTests' print '\nFor all tests:' print '--sneeql-root=<dir> \n\tdefault: '+ optSneeqlRoot print '--num-epochs=<sec> \n\tdefault: ' + str(optNumEpochs) print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--targets={avrora1,avrora2,tossim1,tossim2,insense} \n\tdefault: ' + str(optTargets) print '--num-avrora-runs \n\tdefault: ' + str(optNumAvroraRuns) print '--tossim-sync-time \n\tdefault: ' + str(optTossimSyncTime) print '--do-avrora-candidates \n\tdefault: ' + str(optDoAvroraCandidates) print '--do-tossim-candidates \n\tdefault: ' + str(optDoTossimCandidates) print '--generate-random-network=[True|False] \n\tdefault: '+str(optGenerateRandomNet) print '\nIf a pre-existing network is to be used:' print '--sneeql-network-file=<file> \n\tdefault: '+ str(optSneeqlNetFile) print '--avrora-network-file=<file> \n\tdefault: '+ str(optAvroraNetFile) + '\n\tif not provided freespace radio model won\'t be used by Avrora' print '\nIf a network is to be generated :' print '--net-num-nodes=<n> \n\tdefault: ' + str(optNetNumNodes) print '--net-x-dim=<n> \n\tdefault: ' + str(optNetXDim) print '--net-y-dim=<n> \n\tdefault: ' + str(optNetYDim) print '\nPhysical schema options:' print '--generate-random-schemas=[True|False] \n\tdefault: '+ str(optGenerateRandomSchemas) print '--num-schemas=<num> \n\tdefault: ' + str(optNumSchemas) + "\n\tonly applies if generate-random-schemas=True" print '--schema-file=<file> \n\tdefault: ' + str(optSchemaFile) + "\n\tonly applies if generate-random-schemas=False" print '\nScenarios to be tested:' print '--queries=[Q1..Qn] \n\tdefault: '+ str(optQueries) print '--acq-rates=[a1,..,an] \n\t default: ' + str(optAcqRates) print '--max-buffering-factors=[b1..bn] \n\t default: ' + str(optMaxBufferingFactors) print '--test-all=[True|False] \n\tdefault: '+ str(optTestAll) print '\nExperiment Parameters:' print '--led-debug\n\tdefault: ' + str(optLedDebug) SneeqlLib.usage() TossimLib.usage() AvroraLib.usage() RandomSeeder.usage() checkTupleCount.usage()
def doExperiment3(): #set up the logger startLogger(currentExperimentRoot) if not os.path.isdir(currentExperimentRoot): os.makedirs(currentExperimentRoot) Globals.recordParameters(currentExperimentRoot,logger) #graph to output total energy consumed by network setupEnergyGraphs('Maximum result delivery time',Globals.exp3DeliveryTimes,Globals.queries,'Acquistion rate: '+str(Globals.exp3AqRate)) for deliveryTime in Globals.exp3DeliveryTimes: for query in Globals.queries: queryInstanceRoot, queryPlanDir, nescDir, outputDir, desc = getExpDescAndDirs (currentExperimentRoot, query, 'deliveryTime', deliveryTime) #run the SNEEql query compiler SNEEqlParams = generateSNEEqlParams(Globals.queryDir+query, queryInstanceRoot, Globals.exp3AqRate, sys.maxint, deliveryTime, Globals.simulationDuration, True) exitVal = ExperimentLib.compileQuery(SNEEqlParams, desc, logger) if (exitVal != 0): continue #compile the nesC code if not os.path.exists(outputDir): os.makedirs(outputDir) print "made "+outputDir else: print "Exists "+outputDir ExperimentLib.compileNesC(nescDir, desc, logger) AvroraLib.runSimulation(nescDir, outputDir, desc, logger) if (os.path.exists(outputDir+'/avrora.txt')): addtoEnergyGraphs(query,deliveryTime,outputDir+'/avrora.txt') else: print 'Did not find '+outputDir+'/avrora.txt' lifetimeGraph.generatePlotFile(currentExperimentRoot+'Exp3lifetime.txt',True,logger) os.chdir(currentExperimentRoot) lifetimeGraph.plotFig17(Globals.gnuPlotExe, logger)
def testAvroraCandidate(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, avroraNetFile): #Compile the nesC exitVal = AvroraLib.compileNesCCode(nescDir) if (exitVal != 0): return; AvroraLib.generateODs(nescDir) for i in range(0, optNumAvroraRuns): if optNumAvroraRuns > 1: report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath)) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(nescDir, outputPath, query, numNodes, simulationDuration = duration, networkFilePath = avroraNetFile) #check all tuples present queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (outputPath, query) actualBFactor = SneeqlLib.getBufferingFactor(queryPlanSummaryFile) checkTupleCount.checkResults(query, traceFilePath, schemaPath, aqRate, actualBFactor, duration)
def usage(): print 'Usage: regTests.py [-options]' print '\t\tto run the experiment.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--short\tdo a short run of the regTests' print '\nFor all tests:' print '--sneeql-root=<dir> \n\tdefault: ' + optSneeqlRoot print '--sim-duration=<sec> \n\tdefault: ' + str(optSimDuration) print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--do-tossim \n\tdefault: ' + str(optDoTossim) print '--do-avrora \n\tdefault: ' + str(optDoAvrora) print '--num-avrora-runs \n\tdefault: ' + str(optNumAvroraRuns) print '--tossim-sync-time \n\tdefault: ' + str(optTossimSyncTime) print '--do-avrora-candidates \n\tdefault: ' + str(optDoAvroraCandidates) print '--do-tossim-candidates \n\tdefault: ' + str(optDoTossimCandidates) print '--sneeql-network-file=<file> \n\tdefault: ' + str(optSneeqlNetFile) print '--net-num-nodes=<n> \n\tdefault: ' + str(optNetNumNodes) print '\nPhysical schema options:' print '--schema-file=<file> \n\tdefault: ' + str( optSchemaFile) + "\n\tonly applies if generate-random-schemas=False" print '\nScenarios to be tested:' print '--queries=[Q1..Qn] \n\tdefault: ' + str(optQueries) print '--acq-rates=[a1,..,an] \n\t default: ' + str(optAcqRates) print '--max-buffering-factors=[b1..bn] \n\t default: ' + str( optMaxBufferingFactors) print '--delivery-times=[D1..Dn] \n\t default: ' + str(optDeliveryTimes) print '--test-all=[True|False] \n\tdefault: ' + str(optTestAll) print '\nExperiment Parameters:' print '--x-val-type=[acq|del|bf]' + str(optXValType) print '--led-debug\n\tdefault: ' + str(optLedDebug) SneeqlLib.usage() TossimLib.usage() AvroraLib.usage() RandomSeeder.usage() checkTupleCount.usage()
def usage(): print 'Usage: test.py [-options]s' print '\t\tto run this script.\n' print 'where options include:' print '-h, --help\tdisplay this message' print '--ouput-root=<dir> \n\tdefault: ' + str(optOutputRoot) print '--timestamp-output \n\tdefault: ' + str(optTimeStampOutput) print '--avrora-network-file=<file> \n\tdefault: ' + str( optAvroraNetworkFile ) + '\n\tif not provided freespace radio model won\'t be used by Avrora' print '--simulation-Duration=sec\n\tdefault: ' + str(optSimulationDuration) print '\nScenarios to be tested:' print '--measurement-name=String\n\tUse either measurement-name or test-list' print '--measurement-Dir=String' print '--test-list=String:Q1,[email protected]:Q1,..Qn\n\tUse either measurement-name or measurement-name-list' print '--queries=Q1,..Qn\n\tUse either queries or test-list' print '--buffering-factors=b1,..bn \n\t default: ' + str( optBufferingFactors) print '--measurements-max-active-agenda-loops=b1,..bn \n\t default: ' + str( optMeasurementsMaxActiveAgendaLoops) print '--measurements-ignore-in-list=St1,..Stn\n\t default: None' print '--measurements-remove-operators-list=St1,..Stn\n\t default: None' print '--measurements-thin-operators-list=St1,..Stn\n\t default: None' print '--remove-unrequired-operators-list=St1,..Stn\n\t default: None' print '--measurements-multi-acquire-list=I1..In\n\t default: None' print 'Ways to do tests:' print '--compile-query=True|False\n\tdefault: ' + str( optCompileQuery ) + '\n\tWhen set to True take precident over input directory' print '--compile-nesc=True|False\n\tdefault: ' + str( optCompileQuery) + '\n\tMust be True if compile query is True' print '--nesc-input-directory=<Dir>"\n\tdefault: Use current directory\n\tParent directory of the Mote0..MoteN directories' print '--report-led-states=True|False\n\tdefualt:' + str( optReportLedStates) print '--report-led-durations=True|False\n\tdefualt:' + str( optReportLedDurations) AvroraLib.usage() RandomSeeder.usage() SneeqlLib.usage()
def testAvroraCandidate(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, avroraNetFile, alphaGraph, deltaGraph, epsilonGraph, lambdaGraph): #Compile the nesC exitVal = AvroraLib.compileNesCCode(nescDir) if (exitVal != 0): return; AvroraLib.generateODs(nescDir) candidateInfo = getCandidateSummaryInformation(nescDir, query, outputPath) candidateInfo['total-energy'] = [] candidateInfo['network-lifetime'] = [] alpha = int(candidateInfo['alpha-ms']) bufferingFactor = int(candidateInfo['beta']) duration = int((float(optNumAgendaEvals) * float(alpha) * float(bufferingFactor)) / 1000.0) for i in range(0, optNumAvroraRuns): if optNumAvroraRuns > 1: report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath)) #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(nescDir, outputPath, query, numNodes, simulationDuration = duration, networkFilePath = avroraNetFile) #check all tuples present queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (outputPath, query) checkTupleCount.checkResults(query, traceFilePath, schemaPath, alpha, bufferingFactor, duration) #Report total energy consumption siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir (sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues(nescDir, duration, inputFile = "avrora-out.txt", ignoreLedEnergy = True, siteLifetimeRankFile = siteLifetimeRankFile) lifetimeDays = UtilLib.secondsToDays(networkLifetime) #Put this into avrora lib so rank file has it too report ("The total energy consumption is %f" % (sumEnergy)) normSumEnergy = (float(sumEnergy) / float(duration)) * float(optQueryDuration) #to do: use new function (below) report ("The normalized total energy consumption is %f" % (normSumEnergy)) report ("The lifetime for this network is %f" % (lifetimeDays)) candidateInfo['total-energy'].append(float(normSumEnergy)) candidateInfo['network-lifetime'].append(float(lifetimeDays)) print "DEBUG: testAvroraCandidate.candidateInfo = " + str(candidateInfo) return candidateInfo
def runSimulation(nescDir): #run avrora simulation (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(nescDir, nescDir, 'sim', optNumNodes, optSimDuration, optTopFile) #Report total energy consumption siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir (sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues( nescDir, optSimDuration, inputFile="avrora-out.txt", ignoreLedEnergy=True, siteLifetimeRankFile=siteLifetimeRankFile) report("The total energy consumption is %f" % (sumEnergy)) report("The lifetime for this network is %f" % (networkLifetime))
def startLogger(timeStamp): global logger logger = logging.getLogger('test') #create the directory if required if not os.path.isdir(optOutputRoot): os.makedirs(optOutputRoot) hdlr = logging.FileHandler('%s/test%s.log' % (optOutputRoot, timeStamp)) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.INFO) logger.info('nn2 sweep') #Register the logger with the libraries this module uses SneeqlLib.registerLogger(logger) #TossimLib.registerLogger(logger) AvroraLib.registerLogger(logger) checkTupleCount.registerLogger(logger)
def parseArgs(args): try: optNames = ["help"] #append the result of getOpNames to all the libraries optNames += AvroraLib.getOptNames() #TODO: What if option with same name provided by more than one library? Use a set? opts, args = getopt.getopt(args, "h", optNames) except getopt.GetoptError: print getopt.GetoptError usage() sys.exit(2) for o, a in opts: if (o == "-h" or o == "--help"): usage() sys.exit() AvroraLib.setOpts(opts)
def startLogger(timeStamp): global logger logger = logging.getLogger('test') #create the directory if required if not os.path.isdir(optOutputRoot): os.makedirs(optOutputRoot) file = '%s/test%s.log' % (optOutputRoot, timeStamp) print file hdlr = logging.FileHandler(file) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.INFO) logger.info('Starting cb Test') #Register the logger with the libraries this module uses AvroraLib.registerLogger(logger) RandomSeeder.registerLogger(logger) SneeqlLib.registerLogger(logger) LedTimes.registerLogger(logger)
def parseArgs(args): global optSneeqlRoot, optSimDuration, optOutputRoot global optTimeStampOutput, optDoTossim, optDoAvrora global optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates global optSneeqlNetFile global optNetNumNodes global optSchemaFile global optQueries, optAcqRates, optMaxBufferingFactors, optDeliveryTimes global optTestAll, optLedDebug, optXValType try: optNames = [ "help", "short", "sneeql-root=", "sim-duration=", "output-root=" ] optNames += [ "timestamp-output=", "compile-sneeql=", "do-tossim=", "do-avrora=" ] optNames += [ "tossim-sync-time=", "do-avrora-candidates=", "do-tossim-candidates=" ] optNames += [ "generate-random-network=", "sneeql-network-file=", "net-num-nodes=" ] optNames += ["schema-file="] optNames += [ "queries=", "acq-rates=", "max-buffering-factors=", "delivery-times=", "test-all=", "x-val-type=" ] #append the result of getOpNames to all the libraries optNames += SneeqlLib.getOptNames() optNames += TossimLib.getOptNames() optNames += AvroraLib.getOptNames() optNames += RandomSeeder.getOptNames() optNames += checkTupleCount.getOptNames() optNames = UtilLib.removeDuplicates(optNames) opts, args = getopt.getopt(args, "h", optNames) except getopt.GetoptError, err: print str(err) usage() sys.exit(2)
def addtoEnergyGraphs(yValue, xValue, avroraOutDir, duration, query): global totalGraph, averageGraph, maxGraph, lifetimeGraph, radioGraph, cpu_cycleGraph, packetGraph, energyGraph, logger print '************ Adding ' + str(xValue) #Get energy used (totalEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues( avroraOutDir, duration, inputFile="avrora-out.txt", ignoreLedEnergy=True) scaling = float(optSimDuration) / float(duration) #TODO: don't know what these are so have left them out for now # packetCount = AvroraLib.getPacketCount() # workingEnergy = AvroraLib.getWorkingEnergy() #add point to the graphs totalGraph.addPoint(yValue, xValue, str(totalEnergy * scaling)) logger.info('yValue= ' + str(yValue) + ' xValue= ' + str(xValue) + ' total energy= ' + str(totalEnergy * scaling)) maxGraph.addPoint(yValue, xValue, str(maxEnergy * scaling)) averageGraph.addPoint(yValue, xValue, str(averageEnergy * scaling)) radioGraph.addPoint(yValue, xValue, str(radioEnergy * scaling)) cpu_cycleGraph.addPoint(yValue, xValue, str(cpu_cycleEnergy * scaling)) # workingGraph.addPoint(yValue,xValue,str(workingEnergy)) secondLifetime = batteryEnergy / (maxEnergy / (duration)) dayLifetime = secondLifetime / (24 * 60 * 60) lifetimeGraph.addPoint(yValue, xValue, str(dayLifetime)) # packetGraph.addPoint(yValue, xValue, packetCount) energyGraph.addPoint("Sensor", query + str(xValue), str(sensorEnergy * scaling)) energyGraph.addPoint("CPU", query + str(xValue), str(cpu_cycleEnergy * scaling)) energyGraph.addPoint("Radio", query + str(xValue), str(radioEnergy * scaling)) energyGraph.addPoint("Other", query + str(xValue), str(otherEnergy * scaling))
def parseArgs(args): global optOutputRoot, optTimeStampOutput global optAvroraNetworkFile, optSimulationDuration global optCompileQuery, optCompileNesc, optNescInputDirectory global testLength, optBufferingFactors, optMeasurementDir, optMeasurementNameList, optQueriesList global optMeasurementsMaxActiveAgendaLoops global optMeasurementsIgnoreInList, optMeasurementsRemoveOperatorsList global optMeasurementsThinOperatorsList, optRemoveUnrequiredOperatorsList global optMeasurementsMultiAcquireList global optReportLedStates, optReportLedDurations, loopLength report("running with: " + str(args)) try: optNames = ['ouput-root=', 'timestamp-output=', 'avrora-network-file='] optNames += ['simulation-Duration=', 'compile-query=', 'compile-nesc='] optNames += [ 'nesc-input-directory=', 'measurement-dir=', 'measurement-name=', 'test-list=' ] optNames += [ 'queries=', 'buffering-factors=', 'measurements-max-active-agenda-loops=' ] optNames += ['measurements-ignore-in-list='] optNames += [ 'measurements-remove-operators-list=', 'measurements-thin-operators-list=' ] optNames += ['measurements-multi-acquire-list='] optNames += ['remove-unrequired-operators-list='] optNames += ['report-led-states=', 'report-led-durations='] #append the result of getOpNames to all the libraries optNames += AvroraLib.getOptNames() optNames += RandomSeeder.getOptNames() optNames += SneeqlLib.getOptNames() opts, args = getopt.getopt(args, "h", optNames) except getopt.GetoptError, err: print str(err) usage() sys.exit(2)
def parseArgs(args): global optSneeqlRoot, optNumAgendaEvals, optQueryDuration, optOutputRoot, optLabel, optTimeStampOutput, optDoTossim, optDoAvrora, optNumAvroraRuns, optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates, optDoModel, optGenerateRandomNet, optSneeqlNetFile, optAvroraNetFile, optNetNumNodes, optNetXDim, optNetYDim, optGenerateRandomSchemas, optNumSchemas, optSchemaFile, optQueries, optAcqRates, optMaxBufferingFactors, optQoS, optQoSAwareRouting, optRoutingTreesToGenerate, optRoutingTreesToKeep, optQoSAwareWhereScheduling, optQoSAwareWhenScheduling, optBufferingFactor try: optNames = ["help", "sneeql-root=", "num-agenda-evals=", "query-duration=", "output-root=", "label=", "timestamp-output=", "do-tossim=", "do-avrora=", "num-avrora-runs=", "tossim-sync-time=", "do-avrora-candidates=", "do-tossim-candidates=", "do-model="] optNames += ["generate-random-network=", "sneeql-network-file=", "avrora-network-file=", "net-num-nodes=", "net-x-dim=", "net-y-dim="] optNames += ["generate-random-schemas=", "num-schemas=", "schema-file="] optNames += ["queries=", "acq-rates=", "max-buffering-factors="] optNames += ["qos-aware-routing=", "routing-trees-to-generate=", "routing-trees-to-keep=", "qos-aware-where-scheduling=", "qos-aware-when-scheduling=","buffering-factor="] #append the result of getOpNames to all the libraries optNames += SneeqlLib.getOptNames(); optNames += TossimLib.getOptNames(); optNames += AvroraLib.getOptNames(); optNames += RandomSeeder.getOptNames(); optNames = UtilLib.removeDuplicates(optNames) opts, args = getopt.getopt(args, "h",optNames) except getopt.GetoptError, err: print str(err) usage() sys.exit(2)
optMaxBufferingFactors = a.split(",") optMaxBufferingFactors = [int(x) for x in optMaxBufferingFactors] continue if (o == "--short"): optQueries = ["Q0"] optNumSchemas = 1 optAcqRates = [5000] optMaxBufferingFactors = [3] optDoTossimCandidates = False optDoAvroraCandidates = False continue SneeqlLib.setOpts(opts) TossimLib.setOpts(opts) AvroraLib.setOpts(opts) RandomSeeder.setOpts(opts) #Ouput info message to screen and logger if applicable def report(message): if (logger != None): logger.info(message) print message #Ouput warning message to screen and logger if applicable def reportWarning(message): if (logger != None): logger.warning(message) print message