📡 Tutorial 7: TCP Reliable Data Transfer and Flow Control (Advanced)

University‑level treatment – COMP347 (TrustOpen University)

Table of Contents

🎯 Learning Objectives

After completing this tutorial, you should be able to:

🔍 Overview

TCP’s reliable data transfer is a sophisticated combination of sliding‑window flow control, cumulative acknowledgments, timeouts, and retransmissions. This tutorial dives into the operational details of the sender and receiver, the precise handling of timeouts and duplicate ACKs, and the fast retransmit/fast recovery mechanisms that improve performance. We also explore flow control in depth—how the receiver advertises its available buffer space, how zero‑window conditions are managed, and how both sender and receiver cooperate to avoid Silly Window Syndrome. These mechanisms are the backbone of TCP’s robustness and efficiency in the Internet.

📘 1. Overview of TCP Reliable Data Transfer

TCP provides reliable, ordered delivery of a byte stream. It achieves this by:

TCP’s reliability is a hybrid of Go‑Back‑N (cumulative ACKs) and Selective Repeat (fast retransmit for individual packets), with SACK providing even finer granularity.

📘 2. TCP Sender Finite‑State Machine

The TCP sender can be modeled as a finite‑state machine with the following states and transitions:

The sender also maintains variables: SendBase (oldest unacknowledged byte), NextSeqNum (next byte to send), and window (min(cwnd, rwnd)).

2.1 Sender Pseudocode

Initialize: SendBase = 0, NextSeqNum = 0, dupACKcount = 0

rdt_send(data):
    if NextSeqNum < SendBase + window:
        create segment with seq = NextSeqNum, send it
        if SendBase == NextSeqNum: start timer
        NextSeqNum += length(data)
    else:
        buffer data (or block)

rdt_rcv(ACK):
    if ACKnum > SendBase:
        SendBase = ACKnum
        if SendBase == NextSeqNum: stop timer
        else: restart timer
        dupACKcount = 0
    else if ACKnum == SendBase:
        dupACKcount += 1
        if dupACKcount == 3:
            retransmit segment with seq = SendBase
            dupACKcount = 0
            // (fast retransmit)
    // ignore if ACKnum < SendBase

timeout:
    retransmit segment with seq = SendBase
    restart timer
    // (exponential backoff may apply)
    

📘 3. TCP Receiver Behaviour and ACK Generation

The receiver’s actions are defined in RFC 5681:

The receiver maintains the variable ExpectedSeqNum (the next byte expected). When a segment arrives with sequence number exactly ExpectedSeqNum, it delivers the data and advances ExpectedSeqNum past any contiguous buffered data, then sends a cumulative ACK.

📘 4. Timer Management and Retransmission Strategies

TCP uses a single retransmission timer for the oldest unacknowledged segment. When that segment’s ACK arrives, the timer is restarted for the next oldest segment. This is simpler than per‑packet timers.

On timeout:

Exponential backoff: After a timeout, the RTO is doubled (up to a maximum) to avoid repeated retransmissions when the network is congested.

📘 5. Fast Retransmit and Fast Recovery

Fast retransmit: When the sender receives 3 duplicate ACKs (i.e., 4 total ACKs for the same byte), it assumes the segment with sequence number SendBase was lost and retransmits it immediately, without waiting for the timeout. This reduces recovery time significantly.

Fast recovery (in TCP Reno): After fast retransmit, the sender sets ssthresh = cwnd/2 and cwnd = ssthresh + 3*MSS (to account for the segments already ACKed), then enters congestion avoidance. This avoids the slow start phase after a loss, improving throughput.

These mechanisms are critical for TCP performance in modern networks.

📘 6. Flow Control: The Advertised Window (rwnd)

Flow control is a separate mechanism from congestion control. The receiver advertises a receive window (rwnd) in each ACK, indicating the amount of free buffer space. The sender limits the amount of unacknowledged data to min(cwnd, rwnd).

The receiver’s buffer is divided into:

The advertised window is computed as:

rwnd = buffer size - (LastByteReceived - LastByteRead)

where LastByteReceived is the highest sequence number received, and LastByteRead is the highest sequence number read by the application.

📘 7. Zero‑Window Probing and Persistent Timer

