TCP Sliding Window Protocol and Flow Control — Receiver Window, Cumulative ACKs, Lost Segments & Numericals
Understand exactly which bytes can be sent, which bytes must wait, and how TCP recovers from gaps. This tutorial follows Tanenbaum and Forouzan with exam-focused explanations, original responsive diagrams and interactive demonstrations.
TCP sliding window is a byte-oriented, dynamically sized mechanism that permits multiple bytes to be in transit while keeping the sender within the receiver's available buffer space. In practice, the sender's transmission is limited by both the receive window (rwnd) and the congestion window (cwnd).
1. What Is the TCP Sliding Window Protocol?
TCP uses a sliding window to allow a sender to transmit more than one piece of data before waiting for an acknowledgement. Instead of a stop-and-wait exchange, TCP keeps a pipeline of bytes in flight. As acknowledgements arrive, the left boundary of the send window advances and new data can become eligible for transmission.
Byte oriented
TCP numbers individual bytes. A single segment may cover many consecutive byte numbers.
Variable sized
The permitted window can change as the receiver consumes data and network conditions change.
Cumulative ACKs
An ACK indicates the next contiguous byte expected, not the most recently arrived segment.
2. The Four Regions of a TCP Sender Window
Visualize the TCP byte stream as four groups: acknowledged bytes, sent but unacknowledged bytes, bytes that can be sent now, and bytes temporarily blocked outside the current window.
Original concept diagram — a 9-byte effective window
Here the window contains min(9,20)=9 bytes. Of those, three are outstanding, so six new bytes are currently allowed.
Opening: right boundary moves right and allows additional bytes. Sliding (closing the left): acknowledgements advance the left boundary. Shrinking: moving the right edge backward is strongly discouraged because the sender may already have transmitted bytes relying on the earlier permission.
3. Receiver Window (rwnd) vs. Congestion Window (cwnd)
rwnd — Receiver flow-control limit
Determined by the receiving TCP from available buffer capacity. Advertised to the sender in TCP's Window field (with scaling when negotiated).
cwnd — Sender congestion-control limit
Maintained by the sender, based on congestion-control logic and feedback. Not a value directly transmitted in the TCP header.
Forouzan Examples 23.4 and 23.5 illustrate both calculations. With a 5000-byte buffer holding 1000 unread bytes, rwnd=4000. If rwnd=3000 and cwnd=3500, the effective window is 3000 bytes.
4. Interactive TCP Receive-Buffer and Window Demonstration
Consider a receiver with a 4096-byte buffer, an empty starting buffer, and a sender whose first data byte is numbered 1000. Click through the steps to see how ACK and rwnd change independently. This is a numerically adjusted recreation of the concept in Tanenbaum Figure 6-40.
Receive buffer: eight cells, 512 bytes each
Next ACK
1000
Advertised rwnd
4096 B
New step
No bytes sent
Animated concept: the blue data packet moves sender → receiver while the green ACK moves receiver → sender. Motion illustrates exchanges rather than actual network timing. Motion pauses when requested and respects reduced-motion preferences.
5. Cumulative ACKs, Lost Segments and Out-of-Order Reception
The TCP acknowledgement number represents the next byte expected in order. If data arrive beyond a missing range, the cumulative ACK normally stays at the beginning of the gap. Modern implementations commonly buffer those later bytes; SACK, when enabled, can report the out-of-order ranges separately.
Try a lost-segment scenario
6. Zero Window, Window Probes, Delayed ACK, Nagle and Silly Window Syndrome
6.1 Zero receiver window (rwnd = 0)
If the application reads no data and the buffer fills, the receiver may advertise rwnd=0. A sender normally stops new data transmission until more room becomes available. In Tanenbaum Figure 6-40, ACK moves forward as bytes arrive, but the advertised window can simultaneously fall to zero.
6.2 Window probes and the persist problem
Suppose the receiver later frees space and sends a window-update segment, but that update is lost. The sender still believes the window is zero and may wait indefinitely. TCP can transmit a window probe to elicit the receiver's latest ACK and window advertisement. The textbook discusses a 1-byte probe exception.
6.3 Delayed ACK
Instead of immediately sending a standalone ACK for every arriving segment, a receiver can delay it briefly in the hope that useful outgoing data will allow piggybacking. Tanenbaum's historical discussion mentions up to 500 ms; this is a textbook explanation, not a recommendation to use 500 ms in every current implementation.
6.4 Nagle's algorithm
The sender transmits the first small piece promptly, then buffers subsequent small writes while an earlier small piece is still unacknowledged, unless enough bytes accumulate to transmit a full MSS. This reduces the number of small packets but can introduce delay for interactive workloads. The socket option TCP_NODELAY is commonly used to disable Nagle's algorithm where appropriate.
6.5 Silly window syndrome (SWS)
When the receiving application reads only one byte at a time, the receiver may repeatedly advertise one byte of free space; the sender responds with 1-byte data segments and disproportionate header overhead. In the textbook's Clark approach, the receiver avoids issuing tiny updates until it can accept at least an MSS or half its buffer, whichever is smaller.
Nagle → Sender side
Controls tiny writes from sending applications, preferring fewer, larger segments.
Clark → Receiver side
Controls tiny window advertisements caused by receiver reads, preferring useful space increments.
7. Flow Control vs. Error Control vs. Congestion Control
| Aspect | Flow control | Error control | Congestion control |
|---|---|---|---|
| Primary concern | Receiver cannot accept more bytes | Bytes lost/corrupted/out of order | Network cannot carry offered load |
| Key TCP signals | Advertised rwnd | ACK, sequence numbers, SACK, retransmission timer | Sender's cwnd, loss/ECN feedback |
| Important mechanism | Variable-size sliding window | Checksum, cumulative ACK, retransmission | Slow Start, AIMD, congestion avoidance |
| Can sender continue? | Only while permitted by receive window | May retransmit lost data | Subject to current congestion window |
Forouzan comparison: TCP's window has aspects of both Go-Back-N and Selective Repeat. Cumulative ACKing resembles Go-Back-N; buffering out-of-order data resembles Selective Repeat. However, TCP is byte-oriented, not simply either of those frame-oriented protocols.
8. Solved TCP Sliding-Window Numerical Problems
Example 1 — Receiver-window calculation (Forouzan Example 23.4)
Given: Receive buffer capacity = 5000 B; unread data = 1000 B.
Answer: rwnd = 4000 bytes.
Example 2 — Effective window (Forouzan Example 23.5)
Given: rwnd = 3000 B, cwnd = 3500 B.
Answer: 3000 bytes; receiver window is limiting.
Example 3 — Outstanding bytes and usable space (Forouzan Example 23.6)
Given: ACK = 200, rwnd = 9, cwnd = 20; bytes 200–202 already sent.
The effective window covers bytes 200–208, so 3 are outstanding and 6 new bytes remain sendable.
Answer: bytes 203–208 may be sent; byte 209 cannot.
Example 4 — TCP cumulative acknowledgement after a gap
Received 1000–1499; missing 1500–1999; received and buffered 2000–2499 and 2500–2999.
Answer before retransmission: ACK = 1500.
After the missing 1500–1999 bytes arrive:
Answer after retransmission: ACK = 3000.
Example 5 — How much data can be sent next?
Given: rwnd = 12 KiB; cwnd = 8 KiB; bytes still unacknowledged = 3 KiB.
Answer: 5 KiB, under the simplified aligned-window assumption.
Example 6 — Zero-window reopening
Given: Receiver buffer = 4096 B, initially full (rwnd = 0). Application reads 1536 B, and no additional data arrive.
Answer: Receiver can advertise a 1536-byte window when it sends a window update.
Example 7 — Window scaling
Given: Advertised TCP window field = 3000 and negotiated window-scale shift = 3.
Answer: 24,000 bytes (assumes scaling successfully negotiated).
Example 8 — Window-limited throughput
Given: An effective window of 65,536 B and round-trip time = 0.100 seconds.
Answer: approximately 5.243 Mbps.
This is a simplified window/RTT estimate, not guaranteed TCP goodput.
Example 9 — Calculate send window right edge
Given: Cumulative ACK=8000, advertised rwnd=2500 bytes, and no extra cwnd restriction.
Answer: Byte positions 8000–10,499 fall inside the advertised receive window.
Example 10 — Sequence and ACK with two in-order segments
Segment A starts SEQ=10,001 and carries 1000 B. Segment B starts SEQ=11,001 and carries another 1000 B; both arrive in order.
Answer: ACK = 12,001.
These problems are original exam exercises unless explicitly attributed to a numbered Forouzan example.
9. APPSC / UGC NET / GATE — 20 Practice MCQs
The questions below are original exam-style practice questions, not claims of verbatim previous-year questions. Choose one answer per question, then click Check Answers.
1. TCP sliding-window units are primarily:
2. The TCP advertised receiver window chiefly prevents:
3. If rwnd=4000 bytes and cwnd=6000 bytes, the effective window is:
4. A receiver buffer is 5000 bytes and 1000 bytes are unread. What is rwnd?
5. ACK=200 and rwnd=9 advertise a receive window covering which bytes?
6. In Forouzan Example 23.6, bytes 200–202 are unacknowledged, rwnd=9. How many new bytes may be sent?
7. TCP cumulative ACK number usually specifies:
8. Seq=3000, data length=500, no SYN/FIN: next expected ACK?
9. Segments 1000–1499 received, 1500–1999 lost, 2000–2499 received: cumulative ACK?
10. When the missing 1500–1999 bytes then arrive, and 2000–2499 are buffered, ACK becomes:
11. What does a TCP advertised window of 0 normally mean?
12. Why does TCP use zero-window probes?
13. Which issue is associated with advertising repeated tiny windows?
14. Clark’s receiver-side approach to silly window syndrome waits for:
15. Nagle’s algorithm primarily aims to reduce:
16. What can a delayed acknowledgement try to achieve?
17. TCP's receiver window and congestion window are:
18. Window scaling with shift count 3 and header window 3000 gives:
19. Which is a valid outcome of out-of-order TCP reception in the textbook?
20. If effective window=8192 B and 3072 B remain outstanding, what is the simplified new-send allowance?
10. FAQs and Quick Revision
What is the TCP sliding window?
It is the moving range of bytes a TCP sender is permitted to have outstanding. Its effective size is limited by receiver flow control and network congestion control.
Is TCP sliding window based on bytes or segments?
TCP sliding-window accounting is byte-oriented. A segment can carry many numbered bytes.
How is the TCP receiver window calculated?
For a simplified receive buffer: rwnd = buffer capacity − currently occupied receive bytes. The receiver advertises its available space.
What is the difference between rwnd and cwnd?
rwnd protects the receiver and is advertised by it; cwnd is maintained by the sender to help avoid congesting the network.
Can a TCP ACK advance across a missing segment?
Not as a cumulative ACK. It remains at the first missing byte, although SACK can separately report later received ranges.
What happens when the receiver advertises a zero window?
New normal data transmission pauses; TCP can use a window probe to discover when the receiver window reopens.
What is silly window syndrome?
It is inefficient TCP behavior involving tiny window updates or tiny transmitted segments, leading to disproportionate header and acknowledgement overhead.
What is Nagle's algorithm?
A sender-side optimization that combines small application writes into larger segments while limiting unacknowledged small sends.
How does a sliding window improve link utilization?
It permits multiple bytes or segments to remain in flight during a round-trip time instead of stopping after every send.
What is the formula for a TCP window-limited throughput estimate?
An approximate upper bound, when a fixed window is the bottleneck, is 8 × window bytes / RTT seconds, in bits per second.
Last-minute formula sheet
| Formula | Application |
|---|---|
rwnd = Buffer − Occupied | Simplified receiver buffer availability |
Effective window = min(rwnd,cwnd) | Actual limiting TCP window (basic exam model) |
Available send = Effective − In-flight | Additional new data, given compatible window boundaries |
Right edge = ACK + rwnd − 1 | Receive-window byte range |
Next ACK = first missing byte | Cumulative ACK logic |
Window scaling = field × 2^shift | When negotiated |
Rate ≈ Window × 8 / RTT | Ideal window-limited throughput in bit/s |
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.