Class NetworkLink

  extended by nachos.machine.NetworkLink

public class NetworkLink
extends Object

A full-duplex network link. Provides ordered, unreliable delivery of limited-size packets to other machines on the network. Packets are guaranteed to be uncorrupted as well.

Recall the general layering of network protocols:

The physical layer provides a bit stream interface to the link layer. This layer is very hardware-dependent.

The link layer uses the physical layer to provide a packet interface to the network layer. The link layer generally provides unreliable delivery of limited-size packets, but guarantees that packets will not arrive out of order. Some links protect against packet corruption as well. The ethernet protocol is an example of a link layer.

The network layer exists to connect multiple networks together into an internet. The network layer provides globally unique addresses. Routers (a.k.a. gateways) move packets across networks at this layer. The network layer provides unordered, unreliable delivery of limited-size uncorrupted packets to any machine on the same internet. The most commonly used network layer protocol is IP (Internet Protocol), which is used to connect the Internet.

The session/transport layer provides a byte-stream interface to the application. This means that the transport layer must deliver uncorrupted bytes to the application, in the same order they were sent. Byte-streams must be connected and disconnected, and exist between ports, not machines.

This class provides a link layer abstraction. Since we do not allow different Nachos networks to communicate with one another, there is no need for a network layer in Nachos. This should simplify your design for the session/transport layer, since you can assume packets never arrive out of order.

Field Summary
static byte networkID
          The address of the network to which are attached all network links in this JVM.
Constructor Summary
NetworkLink(Privilege privilege)
          Allocate a new network link.
Method Summary
 int getLinkAddress()
          Returns the address of this network link.
 Packet receive()
          Return the next packet received.
 void send(Packet pkt)
          Send another packet.
 void setInterruptHandlers(Runnable receiveInterruptHandler, Runnable sendInterruptHandler)
          Set this link's receive and send interrupt handlers.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final byte networkID
The address of the network to which are attached all network links in this JVM. This is a hash on the account name of the JVM running this Nachos instance. It is used to help prevent packets from other users from accidentally interfering with this network.

Constructor Detail


public NetworkLink(Privilege privilege)
Allocate a new network link.

nachos.conf specifies the reliability of the network. The reliability, between 0 and 1, is the probability that any particular packet will not get dropped by the network.

privilege - encapsulates privileged access to the Nachos machine.
Method Detail


public int getLinkAddress()
Returns the address of this network link.

the address of this network link.


public void setInterruptHandlers(Runnable receiveInterruptHandler,
                                 Runnable sendInterruptHandler)
Set this link's receive and send interrupt handlers.

The receive interrupt handler is called every time a packet arrives and can be read using receive().

The send interrupt handler is called every time a packet sent with send() is finished being sent. This means that another packet can be sent.

receiveInterruptHandler - the callback to call when a packet arrives.
sendInterruptHandler - the callback to call when another packet can be sent.


public Packet receive()
Return the next packet received.

the next packet received, or null if no packet is available.


public void send(Packet pkt)
Send another packet. If a packet is already being sent, the result is not defined.

pkt - the packet to send.