Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Show all graphs
Added a button in the front-end to show all buttons at once.
Revised the back-end to generate all-in-one page.
Added a filter to prohibit malicious storage requests.
  • Loading branch information
yat17006 committed Mar 27, 2021
1 parent 8ac51c6 commit 64cc7f3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,9 +3,11 @@ __pycache__/
*.pyc

# Simulation Output
Graph.html
animationInstructions*.*
*.csv
*.svg

# Visual Studio
bin
Bin
Expand Down
11 changes: 10 additions & 1 deletion Python/filegenerator.py
Expand Up @@ -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):
Expand All @@ -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("<h2></h2>")
html_code = "{0}<h2>Session {1}</h2>{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):
Expand Down
52 changes: 35 additions & 17 deletions pserver.py
Expand Up @@ -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')

Expand All @@ -67,12 +70,13 @@ def runSimulation(input1):
@app.route('/download/<storageFolder>/<sessionId>/<fileName>') # 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:
Expand All @@ -87,19 +91,33 @@ 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:
abort(404)
else:
abort(400)

@app.route('/render_image/<storageFolder>/<sessionId>/<fileName>')
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
Expand Down
8 changes: 7 additions & 1 deletion static/js/requests.js
Expand Up @@ -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();
Expand Down Expand Up @@ -154,4 +160,4 @@ function downloadFile(){
window.open(request2, '_blank');
}
}
}
}
15 changes: 15 additions & 0 deletions templates/temp_graph.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Simulation Result Graphs</h1>
<h2></h2>
<p>This page renders all graphs of statistics of Simulation</p>
<img src="Sent.svg">
<img src="Received.svg">
<img src="Received on Average.svg">
<img src="Dropped.svg">
<img src="Dropped on Average.svg">
<p>Copyright (c) University of Connecticut, 2020-2021. All Rights Reserved.</p>
<p>This project is under the NCSA License.</p>
</body>
</html>
4 changes: 4 additions & 0 deletions templates/temp_index.html
Expand Up @@ -196,6 +196,10 @@
<p><button onclick="downloadFile()" class="btn btn-light btn-sm"><abbr title="Click here to download your files">Download</abbr></button></p>
</div>

<div style="float:right; padding-top: 40px; padding-right: 20px; display:true;" class = "grapher" id = "grapher">
<p><button onclick="showGraph()" class="btn btn-light btn-sm"><abbr title="Click here to show simulation graphs">Show Graphs</abbr></button></p>
</div>

<ul class="legend" id = "legend" >
<li><span class="green"></span><abbr title="In TCP, SYN packet is sent by client intended to connect to server">Syn Packets</abbr></li>
<li><span class="red"></span><abbr title="Dropped packet are lost in transmission">Drop Packets</abbr></li>
Expand Down

0 comments on commit 64cc7f3

Please sign in to comment.