nachos.machine
Class Network

java.lang.Object
  extended by nachos.machine.Network

public class Network
extends java.lang.Object

Network that provides ordered, reliable delivery of limited-size packets to other machines on the nachos network. Reliable means that packets are not lost or corrupted. IMPORTANT: All of the processes corresponding to nachos machines on a single nachos network must run on the same actual host (computer). The nachos network is implemented using UDP, so in principle it is unreliable. In practice, UDP is very reliable when the communicating processes run on the same host, provided we don't flood it with large bursts of messages that cause it to run out of buffers.


Field Summary
static byte networkID
          The address of the network.
 
Constructor Summary
Network(byte id, InterruptHandler readAvail, InterruptHandler writeDone)
          Create a new nachos network.
 
Method Summary
 Packet receive()
          Return the next packet received.
 void send(Packet p)
          Send another packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

networkID

public static final byte networkID
The address of the network. It is computed from portBase. It is used internally by the network class to detect whether a packet intended for another nachos network was accidentally received by this nachos network, due to a collision in the choice of port numbers. The detection is done in Packet.java.

Constructor Detail

Network

public Network(byte id,
               InterruptHandler readAvail,
               InterruptHandler writeDone)
Create a new nachos network.

Parameters:
id - network address of this machine
readAvail - is the interrupt handler called when a packet arrives from the network
writeDone - is the interrupt handler called when a send is completed, indicating that it is safe to send the next packet
Method Detail

receive

public Packet receive()
Return the next packet received.

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

send

public void send(Packet p)
Send another packet. If a packet is already being sent, an error occurs.

Parameters:
p - the packet to send.