This program simulates the routine of a TCP-like reliable transport protocol.
This program is provided for educational purpose. Please do not clone this program for your submission and do not use this resource for commercial purpose, because there are still many bugs to be fixed and we modify some code in the NetworkSimulator.java. Besides, if you use this program, your professor and TA will find out.
- default packet
- Project.java
- event
- Event.java
- EventList.java
- EventListImpl.java
- packet
- Message.java
- Packet.java
- simulator
- GoBackNSimulator.java
- NetworkSimulator.java
- SelectiveRepeatSimulator.java
- util
- GoBackNReceiverQueue.java
- GoBackNSenderQueue.java
- OSIRandom.java
- SelectiveRepeatReceiveQueue.java
- SelectiveRepeatSenderQueue.java
- SlidingWindowQueue.java
Project.java is the entrance of this program.
- Find Project.java.
- Find simulator at the end of this file.
- Run Selective Repeat Simulator or Go Back N simulator.
- This program does not use multithreading or multiprocessing. For simplicity, TA adopts an event list (like a queue) to simulate what happen in this communication model. Please refer to packet event.
- How do we simulate the time in the event list? TA adopts a smart and simple strategy: suppose the start time of this program is 0 and the happening time of the next event will be 0 + a random number. Different actions will generate different events and the simulator will push these events into the event list. Every time we simulate an event happens, we pop the next event which has the smallest time number up and execute this event.
- Message and Packet.
struct msg {
char data[20];
}
struct packet {
int seqnum;
int acknum;
int checksum;
char payload[20];
}
-
Event: data received from above.
Action:
- Buffer it.
- Check the next available sequence number for the packet. If the sequence number is within the sender’s window, the data is packetized and sent.
- Start timer.
-
Event: timeout or duplicate ACK.
Action:
- Retransmit only the next missing (unACK’ed) packet.
- Restart timer.
-
Event: ACK received.
Action: slide window and transmit the packets that now fall within the window. If the packet corrupts, discard it.
-
Packet with sequence number in [rcv_base, rcv_base+N-1] is correctly received.
- If the received packet falls within the receiver’s window, it is buffered.
- If this packet has a sequence number equal to the base of the receive window, then this packet, and any previously buffered and consecutively numbered packets are delivered to the upper layer.The receive window is then moved forward by the number of packets delivered to the upper layer.
-
Packet with sequence number in [rcv_base – N, rcv_base – 1] is correctly received. An ACK must be generated, even though this is a packet that the receiver has previously acknowledged.
-
Otherwise. Ignore the packet.
-
Event: Call from layer 5.
Action:
- Check the next available sequence number for the packet.
- Make a packet and add it into the queue of sender.
- If the window is not full, send the next packet in the queue of sender to layer 3.
- Start timer.
-
Event: Timeout.
Action:
- Retransmit all unACK’ed packets in the queue of sender.
- Restart timer.Event: ACK received.
-
Event: Received an ACK packet.
Action:
- For a corrupted packet, do nothing.
- For an uncorrupted packet and the sequence number of ACK is in the queue of sender, which indicates an effective ACK,
- Stop the timer.
- Slide the window according to the sequence number of ACK
- Send other packets in the queue of sender until the window becomes full.
- If it is a SACK packet, handle it and send packets in the queue of sender.
- For an uncorrupted packet but the sequence number of ACK is not in the queue of sender, which indicates a duplicate ACK, do nothing
- If there are unACK’ed packets in the queue of sender, restart the timer
- For a corrupted packet, do nothing.
- For an in-order packet, response an ACK with its sequence number. If there are buffered packets in the queue of receiver, try to send sequential packets to layer5.
- For an out of order packet, buffered in the queue of receiver. If the receiver queue is full, send an SACK packet to the sender and tell the sender which packets the receiver has.