diff --git a/src/programs/echo_sender.ts b/src/programs/echo_sender.ts index 65943d94..0235a945 100644 --- a/src/programs/echo_sender.ts +++ b/src/programs/echo_sender.ts @@ -59,6 +59,7 @@ export class SingleEcho extends ProgramBase { ); let src: { ip: IpAddress; mac: MacAddress }, dst: { ip: IpAddress; mac: MacAddress }, + nextHop: { ip: IpAddress; mac: MacAddress }, sendingIface: number; if (!forwardingData) { console.warn( @@ -74,23 +75,23 @@ export class SingleEcho extends ProgramBase { }; sendingIface = 0; } else { - ({ src, dst, sendingIface } = forwardingData); + ({ src, dst, nextHop, sendingIface } = forwardingData); } const echoRequest = new EchoRequest(0); // Wrap in IP datagram const ipPacket = new IPv4Packet(src.ip, dst.ip, echoRequest); // Resolve destination MAC address - const dstMac = srcDevice.resolveAddress(dst.ip); - if (!dstMac) { + const nextHopMac = srcDevice.resolveAddress(nextHop.ip); + if (!nextHopMac) { console.debug( - `Device ${this.srcId} couldn't resolve MAC address for device with IP ${dst.ip.toString()}. Program cancelled`, + `Device ${this.srcId} couldn't resolve MAC address for device with IP ${nextHop.ip.toString()}. Program cancelled`, ); return; } // Wrap in Ethernet frame - const ethernetFrame = new EthernetFrame(src.mac, dst.mac, ipPacket); + const ethernetFrame = new EthernetFrame(src.mac, nextHopMac.mac, ipPacket); sendViewPacket(this.viewgraph, this.srcId, ethernetFrame, sendingIface); } diff --git a/src/programs/http_client.ts b/src/programs/http_client.ts index f72668ef..6fda7a0f 100644 --- a/src/programs/http_client.ts +++ b/src/programs/http_client.ts @@ -90,7 +90,8 @@ export class HttpClient extends ProgramBase { // Write request const socket = await this.runner.tcpConnect(this.dstId); if (!socket) { - console.warn("HttpClient failed to connect"); + console.error("HttpClient failed to connect"); + showError("Failed to connect to HTTP server. Make sure the forwarding table is set up correctly."); return; } if (this.stopped) { diff --git a/src/types/network-modules/tcp/tcpState.ts b/src/types/network-modules/tcp/tcpState.ts index 22976d7f..d8a85bbd 100644 --- a/src/types/network-modules/tcp/tcpState.ts +++ b/src/types/network-modules/tcp/tcpState.ts @@ -57,23 +57,20 @@ function sendIpPacket( console.warn(`Device ${dst.id} is not reachable from device ${src.id}`); return false; } - const [srcData, dstData, sendingIface] = [ - forwardingData.src, - forwardingData.dst, - forwardingData.sendingIface, - ]; + const [srcData, dstData] = [forwardingData.src, forwardingData.dst]; + const {nextHop, sendingIface} = forwardingData; // Resolve destination MAC address - const dstMac = src.resolveAddress(dstData.ip); - if (!dstMac) { + const nextHopMac = src.resolveAddress(nextHop.ip); + if (!nextHopMac) { console.warn( - `Device ${src.id} couldn't resolve MAC address for device with IP ${dstData.ip.toString()}. Program cancelled`, + `Device ${src.id} couldn't resolve MAC address for device with IP ${nextHop.ip.toString()}. Program cancelled`, ); return false; } const ipPacket = new IPv4Packet(srcData.ip, dstData.ip, payload); - const frame = new EthernetFrame(srcData.mac, dstData.mac, ipPacket); + const frame = new EthernetFrame(srcData.mac, nextHopMac.mac, ipPacket); sendViewPacket(src.viewgraph, src.id, frame, sendingIface); return true; diff --git a/src/types/view-devices/vDevice.ts b/src/types/view-devices/vDevice.ts index d0610363..e875c164 100644 --- a/src/types/view-devices/vDevice.ts +++ b/src/types/view-devices/vDevice.ts @@ -45,7 +45,6 @@ export enum DeviceType { export interface NetworkInterface { name: string; mac: MacAddress; - // TODO: add IP address ip?: IpAddress; } diff --git a/src/types/view-devices/vNetworkDevice.ts b/src/types/view-devices/vNetworkDevice.ts index 18ae51f4..974c9c60 100644 --- a/src/types/view-devices/vNetworkDevice.ts +++ b/src/types/view-devices/vNetworkDevice.ts @@ -35,6 +35,10 @@ interface ForwardingData { ip: IpAddress; mac: MacAddress; }; + nextHop: { + ip: IpAddress; + mac: MacAddress; + }; sendingIface: number; } @@ -84,20 +88,21 @@ export abstract class ViewNetworkDevice extends ViewDevice { const dstDevice = viewgraph.getDevice(dstId); const dstIface = dstDevice.interfaces[receivingIface]; // Get dstMac - let dstMac: MacAddress = dstIface.mac; + let nextHop = dstIface; for (const idx of path.slice(1).keys()) { const [sendingId, receivingId] = [path[idx], path[idx + 1]]; const receivingDevice = viewgraph.getDevice(receivingId); if (receivingDevice instanceof ViewNetworkDevice) { const edge = viewgraph.getEdge(sendingId, receivingId); const receivingIface = edge.getDeviceInterface(receivingId); - dstMac = receivingDevice.interfaces[receivingIface].mac; + nextHop = receivingDevice.interfaces[receivingIface]; break; } } const forwardingData = { src: { mac: srcIface.mac, ip: srcIface.ip }, - dst: { mac: dstMac, ip: dstIface.ip }, + dst: { mac: dstIface.mac, ip: dstIface.ip }, + nextHop: { mac: nextHop.mac, ip: nextHop.ip }, sendingIface, }; return forwardingData; @@ -204,7 +209,7 @@ export abstract class ViewNetworkDevice extends ViewDevice { const { sha, spa, tha, tpa } = packet; const { mac, ip } = this.interfaces[iface]; if (packet.op === ARP_REQUEST_CODE) { - // NOTE: We don’t take into account htype, ptype, hlen and plen, + // NOTE: We don't take into account htype, ptype, hlen and plen, // as they always will be MAC Address and IP address // Check if tpa is device ip if (!tpa.equals(ip)) {