Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions src/programs/echo_sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/programs/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 6 additions & 9 deletions src/types/network-modules/tcp/tcpState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/types/view-devices/vDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export enum DeviceType {
export interface NetworkInterface {
name: string;
mac: MacAddress;
// TODO: add IP address
ip?: IpAddress;
}

Expand Down
13 changes: 9 additions & 4 deletions src/types/view-devices/vNetworkDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ interface ForwardingData {
ip: IpAddress;
mac: MacAddress;
};
nextHop: {
ip: IpAddress;
mac: MacAddress;
};
sendingIface: number;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 dont 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)) {
Expand Down
Loading