Detailed Explanation of TCP SACK (Selective Acknowledgment) Mechanism
Description
TCP SACK (Selective Acknowledgment) is a mechanism that optimizes TCP retransmission. In the standard TCP acknowledgment mechanism, the receiver can only acknowledge sequentially received data (e.g., the acknowledgment number indicates all data before it has been received). If a packet is lost in the middle, the sender must retransmit all subsequent data starting from the lost packet (even if some packets have been correctly received), leading to bandwidth wastage. SACK allows the receiver to explicitly inform the sender which non-contiguous data blocks have been successfully received, enabling the sender to retransmit only the truly lost packets, thereby improving efficiency.
Background Knowledge
- TCP achieves reliable transmission through acknowledgment numbers (ACK): acknowledgment number N indicates all data before N has been received.
- If packets arrive out of order or are lost, the receiver will repeatedly send the latest ACK (e.g., ACK=N), triggering the sender to retransmit (e.g., fast retransmit). However, standard retransmission retransmits all unacknowledged data after the ACK number, causing redundancy.
Problems SACK Solves
Assume the sender sends packets with sequence numbers 1-1000, 1001-2000, 2001-3000, and 3001-4000:
- If packet 1001-2000 is lost, but packets 2001-3000 and 3001-4000 arrive at the receiver.
- Without SACK: The receiver can only repeatedly send ACK=1001 (acknowledging data before 1001), and the sender must retransmit all data from 1001 to 4000 (including the already received 2001-4000).
- With SACK: The receiver can additionally declare "packets 2001-3000 and 3001-4000 have been received," and the sender only retransmits 1001-2000.
Detailed SACK Mechanism
-
Negotiation and Enablement:
- During the TCP three-way handshake, both parties include the
SACK-Permittedoption (Kind=4) in the options field to indicate SACK support. - SACK information can only be used in subsequent communication if both parties support it.
- During the TCP three-way handshake, both parties include the
-
SACK Option Structure:
- In the TCP header's options field, the SACK option has Kind=5 and a variable length.
- Each SACK block contains the starting and ending sequence numbers of a contiguous data range (left-closed, right-open), e.g.,
[left edge, right edge). - One SACK option can include multiple SACK blocks (limited by the TCP option length, typically up to 3-4 blocks).
- Example: If data segments 2001-3000 and 3001-4000 are received, SACK blocks can be represented as
[2001, 3001)and[3001, 4001).
-
Receiver Behavior:
- When non-contiguous data is received, the receiver attaches a SACK option to the ACK packet, reporting all received but unacknowledged data blocks.
- Each time an ACK is sent, the SACK block content can be updated (e.g., when new data blocks are received).
- Note: SACK is supplementary information; the main acknowledgment number (ACK number) still points to the boundary of contiguous data.
-
Sender Behavior:
- Maintains a "SACK table" to record data blocks acknowledged by the receiver.
- When packet loss is detected (e.g., upon receiving 3 duplicate ACKs), checks the SACK information:
- If SACK blocks indicate certain data has been received, skip that data and retransmit only the missing intervals not covered by SACK.
- Works in conjunction with the fast retransmit mechanism for efficient recovery.
Example Demonstration
Assume the sender sends packets:
- Seq=1:1000 (normally acknowledged)
- Seq=1001:2000 (lost)
- Seq=2001:3000 (arrives, triggers ACK=1001 with SACK=[2001,3001))
- Seq=3001:4000 (arrives, triggers ACK=1001 with updated SACK=[2001,3001) and [3001,4001))
The sender receives 3 ACK=1001 and sees from SACK that 2001-4000 has been received, so it only retransmits 1001-2000.
Limitations of SACK
- Depends on receiver support: If one end does not support SACK, the connection falls back to standard TCP.
- Network overhead: The SACK option increases TCP header size (especially with multiple data blocks).
- Implementation complexity: The sender must maintain SACK state and handle block merging and overlapping.
Summary
SACK reduces unnecessary retransmissions by explicitly reporting non-contiguous data blocks, making it particularly suitable for high-bandwidth or high-packet-loss networks. It is an important component of TCP performance optimization and often works in conjunction with fast retransmission and congestion control.