3.6 Network link

Separate Nachos instances running on the same real-life machine can communicate with each other over a network, using the NetworkLink class. An instance of this class is returned by Machine.networkLink().

The network link’s interface is similar to the serial console’s interface, except that instead of receiving and sending bytes at a time, the network link receives and sends packets at a time. Packets are instances of the Packet class.

Each network link has a link address, a number that uniquely identifies the link on the network. The link address is returned by getLinkAddress().

A packet consists of a header and some data bytes. The header specifies the link address of the machine sending the packet (the source link address), the link address of the machine to which the packet is being sent (the destination link address), and the number of bytes of data contained in the packet. The data bytes are not analyzed by the network hardware, while the header is. When a link transmits a packet, it transmits it only to the link specified in the destination link address field of the header. Note that the source address can be forged.

The remainder of the interface to NetworkLink is equivalent to that of SerialConsole. The kernel can check for a packet by calling receive(), which returns null if no packet is available. Whenever a packet arrives, a receive interrupt is generated. The kernel can send a packet by calling send(), but it must wait for a send interrupt before attempting to send another packet.