Class EmulatorPacket

java.lang.Object
  extended byEmulatorPacket

public class EmulatorPacket
extends java.lang.Object

Packet used by emulated nodes to send data to each other via UDP


Field Summary
static int HEADER_SIZE
           
static int MAX_PACKET_SIZE
           
 
Constructor Summary
EmulatorPacket(int destAddr, int srcAddr, byte[] payload)
          Constructing a new packet
 
Method Summary
 int getDest()
          Get the address of the destination node
 byte[] getPayload()
          Get the payload
 int getSrc()
          Get the address of the source node
 byte[] pack()
          Convert packet into byte[] for sending over UDP Socket Format: destination address: 8 bits source address: 8 bits packet length: 8 bits payload: <= (MAX_PACKET_SIZE - HEADER_SIZE) bytes
 java.lang.String toString()
          Return a string representation of this packet
static EmulatorPacket unpack(byte[] packet)
          Unpacks a byte array to create a EmulatorPacket object Assumes the array has been formatted using pack method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEADER_SIZE

public static int HEADER_SIZE

MAX_PACKET_SIZE

public static int MAX_PACKET_SIZE
Constructor Detail

EmulatorPacket

public EmulatorPacket(int destAddr,
                      int srcAddr,
                      byte[] payload)
               throws java.lang.IllegalArgumentException
Constructing a new packet

Parameters:
destAddr - The fishnet address of the destination node
srcAddr - The fishnet address of the source node
payload - The payload of the packet
Throws:
java.lang.IllegalArgumentException - If the size of the payload is too big
Method Detail

getDest

public int getDest()
Get the address of the destination node

Returns:
The address of the destination node

getSrc

public int getSrc()
Get the address of the source node

Returns:
The address of the source node

getPayload

public byte[] getPayload()
Get the payload

Returns:
The payload

toString

public java.lang.String toString()
Return a string representation of this packet

Returns:
A string representation of this packet

pack

public byte[] pack()
Convert packet into byte[] for sending over UDP Socket Format: destination address: 8 bits source address: 8 bits packet length: 8 bits payload: <= (MAX_PACKET_SIZE - HEADER_SIZE) bytes

Returns:
A byte[] for sending over UDP

unpack

public static EmulatorPacket unpack(byte[] packet)
Unpacks a byte array to create a EmulatorPacket object Assumes the array has been formatted using pack method

Parameters:
packet - String representation of the packet
Returns:
EmulatorPacket object created or null if the byte[] representation was corrupted