-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add port filter functionality to router
- Loading branch information
Abhinna Adhikari
committed
Dec 6, 2020
1 parent
393a44b
commit cbc4859
Showing
3 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|