diff --git a/Python/filegenerator.py b/Python/filegenerator.py index 2f9bb3a..b616996 100644 --- a/Python/filegenerator.py +++ b/Python/filegenerator.py @@ -12,11 +12,14 @@ def __init__(self, make_log, make_summary, MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange, overlapTime, numbSynAckResends, attackerType, - isAmplification): + isAmplification,sessionId): # boolean statements for deciding which files to make self.makeLog = make_log self.makeSummary = make_summary self.makeAnimation = make_animation + # File Name to be used + self.logFileName = "log-{0}.csv".format(str(sessionId)) + self.summaryFileName = "summary-{0}.csv".format(str(sessionId)) # names of the output files self.logName = log_name self.summaryName = summary_name @@ -194,7 +197,7 @@ def addSummaryDataToLog(self, client, attacker, self.lengthLongestEntry = len(self.packetDictionary["S: " + ' Step']) def initializeSummary(self): # initializer for the summary file - self.summaryFile = open("summary.csv", "w") + self.summaryFile = open(self.summaryFileName, "w") self.headerGen(self.summaryFile) def initializeAnimationInstructions(self): @@ -358,7 +361,7 @@ def outputFile(self): while (len(self.packetDictionary.get(key)) < self.lengthLongestEntry): self.packetDictionary.get(key).append("") sortedKeys = sorted(self.packetDictionary.keys(), key=self.sortHelper) - outputLogFile = open("log.csv", "w", newline='') + outputLogFile = open(self.logFileName, "w", newline='') self.headerGen(outputLogFile, "%L") generator = csv.writer(outputLogFile) generator.writerow(sortedKeys) diff --git a/Python/main.py b/Python/main.py index b61e862..0bf1ebe 100644 --- a/Python/main.py +++ b/Python/main.py @@ -1,3 +1,4 @@ +import uuid from . import packet from . import connectionObject from . import attacker @@ -22,6 +23,9 @@ def runSimulation(dddState, skipsim, sumOut, routertoNormal, normaltoRouter, reflectortoRouter, attackertoReflector, queueLimit, attackerType, amplification): + # For a simulation session, we create a unique session id for it using GUID. + sessionGuid = uuid.uuid4() # Generate a GUID/UUID for this session + print(amplification) print(attackerType) @@ -34,7 +38,8 @@ def runSimulation(dddState, skipsim, sumOut, MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange, overlapTime, - numbSynAckResends, attackerType, amplification) + numbSynAckResends, attackerType, + amplification, sessionGuid) debug_mode = False @@ -281,4 +286,6 @@ def runSimulation(dddState, skipsim, sumOut, fileGen.outputFile() # Return value will be the animateInstructions - return fileGen.instructions if hasattr(fileGen, 'instructions') else [] + response = fileGen.instructions if hasattr(fileGen, 'instructions') else [] + response.append(str(sessionGuid)) + return response diff --git a/cleanup.bat b/cleanup.bat new file mode 100644 index 0000000..7dc45eb --- /dev/null +++ b/cleanup.bat @@ -0,0 +1,2 @@ +@echo off +del *.csv \ No newline at end of file diff --git a/static/js/requests.js b/static/js/requests.js index 40d310b..32f3ed7 100644 --- a/static/js/requests.js +++ b/static/js/requests.js @@ -33,6 +33,9 @@ var queueLimit; var attackerType; var amplification; +// When simulation started, we will retrieve a session ID. +var sessionId + function startSimulation(){ DDDstate = document.getElementById("DDDstate").checked; skipsim = document.getElementById("simOption").checked; @@ -80,6 +83,8 @@ function sendGet(){ xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ let jsonObj = JSON.parse(xmlHttp.responseText); + sessionId = jsonObj[jsonObj.length - 1]; + console.log('Session GUID = ' + sessionId) console.log('length of animateInstructions list is ' + jsonObj.length); setAnimateInstructions(jsonObj); } @@ -123,26 +128,27 @@ function downloadFile(){ var request1; var request2; -console.log(summfile); -console.log(logfile); + console.log(summfile); + console.log(logfile); + if(summfile){ if(filename1){ - request1 = baseUrl + "download2/" + 'summary.csv' + "&" +filename1; + request1 = baseUrl + "download2/" + 'summary-' + sessionId + '.csv' + "&" +filename1; window.open(request1, '_blank'); } else{ - request1 = baseUrl + "download/" + 'summary.csv'; + request1 = baseUrl + "download/" + 'summary-' + sessionId + '.csv'; window.open(request1, '_blank'); } } if(logfile){ if(filename2){ - request2 = baseUrl + "download2/" + 'log.csv' + "&" +filename2; + request2 = baseUrl + "download2/" + 'log-' + sessionId + '.csv' + "&" +filename2; window.open(request2, '_blank'); } else{ - request2 = baseUrl + "download/" + 'log.csv'; + request2 = baseUrl + "download/" + 'log-' + sessionId + '.csv'; window.open(request2, '_blank'); } }