# Automatic Repeat reQuest (ARQ)

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 2: Data Transmission
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

Error detection methods (such as parity checks and checksums) inform a receiving device *that* an error may have occurred when a check fails, but on their own they do not guarantee that the missing or corrupted data is successfully recovered.

**Automatic Repeat reQuest (ARQ)** is an error-control protocol that works in conjunction with error-detection algorithms to provide **retransmission when an error or missing acknowledgement is detected** across computer networks.

---

## Learning Objectives

- Explain the role and operation of **Automatic Repeat reQuest (ARQ)**.
- Define the core ARQ mechanisms: **Acknowledgements (ACK)**, **Negative Acknowledgements (NACK)**, and **Timeouts**.
- Trace data transmission workflows under **Stop-and-Wait ARQ** during successful delivery, corrupted data, and lost packets.

---

## The Core Mechanisms of ARQ

ARQ relies on three fundamental building blocks:

1. **Positive Acknowledgement (ACK)**:

- A short control message returned by the receiver to the sender confirming that a data packet was received successfully and passed all integrity checks (checksum/CRC).

1. **Negative Acknowledgement (NACK)**:

- A control message returned by the receiver to the sender indicating that a packet arrived corrupted (failed checksum). It explicitly requests the sender to retransmit that specific packet.

1. **Timeouts**:

- A countdown timer started by the transmitting device the instant a packet is dispatched.
- If neither an ACK nor a NACK is received before the timer expires, the sender assumes the packet (or the returning ACK) was completely lost in transit and automatically re-sends the packet.

---

## Stop-and-Wait ARQ Operation

In **Stop-and-Wait ARQ**, the sender transmits a single packet and pauses, waiting for confirmation before sending subsequent data.

```text
SENDER                                                     RECEIVER
  |                                                           |
  | -------- Packet 1 (Start Timer) ------------------------> |
  |                                                           | (Checksum OK)
  | <------- ACK 1 (Stop Timer) ----------------------------- |
  |                                                           |
  | -------- Packet 2 (Start Timer) ------------------------> |
  |                                                           | (Checksum Error!)
  | <------- NACK 2 ----------------------------------------- |
  |                                                           |
  | -------- Packet 2 Retransmitted (Restart Timer) --------> |
  |                                                           | (Checksum OK)
  | <------- ACK 2 ------------------------------------------ |
  v                                                           v
```

### Three Operational Scenarios:

#### Scenario 1: Normal Error-Free Transmission

1. Sender transmits Packet 1 and starts its timeout timer.
2. Receiver receives Packet 1, calculates the checksum, finds it matches the trailer checksum, and stores the data.
3. Receiver sends back an **ACK 1**.
4. Sender receives ACK 1 before the timer expires, stops the timer, and proceeds to transmit Packet 2.

#### Scenario 2: Corrupted Packet (NACK Triggered)

1. Sender transmits Packet 2 and starts its timer.
2. Receiver receives Packet 2, but electrical noise has flipped one or more bits.
3. The receiver calculates the checksum; it does not match the trailer value.
4. Receiver discards the corrupted packet and transmits a **NACK 2**.
5. Sender receives NACK 2, immediately re-transmits Packet 2, and resets the timer.

#### Scenario 3: Lost Packet (Timeout Triggered)

1. Sender transmits Packet 3 and starts its timer.
2. Due to a congested router or broken link, Packet 3 is completely dropped and never arrives.
3. The receiver cannot send an ACK or a NACK because it has no knowledge that Packet 3 was ever sent.
4. The sender's countdown timer reaches zero without receiving any response $\implies$ **Timeout**.
5. The sender automatically retransmits Packet 3 and resets the timer.

---

## Handling the Lost ACK Problem

What happens if the receiver receives a packet correctly and sends an ACK, but the **ACK itself is lost on the return journey**?

