Skip to content
Merged
4 changes: 2 additions & 2 deletions src/programs/echo_sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ export class SingleEcho extends ProgramBase {

// Resolve destination MAC address
const dstMac = srcDevice.resolveAddress(dst.ip);
if (!dstMac) {
if (!dstMac || !dstMac.mac) {
console.debug(
`Device ${this.srcId} couldn't resolve MAC address for device with IP ${dst.ip.toString()}. Program cancelled`,
);
return;
}

// Wrap in Ethernet frame
const ethernetFrame = new EthernetFrame(src.mac, dst.mac, ipPacket);
const ethernetFrame = new EthernetFrame(src.mac, dstMac.mac, ipPacket);
sendViewPacket(this.viewgraph, this.srcId, ethernetFrame, sendingIface);
}

Expand Down
11 changes: 8 additions & 3 deletions src/types/data-devices/dNetworkDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export abstract class DataNetworkDevice extends DataDevice {
): { mac: MacAddress; edited: boolean } | undefined {
const entry = this.arpTable.get(ip.toString());
if (!entry) {
// Buscar el dispositivo y la MAC real si no está en la tabla
// Search for the device and the real MAC if it is not in the table
const device = this.datagraph.getDeviceByIP(ip);
if (!device) {
console.warn(`Device with ip ${ip.toString()} not found in DataGraph`);
Expand All @@ -62,8 +62,13 @@ export abstract class DataNetworkDevice extends DataDevice {
const iface = device.interfaces.find((iface) => iface.ip?.equals(ip));
return iface ? { mac: iface.mac, edited: false } : undefined;
}
// Si la entrada existe pero la MAC es "", se considera eliminada
if (entry.mac === "") return undefined;
// If the entry exists but the MAC is "", it is considered deleted
if (entry.mac === "") {
console.debug(
`Interface ${ip.toString()} from device ${this.id} is deleted`,
);
return undefined;
}
return { mac: MacAddress.parse(entry.mac), edited: entry.edited };
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/network-modules/tables/arp_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function removeArpTableEntry(
): void {
const device = dataGraph.getDevice(deviceId);
if (!device || !(device instanceof DataNetworkDevice)) {
console.warn(`Device with ID ${deviceId} is not a network device.`);
console.error(`Network Device with ID ${deviceId} not found.`);
return;
}
device.arpTable.add({ ip, mac: "", edited: false });
Expand Down
13 changes: 2 additions & 11 deletions src/types/view-devices/vNetworkDevice.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Texture } from "pixi.js";
import {
ICMP_PROTOCOL_NUMBER,
IpAddress,
IPv4Packet,
TCP_PROTOCOL_NUMBER,
} from "../../packets/ip";
import { ICMP_PROTOCOL_NUMBER, IpAddress, IPv4Packet } from "../../packets/ip";
import { DeviceId, NetworkInterfaceData } from "../graphs/datagraph";
import { ViewDevice } from "./vDevice";
import { ViewGraph } from "../graphs/viewgraph";
Expand Down Expand Up @@ -169,7 +164,7 @@ export abstract class ViewNetworkDevice extends ViewDevice {
const dstDevice = this.viewgraph.getDeviceByIP(datagram.sourceAddress);
if (!(dstDevice instanceof ViewNetworkDevice)) {
console.warn(
`Device with IP ${datagram.sourceAddress.toString} was not found or was not a Network Device`,
`Network Device with IP ${datagram.sourceAddress.toString()} was not found.`,
);
return;
}
Expand All @@ -192,10 +187,6 @@ export abstract class ViewNetworkDevice extends ViewDevice {
}
break;
}
case TCP_PROTOCOL_NUMBER: {
// For the moment
return;
}
default:
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/types/view-devices/vSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { Texture } from "pixi.js";
import { EthernetFrame, MacAddress } from "../../packets/ethernet";
import { GlobalContext } from "../../context";
import { sendViewPacket } from "../packet";
import { dropPacket, sendViewPacket } from "../packet";

Check failure on line 15 in src/types/view-devices/vSwitch.ts

View workflow job for this annotation

GitHub Actions / lint

'dropPacket' is defined but never used
import { DataSwitch } from "../data-devices";
import { DeviceInfo } from "../../graphics/renderables/device_info";
import { ArpRequest } from "../../packets/arp";
Expand Down Expand Up @@ -87,7 +87,7 @@
sendingIface: number,
iface: number,
) {
if (sendingIface === iface) {
if (sendingIface === iface || sendingIface >= this.interfaces.length) {
// Packet would be sent to the interface where it came, discard it
return;
}
Expand All @@ -103,6 +103,8 @@
}

receiveFrame(frame: EthernetFrame, iface: number): void {
// Update the forwarding table with the source MAC address
this.updateForwardingTable(frame.source, iface);
if (frame.payload instanceof ArpRequest) {
const { sha, spa, tha, tpa } = frame.payload;
this.interfaces.forEach((sendingIface, idx) => {
Expand All @@ -116,8 +118,6 @@
});
return;
}
// Update the forwarding table with the source MAC address
this.updateForwardingTable(frame.source, iface);

// If the destination MAC address is in the forwarding table, send the frame
// to the corresponding device
Expand Down
Loading