Back to the 2024 paper

Module 4: Transport Layer & Congestion Control

20247m

Explain how TCP provide a flow control service by using different variables.

Worked SolutionAI Assisted

TCP flow control

Flow control ensures the sender does not send data faster than the receiver can process it, so the receiver's buffer does not overflow. TCP uses a sliding window in which the receiver advertises how much free buffer space it has (the receive window, rwnd) in every segment's Window field (16 bits).

Variables used

At the receiver (connection has a receive buffer of size RcvBuffer):

Variable Meaning
RcvBuffer Total size of the receive buffer
LastByteRcvd Number of the last byte that arrived from the network and was placed in the buffer
LastByteRead Number of the last byte the application has read from the buffer
rwnd Free space advertised to the sender

Buffered data = LastByteRcvd − LastByteRead ≤ RcvBuffer, so

rwnd = RcvBuffer − (LastByteRcvd − LastByteRead)

The receiver puts the current rwnd in the window field of every ACK it sends.

At the sender:

Variable Meaning
LastByteSent Last byte sent
LastByteAcked Last byte acknowledged
rwnd Latest window advertised by the receiver

The sender keeps the amount of unacknowledged (in-flight) data within the advertised window:

LastByteSent − LastByteAcked ≤ rwnd

(In practice the limit is min(rwnd, cwnd), where cwnd is the congestion window.)

Working

  1. At connection setup, rwnd = RcvBuffer.
  2. The sender transmits up to rwnd bytes without waiting for ACKs.
  3. As data arrives and the application reads it, the receiver updates rwnd and sends it back with each ACK.
  4. If the application is slow, the buffer fills, rwnd shrinks, and the sender slows down.
  5. When rwnd = 0, the sender stops. To avoid deadlock, it keeps sending 1-byte probe segments so the receiver can reply with a new rwnd once buffer space becomes free.
  6. When space opens, the receiver sends a window update and transmission resumes.

Example

RcvBuffer = 4000 bytes. Sender sends bytes 0–2999. Receiver has read 1000 bytes (LastByteRead = 999, LastByteRcvd = 2999):

rwnd = 4000 − (2999 − 999) = 2000. The sender may have at most 2000 unacknowledged bytes.

Silly window syndrome

Tiny window updates would cause tiny segments. It is avoided by Clark's solution (receiver advertises a window only when it has a useful amount of space free) and Nagle's algorithm (sender waits to combine small writes).

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.