```text
SENDER                                                     RECEIVER
  |                                                           |
  | -------- Packet 4 (Start Timer) ------------------------> |
  |                                                           | (Stored in buffer)
  | <---X--- ACK 4 (LOST IN TRANSIT)                          |
  |                                                           |
  | (TIMEOUT EXPIRES!)                                        |
  | -------- Packet 4 (Retransmitted) ----------------------> |
  |                                                           | (Duplicate detected!)
  | <------- ACK 4 (Re-sent) -------------------------------- |
```

If the ACK is lost:

1. The sender's timer expires and the sender re-transmits Packet 4.
2. The receiver receives a second copy of Packet 4.
3. Because every packet carries a **Packet Sequence Number** in its header, the receiver recognizes that it has already received Packet 4!
4. The receiver discards the duplicate packet (avoiding data corruption) and re-sends an **ACK 4** so the sender can finally advance to Packet 5.

---

## Summary of ARQ Protocols

  
| Protocol | Description | Throughput Efficiency | Complexity |
| --- | --- | --- | --- |
| **Stop-and-Wait ARQ** | Transmits one packet at a time; waits for ACK before sending next packet. | Lower (idle time waiting for round-trip latency). | Very simple to implement. |

## Written practice and self-review

A client computer transmits data packets to a server using **Stop-and-Wait ARQ**.

Describe step-by-step what happens in each of the following two failure scenarios:

1. **Scenario A**: Packet 1 arrives at the server, but its payload has been corrupted by electrical noise.
2. **Scenario B**: Packet 2 is completely dropped by a congested network router and never reaches the server.

Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Automatic Repeat reQuest (ARQ) Operation (Multiple choice, 25 XP)

**Instructions:**
In an Automatic Repeat reQuest (ARQ) error control system, what triggers the transmitting device to automatically re-send a packet?

**Options:**
- **A**: The receiver sends an Acknowledgment (ACK) before transmission finishes.
- **B**: The user presses Ctrl+C in the terminal.
- **C**: The baud rate increases beyond 100 Mbps.
- **D**: The sender receives a Negative Acknowledgment (NACK), or a pre-set timeout expires before an Acknowledgment is received.


**Autotest Expectations:**
- **Correct option selected**: `selection_match` -> Expected: `b`

### Exercise 2: Exam-Style Question: ARQ Protocol Components (Fill in blank, 35 XP)

**Instructions:**
Complete the following statements describing the operation of an **Automatic Repeat reQuest (ARQ)** protocol:

1. The positive message sent by a receiver to confirm that a packet passed the error checks is called an: [blank_1]
2. The negative message returned when a packet arrives with checksum errors is called a: [blank_2]
3. If the transmitting device receives neither confirmation within a fixed time window, a **[blank_3]** occurs and the packet is re-sent.


**Starter Code:**
```text
{"word_bank":["ACK","NACK","timeout","SYN","checksum","parity"],"template":"1. Positive confirmation: [blank_1]\n2. Negative confirmation: [blank_2]\n3. Timer expiration event: [blank_3]","prompt":"Exam-Style Question: ARQ Protocol Components","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}]}
```

**Autotest Expectations:**
- **ARQ protocol terms**: `text_exact` -> Expected: `{&quot;blank_1&quot;:&quot;ACK&quot;,&quot;blank_2&quot;:&quot;NACK&quot;,&quot;blank_3&quot;:&quot;timeout&quot;}`

### Exercise 3: Application: Check the reasoning (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Reply confirming receipt is an ACK or a timeout? If no reply arrives in time, sender should retransmit or assume success? Does ARQ replace error detection: yes or no?


**Starter Code:**
```text
{"prompt":"Application: Check the reasoning","template":"1. Reply confirming receipt is an ACK or a timeout? [blank_1]\n2. If no reply arrives in time, sender should retransmit or assume success? [blank_2]\n3. Does ARQ replace error detection: yes or no? [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["ACK","retransmit","no","NACK","assume success","yes","discard"]}
```


