TCP flow control
How TCP stops a fast sender from overflowing a slow receiver: the receive buffer and the advertised receive window rwnd = RcvBuffer - (LastByteRcvd - LastByteRead), the rule LastByteSent - LastByteAcked <= rwnd, the window field in every acknowledgement, the zero-window probe, the silly window syndrome, the throughput limit rwnd / RTT of a 16-bit window and the window scale option, and the difference from congestion control; a round-based simulation checks that the buffer never overflows and that the long-run rate is the slower of the application and the buffer per round.
Why it exists
The receiving application reads data from TCP's receive buffer at its own speed. If the sender transmits faster than the application reads, the buffer overflows and data are dropped. Flow control lets the receiver tell the sender how much room is left. It is about protecting the receiver; protecting the network is congestion control, a separate mechanism (congestion control).
Prerequisites
You need the TCP segment, its window field and the byte numbering (TCP basics), and the sliding window idea (sliding window protocols).
Precise definitions
The receiver has a buffer of size . Let be the number of the last byte that arrived in order, and the number of the last byte the application has taken out. The data waiting in the buffer are , and the free space the receiver advertises in the window field of every segment it sends (including acknowledgements) is the receive window:
The sender keeps the number of bytes that are outstanding (sent, not yet acknowledged) no greater than the latest rwnd:
Hence the receive buffer cannot overflow. The window advertised is a count of bytes, counted from the acknowledgement number.
Zero window. If rwnd the sender stops. Since no acknowledgement will arrive to reopen the window if the receiver sends nothing more, the sender sends tiny probe segments (one byte) periodically; the reply carries the current window (quoted).
Window limit. The window field is 16 bits: bytes. For fast long links the window scale option (negotiated in the handshake) multiplies the field by (quoted).
How it works
A receiver that reads slowly
Flow control: receive buffer 4000 bytes, application reads 1000 bytes per round: start
Computed by a script, not typed| round (one RTT) | advertised window | bytes sent | buffer after arrival | buffer after the application reads |
|---|---|---|---|---|
| round 1 | ||||
| round 2 | ||||
| round 3 | ||||
| round 4 | ||||
| round 5 | ||||
| round 6 | ||||
| round 7 |
Step 0
The sender may not have more than the advertised window outstanding; the window advertised in round r+1 depends on how much the application has read. 10 000 bytes to send, MSS 1000.
The receive buffer is bytes and the application reads only bytes per round trip. The sender starts with an advertised window of bytes and sends at once; the application reads , so the next advertised window is : the sender is slowed down to the speed of the application. In steady state each round sends bytes, the buffer stays almost full ( to bytes), and the transfer of bytes needs rounds. The sender's average rate is the application's read rate, not the link rate: the receiver controls the speed.
Throughput limit of a window
At most one window of data can be sent per round-trip time, so
A link can be filled only if the window is at least the bandwidth-delay product (performance metrics).
Throughput limit of a 16-bit window: start
Computed by a script, not typed| round-trip time | maximum throughput with 65 535 bytes | window needed for 1 Gbps | window scale shift needed |
|---|---|---|---|
| RTT 10 ms | |||
| RTT 50 ms | |||
| RTT 100 ms | |||
| RTT 200 ms |
Step 0
Throughput ≤ window / RTT. The window field of the TCP header has 16 bits.
With the maximum 16-bit window of bytes and a round-trip time of ms the throughput cannot exceed Mbps, even on a Gbps link. A Gbps link with ms RTT has a bandwidth-delay product of MB, which needs a window about times larger than the field allows: that is what the window scale option provides.
Silly window syndrome (quoted)
If the receiver advertises every tiny amount of freed space (for example byte) and the sender sends a tiny segment each time, the connection exchanges -byte headers for byte of data. The remedies: the receiver does not advertise a window increase until it is at least one MSS or half its buffer (Clark's solution), and the sender waits until it can send a full segment (Nagle's algorithm).
Flow control against congestion control
| flow control | congestion control | |
|---|---|---|
| protects | the receiver's buffer | the network (routers) |
| window | rwnd, advertised by the receiver in every segment | cwnd, computed by the sender |
| information | explicit, in the header | inferred from losses and delays |
The sender uses the smaller of the two: .
Worked examples
EX 1Advertised window
EasyReceive buffer bytes. bytes have arrived in order and the application has read of them. Data in the buffer: . .
EX 2Throughput limit
MediumWindow KB bytes, RTT ms: at most Mbps. For a link of Mbps and RTT ms the bandwidth-delay product is bytes; the window should be about times larger, so the scale shift would be ().
EX 3A slow application
MediumBuffer , MSS , the application reads bytes per round trip. Round 1: window , send , after reading remain, so the new window is . Rounds onwards: window , send , read : the long-run rate is bytes per RTT, the application's rate.
EX 4Typical questions
GATE level(a) "Which field implements TCP flow control?" The window field (receive window). (b) "What stops a sender if rwnd ?" It waits (and sends probes) until a segment reopens the window. (c) "Effective window of the sender with cwnd KB and rwnd KB?" KB. (d) "Maximum throughput with a -bit window and RTT ms?" Mbps. (e) "Time to send a file with a window of bytes and RTT over a fast link?" About .
Cheat box
Cheat box
- rwnd RcvBuffer (LastByteRcvd LastByteRead); advertised in every segment.
- Sender: LastByteSent LastByteAcked rwnd (and cwnd).
- Throughput rwnd / RTT; 16-bit window bytes; window scale option for more.
- rwnd : stop and probe. Silly window: avoid tiny windows and segments.
- Flow control protects the receiver; congestion control the network.
Traps and GATE patterns
Connections
Builds on
Across subjects
No cross-subject links yet.
The advertised window is the window of the sliding window protocol, carried in TCP (sliding window protocols, TCP basics); the sender's other limit comes from congestion control. The buffer-and-reader situation is the producer-consumer problem of the operating system (classic synchronization problems).
PYQs
2 previous year questions from your book. I re-solved each one myself (1 by running or simulating, 1 by reasoning only); the book's key is shown next to my answer. All PYQs
Assume that the bandwidth for a TCP connection is 1048560 bits/sec. Let α be the value of RTT in milliseconds (rounded off to the nearest integer) after which the TCP window scale option is needed. Let β be the maximum possible window size with window scale option. Then the values of α and β are:
- (a)63 milliseconds 65535 × 214
- (b)63 milliseconds 65535 × 216
- (c)500 milliseconds 65535 × 214
- (d)500 milliseconds 65535 × 216
Suppose two hosts use a TCP connection to transfer a large file. Which of the following statements is/are FALSE with respect to the TCP connection? 1. If the sequence number of a segment is m, then the sequence number of the subsequent segment is always m+1. 2. If the estimated round trip time at any given point of time is t sec, the value of the retransmission timeout is always set to greater than or equal to t sec. 3. The size of the advertised window never changes during the course of the TCP connection. 4. The number of unacknowledged bytes at the sender is always less than or equal to the advertised window.
- (a)3 only
- (b)1 and 3 only
- (c)1 and 4 only
- (d)2 and 4 only
Self-check
Question 1
RcvBuffer KB, KB in the buffer unread. What does the receiver advertise?
Show answerHide
KB.
Question 2
Why can a -bit window not fill a Gbps, ms path?
Show answerHide
The bandwidth-delay product is MB, far above bytes; only one window per RTT can be sent, giving Mbps.
Question 3
The advertised window is . How does the sender learn that it has reopened?
Show answerHide
It sends periodic one-byte probe segments; the acknowledgement of a probe carries the current window.
Revision card
One-screen revision
- rwnd = free buffer space, in every ACK; outstanding .
- Throughput rwnd / RTT; scale option beyond .
- Zero window: probe. Silly window: wait for a full segment / half a buffer.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 3, Section 3.5.5 (Flow control)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 6, Section 6.5.9 (TCP sliding window)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 24, Section 24.3 (Flow control)
Verification
scripts/enum-checks/cn_tcp_check.py: the round-based simulation of scripts/cn_tcp.py (flow_sim; one round = one round trip, the sender sends at most the advertised window in whole segments, the application reads a fixed number of bytes per round, the new window is the free buffer space) was run on 500 random cases (buffers 4000 to 65535 bytes, MSS 500 to 1460, read rates 200 to 20000 bytes per round, transfers up to 400 000 bytes): all bytes are delivered, the buffer never exceeds its size, the bytes sent in a round never exceed the advertised window, and in the steady state the bytes sent per round equal min(read rate, buffer size) within one MSS. The throughput limit 65535 x 8 / RTT is arithmetic. MODEL: the receiver advertises the free space after the application's read of that round; sender and receiver proceed in lock step per round trip; real TCP overlaps rounds, delays acknowledgements and updates the window on every ACK. QUOTED, not verified here: the silly window syndrome and its remedies (Clark's receiver rule, Nagle's algorithm), the zero window probe, the window scale option (shift count up to 14, windows up to about 1 GB), the statement that the sender is also limited by the congestion window (min of the two), and the fields LastByteRead / LastByteRcvd of the textbook. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)