Working Principles of TCP Congestion Window (cwnd) and Receive Window (rwnd) Coordination

Working Principles of TCP Congestion Window (cwnd) and Receive Window (rwnd) Coordination

1. Knowledge Point Description
In TCP communication, the sender needs to control the data transmission rate to avoid network congestion and receiver buffer overflow. This is achieved through two key windows:

  • Congestion Window (cwnd): A flow control window maintained by the sender based on the degree of network congestion.
  • Receive Window (rwnd): A flow control window advertised by the receiver based on the remaining buffer size.

Actual sending window size = min(cwnd, rwnd). These two windows limit the sending rate from different dimensions and need to work together to achieve efficient flow control.

2. Independent Operating Mechanisms of the Windows

  1. Operation of the Receive Window (rwnd)

    • The receiver advertises the current available buffer space via the "Window Size" field in each ACK packet.
    • The sender must ensure: amount of data sent but not acknowledged ≤ current receive window size.
    • Example: When rwnd=0, the sender pauses transmission (except for zero-window probe packets).
  2. Operation of the Congestion Window (cwnd)

    • An internal variable dynamically adjusted by the sender based on network conditions.
    • Follows algorithms such as Slow Start, Congestion Avoidance, and Fast Retransmit.
    • The sender guarantees: amount of in-flight data ≤ current congestion window size.

3. Detailed Coordination Workflow

  1. Normal Transmission Phase

    Initial state: cwnd=1 MSS, rwnd=64 KB
    Sending window = min(1 MSS, 64 KB) = 1 MSS
    
    As transmission proceeds:
    - cwnd grows exponentially via slow start to 16 MSS
    - rwnd remains large due to timely processing by the receiver
    Actual sending window = min(16 MSS, 64 KB) = 16 MSS
    
  2. Receive Window Limited Scenario

    Scenario: Slow application processing speed at receiver, buffer gradually fills up.
    - cwnd=32 MSS (good network condition)
    - rwnd decreases from 64 KB to 8 KB (approx. 4 MSS)
    Actual sending window = min(32 MSS, 4 MSS) = 4 MSS
    → Sending rate is determined by receiver's processing capability.
    
  3. Congestion Window Limited Scenario

    Scenario: Network congestion occurs, but receiver buffer is sufficient.
    - rwnd=64 KB (strong receiving capability)
    - cwnd reduces from 32 MSS to 16 MSS due to congestion
    Actual sending window = min(16 MSS, 64 KB) = 16 MSS
    → Sending rate is determined by the degree of network congestion.
    

4. Coordination Handling in Special Scenarios

  1. Zero Window Handling

    • When rwnd=0, the sender starts a persistence timer.
    • Sends zero-window probe packets to confirm receiver buffer status.
    • Resumes sending upon receiving non-zero window advertisement.
  2. Window Update Mechanism

    • The receiver sends a window update packet after a certain amount of buffer space is freed.
    • To avoid deadlock, TCP allows the receiver to send window update information at any time.
  3. Congestion Event Response

    • Upon packet loss, cwnd is immediately halved (Congestion Avoidance) or reset (Timeout Retransmission).
    • Regardless of rwnd size, the sending window is limited by cwnd.

5. Optimizations in Practical Applications

  1. Window Scaling Option

    • Addresses the limitation of rwnd's maximum value of 65,535 bytes.
    • Negotiates a scaling factor during the three-way handshake to support larger windows.
  2. Consideration of Bandwidth-Delay Product (BDP)

    • Ideal scenario: max(cwnd, rwnd) ≥ Bandwidth × Delay (BDP)
    • Ensures the network pipe can be fully utilized.

This coordination mechanism allows TCP to adapt to network congestion changes while matching the receiver's processing capability, achieving intelligent end-to-end flow control.