Skip to content

Commit

Permalink
Add port filter functionality to router
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinna Adhikari committed Dec 6, 2020
1 parent 393a44b commit cbc4859
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ <h2 class="text-white mb-4">DDD Filter applications in the Network</h2>

<!--THIS IS THE SIDEBAR. I ALSO ADDED THE BUTTONS TO IT AS WELL-->
<div id="mySidebar" class="sidebar">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<form style="float:left; padding-top: 30px; padding-left: 30px;"">
<label>Number of Packets:</label><br>
<input type="number" id="npackets" name="npackets" value=3><br>
Expand Down
6 changes: 3 additions & 3 deletions js/ddd.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class DDD extends Entity {

// Bind methods
this.sendPackets = this.sendPackets.bind(this);
this.passFilter = this.passFilter.bind(this);
this.passPortFilter = this.passPortFilter.bind(this);
this.openNewPorts = this.openNewPorts.bind(this);

}
Expand Down Expand Up @@ -41,7 +41,7 @@ export class DDD extends Entity {
return newOpenPorts;
}

passFilter(packet) {
passPortFilter(packet) {
return this.openPorts.includes(packet.dstPort);
}

Expand All @@ -56,7 +56,7 @@ export class DDD extends Entity {
for (let i = 0; i < this.packetsPerTimeUnit; ++i) {
let packet = this.dequeue();
if (packet) {
if (!this.passFilter(packet)) {
if (!this.passPortFilter(packet)) {
packet.dropped = true;
this.garbage.enqueue(packet);
}
Expand Down
27 changes: 26 additions & 1 deletion js/router.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import { Entity } from './entity.js';
import { DDD } from './ddd.js';

export class Router extends Entity{
constructor(x, y, nextEntity, packetsPerTimeUnit, queue=[]) {
super('images/router.png', 'Router', x, y, 100, 100, nextEntity, packetsPerTimeUnit, queue);
this.openPorts = []

// Bind methods
}

sendPackets(dstEntity = undefined) {
// Send packet from srcEntity to dstEntity. If dstEntity undefined, then send to nextEntity
if (!dstEntity) {
dstEntity = this.nextEntity;
}

// Send packetsPerTimeUnit packets from current entity to dstEntity
let sentPackets = [];
for (let i = 0; i < this.packetsPerTimeUnit; ++i) {
let packet = this.dequeue();
if (packet) {
if (this.nextEntity instanceof DDD && !this.nextEntity.passPortFilter(packet)) {
packet.dropped = true;
this.nextEntity.garbage.enqueue(packet);
}
else {
packet.nextEntity = dstEntity; // Used for packet animation
dstEntity.enqueue(packet);
}
sentPackets.push(packet);
}
}
return sentPackets;
}
}

0 comments on commit cbc4859

Please sign in to comment.