Class Transport
java.lang.Object
Transport
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.
Constructor Summary |
Transport(int srcPort,
int destPort,
int type,
int window,
int seqNum,
byte[] payload)
Constructing a new transport packet. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
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 portdestPort
- The destination porttype
- The type of packet. Either SYN, ACK, FIN, or DATAwindow
- The window sizeseqNum
- The sequence number of the packetpayload
- The payload of the packet.
- Throws:
java.lang.IllegalArgumentException
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