Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/types/view-devices/vRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,28 @@ export class ViewRouter extends ViewNetworkDevice {

addPacketToQueue(datagram: IPv4Packet) {
const wasEmpty = this.packetQueue.isEmpty();
datagram.timeToLive -= 1;
if (datagram.timeToLive <= 0) {
console.debug(`Device ${this.id} dropped packet with TTL 0`);
this.dropPacket(datagram);
}
if (!this.packetQueue.enqueue(datagram)) {
console.debug("Packet queue full, dropping packet");
// dummy values
const dummyMac = this.interfaces[0].mac;
const frame = new EthernetFrame(dummyMac, dummyMac, datagram);
dropPacket(this.viewgraph, this.id, frame);
this.dropPacket(datagram);
return;
}
if (wasEmpty) {
this.startPacketProcessor();
}
}

dropPacket(datagram: IPv4Packet) {
// dummy values
const dummyMac = this.interfaces[0].mac;
const frame = new EthernetFrame(dummyMac, dummyMac, datagram);
dropPacket(this.viewgraph, this.id, frame);
}

processPacket(ticker: Ticker) {
const elapsedTime = ticker.deltaMS * this.viewgraph.getSpeed();
const datagram = this.getPacketsToProcess(elapsedTime);
Expand Down Expand Up @@ -239,7 +248,7 @@ export class ViewRouter extends ViewNetworkDevice {

routePacket(datagram: IPv4Packet): number {
console.debug(
`Device ${this.id} va a rutear el datagram con origen ${datagram.sourceAddress.toString()} y destino ${datagram.destinationAddress.toString()}`,
`Device ${this.id} will route datagram of origin ${datagram.sourceAddress.toString()} and destination ${datagram.destinationAddress.toString()}`,
);
const device = this.viewgraph.getDataGraph().getDevice(this.id);
if (!device || !(device instanceof DataRouter)) {
Expand Down