TCP Sequence Diagrams
A TCP connection opens with a three-way handshake (SYN, SYN-ACK, ACK) and closes with a FIN and an ACK in each direction. To avoid overloading the network, the sender keeps its unacknowledged data within a congestion window (cwnd). The window grows quickly in slow start, then slowly in congestion avoidance, and shrinks when a segment is lost.
The rules below follow RFC 5681. SMSS is the sender's maximum segment size; ssthresh is the slow start threshold.
- Slow start (cwnd < ssthresh): cwnd grows by up to 1 SMSS for each ACK, so it roughly doubles every round trip.
- Congestion avoidance (cwnd ≥ ssthresh): cwnd grows by about SMSS × SMSS / cwnd for each ACK, about 1 SMSS per round trip.
- Three duplicate ACKs (fast retransmit and fast recovery): resend the missing segment at once, set ssthresh = max(FlightSize / 2, 2 × SMSS), and once the lost data is acknowledged, continue in congestion avoidance at cwnd = ssthresh rather than restarting slow start. FlightSize is the data sent but not yet acknowledged.
- Retransmission timeout: set ssthresh = max(FlightSize / 2, 2 × SMSS) and cwnd = 1 SMSS, then slow start again.
These diagrams cover the TCP three-way handshake, slow start, congestion avoidance, and fast retransmit.
TCP 3-way handshake
The sequence diagrams presented here describe the 3-way handshake setup and release of a TCP connection. The byte level sequence numbers and TCP Ack handling is also shown.
TCP slow start
Analyse "Slow start" congestion control mechanisms built right into TCP. As the name suggests, "Slow Start" starts slowly, increasing its window size as it gains confidence about the network's throughput.
TCP congestion avoidance
TCP connection starts up in slow start mode, geometrically increasing the congestion window (cwnd) until it crosses the slow start threshold (ssthresh). Once cwnd is greater that ssthresh, TCP enters the congestion avoidance mode of operation. In this mode, the primary objective is to maintain high throughput without causing congestion. If TCP detects segment loss, TCP reduces its data flow rate by reducing cwnd. After reducing cwnd, TCP goes back to slow start.
TCP Fast Retransmit and Fast Recovery Sequence Diagram
Fast Retransmit and Recovery detect a segment loss via duplicate acknowledgements. When a segment is lost, TCP at the receiver will keep sending ack segments indicating the next expected sequence number. This triggers fast recovery at the transmitter.