Reliable data transfer is one of the most critical challenges in computer networking. Because the underlying network layers (such as the IP layer) are inherently connectionless and best-effort, packets can be corrupted, lost, duplicated, or delivered out of order. This curriculum document details the theoretical design of reliable data transfer protocols, transitioning from basic stop-and-wait models to highly optimized sliding window protocols, and concluding with their real-world implementation within the Transmission Control Protocol (TCP).
To design a reliable data transfer protocol, we must establish mechanisms that bridge the gap between a reliable upper-layer channel and an unreliable underlying channel.
+---------------------------------------------+
| Application Layer |
+---------------------------------------------+
| send_data() ^ deliver_data()
v |
+---------------------------------------------+
| Transport Layer | <--- Reliable Data Transfer
+---------------------------------------------+ (Flow & Error Control)
| ip_send() ^ ip_recv()
v |
+---------------------------------------------+
| Network Layer | <--- Unreliable Channel
+---------------------------------------------+At the transport layer, communication is process-to-process. While IP addresses route packets to a specific host machine, port numbers are used to select the specific application process.
A Socket Address uniquely identifies a process across the global network and is defined as:
The Stop-and-Wait Protocol is the simplest protocol with flow and error control. The sender transmits a single packet and stops, waiting for a feedback acknowledgment from the receiver before initiating the next transmission.
To distinguish between a new packet and a retransmitted duplicate, packets are sequentially numbered. In Stop-and-Wait, sequence numbers are calculated using modulo-2 arithmetic:
The acknowledgment number always specifies the sequence number of the next packet expected by the receiver.
SENDER RECEIVER
| |
|--- Send Packet 0 ---------------------------------------->| (Expected: 0)
| |-- Process & Ack
|<-- Send ACK 1 --------------------------------------------| (Expects 1 next)
| |
|--- Send Packet 1 ---------------------------------------->| (Expected: 1)
| (Packet Lost) |
| X |
| |
|--[Timer Expires]-- |
|--- Retransmit Packet 1 ---------------------------------->| (Expected: 1)
| |-- Process & Ack
|<-- Send ACK 0 --------------------------------------------| (Expects 0 next)While robust, the Stop-and-Wait protocol is highly inefficient on channels with a high bandwidth-delay product.
Let:
The transmission time of a single packet () is:
The total time to complete one cycle of packet transmission and acknowledgment is . The link utilization () is defined as:
Assume a link bandwidth of , and a round-trip propagation delay () of .
The channel is idle for over of the transmission cycle. To reclaim this wasted capacity, we must use pipelined sliding window protocols.
The Go-Back-N (GBN) protocol improves link utilization by allowing the sender to transmit multiple packets before waiting for an acknowledgment. This pipelining technique relies on an abstract sliding window.
Sequence numbers in GBN are modulo , where is the bit-width of the sequence number field.
<--- Sent, ACKed ---> [ Outstanding, UnACKed ] <--- Can Send --->
+-----+-----+-----+---+-----+-----+-----+-----+---+-----+-----+-----+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 |
+-----+-----+-----+---+-----+-----+-----+-----+---+-----+-----+-----+
^ ^
| |
Sf Sn
* Sf (Send window First): Oldest outstanding, unacknowledged packet.
* Sn (Send window Next): Sequence number of the next packet to be sent.In GBN, acknowledgments are cumulative. When the receiver sends an , it declares that all packets up to and including have been received correctly, and that it is expecting packet next.
If a packet in the middle of a pipeline sequence is lost, the receiver discards all subsequent packets (even if they arrive undamaged) because they are received out-of-order. When the sender's timer for the oldest unacknowledged packet () expires, the sender must go back and retransmit the entire window starting from .
SENDER (S_size = 4) RECEIVER (R_size = 1)
| |
|--- Send Packet 0 ---------------------------------------->| (Expected: 0) -> ACK 1
|--- Send Packet 1 ---------------------------------------->| (Expected: 1) -> Lost!
|--- Send Packet 2 ---------------------------------------->| (Expected: 1) -> Discard, ACK 1
|--- Send Packet 3 ---------------------------------------->| (Expected: 1) -> Discard, ACK 1
| |
|--[Timer for Packet 1 Expires]-- |
|--- Go Back & Resend Packet 1 ---------------------------->| (Expected: 1) -> ACK 2
|--- Resend Packet 2 -------------------------------------->| (Expected: 2) -> ACK 3
|--- Resend Packet 3 -------------------------------------->| (Expected: 3) -> ACK 4While GBN utilizes link bandwidth much more efficiently than Stop-and-Wait, it performs poorly on lossy links because a single dropped packet triggers the retransmission of many correctly received packets. The Selective-Repeat (SR) protocol addresses this inefficiency.
In Selective-Repeat, both the sender and the receiver maintain sliding windows.
Why SR window size must be <= 2^(m-1):
Suppose m = 2 (Sequence numbers: 0, 1, 2, 3). If window size = 3 (violating 2^(2-1) = 2):
1. Sender transmits Packets 0, 1, 2.
2. Receiver receives all, buffers them, slides window to expect 3, 0, 1. Sends ACKs.
3. All ACKs are lost.
4. Sender's timer expires, resends Packet 0.
5. Receiver (expecting 3, 0, 1) accepts this retransmitted Packet 0 as a brand new packet.
This leads to duplicate, corrupted data delivery.
If window size was <= 2, the receiver would expect 2, 3, preventing this overlap.Instead of cumulative ACKs, SR uses individual acknowledgments. An acknowledgment number confirms only that the specific packet with sequence number was received correctly. It does not imply the receipt of any prior packets.
SENDER (S_size = 4) RECEIVER (R_size = 4)
| |
|--- Send Packet 0 ---------------------------------------->| (Expect: 0..3) -> Buffers 0, ACK 0
|--- Send Packet 1 ---------------------------------------->| (Expect: 1..4) -> Lost!
|--- Send Packet 2 ---------------------------------------->| (Expect: 1..4) -> Buffers 2, ACK 2
|--- Send Packet 3 ---------------------------------------->| (Expect: 1..4) -> Buffers 3, ACK 3
| |
|--[Timer for Packet 1 Expires]-- |
|--- Resend Packet 1 ONLY --------------------------------->| (Expect: 1..4) -> Buffers 1, ACK 1
| | (Delivers 0, 1, 2, 3 in-order)The transmission mechanisms detailed above are directly implemented and optimized in the Transmission Control Protocol (TCP).
Unlike the packet-oriented protocols studied conceptually, TCP is a stream-oriented protocol. It numbers the individual bytes of data being transferred, rather than numbering the packet segments.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options (0 to 40 bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+TCP establishes a virtual connection using a three-way handshake:
CLIENT (Active Open) SERVER (Passive Open)
| | (State: LISTEN)
|--- SYN (seq=x, ACK=0) ----------------------------------->| (State: SYN_RCVD)
| |
|<-- SYN-ACK (seq=y, ack=x+1) ------------------------------|
| |
|--- ACK (seq=x+1, ack=y+1) ------------------------------->| (State: ESTABLISHED)During connection termination, TCP uses a four-way handshake to gracefully close each direction of the bidirectional link separately:
CLIENT SERVER
|--- FIN -------------------------------------------------->| (State: CLOSE_WAIT)
|<-- ACK ---------------------------------------------------|
| |
|<-- FIN ---------------------------------------------------| (State: LAST_ACK)
|--- ACK --------------------------------------------------->| (State: CLOSED)To guarantee that the final ACK was delivered and to prevent delayed duplicate segments from corrupting future connections, the initiating client enters the TIME-WAIT state for a duration of (Maximum Segment Lifetime).
Silly Window Syndrome occurs when either the sender writes data very slowly or the receiver consumes data very slowly, resulting in the exchange of extremely small TCP segments (sometimes containing only a 1-byte payload wrapped in 40 bytes of header).
Nagle’s algorithm prevents the sender from emitting tiny segments by waiting to buffer data based on the network's feedback speed:
# Pseudo-code for Nagle's Algorithm
def on_application_write(data):
append_to_send_buffer(data)
if length(send_buffer) >= MSS:
send_segment(get_bytes(send_buffer, MSS))
else:
if no_unacknowledged_data_in_flight():
send_segment(clear_buffer(send_buffer))
else:
# Keep buffering until an ACK arrives or we reach MSS
hold_in_buffer()TCP couples flow control, error control, and congestion control to maximize network throughput while preventing congestion collapse.
To adapt to varying network paths, TCP continuously measures the round-trip time () of transmitted segments and dynamically computes a Retransmission Timeout ().
Using the Jacobsson/Karels algorithm, let:
For each successful, non-retransmitted segment measurement :
Note: If a segment must be retransmitted, Karn’s algorithm dictates that the RTT of that retransmitted segment cannot be used to update and (due to acknowledgment ambiguity). Instead, the RTO is temporarily doubled for each subsequent timeout (exponential backoff).
TCP implements a congestion window () to throttle transmission rates based on estimated network capacity.
Congestion Window (cwnd)
^
| +-- Congestion Detected
| / (3 Duplicate ACKs)
| +---+ +---+ --> cwnd = ssthresh
| +---+ | / --> Additive Increase
| +---+ |/ (Congestion Avoid)
| +---+ +
| +---+
| +---+ <--- Exponential Increase
| +---+ (Slow Start)
| +---+
| +---+
+------------------------------------------------------------> Time
This leads to an exponential growth of the congestion window size each RTT, continuing until reaches a slow start threshold (). 2. Congestion Avoidance: Once , the window growth transitions to an additive increase phase. For each ACK received:
This results in an increase of per RTT, allowing the sender to probe the network's capacity safely. 3. Congestion Detection and Policy:
A fundamental protocol where the sender transmits one packet and pauses for an acknowledgment before sending the next, resolving flow control but offering low channel utilization.
A pipelined sliding window protocol allowing multiple outstanding unacknowledged packets, but requiring the retransmission of all packets starting from the lost one upon timeout.
An advanced sliding window protocol where the receiver accepts out-of-order packets and buffers them, allowing the sender to retransmit only those individual packets that were lost or corrupted.
An abstract concept representing a buffer range of sequence numbers that slides forward as packets are acknowledged, enabling efficient utilization of high bandwidth-delay product links.
Mechanisms to balance the production-consumption rates of packets (flow control) and detect/retransmit lost, corrupted, or duplicated packets (error control).
Test your understanding with 5 questions
In the Stop-and-Wait protocol, what is the size of the sequence number field, and what modulo arithmetic is used to number the packets?
If m is the size of the sequence number field in bits, what is the maximum send window size (S_size) for a Go-Back-N (GBN) protocol?
What is the maximum window size (S_size and R_size) for the Selective-Repeat (SR) protocol, given a sequence number space of size 2^m?
Which algorithm/mechanism is specifically designed to solve the Silly Window Syndrome (SWS) when it is created by a slow-sending application program?
If a receiver using Go-Back-N receives packets 0, 1, and 2, but packet 1 is lost in transit, what action does the receiver take when packet 2 arrives?
6 Modules
6 Modules