diff --git a/Python/filegenerator.py b/Python/filegenerator.py index 63ee4ca..73878b0 100644 --- a/Python/filegenerator.py +++ b/Python/filegenerator.py @@ -13,14 +13,22 @@ class filegenerator: MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange, overlapTime, numbSynAckResends, attackerType, - isAmplification,sessionId): + isAmplification, storageFolder, sessionId): # boolean statements for deciding which files to make self.makeLog = make_log self.makeSummary = make_summary self.makeAnimation = make_animation + # Make folders + try: + os.mkdir(storageFolder) + except FileExistsError: + pass # This error is to be expected. + # If FileExistsError happens here, this means a GUID collision. I don't think it is possible. + os.mkdir(os.path.join(storageFolder, str(sessionId))) + self.storageFolder = os.path.join(storageFolder, str(sessionId)) # File Name to be used - self.logFileName = os.path.join("logs", "log-{0}.csv".format(str(sessionId))) - self.summaryFileName = os.path.join("summaries", "summary-{0}.csv".format(str(sessionId))) + self.logFileName = os.path.join(self.storageFolder, "log.csv") + self.summaryFileName = os.path.join(self.storageFolder, "summary.csv") # names of the output files self.logName = log_name self.summaryName = summary_name @@ -598,5 +606,5 @@ class filegenerator: plt.title("Packets " + name + " vs. Time") plt.legend() - plt.savefig(os.path.join("plots", name + "-{0}.svg".format(str(self.sessionId)))) + plt.savefig(os.path.join(self.storageFolder, name + ".svg")) plt.close() diff --git a/Python/main.py b/Python/main.py index 2d46707..79b5c7b 100644 --- a/Python/main.py +++ b/Python/main.py @@ -23,7 +23,8 @@ def runSimulation(dddState, skipsim, sumOut, routertoClient, routertoReflector, routertoNormal, normaltoRouter, reflectortoRouter, attackertoReflector, - queueLimit, attackerType, amplification): + queueLimit, attackerType, amplification, + storageFolder): # For a simulation session, we create a unique session id for it using GUID. sessionGuid = uuid.uuid4() # Generate a GUID/UUID for this session @@ -40,7 +41,7 @@ def runSimulation(dddState, skipsim, sumOut, NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange, overlapTime, numbSynAckResends, attackerType, - amplification, sessionGuid) + amplification, storageFolder, sessionGuid) debug_mode = False diff --git a/cleanup.bat b/cleanup.bat deleted file mode 100644 index b4a5735..0000000 --- a/cleanup.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -del *.csv -del logs\log-*.csv -del summaries\summary-*.csv -del plots\*.svg \ No newline at end of file diff --git a/pserver.py b/pserver.py index 231743c..f6632af 100644 --- a/pserver.py +++ b/pserver.py @@ -16,8 +16,8 @@ def runSimulation(input1): # Parse simulation parameters. Param = input1.split("&") # Parameters are separated by '&' delimiter. print(Param) - # Check parameter count. - if len(Param)==24: # VERY-IMPORTANT: Modify here if there are changes to total number of requests! + # Check parameter count. If simulation never happens then check here! + if len(Param)==25: # VERY-IMPORTANT: Modify here if there are changes to total number of requests! ddd_state = (Param[0] == "true") skip_sim = (Param[1] == "true") sumOut = (Param[2] == "true") @@ -43,6 +43,7 @@ def runSimulation(input1): queueLimit = int(Param[21]) attackerType = float(Param[22]) amplification = float(Param[23]) + storageFolder = Param[24] response = main.runSimulation(ddd_state, skip_sim, sumOut, logOut, packet_size, rtsa, @@ -53,7 +54,7 @@ def runSimulation(input1): routertoClient, routertoReflector, routertoNormal, normaltoRouter, reflectortoRouter, attackertoReflector, queueLimit, attackerType, - amplification) + amplification, storageFolder) print('Backend Simulation Total Elapsed Time:', time.time() - start_time, 'seconds') @@ -63,21 +64,23 @@ def runSimulation(input1): abort(400) -@app.route('/download/') # This is the endpoint that the javascript code will call to run simulation on server -def download(fileName): +@app.route('/download///') # This is the endpoint that the javascript code will call to run simulation on server +def download(storageFolder, sessionId, fileName): try: if fileName.startswith("log"): - return send_file(os.path.join("logs", fileName), as_attachment=True) + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) elif fileName.startswith("summary"): - return send_file(os.path.join("summaries", fileName), as_attachment=True) + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) + elif fileName.endswith(".svg"): + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) else: abort(400) except FileNotFoundError: abort(404) -@app.route('/download2/') -def download2(statement): +@app.route('/download2///') +def download2(storageFolder, sessionId, statement): # We may use split function to process the request. tmp = statement.split("&") fileName = tmp[0] @@ -85,9 +88,11 @@ def download2(statement): if len(tmp)==2: try: if fileName.startswith("log"): - return send_file(os.path.join("logs", fileName), as_attachment=True, attachment_filename=newName) + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True, attachment_filename=newName) elif fileName.startswith("summary"): - return send_file(os.path.join("summaries", fileName), as_attachment=True, attachment_filename=newName) + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True, attachment_filename=newName) + elif fileName.endswith(".svg"): + return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True, attachment_filename=newName) else: abort(400) except FileNotFoundError: diff --git a/readme.md b/readme.md index 202ac48..886e468 100644 --- a/readme.md +++ b/readme.md @@ -17,14 +17,7 @@ pip install flask pip install matplotlib ``` -3. If it is your first time to run the server, you should create some folders: -```bat -mkdir logs -mkdir summaries -mkdir plots -``` - -4. Execute the following commands to run flask: +3. Execute the following commands to run flask: ```bat set FLASK_APP=pserver set FLASK_ENV=development @@ -32,7 +25,7 @@ python -m flask run ``` Alternatively, you may double-click `run_server.bat` file in lieu of manually typing these commands. -5. In certain circumstances, your system might be configuring the `*.js` files with incorrect treatings. Locate registry key `HKEY_CLASSES_ROOT\.js` and edit the key value `Content Type` to be `text/javascript`.
+4. In certain circumstances, your system might be configuring the `*.js` files with incorrect treatings. Locate registry key `HKEY_CLASSES_ROOT\.js` and edit the key value `Content Type` to be `text/javascript`.
Please note that you are all set if key value `Content Type` does not exist in `HKEY_CLASSES_ROOT\.js` key at all: just leave the registry as is. Usually, things are problematic if the value of `Content Type` equals to `text/plain`. ### Option 2: Get Started on Windows with WSL @@ -55,25 +48,11 @@ Link: https://www.digitalocean.com/community/tutorials/how-to-make-a-web-applica ```bash export FLASK_APP=pserver export FLASK_ENV=development -``` - -### To run the server: -1) Navigate to the top of this repo -2) If it is your first time to run the server, then run -```bat -mkdir summaries -mkdir logs -mkdir plots -``` - -3) Run the following -```bat flask run ``` -## Summary and Log Files -For each session, the backend would generate a summary file and a log file. They will be separately placed in two directories: `logs` and `summaries`.
-There is also a `cleanup.bat`. If you would like to delete all summaries and logs for previous sessions, run it.
+## Output Files +For each simulation session, the backend would generate a summary file, a log file and several statistical graphs. Their locations are specified by your input on frontend.
## License This project is under NCSA License. For more information, view the [license](license.txt). \ No newline at end of file diff --git a/run_server.bat b/run_server.bat index 1f69c73..46738b7 100644 --- a/run_server.bat +++ b/run_server.bat @@ -1,8 +1,5 @@ @echo off set FLASK_APP=pserver set FLASK_ENV=development -mkdir logs -mkdir summaries -mkdir plots python -m flask run pause. \ No newline at end of file diff --git a/run_server.sh b/run_server.sh index 8711815..a8281bd 100644 --- a/run_server.sh +++ b/run_server.sh @@ -2,7 +2,4 @@ export FLASK_APP=pserver export FLASK_ENV=development -mkdir logs -mkdir summaries -mkdir plots flask run \ No newline at end of file diff --git a/static/js/requests.js b/static/js/requests.js index 32f3ed7..546de71 100644 --- a/static/js/requests.js +++ b/static/js/requests.js @@ -32,9 +32,10 @@ var attackertoReflector; var queueLimit; var attackerType; var amplification; +var storageFolder; // When simulation started, we will retrieve a session ID. -var sessionId +var sessionId; function startSimulation(){ DDDstate = document.getElementById("DDDstate").checked; @@ -73,6 +74,7 @@ function startSimulation(){ queueLimit=document.getElementById("queueLimit").value; attackerType = document.getElementById("AtkType").value; amplification = document.getElementById("Amp").value; + storageFolder = document.getElementById("storageFolder").value; } // sendGet is the function that is called when user presses button on index.html @@ -84,7 +86,7 @@ function sendGet(){ 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('Session GUID = ' + sessionId); console.log('length of animateInstructions list is ' + jsonObj.length); setAnimateInstructions(jsonObj); } @@ -98,7 +100,7 @@ function sendGet(){ dddmappingdelay+ "&" + propagationdelay + "&" + numofDDDport + "&" + timetonextDDDport +"&" + overlaptimeoldDDD + "&" + durationSim + "&" + numbSynAckResends + "&" + clienttoRouter + "&" + routertoClient + "&" + routertoReflector + "&" + routertoNormal + "&" + normaltoRouter + "&" + reflectortoRouter + "&" + attackertoReflector + "&" + queueLimit +"&" + attackerType + "&" - + amplification; + + amplification + "&" + storageFolder; console.log(sendRequestUrl); xmlHttp.open("GET", sendRequestUrl, true); // true for asynchronous xmlHttp.send(null); @@ -133,22 +135,22 @@ function downloadFile(){ if(summfile){ if(filename1){ - request1 = baseUrl + "download2/" + 'summary-' + sessionId + '.csv' + "&" +filename1; + request1 = `${baseUrl}download2/${storageFolder}/${sessionId}/summary.csv&${filename1}`; window.open(request1, '_blank'); } else{ - request1 = baseUrl + "download/" + 'summary-' + sessionId + '.csv'; + request1 = `${baseUrl}download/${storageFolder}/${sessionId}/summary.csv`; window.open(request1, '_blank'); } } if(logfile){ if(filename2){ - request2 = baseUrl + "download2/" + 'log-' + sessionId + '.csv' + "&" +filename2; + request2 = `${baseUrl}download2/${storageFolder}/${sessionId}/log.csv&${filename2}`; window.open(request2, '_blank'); } else{ - request2 = baseUrl + "download/" + 'log-' + sessionId + '.csv'; + request2 = `${baseUrl}download/${storageFolder}/${sessionId}/log.csv`; window.open(request2, '_blank'); } } diff --git a/templates/temp_index.html b/templates/temp_index.html index 9d37295..dacf60d 100644 --- a/templates/temp_index.html +++ b/templates/temp_index.html @@ -72,6 +72,9 @@
+ + +
@@ -455,6 +458,7 @@ document.getElementById("queueLimit").value = queueLimit; document.getElementById("AtkType").value = attackerType; document.getElementById("Amp").value = amplification; + document.getElementById("storageFolder").value = storageFolder; // Conditions to set for different checkboxes. if(DDDstate == "Yes" || DDDstate =="yes"){ @@ -553,7 +557,7 @@

Email


- + @@ -575,7 +579,7 @@ -
Copyright © Your Website 2020
+
Copyright © UConn CSEGroup22SDP, 2020-2021. All Rights Reserved.