Not Quite TCP: Reliable Communication

In this assignment you will implement a sender for a TCP-like protocol called NQTCP. A receiver is provided that intentionally loses packet and acknowledgements, but otherwise implements the reliable protocol. The underlying protocol is UDP. A framework for the sender is provided that manages the user input and multi-threading concerns.

NQTCP Protocol

Message format

NQTCP messages consist of an 8 byte header followed by data of up to 10 bytes. Note the value of packet length can be much bigger, but you will only be sending up to 10 at a time.

Numbers are stored in Big-Endian format meaning the high order byte of the number is first. For example, if the sequnce number is 522 (0x020A in hex) then the value at data[0] is 2 (0x02) and the value in data[1] is 10 (0x0A).

Header Bytes Data Bytes
0..1 2..3 4..5 6..7 8..17
Sequence Number Acknowledgement Number Packet Length in bytes (including the header) Unused Data (optional)

Like TCP, the sequence number represents the location in the data stream for the data carried in the packet. The acknowledgement number indicates the next expected sequence number we will receive from the other end of the communication. Unlike TCP both values start at 1.

Since only the sender will be sending data, the acknowledgement numbers of the packets you send and the sequence numbers of the packets you receive will be 1.

Receiver

The following table lists the events related to the program receiving data and the actions the receiver takes when the events occur.

EventActions
Segment received with expected sequence number. No out-of-order packets or delayed ACKs.
  1. Create an ACK.
  2. Delay 500 ms before sending it.
  3. Update the expected sequence number.
Segment received with expected sequence number and one delayed ACK.
  1. Send one cumulative ACK that covers both this packet and the delayed ACK.
  2. Stop timer for the delayed ACK.
  3. Update the expected sequence number.
Segment received with expected sequence number and there are waiting out-of-order packets.
  1. Send a cumulative ACK that might include some of the out-of-order packets.
  2. Update the expected sequence number.
Receive out-of-order new segment.
  1. Send duplicate ACK with next expected sequence number.
Receive duplicate segment.
  1. Send cumulative ACK.

Sender

The following table described the events that occur in the sender and the actions that the sender should take. The "Method" column refers to the methods that handle the events as required by the assignment.

MethodEventActions
sendPacket App provides data to be transmitted.
  1. Create a new packet.
  2. Update the sequence number.
  3. Send the packet.
  4. Store the packet with unACKed packets.
  5. Start the timer, if it isn't already running.
receivePacket Receive an ACK from the network (special case below)
  1. Remove any acknowledged packets from the unACKed packets.
  2. If there are no unACKed packets, stop the timer.
  3. Otherwise, restart the timer.
Receive three ACKs with the same ACK number in a row. (Fast Retransmit)
  1. Resend the unACKed packet with the smallest sequence number.
  2. Restart the timer.
timeout Timer times out.
  1. Resend all unACKed packets.
  2. Restart the timer.

Assignment

For this assignment you will complete the implementation of MyNQTCPSender.java. Several files are provided for your use. You can find the files in http://cs.gettysburg.edu/~cpresser/cs322/NQTCP/

FIleDescription
NQTCPReceiver.jar The NQTCPReceiver program. You can run this with the command line
        java -jar NQTCPReceiver.jar
See the NQTCPReceiver section for instructions on how this program works.
NQTCPSender.java An abstract class containing the framework for sending data. It manages user input as well as additional threads and timers. It also creates the DatagramSocket that is to be used in the subclass MyNQTCPSender. This is the sender's main program. Run this to execute your sender (kill the messanger?) in eclipse or with the command line:
    	java NQTCPSender
It optionally takes a hostname on the command line if you prefer running across a network.
MyNQTCPSender.java A subclass of NQTCPSender with an empty constructor and methods. Your job is to add code to this to make a correct sender.
SampleRun.pdf Two sample runs with explanations.

MyNQTCPSender.java

To complete the file MyNQTCPSender.java and implement the reliable protocol, you must do the following.

NQTCPSender.java

NQTCPReceiver.jar

Notes