nachos.machine
Class Packet

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

public class Packet
extends java.lang.Object

A link-layer packet.

See Also:
Network

Field Summary
 byte[] contents
          The contents of this packet, excluding the header.
 int dst
          The address of the destination of this packet.
static int headerLength
          The number of bytes in a packet header.
static int maxContentsLength
          The maximum number of content bytes (not including the header).
static int maxNumMach
          Upper limit on the number of machines.
static int maxPacketLength
          The maximum length, in bytes, of a packet that can be sent or received on the network.
 byte[] packetBytes
          This packet, as an array of bytes that can be sent on a network.
 int src
          The address of the source of this packet.
 
Constructor Summary
Packet(byte[] packetBytes)
          Allocate a new packet using the specified array of bytes received from the network.
Packet(int dst, int src, byte[] contents)
          Allocate a new packet to be sent, using the specified parameters.
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packetBytes

public byte[] packetBytes
This packet, as an array of bytes that can be sent on a network.


dst

public int dst
The address of the destination of this packet.


src

public int src
The address of the source of this packet.


contents

public byte[] contents
The contents of this packet, excluding the header.


headerLength

public static final int headerLength
The number of bytes in a packet header. The header is formatted as follows (offset and size are measured in bytes):
offsetsizevalue
01network ID (for collision detection)
11destination address
21source address
31length of contents

See Also:
Constant Field Values

maxPacketLength

public static final int maxPacketLength
The maximum length, in bytes, of a packet that can be sent or received on the network.

See Also:
Constant Field Values

maxContentsLength

public static final int maxContentsLength
The maximum number of content bytes (not including the header). Note that this is just maxPacketLength - headerLength.

See Also:
Constant Field Values

maxNumMach

public static final int maxNumMach
Upper limit on the number of machines. All machine ids are between 0 and maxNumMach - 1. We require maxNumMach <= Byte.MAX_VALUE.

See Also:
Constant Field Values
Constructor Detail

Packet

public Packet(int dst,
              int src,
              byte[] contents)
       throws MalformedPacketException
Allocate a new packet to be sent, using the specified parameters.

Parameters:
dst - the destination machine.
src - the source machine.
contents - the contents of the packet.
Throws:
MalformedPacketException

Packet

public Packet(byte[] packetBytes)
       throws MalformedPacketException
Allocate a new packet using the specified array of bytes received from the network.

Parameters:
packetBytes - the bytes making up this packet.
Throws:
MalformedPacketException