Skip to content

Commit

Permalink
Add ddd open port nums and num dropped packets to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinna Adhikari committed Dec 6, 2020
1 parent 6fd5c52 commit 3484473
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ <h2 class="text-white mb-4">DDD Filter applications in the Network</h2>
<p><button onclick="startSimulation()" class="btn btn-light btn-sm">Start Simulation</button></p>
<p><button onclick="stopSimulation()" class="btn btn-light btn-sm">Stop Simulation</button></p>
</div>

<div style="float:left; padding-top: 40px; padding-left: 20px;">
<p><button onclick="pauseSimulation()" class="btn btn-light btn-sm">Pause Simulation</button></p>
<p><button onclick="resumeSimulation()" class="btn btn-light btn-sm">Resume Simulation</button></p>
</div>

<div style="float:left; padding-top: 40px; padding-left: 30px;">
<p id="openPorts" style="color: white; text-align: left;"></p>
<p id="droppedPackets" style="color: white; text-align: left;"></p>
</div>


</div>


<div id="main">
<button class="openbtn" onclick="openNav()"></button>
</div>
Expand Down
16 changes: 16 additions & 0 deletions js/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ function allEmpty(entities) {
return true;
}

// dashboard functions

function dashboardOpenPorts(ddd){
document.getElementById("openPorts").textContent = "DDD Open Ports: " + ddd.openPorts;
}
function dashboardDroppedPackets(garbage){
document.getElementById("droppedPackets").textContent = "Dropped Packets: " + garbage.droppedPackets;
}


//Stop simulation
var stop = false;
window.stopSimulation = stopSimulation;
Expand Down Expand Up @@ -198,6 +208,12 @@ async function startSimulation() {
}
}

// Update dashboard
if(ddd){
dashboardOpenPorts(ddd);
}
dashboardDroppedPackets(garbage);

// Animate the packets moving through the system
await animatePacket(packets, allEntities);

Expand Down
3 changes: 3 additions & 0 deletions js/garbage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Entity } from './entity.js';
export class Garbage extends Entity {
constructor(x, y, nextEntity, packetsPerTimeUnit, queue = []) {
super('images/Trash.jpg', 'Garbage', x, y, 150, 100, nextEntity, packetsPerTimeUnit, queue);
this.droppedPackets = 0;

// Bind methods
//this.fillPossibleMoves = this.fillPossibleMoves.bind(this);
Expand All @@ -14,10 +15,12 @@ export class Garbage extends Entity {
dstEntity = this.nextEntity;
}


// Send packetsPerTimeUnit packets from current entity to dstEntity
for (let i = 0; i < this.packetsPerTimeUnit; ++i) {
let packet = this.dequeue();
if (packet) {
this.droppedPackets++;
console.log(packet);
packet.nextEntity = dstEntity; // Used for packet animation
packet.dropped = false;
Expand Down

0 comments on commit 3484473

Please sign in to comment.