If rwnd = 0, the sender stops sending data. However, the receiver may later free buffer space and send an ACK with a non‑zero window. If that ACK is lost, the sender would wait forever. To prevent deadlock, the sender uses a persistent timer. When the persistent timer expires, the sender sends a zero‑window probe (a single byte of data) to the receiver. The receiver responds with an ACK containing the current window. If the window is still zero, the persistent timer is reset with exponential backoff.

📘 8. Silly Window Syndrome (SWS) Avoidance

Silly Window Syndrome occurs when the receiver advertises very small windows (e.g., a few bytes), and the sender sends tiny segments, leading to poor network utilization. Both sides take action:

These mechanisms prevent the inefficient transmission of many small packets.

📘 9. TCP Buffering and Window Update Semantics

The send buffer holds data sent but not yet ACKed. The receive buffer holds data received but not yet read. When the application reads data, the receiver’s window opens. The receiver may send a window update (an ACK with a new rwnd) even without receiving new data to inform the sender of the increased space. This is called a window update.

📘 10. Advanced Topics: ACK Clocking, Cumulative vs. Selective ACKs

ACK clocking: In steady state, TCP’s transmission is paced by the rate of incoming ACKs. Each ACK allows the sender to transmit a new segment (if window permits). This self‑clocking helps maintain smooth traffic and is important for congestion control.

Cumulative ACKs are simple but can cause unnecessary retransmissions if multiple packets are lost. Selective ACKs (SACK) allow the receiver to inform the sender of non‑contiguous blocks of received data, enabling selective retransmission and improving performance under loss.

📝 Quiz

Test your understanding with these 35 questions. Answers are hidden below each.

  1. What event triggers a TCP timeout retransmission?
    AnswerThe retransmission timer expires for the oldest unacknowledged segment.
  2. What does TCP do when it receives a duplicate ACK?
    AnswerIt increments the duplicate ACK count; after 3 duplicate ACKs, it triggers fast retransmit.
  3. What is the purpose of fast retransmit?
    AnswerTo retransmit a lost segment before the timeout expires, reducing recovery time.
  4. How many duplicate ACKs are needed to trigger fast retransmit?
    Answer3 duplicate ACKs (i.e., total 4 ACKs for the same byte).
  5. What is the difference between fast retransmit and timeout retransmission?
    AnswerFast retransmit occurs after 3 duplicate ACKs without waiting for timeout; timeout retransmission occurs when the timer expires.
  6. What is the purpose of the advertised window (rwnd)?
    AnswerTo inform the sender of the receiver’s available buffer space for flow control.
  7. How is rwnd computed at the receiver?
    Answerrwnd = buffer size - (LastByteReceived - LastByteRead).
  8. What happens when rwnd becomes 0?
    AnswerThe sender stops sending data and starts a persistent timer to probe for window updates.
  9. What is a zero‑window probe?
    AnswerA segment with 1 byte of data sent by the sender when rwnd=0 to check if the window has opened.
  10. What is the persistent timer used for?
    AnswerTo prevent deadlock when rwnd=0 and the window update ACK is lost; it triggers zero‑window probes.
  11. What is Silly Window Syndrome (SWS)?
    AnswerA condition where small window advertisements cause the sender to send tiny segments, wasting bandwidth.
  12. How does the receiver avoid SWS?
    AnswerBy not advertising a window smaller than the MSS or a threshold, and delaying window updates until they are significant.
  13. How does the sender avoid SWS?
    AnswerBy using Nagle’s algorithm (buffering small data) and not sending segments smaller than the MSS unless it has a full buffer.
  14. What is Nagle’s algorithm?
    AnswerAn algorithm that reduces small packet transmissions by buffering small data until an ACK arrives or the segment reaches the MSS.
  15. What is a delayed ACK?
    AnswerAn ACK that is delayed up to 500 ms in the hope of piggybacking on outgoing data, reducing ACK overhead.
  16. How does the TCP sender’s window size affect throughput?
    AnswerA larger window allows more data in flight, increasing throughput up to the bandwidth‑delay product.
  17. What is ACK clocking?
    AnswerThe pacing of sender transmissions by the arrival of ACKs, which helps smooth traffic.
  18. What is the advantage of SACK over cumulative ACKs?
    AnswerSACK allows selective retransmission of only lost packets, improving performance under loss.
  19. When does TCP use exponential backoff for RTO?
    AnswerAfter a timeout, the RTO is doubled to reduce network load.
  20. What is the purpose of the SendBase variable?
    AnswerIt is the sequence number of the oldest unacknowledged byte (the left edge of the send window).
  21. What is NextSeqNum?
    AnswerThe sequence number of the next byte to be sent (the right edge of the send window).
  22. How does the receiver handle an out‑of‑order segment?
    AnswerIt buffers the segment and sends a duplicate ACK for the next expected byte.
  23. How does the receiver handle a duplicate segment?
    AnswerIt discards the duplicate and sends an ACK for the next expected byte.
  24. What is a window update?
    AnswerAn ACK segment that updates the advertised window (rwnd) without containing new data.
  25. What is the effect of a very small rwnd on TCP performance?
    AnswerIt limits the sender’s throughput, potentially underutilizing the network.
  26. What is the relationship between rwnd and the receive buffer?
    Answerrwnd = buffer size - unread data; it represents the free space.
  27. What is the purpose of the dupACKcount variable?
    AnswerTo count the number of duplicate ACKs received, used to trigger fast retransmit.
  28. What happens to dupACKcount when a new cumulative ACK arrives?
    AnswerIt is reset to 0.
  29. Can TCP send data while rwnd=0?
    AnswerIt cannot send normal data, but it may send zero‑window probes (1 byte).
  30. What is the difference between flow control and congestion control?
    AnswerFlow control prevents receiver overload; congestion control prevents network overload.
  31. How does fast recovery differ from slow start?
    AnswerFast recovery after fast retransmit sets cwnd to ssthresh (half) and grows linearly (congestion avoidance), avoiding slow start’s exponential growth.
  32. What is the role of the ssthresh variable in TCP?
    AnswerSlow start threshold; when cwnd reaches ssthresh, TCP switches from slow start to congestion avoidance.
  33. Why does TCP use a single timer for the oldest segment instead of per‑packet timers?
    AnswerTo reduce overhead; it works because cumulative ACKs acknowledge all earlier packets.
  34. What is a window scale option?
    AnswerAn option that allows the advertised window to be scaled, enabling windows larger than 65535 bytes.
  35. How does TCP handle a retransmitted segment if the original segment was already received?
    AnswerThe receiver discards the duplicate and sends an ACK for the next expected byte.

