Class Transport

java.lang.Object
  extended byTransport

public class Transport
extends java.lang.Object

   
 This conveys the header for reliable message transfer.
 This is carried in the payload of a Packet, and in turn the data being
 transferred is carried in the payload of the Transport packet.
 


Field Summary
static int ACK
           
static int DATA
           
static int FIN
           
static int HEADER_SIZE
           
static int MAX_PACKET_SIZE
           
static int MAX_PAYLOAD_SIZE
           
static int MAX_PORT_NUM
           
static int SYN
           
 
Constructor Summary
Transport(int srcPort, int destPort, int type, int window, int seqNum, byte[] payload)
          Constructing a new transport packet.
 
Method Summary
 int getDestPort()
           
 byte[] getPayload()
           
 int getSeqNum()
           
 int getSrcPort()
           
 int getType()
           
 int getWindow()
           
 byte[] pack()
          Convert the Transport packet object into a byte array for sending over the wire.
static Transport unpack(byte[] packet)
          Unpacks a byte array to create a Transport object Assumes the array has been formatted using pack method in Transport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PACKET_SIZE

public static final int MAX_PACKET_SIZE
See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
See Also:
Constant Field Values

MAX_PAYLOAD_SIZE

public static final int MAX_PAYLOAD_SIZE
See Also:
Constant Field Values

MAX_PORT_NUM

public static final int MAX_PORT_NUM
See Also:
Constant Field Values

SYN

public static final int SYN
See Also:
Constant Field Values

ACK

public static final int ACK
See Also:
Constant Field Values

FIN

public static final int FIN
See Also:
Constant Field Values

DATA

public static final int DATA
See Also:
Constant Field Values
Constructor Detail

Transport

public Transport(int srcPort,
                 int destPort,
                 int type,
                 int window,
                 int seqNum,
                 byte[] payload)
          throws java.lang.IllegalArgumentException
Constructing a new transport packet.

Parameters:
srcPort - The source port
destPort - The destination port
type - The type of packet. Either SYN, ACK, FIN, or DATA
window - The window size
seqNum - The sequence number of the packet
payload - The payload of the packet.
Method Detail

getSrcPort

public int getSrcPort()
Returns:
The source port

getDestPort

public int getDestPort()
Returns:
The destination port

getType

public int getType()
Returns:
The type of the packet

getWindow

public int getWindow()
Returns:
The window size

getSeqNum

public int getSeqNum()
Returns:
The sequence number

getPayload

public byte[] getPayload()
Returns:
The payload

pack

public byte[] pack()
Convert the Transport packet object into a byte array for sending over the wire. Format: source port = 1 byte destination port = 1 byte type = 1 byte window size = 4 bytes sequence number = 4 bytes packet length = 1 byte payload <= MAX_PAYLOAD_SIZE bytes

Returns:
A byte[] for transporting over the wire. Null if failed to pack for some reason

unpack

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

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