📡 Tutorial 4: Principles of Reliable Data Transfer – Advanced
University‑level treatment – COMP347 (TrustOpen University)
🎯 Learning Objectives
After completing this tutorial, you should be able to:
- Explain the core challenges of reliable data transfer over an unreliable network layer.
- Model reliable protocols using finite‑state machines (FSMs) and understand state transitions.
- Describe the role of checksums, acknowledgments (ACKs), negative acknowledgments (NAKs), sequence numbers, and timeouts in achieving reliability.
- Analyze the operation of stop‑and‑wait (rdt3.0) protocols and derive their performance limits.
- Evaluate the impact of the bandwidth‑delay product on protocol efficiency.
- Compare stop‑and‑wait with pipelined approaches and justify the need for pipelining in high‑speed networks.
🔍 Overview
Reliable data transfer (RDT) is a fundamental problem in computer networking. The network layer (IP) provides a best‑effort service: packets may be lost, corrupted, or reordered. The transport layer must mask these imperfections and provide a reliable, ordered, error‑free service to applications. This tutorial systematically develops the principles of RDT, starting from simple protocols and gradually adding mechanisms to handle increasingly complex failure scenarios. We use finite‑state machines to rigorously specify protocol behaviour, and we analyse the performance of stop‑and‑wait protocols to understand why more sophisticated pipelined protocols are needed for modern networks.
📘 1. The Reliable Data Transfer Problem
Consider a sender that wants to send a stream of data to a receiver across an unreliable channel. The channel may:
- Corrupt bits (bit errors).
- Lose packets (packet drops).
- Reorder packets (out‑of‑order delivery).
- Duplicate packets (due to retransmissions).
The goal of a reliable data transfer protocol is to ensure that the receiver delivers an exact, in‑order copy of the sender’s data to the application, despite these imperfections. The protocol operates at the transport layer, using the network layer’s unreliable service.
We abstract the sender and receiver as two processes that exchange messages (packets) over an unreliable channel. The protocol is defined by the actions taken upon events: data from the application, packet arrival from the network, and timeout expiration.
📘 2. Formal Modeling with Finite‑State Machines
A finite‑state machine (FSM) is a mathematical model used to specify the behaviour of a protocol. It consists of:
- A finite set of states.
- A set of transitions triggered by events.
- Actions that occur during transitions (e.g., send a packet, start a timer).
For a reliable data transfer protocol, we typically model the sender and receiver separately. Each has an FSM that describes its response to events. For example, the sender might have states: Wait for data from application, Wait for ACK, etc. Transitions occur on events like rdt_send(data) (application calls send), rdt_rcv(packet) (a packet arrives from the network), and timeout.
FSMs are crucial for proving correctness and detecting design flaws. They are also used in protocol specification documents.
📘 3. Basic Mechanisms
3.1 Error Detection
To detect corrupted packets, we add a checksum field to the packet. The receiver verifies the checksum; if it fails, the packet is discarded. This is the first line of defence against bit errors.
3.2 Acknowledgments (ACKs) and Negative Acknowledgments (NAKs)
- ACK: The receiver sends a positive acknowledgment to confirm correct receipt.
- NAK: The receiver sends a negative acknowledgment to indicate that the packet was corrupted.
Using ACKs, the sender knows when to send the next packet. Using NAKs, the sender can retransmit a corrupted packet without waiting for a timeout (though timeouts are still needed for lost packets).
3.3 Sequence Numbers
Sequence numbers are used to distinguish between different packets, especially when retransmissions occur. Without sequence numbers, the receiver could not tell if an incoming packet is a new packet or a duplicate. For stop‑and‑wait, a 1‑bit sequence number (0 and 1) is sufficient because only one packet is outstanding at a time.
3.4 Timeouts and Retransmissions
If a packet or its ACK is lost, the sender will never receive an acknowledgment. To recover, the sender sets a timer when sending a packet. If the timer expires before an ACK arrives, the sender retransmits the packet. This is the fundamental mechanism for handling packet loss.
📘 4. Stop‑and‑Wait Protocol (rdt3.0)
The stop‑and‑wait protocol (also called rdt3.0) is the simplest reliable protocol that handles packet loss and corruption. It works as follows:
- The sender sends one packet and then waits for an ACK.
- It uses a 1‑bit sequence number to detect duplicates.
- It uses a checksum for error detection.
- The receiver sends an ACK if the packet is correctly received; if corrupted, it discards and waits (no NAK).
- The sender uses a timeout to retransmit if no ACK arrives within a certain period.
The sender FSM has two main states: Wait for call from above (ready to send) and Wait for ACK (packet sent, timer running). The receiver FSM has one state: Wait for packet.
The protocol handles:
- Corruption: checksum detects corruption, packet discarded, sender times out and retransmits.
- Loss: timer expires, sender retransmits.
- Duplicate ACKs/packets: sequence numbers allow receiver to discard duplicates and sender to ignore duplicate ACKs.
Despite its correctness, stop‑and‑wait is inefficient for high‑bandwidth or long‑distance networks because the sender spends most of the time waiting for ACKs.
📘 5. Performance Analysis of Stop‑and‑Wait
The performance of stop‑and‑wait is determined by the utilization (or efficiency) of the link:
U = t_trans / (t_trans + 2 * t_prop)
where:
t_trans = transmission time of the packet (L / R, where L is packet size in bits, R is bandwidth).
t_prop = propagation delay (distance / speed of light).
- The factor 2 accounts for the round‑trip time (RTT) = 2 * t_prop (assuming negligible processing and queueing).
This formula ignores the time to transmit the ACK (which is usually small).
The maximum throughput is U * R. For example, with a 1 Gbps link, 100 ms RTT, and 1500‑byte packets, the utilization is about 0.012%, meaning the effective throughput is only ~120 kbps. This is clearly insufficient.
The key limitation is the bandwidth‑delay product: the amount of data that can be in transit (BDP = R * RTT). For stop‑and‑wait to fully utilise the link, the packet size must be at least as large as BDP, which is often impractical.
📘 6. The Bandwidth‑Delay Product and Link Utilization
The bandwidth‑delay product (BDP) is the number of bits that can be in the pipeline (in transit) at any time. To achieve 100% utilization, the sender must have enough data in flight to fill the pipe. In stop‑and‑wait, the amount of data in flight is at most one packet. If the packet size is smaller than BDP, the link is underutilized.
To improve utilization, we need a protocol that allows multiple packets to be outstanding simultaneously – a pipelined protocol. This is the motivation for Go‑Back‑N and Selective Repeat, covered in the next tutorial.
📘 7. Limitations and the Need for Pipelining
Stop‑and‑wait has several drawbacks:
- Low throughput: for large BDP, utilization is very low.
- Inefficient for long RTT: even with moderate bandwidth, long RTTs cause poor performance.
- Limited by packet size: even with large packets, the waiting time dominates.
These limitations led to the development of pipelined protocols, where the sender can transmit multiple packets before waiting for ACKs. The window size determines how many packets can be in flight, allowing the sender to fill the BDP. We will explore Go‑Back‑N and Selective Repeat in Tutorial 5.
📘 8. Advanced Topics: Duplicate Suppression and Cumulative ACKs
8.1 Duplicate Suppression
In stop‑and‑wait, sequence numbers (0 and 1) are sufficient to avoid ambiguity between a new packet and a retransmission. However, if the sender receives a duplicate ACK (e.g., because the receiver sent an ACK that was delayed), the sender must ignore it. The FSM design ensures that duplicate ACKs are simply ignored because the sender only transitions on the first ACK.
8.2 Cumulative ACKs (preview)
In pipelined protocols, cumulative ACKs (where an ACK acknowledges all packets up to a sequence number) reduce the number of ACKs sent and simplify receiver logic. This concept is central to TCP and will be covered in detail later.
8.3 Timer Management
In stop‑and‑wait, a single timer is sufficient. In pipelined protocols, multiple timers or a single timer for the oldest packet may be used (as in Go‑Back‑N). The choice affects performance.
📝 Quiz
Test your understanding with these 25 questions. Answers are hidden below each.
- What is the primary goal of a reliable data transfer protocol?
Answer
To deliver an exact, in‑order copy of the sender's data to the receiver despite packet corruption, loss, reordering, or duplication.
- What is the role of a checksum in reliable data transfer?
Answer
To detect bit errors in a received packet.
- What is an ACK and what is a NAK?
Answer
ACK = positive acknowledgment; NAK = negative acknowledgment, indicating corruption.
- Why are sequence numbers needed in reliable protocols?
Answer
To distinguish between new packets and retransmissions, and to detect duplicates.
- How does the sender detect packet loss in a stop‑and‑wait protocol?
Answer
Using a timeout; if an ACK does not arrive within a specified time, the sender retransmits the packet.
- What is the minimum number of sequence bits needed for stop‑and‑wait?
Answer
1 bit (0 and 1) because only one packet is outstanding.
- In stop‑and‑wait, what happens if a packet is corrupted?
Answer
The receiver discards it (silently) and does not send an ACK. The sender times out and retransmits.
- How does stop‑and‑wait handle duplicate packets?
Answer
The receiver uses the sequence number to detect duplicates; if the sequence number is the same as the last received, it discards the packet but sends an ACK.
- Define utilization in the context of stop‑and‑wait.
Answer
The fraction of time the sender is actually transmitting data, i.e., t_trans / (t_trans + 2*t_prop).
- What is the bandwidth‑delay product?
Answer
The amount of data that can be in transit in the network at any time, equal to bandwidth multiplied by RTT.
- Why is stop‑and‑wait inefficient for high‑speed networks?
Answer
Because the sender spends most of its time waiting for ACKs, resulting in low link utilization.
- What is the effect of a long RTT on stop‑and‑wait performance?
Answer
It increases the waiting time, reducing utilization and effective throughput.
- How can the utilization of stop‑and‑wait be improved?
Answer
By increasing the packet size (L) or decreasing propagation delay, but fundamentally a pipelined protocol is needed.
- What is a finite‑state machine (FSM) and why is it used in protocol design?
Answer
An FSM is a model of states and transitions; it is used to rigorously specify and verify protocol behaviour.
- In the sender FSM for stop‑and‑wait, what event triggers the transition from "Wait for ACK" to "Wait for call from above"?
Answer
The receipt of an ACK for the sent packet.
- What event keeps the sender in the "Wait for ACK" state?
Answer
Timeout or receipt of a NAK (or corrupted ACK).
- How does the receiver FSM handle a corrupted packet?
Answer
It discards the packet and remains in the same state, waiting for a new packet.
- Is a NAK strictly necessary in stop‑and‑wait?
Answer
No; the protocol can rely on timeouts for both corruption and loss, as in rdt3.0 which does not use NAKs.
- What is the purpose of the timer in the sender?
Answer
To trigger retransmission if an ACK is not received within a reasonable time, handling loss.
- How does the receiver distinguish between a duplicate packet and a new packet?
Answer
By comparing the sequence number of the received packet with the sequence number of the last packet it accepted.
- In stop‑and‑wait, can the sender send a new packet before receiving an ACK?
Answer
No, it must wait for the ACK.
- What is the maximum throughput of a stop‑and‑wait link with bandwidth R and packet size L?
Answer
Throughput = (L / (L/R + RTT)) = R * (L / (L + R*RTT)).
- What happens if the ACK is lost in stop‑and‑wait?
Answer
The sender times out and retransmits the packet. The receiver gets a duplicate, discards it, but sends another ACK.
- What is the main drawback of using a single timer in stop‑and‑wait?
Answer
Since only one packet is outstanding, a single timer is sufficient, but it cannot be reused for pipelining.
- How does stop‑and‑wait handle packet reordering?
Answer
Since only one packet is outstanding, reordering is not a problem; the protocol treats any out‑of‑order arrival as an error and discards.
🛠️ Exercises
Apply your understanding with these 15 exercises. Solutions are provided below each.
- Exercise 1: Utilization Calculation
A stop‑and‑wait protocol uses 1000‑byte packets on a 10 Mbps link with a propagation delay of 20 ms. What is the maximum utilization?
Solution
t_trans = (1000*8)/10e6 = 0.0008 s = 0.8 ms. t_prop = 20 ms. RTT = 40 ms. U = 0.8 / (0.8 + 40) = 0.8/40.8 ≈ 0.0196 = 1.96%.
- Exercise 2: Throughput Calculation
Using the same parameters as Exercise 1, what is the effective throughput?
Solution
Throughput = U * R = 0.0196 * 10 Mbps ≈ 196 kbps.
- Exercise 3: Packet Size for Full Utilization
For a 1 Gbps link with RTT = 50 ms, what packet size (in bytes) is needed for stop‑and‑wait to achieve 100% utilization?
Solution
For U=1, L = R * RTT = 1e9 * 0.05 = 50,000,000 bits = 6.25 MB. This is impractical.
- Exercise 4: Bandwidth‑Delay Product
A link has bandwidth 100 Mbps and RTT = 40 ms. What is the bandwidth‑delay product in bits and bytes?
Solution
BDP = 100e6 * 0.04 = 4,000,000 bits = 500,000 bytes.
- Exercise 5: FSM Transition
In stop‑and‑wait, the sender is in "Wait for ACK" state and receives a corrupted ACK. What does it do?
Solution
It ignores the ACK (since it's corrupted) and stays in "Wait for ACK"; the timer will eventually expire and it will retransmit.
- Exercise 6: Duplicate Packet Handling
In stop‑and‑wait, the receiver receives a packet with sequence number 0, but it already accepted a packet with sequence number 0 earlier. What does the receiver do?
Solution
It discards the duplicate packet and sends an ACK for sequence number 0 again.
- Exercise 7: Loss Recovery
Suppose the sender sends packet 0, the packet is lost. Describe the sequence of events until packet 0 is successfully delivered.
Solution
Sender times out, retransmits packet 0. Receiver gets it, sends ACK 0. Sender receives ACK, moves to next packet.
- Exercise 8: ACK Loss Recovery
Sender sends packet 0, receiver gets it and sends ACK 0, but the ACK is lost. What happens?
Solution
Sender times out, retransmits packet 0. Receiver gets duplicate, sends ACK 0 again. Sender gets ACK, moves on.
- Exercise 9: Timer Granularity
If the timer resolution is coarser than the actual RTT, what could happen?
Solution
The sender might unnecessarily delay retransmission, reducing performance, or if the timer is too long, it may not retransmit quickly enough, but correctness is maintained.
- Exercise 10: NAK vs Timeout
Compare the use of NAKs vs. timeouts for error recovery in stop‑and‑wait. Which is more efficient?
Solution
NAK can trigger faster retransmission for corrupted packets, but for lost packets, timeout is still needed. NAK adds complexity.
- Exercise 11: Propagation Delay Dominance
If propagation delay is much larger than transmission time, what is the approximate utilization?
Solution
U ≈ t_trans / (2*t_prop), which is very small.
- Exercise 12: Effect of Increasing Bandwidth
If bandwidth doubles while packet size and RTT remain the same, what happens to utilization?
Solution
t_trans halves, so U decreases (since U = t_trans / (t_trans + 2*t_prop)), making the link even less utilised.
- Exercise 13: Minimum Sequence Number Bits
Why is 1 bit sufficient for stop‑and‑wait? Show that 2 bits would be redundant.
Solution
Only one packet is outstanding; the receiver only needs to distinguish between two possibilities: the current packet and the previous one. Thus 0 and 1 are enough.
- Exercise 14: FSM Design for Receiver
Draw the receiver FSM for stop‑and‑wait (rdt3.0) indicating states and transitions on receiving packets.
Solution
Receiver has one state: "Wait for packet". On arrival: if corrupted, discard; if seq number matches expected, deliver, send ACK, flip expected seq; else (duplicate), send ACK.
- Exercise 15: Impact of Processing Delay
How would adding a non‑negligible processing delay at the receiver affect the utilization formula?
Solution
The effective RTT increases, reducing U further. The formula becomes U = t_trans / (t_trans + 2*t_prop + t_process).
📚 Homework
These advanced problems require synthesis, research, and quantitative analysis. Sample answers are provided below.
- Problem 1: Derive Utilization for Stop‑and‑Wait with ACK Transmission
Extend the utilization formula to include the time to transmit the ACK packet (t_ack). Assume t_ack is small but non‑zero. Show the new formula.
Sample Answer
U = t_trans / (t_trans + 2*t_prop + t_ack). The ACK transmission time adds to the idle period.
- Problem 2: Optimal Packet Size
Given a link with bandwidth R and propagation delay t_prop, derive the packet size L that maximizes throughput in stop‑and‑wait, assuming overhead is negligible. Is there a trade‑off?
Sample Answer
Throughput = L / (L/R + 2*t_prop). As L increases, throughput increases asymptotically to R. There is no finite optimum; larger L always improves utilization, but also increases latency and memory.
- Problem 3: Sequence Number Wrap‑Around
In stop‑and‑wait, with 1‑bit sequence numbers, what happens if a duplicate ACK is delayed long enough that the sender has already moved to the next sequence number? Could this cause a problem?
Sample Answer
The sender ignores ACKs that do not match the expected sequence number. Since the protocol alternates, a delayed ACK for the previous packet will have the wrong sequence number and will be ignored, so no problem.
- Problem 4: Timer Granularity and Spurious Retransmissions
If the timer is set too short, the sender may retransmit unnecessarily. What is the impact on throughput and network load?
Sample Answer
Spurious retransmissions waste bandwidth and increase congestion, reducing effective throughput. The receiver may see duplicates, but handles them correctly.
- Problem 5: Lossy Channel with NAKs
Compare the performance of a stop‑and‑wait protocol that uses NAKs vs. one that only uses timeouts, when the channel has a high bit error rate but low loss.
Sample Answer
With NAKs, corrupted packets are retransmitted quickly, avoiding the timeout delay. This improves throughput. However, NAKs add complexity.
- Problem 6: Reliable Broadcast
Can the stop‑and‑wait protocol be extended for one‑to‑many reliable broadcast? What are the challenges?
Sample Answer
It would require collecting ACKs from all receivers; the sender must wait for all ACKs, or use a negative ACK approach. Scalability is a major issue.
- Problem 7: Unreliable ACKs
What if ACKs themselves can be corrupted? How does stop‑and‑wait handle this?
Sample Answer
Corrupted ACKs are treated as no ACK; the sender times out and retransmits. The receiver may get a duplicate, but handles it.
- Problem 8: Multi‑packet Duplicates
In stop‑and‑wait, a duplicate packet can arrive after the sender has received the ACK and moved on. The receiver's expected sequence number will have flipped, so the duplicate is discarded. Explain.
Sample Answer
If sender sent packet 0 and got ACK 0, it moves to packet 1. If a delayed duplicate of packet 0 arrives, the receiver is now expecting packet 1, so it discards the duplicate and sends an ACK for packet 0 (which the sender ignores if it's already past).
- Problem 9: Performance with Multiple Applications
If multiple stop‑and‑wait connections share the same link, how does the utilization scale? Compare with a single connection.
Sample Answer
Each connection individually has low utilization, but together they may fill the link. However, they all waste time waiting for ACKs, so overall efficiency is low.
- Problem 10: Approaching Pipelining
Propose a modification to stop‑and‑wait that allows sending a second packet before the ACK for the first arrives, without changing the 1‑bit sequence number. Is it possible?
Sample Answer
No, with 1‑bit sequence numbers, you cannot have two outstanding packets because you need to distinguish between them. You would need more sequence bits, which leads to pipelining.
- Problem 11: RTT Estimation
How would you estimate RTT in stop‑and‑wait to set the timer? Discuss the challenges.
Sample Answer
You can measure the time from sending a packet to receiving its ACK. However, due to variable delays, use exponential smoothing (as in TCP). The challenge is to avoid unnecessary retransmissions while not waiting too long.
- Problem 12: Stop‑and‑Wait with Piggybacking
If data flows in both directions, ACKs can be piggybacked on data packets. How does this affect utilization?
Sample Answer
It reduces the number of separate ACK packets, saving bandwidth, but does not eliminate the waiting time; the sender still cannot send new data until the piggybacked ACK arrives.
- Problem 13: Error Correction vs. Detection
Why do transport protocols typically use error detection (checksum) rather than forward error correction (FEC)? Discuss the trade‑offs.
Sample Answer
FEC adds redundancy that can correct errors without retransmission, but increases overhead. In networks with low bit error rates, detection+retransmission is more efficient.
- Problem 14: Stop‑and‑Wait in Space Communications
In deep‑space communications, propagation delays can be minutes. How does stop‑and‑wait perform? What alternatives exist?
Sample Answer
Utilization is extremely low. Protocols like Delay‑Tolerant Networking (DTN) use store‑and‑forward and bundle protocols to cope with long delays.
- Problem 15: Formal Verification of Stop‑and‑Wait
Prove that stop‑and‑wait (rdt3.0) is correct: it does not deliver duplicate data and delivers data in order. Outline the proof using invariants.
Sample Answer
Invariant: the sender's sequence number equals the receiver's expected sequence number after each successful transmission. The protocol ensures that the sender only increments after receiving an ACK for the current sequence, and the receiver only accepts a packet if its sequence matches the expected one. Thus duplicates are discarded and order is preserved.
📌 Summary
- Reliable data transfer is essential for many applications and is built on top of unreliable network layer services.
- Key mechanisms include checksums, ACKs/NAKs, sequence numbers, and timeouts.
- Stop‑and‑wait (rdt3.0) provides a correct solution but suffers from low link utilization, especially on high‑speed or long‑delay networks.
- Utilization is limited by the bandwidth‑delay product; to improve, pipelined protocols are needed.
- FSMs are a powerful tool for specifying and verifying protocol behaviour.
In the next tutorial, we will explore Pipelined Protocols: Go‑Back‑N and Selective Repeat, which address the performance limitations of stop‑and‑wait.