🛠️ Exercises

Apply your knowledge with these 20 exercises. Solutions are provided below each.

  1. Exercise 1: Sender State Update
    A TCP sender has SendBase = 1000, NextSeqNum = 1200, window = 500. It receives an ACK with ACKnum = 1100. What are the new SendBase and NextSeqNum?
    SolutionSendBase = 1100, NextSeqNum remains 1200 (since the ACK acknowledges up to 1099). The window allows sending up to 1100+500=1600, so NextSeqNum can advance if data available.
  2. Exercise 2: Duplicate ACK Count
    A sender receives three duplicate ACKs in a row. What does it do?
    SolutionIt triggers fast retransmit: retransmits the segment with sequence number equal to SendBase.
  3. Exercise 3: Timeout Retransmission
    After a timeout, the sender retransmits the oldest segment. What else happens to the timer?
    SolutionThe timer is restarted (with possible exponential backoff) for the same segment.
  4. Exercise 4: Advertised Window Calculation
    Receiver buffer size = 8192 bytes. LastByteRead = 2000, LastByteReceived = 5000. What is rwnd?
    Solutionrwnd = 8192 - (5000 - 2000) = 8192 - 3000 = 5192 bytes.
  5. Exercise 5: Zero‑Window Scenario
    If rwnd = 0, the sender stops sending. How does it know when to resume?
    SolutionIt sends zero‑window probes periodically until it receives an ACK with a non‑zero rwnd.
  6. Exercise 6: SWS Avoidance on Receiver
    A receiver has 100 bytes free. Should it advertise 100 bytes? Explain.
    SolutionNo, it should not advertise such a small window to avoid SWS. It should wait until the free space reaches the MSS or a threshold.
  7. Exercise 7: Nagle’s Algorithm Effect
    An application sends 10 bytes every 10 ms. Nagle’s algorithm is enabled. How does this affect transmission?
    SolutionThe first byte may be sent immediately; subsequent bytes may be buffered until an ACK is received or enough data accumulates, increasing latency but reducing the number of small packets.
  8. Exercise 8: Delayed ACK Impact
    A receiver delays ACKs for 200 ms. How might this affect the sender’s RTT estimation?
    SolutionIt increases the measured RTT, potentially causing the sender to set a larger RTO, which can reduce performance.
  9. Exercise 9: Fast Retransmit Trigger
    How many duplicate ACKs are needed for fast retransmit? What if only 2 duplicates arrive?
    Solution3 duplicate ACKs are needed. With 2, the sender continues waiting; it may later timeout if no further ACKs arrive.
  10. Exercise 10: Persistent Timer
    Why is the persistent timer needed in addition to the retransmission timer?
    SolutionThe persistent timer handles the case where rwnd=0 and the window update ACK is lost, preventing deadlock.
  11. Exercise 11: ACK Clocking Example
    In steady state, an ACK arrives for a segment. How does this allow the sender to send a new segment?
    SolutionThe ACK slides the window, freeing up space; the sender can then transmit a new segment if data is available.
  12. Exercise 12: Cumulative vs. SACK
    If two segments are lost (e.g., seq 100 and 300) but intervening segments are received, how does cumulative ACK behave compared to SACK?
    SolutionCumulative ACK only acknowledges up to the highest in‑order byte, so it only indicates the first loss. SACK can specify both gaps, allowing the sender to retransmit both without waiting.
  13. Exercise 13: RTO Doubling
    After a timeout, the RTO is doubled. Why is this necessary?
    SolutionTo reduce the sending rate and alleviate potential network congestion.
  14. Exercise 14: Send Window Limitation
    If cwnd = 4000, rwnd = 2000, what is the effective window size?
    Solutionmin(cwnd, rwnd) = 2000 bytes.
  15. Exercise 15: Receiver Buffer Full
    If the receive buffer is full (rwnd=0) and the sender sends a zero‑window probe, what does the receiver respond with?
    SolutionIt responds with an ACK containing the current rwnd (which may still be 0) and the acknowledgment number.
  16. Exercise 16: Fast Recovery
    After fast retransmit, what happens to cwnd and ssthresh in TCP Reno?
    Solutionssthresh = cwnd/2; cwnd = ssthresh + 3*MSS; then congestion avoidance.
  17. Exercise 17: Duplicate ACK Handling
    A sender receives an ACK with ACKnum less than SendBase. How does it handle it?
    SolutionIt ignores it (it's a duplicate ACK for an already acknowledged segment).
  18. Exercise 18: Window Update without Data
    Can a receiver send an ACK that only updates the window (no data)?
    SolutionYes, when the application reads data from the buffer, the receiver may send a window update to inform the sender.
  19. Exercise 19: SWS Avoidance Sender Side
    How does Nagle’s algorithm help prevent SWS?
    SolutionIt buffers small amounts of data until either an ACK arrives or enough data to fill a maximum segment, preventing many tiny segments.
  20. Exercise 20: Throughput Calculation
    If window = 64 KB and RTT = 100 ms, what is the maximum throughput?
    SolutionThroughput = (64 * 1024 * 8) / 0.1 = 524,288 bits/sec ≈ 5.24 Mbps.

📚 Homework

These advanced problems require synthesis, research, and quantitative analysis. Sample answers are provided below.

  1. Problem 1: Sender FSM Formalization
    Provide a formal FSM specification of the TCP sender including all states, events, and actions, covering both normal operation and fast retransmit.
    Sample AnswerStates: Ready, WaitingForACK (when at least one segment outstanding). Transitions: on rdt_send if window not full -> send segment, start timer; on ACK with acknum > SendBase -> slide window, reset dupACKcount, restart timer; on ACK with acknum == SendBase -> increment dupACKcount, if count==3 -> fast retransmit; on timeout -> retransmit oldest, double RTO.
  2. Problem 2: Derive Fast Retransmit Behavior
    Explain why fast retransmit uses 3 duplicate ACKs, not 2 or 4. What are the trade‑offs?
    Sample Answer3 is a compromise: 2 might cause spurious retransmissions due to packet reordering; 4 would delay recovery too long. It is based on empirical observation that 3 duplicates indicates a lost segment.
  3. Problem 3: Flow Control and Congestion Control Interaction
    How does the sender use both rwnd and cwnd? What happens if one is smaller than the other?
    Sample AnswerSender uses min(cwnd, rwnd) as the effective window. If rwnd < cwnd, flow control is the bottleneck; if cwnd < rwnd, congestion control is the bottleneck.
  4. Problem 4: Zero‑Window Probing and RTT Estimation
    Should zero‑window probes affect the RTT estimation? Why or why not?
    Sample AnswerNo, because they are not normal data segments; they are probes. They may be retransmitted without ACK, so they should not be used for RTT measurement.
  5. Problem 5: Delayed ACK and Fast Retransmit
    Can delayed ACKs interfere with fast retransmit? How?
    Sample AnswerDelayed ACKs can reduce the number of duplicate ACKs sent, delaying fast retransmit. However, the standard ensures that duplicate ACKs are sent for out‑of‑order segments, so it usually works.
  6. Problem 6: SWS Avoidance Algorithm
    Describe the receiver‑side SWS avoidance algorithm in detail, including the conditions for sending a window update.
    Sample AnswerThe receiver should send a window update only when the available space is at least the MSS (or half the buffer). This prevents advertising tiny windows.
  7. Problem 7: Timer Granularity and Performance
    If the timer granularity is coarse (e.g., 100 ms), how does that affect TCP performance? Derive the impact on throughput for a given RTT.
    Sample AnswerA coarse timer causes the RTO to be larger, increasing idle time and reducing throughput, especially when RTT is small.
  8. Problem 8: Cumulative ACK and Duplicate ACK Count
    Why does the sender not count duplicate ACKs that acknowledge a byte beyond SendBase?
    Sample AnswerIf an ACK acknowledges beyond SendBase, it slides the window, so it's a new ACK, not a duplicate. Duplicates are only those with acknum == SendBase.
  9. Problem 9: Fast Recovery Details
    Explain the difference between TCP Tahoe and TCP Reno in handling fast retransmit.
    Sample AnswerTahoe after fast retransmit sets cwnd to 1 MSS and goes to slow start. Reno uses fast recovery: sets cwnd to ssthresh+3*MSS, then grows linearly.
  10. Problem 10: Impact of Buffer Size on Throughput
    Derive the relationship between receiver buffer size and achievable throughput for a given RTT and bandwidth. What is the minimum buffer size needed to achieve 100 Mbps over a 100 ms RTT?
    Sample AnswerBuffer size must be at least BDP = bandwidth * RTT = 100e6 * 0.1 = 10,000,000 bits = 1.25 MB.
  11. Problem 11: Zero‑Window Deadlock Scenario
    Describe a scenario where a zero‑window condition could lead to deadlock if persistent timers were not used.
    Sample AnswerReceiver advertises window 0, sender stops. Receiver later frees buffer and sends ACK with window >0, but that ACK is lost. Sender waits forever; persistent timer breaks deadlock.
  12. Problem 12: ACK Piggybacking and Delayed ACKs
    How do delayed ACKs interact with piggybacking on data?
    Sample AnswerIf the receiver has outgoing data, it can piggyback the ACK on that data; if not, it delays the ACK to allow for piggybacking.
  13. Problem 13: SACK and Reno Integration
    How does SACK improve upon Reno’s fast recovery?
    Sample AnswerSACK provides information about which segments have been received, allowing the sender to retransmit only the missing ones during recovery, improving efficiency.
  14. Problem 14: Window Update Loss
    If a window update ACK is lost, the sender may have a stale small window. How does the system recover?
    Sample AnswerThe sender may use a zero‑window probe if the window is 0; if the window is non‑zero but small, the sender may eventually timeout or the receiver may send another update.
  15. Problem 15: Throughput with Loss and Fast Recovery
    Derive a simplified expression for TCP throughput incorporating loss rate p, RTT, and MSS, considering fast retransmit/recovery.
    Sample AnswerA common approximation: Throughput ≈ (1.22 * MSS) / (RTT * sqrt(p)). This is derived from the square root law for TCP Reno.

📌 Summary

In the next tutorial, we will cover TCP Connection Establishment and Termination.

COMP347 – Computer Networks (Rev. 10) · TrustOpen University · Based on Kurose & Ross, Computer Networking: A Top‑Down Approach, 9th ed. (2025).