,

Contents · TCP (handshake, congestion control: Reno, CUBIC, BBR)


Three-way handshake and teardown

  • Handshake: SYN → SYN-ACK → ACK establishes initial sequence numbers (ISNs).
  • Teardown: FIN/ACK half-closes; TIME_WAIT prevents old segments from confusing new conns.
  • Simultaneous open/close exist but are rare; RST aborts connections.
Client: SYN seq=x → Server
Server: SYN-ACK seq=y ack=x+1 → Client
Client: ACK ack=y+1 → Server

Reliability: sequence numbers, ACKs, retransmissions

  • Ordered byte stream tracked by sequence numbers; cumulative ACKs confirm receipt.
  • Retransmission timeout (RTO) and fast retransmit (duplicate ACK threshold).
  • SACK improves recovery by indicating non-contiguous blocks received.

Flow control vs congestion control

  • Flow control: receiver-advertised window (rwnd) prevents overrunning buffers.
  • Congestion control: sender regulates cwnd to avoid network congestion.
  • Throughput ≈ min(rwnd/RTT, cwnd/RTT) bounded by the tightest window.

Reno: AIMD, slow start, fast retransmit/recovery

  • Slow start: cwnd grows exponentially until ssthresh or loss; then AIMD.
  • Loss detection by 3 dupACKs triggers fast retransmit; cwnd cut, then additive increase.
  • Reno fair in steady-state; suffers on long RTT and loss-prone links.
on 3 dupACKs: ssthresh = cwnd/2; cwnd = ssthresh + 3*MSS → fast recovery

CUBIC: cubic growth, BIC heritage

  • Cubic function of time since last loss; RTT-independent growth improves fairness.
  • Stability around previous max cwnd; TCP-friendly mode for Reno coexistence.
  • Default in Linux for years; good for high-bandwidth-delay networks.

BBR: model-based bottleneck bandwidth + RTT

  • Estimates bottleneck bandwidth (BtlBw) and minimum RTT (RTprop) to set pacing rate.
  • Keeps small queues by pacing; avoids loss-based sawtoothing; versions v1/v2 refine fairness.
  • Requires accurate measurement; pacing and GSO/TSO help implementation.
pacing_rate ≈ BtlBw; inflight ≈ BtlBw * RTprop

TCP options: MSS, WS, SACK, Timestamps, Fast Open

  • MSS: max segment size; Window Scale extends rwnd beyond 64KB.
  • SACK and Timestamps improve loss recovery and RTT estimation.
  • Fast Open (TFO) sends data in SYN with cookies; beware middlebox issues.

Performance tuning and pitfalls

  • Bufferbloat vs underutilization; AQM (CoDel/FQ-CoDel) and pacing mitigate queues.
  • Tune send/receive buffers, enable SACK/TS; set MSS clamping for tunnels.
  • Beware asymmetric paths, NAT timeouts, middleboxes altering options.

Troubleshooting TCP

  • Use packet captures to inspect handshake, options, and loss/dupACK patterns.
  • Graph cwnd/RTT where available; check server kernel congestion control algorithm.
  • Look for PMTUD black holes (ICMP blocked) and excessive retransmissions.

Exercises

  1. Capture a TCP handshake and identify MSS, WS, SACK, and TS options.
  2. Induce loss in a lab and observe Reno vs CUBIC cwnd behavior.
  3. Test BBR on a high BDP path; compare throughput, latency, and queueing vs CUBIC.
TCP’s evolution balances fairness, throughput, and latency—know the algorithms to tune performance.