diff --git a/.gitignore b/.gitignore index 317ada2..67d388b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,11 @@ __pycache__/ *.pyc # Simulation Output +Graph.html animationInstructions*.* *.csv *.svg + # Visual Studio bin Bin diff --git a/Python/filegenerator.py b/Python/filegenerator.py index 73878b0..b7ac903 100644 --- a/Python/filegenerator.py +++ b/Python/filegenerator.py @@ -508,6 +508,7 @@ class filegenerator: self.genPlot("Dropped", 3) self.genPlot("Dropped on Average", 4) self.genPlot("Received on Average", 5) + self.genPlotPage() if (self.makeLog): # self.packetDictionary["Inputs: "] = ["DDD State " + str(self.dddState), "Send Rate: " + str("self.sendRate") + " MB/s", "Packet Size: " + str(self.packetSize) + " MB", "Resend Time for SYN-ACKs: " + str(self.resendSynAckTime) + " ms", "Max Queue Size for half open connections: " + str(self.MaxQueueSize) + '" MB"', "DDD Mapping Delay" + str(self.dddMappingDelay) + " ms", "Propagation Delay: " + str(self.PropDelay) + " ms", "Number of DDD ports open: " + str(self.NumbDDDPortsOpen), "Bandwidth of connections: " + str("N/A") + " MB/s", "Time until next DDD port change: " + str(self.timeUntilNextDDDChange) + " ms", "Overlap time for old DDD Ports: " + str(self.overlapTime) + " ms", " ", "Program Version 2", "Date and time: " + str(getTime("%c"))] # if (len(self.packetDictionary[ "Inputs: "]) > self.lengthLongestEntry): @@ -524,7 +525,15 @@ class filegenerator: outputLogFile.close() - + def genPlotPage(self): + fp = open(os.path.join("templates", "temp_graph.html"),"rt") + html_code = fp.read() + fp.close() + fp = open(os.path.join(self.storageFolder, "Graph.html"),"w") + code_part = html_code.split("

") + html_code = "{0}

Session {1}

{2}".format(code_part[0], str(self.sessionId), code_part[1]) + fp.write(html_code) + fp.close() def sortHelper(self, string): if ("Input" in string) or ("Program" in string): diff --git a/pserver.py b/pserver.py index f6632af..80ddb3f 100644 --- a/pserver.py +++ b/pserver.py @@ -44,17 +44,20 @@ def runSimulation(input1): attackerType = float(Param[22]) amplification = float(Param[23]) storageFolder = Param[24] - - response = main.runSimulation(ddd_state, skip_sim, sumOut, - logOut, packet_size, rtsa, - max_queue_size, ddd_mapping_delay, - propagation_delay, number_of_ddd_ports, - time_to_next_ddd_port, overlap_time_old_ddd, - durationSim, numbSynAckResends, clienttoRouter, - routertoClient, routertoReflector, routertoNormal, - normaltoRouter, reflectortoRouter, - attackertoReflector, queueLimit, attackerType, - amplification, storageFolder) + + if storageFolder=="Python" or storageFolder=="static" or storageFolder=="templates": + abort(400) # NEVER ALLOW FILES TO BE GENERATED IN CODE FOLDERS! + else: + response = main.runSimulation(ddd_state, skip_sim, sumOut, + logOut, packet_size, rtsa, + max_queue_size, ddd_mapping_delay, + propagation_delay, number_of_ddd_ports, + time_to_next_ddd_port, overlap_time_old_ddd, + durationSim, numbSynAckResends, clienttoRouter, + routertoClient, routertoReflector, routertoNormal, + normaltoRouter, reflectortoRouter, + attackertoReflector, queueLimit, attackerType, + amplification, storageFolder) print('Backend Simulation Total Elapsed Time:', time.time() - start_time, 'seconds') @@ -67,12 +70,13 @@ def runSimulation(input1): @app.route('/download///') # This is the endpoint that the javascript code will call to run simulation on server def download(storageFolder, sessionId, fileName): try: + filePath = os.path.join(storageFolder, sessionId, fileName) if fileName.startswith("log"): - return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) + return send_file(filePath, as_attachment=True) elif fileName.startswith("summary"): - return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) + return send_file(filePath, as_attachment=True) elif fileName.endswith(".svg"): - return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True) + return send_file(filePath, as_attachment=True) else: abort(400) except FileNotFoundError: @@ -87,12 +91,13 @@ def download2(storageFolder, sessionId, statement): newName = tmp[1] if len(tmp)==2: try: + filePath = os.path.join(storageFolder, sessionId, fileName) if fileName.startswith("log"): - return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True, attachment_filename=newName) + return send_file(filePath, as_attachment=True, attachment_filename=newName) elif fileName.startswith("summary"): - return send_file(os.path.join(storageFolder, sessionId, fileName), as_attachment=True, attachment_filename=newName) + return send_file(filePath, 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) + return send_file(filePath, as_attachment=True, attachment_filename=newName) else: abort(400) except FileNotFoundError: @@ -100,6 +105,19 @@ def download2(storageFolder, sessionId, statement): else: abort(400) +@app.route('/render_image///') +def render_image(storageFolder, sessionId, fileName): + try: + filePath = os.path.join(storageFolder, sessionId, fileName) + if fileName.endswith(".svg"): + return send_file(filePath) + elif fileName.endswith(".html"): + return send_file(filePath) + else: + abort(400) + except FileNotFoundError: + abort(404) + @app.route('/') def index(): return render_template('temp_index.html') # This renders index.html as the starting screen diff --git a/static/js/requests.js b/static/js/requests.js index 546de71..bbafc03 100644 --- a/static/js/requests.js +++ b/static/js/requests.js @@ -121,6 +121,12 @@ function downloadFiles(){ } } +window.showGraph = showGraph; +function showGraph(){ + var request_string = `${baseUrl}render_image/${storageFolder}/${sessionId}/Graph.html`; + window.open(request_string, "_blank"); +} + window.downloadFile = downloadFile; function downloadFile(){ downloadFiles(); @@ -154,4 +160,4 @@ function downloadFile(){ window.open(request2, '_blank'); } } -} +} \ No newline at end of file diff --git a/templates/temp_graph.html b/templates/temp_graph.html new file mode 100644 index 0000000..e2df108 --- /dev/null +++ b/templates/temp_graph.html @@ -0,0 +1,15 @@ + + + +

Simulation Result Graphs

+

+

This page renders all graphs of statistics of Simulation

+ + + + + +

Copyright (c) University of Connecticut, 2020-2021. All Rights Reserved.

+

This project is under the NCSA License.

+ + \ No newline at end of file diff --git a/templates/temp_index.html b/templates/temp_index.html index dacf60d..9c43414 100644 --- a/templates/temp_index.html +++ b/templates/temp_index.html @@ -196,6 +196,10 @@

+
+

+
+
  • Syn Packets
  • Drop Packets