Stop-and-Wait Protocol

 

Stop-and-Wait Protocol

Introduction

The Stop-and-Wait Protocol is one of the simplest connection-oriented transport-layer protocols. Unlike the Simple Protocol, it provides both Flow Control and Error Control, making data transmission reliable.

The protocol gets its name from its operation:

  • The sender sends one packet.
  • It then stops and waits for an acknowledgment (ACK) from the receiver.
  • Only after receiving the ACK does it send the next packet.

If the ACK does not arrive within a specified time, the sender assumes that the packet or ACK has been lost and retransmits the packet.


Definition

Stop-and-Wait Protocol is a connection-oriented protocol in which the sender transmits only one packet at a time and waits for its acknowledgment before sending the next packet. It provides flow control and error control using acknowledgments, timers, checksums, and sequence numbers.


Features of Stop-and-Wait Protocol

  • Connection-oriented protocol
  • Provides flow control
  • Provides error control
  • Uses a sliding window of size 1
  • Uses sequence numbers
  • Uses acknowledgment numbers
  • Uses checksums for error detection
  • Uses timers for retransmission
  • Only one packet can be outstanding at any time

Why Do We Need Stop-and-Wait Protocol?

The Simple Protocol assumes that:

  • Packets are never lost.
  • Packets are never corrupted.
  • Receiver is always ready.

These assumptions are unrealistic in real networks.

The Stop-and-Wait Protocol overcomes these problems by ensuring:

  • The receiver is not overloaded (Flow Control).
  • Lost or corrupted packets are retransmitted (Error Control).

Layout of Stop-and-Wait Protocol

        

Only one data packet and one acknowledgment can be in the network at any time.


Working of Stop-and-Wait Protocol

The protocol works as follows.

Step 1: Sender Receives Data

The application generates a message.

Application

↓

Message

Step 2: Sender Creates a Packet

The transport layer

  • adds a sequence number
  • adds a checksum
+-----------------------------------------------+
| Seq No | Checksum | Application Data          |
+-----------------------------------------------+

Step 3: Sender Sends the Packet

Sender

Packet 0

↓

Network

The sender

  • keeps a copy of the packet
  • starts a timer

Step 4: Receiver Receives Packet

Receiver checks the checksum.

If packet is correct

Packet Correct

↓

Deliver to Application

↓

Send ACK

If packet is corrupted

Packet Corrupted

↓

Discard Packet

↓

No ACK Sent

The receiver remains silent.

This silence tells the sender that something has gone wrong.


Step 5: Sender Waits

Two situations are possible.

Case 1: ACK Arrives

Packet

↓

Receiver

↓

ACK

↓

Sender

The sender

  • stops the timer
  • deletes the stored copy
  • sends the next packet

Case 2: ACK Does Not Arrive

Packet Lost

or

ACK Lost

↓

Timer Expires

↓

Sender Resends Packet

Thus,

the protocol automatically recovers from packet loss.


Flow Control

Stop-and-Wait provides Flow Control because the sender sends only one packet before waiting.

Sender

Packet 0

↓

WAIT

↓

ACK

↓

Packet 1

The receiver is never overwhelmed.


Error Control

The protocol provides Error Control using

  • Checksum
  • Timer
  • Retransmission
  • ACK

Example

Packet Corrupted

↓

Receiver Discards

↓

No ACK

↓

Timeout

↓

Sender Retransmits

Sliding Window

Both sender and receiver use a Sliding Window of Size 1.

Sender Window

+---------+
| Packet  |
+---------+

Only one packet can be transmitted.


Receiver Window

+---------+
| Packet  |
+---------+

Receiver also accepts only one packet at a time.


Why Sequence Numbers are Needed?

Suppose

Packet 0 reaches the receiver.

Receiver sends ACK.

But ACK is lost.

Sender

Packet 0

↓

Receiver

↓

ACK Lost

Sender thinks Packet 0 was lost.

So it sends Packet 0 again.

Packet 0

↓

Receiver

Receiver must determine

Is this

  • a new packet?

or

  • a duplicate?

This is possible only with Sequence Numbers.


Sequence Numbers

Since only one packet is outstanding,

only two sequence numbers are sufficient.

0

1

0

1

0

1 ...

This is called

Modulo-2 Arithmetic

Only one bit is required.


Why Only 0 and 1?

Suppose current packet number is x.

Three possibilities exist.


Case 1

Packet arrives successfully.

Sender

Packet x

↓

Receiver

↓

ACK

↓

Next Packet = x+1

Case 2

Packet is lost.

Sender

Packet x

↓

Lost

↓

Timeout

↓

Packet x Again

Same packet is retransmitted.


Case 3

ACK is lost.

Packet x

↓

Receiver

↓

ACK Lost

↓

Timeout

↓

Packet x Again

Receiver receives

Packet x twice.

The receiver knows it is a duplicate because it was expecting

Packet x+1

Therefore,

only x and x+1 are needed.

Instead of large numbers,

we use

0

1

0

1

0...

Acknowledgment Numbers

The ACK number always indicates

"The next packet expected."

Example

If Packet 0 arrives correctly

Receiver sends

ACK = 1

Meaning

I have received Packet 0.

Now send Packet 1.

If Packet 1 arrives

Receiver sends

ACK = 0

Meaning

I have received Packet 1.

Now send Packet 0.

Thus,

ACK always contains the sequence number of the next expected packet.


Sender Control Variable (S)

The sender maintains a variable

S

which stores the sequence number of the next packet.

Initially

S = 0

Example

Packet Sent

Seq = 0

↓

ACK =1

↓

S=1

↓

Next Packet

Seq=1

Receiver Control Variable (R)

Receiver maintains

R

Initially

R=0

It represents

Next packet expected.

FSMs

Figure 3.21 shows the FSMs for the Stop-and-Wait protocol. Since the protocol is a connection-oriented protocol, both ends should be in the established state before exchanging data packets. The states are actually nested in the established state.


Sender FSM

The sender has two states.

Ready State

When the sender is in this state, it is only waiting for one event to occur. 

The sender waits for data from the application.

When data arrives

  • Create packet
  • Assign sequence number S
  • Save copy
  • Send packet
  • Start timer

Move to

Blocking State

Blocking State

When the sender is in this state, three events can occur:

The sender waits for ACK.

Three events may occur.

Event 1

Correct ACK arrives.

Stop Timer

↓

Slide Window

↓

S=(S+1) mod2

↓

Ready State

Event 2

Wrong or Corrupted ACK

Discard ACK

↓

Remain in Blocking State

Event 3

Timeout

Timer Expires

↓

Resend Packet

↓

Restart Timer
↓

Remain in Blocking State

Receiver FSM

Receiver always stays in

READY

Three events occur.


Event 1

Correct Packet

Seq=R

↓

Deliver Data to Application

↓

R=(R+1) mod2

↓

Send ACK with ACK NO R

Event 2

Duplicate Packet

Seq ≠ R

↓

Discard Packet

↓

Send Previous ACK Again

Event 3

Corrupted Packet

Discard Packet

↓

No ACK

Example

Suppose

Packet 0

Sender

Packet0

↓

Receiver

↓

ACK1

Successful.


Packet 1

Sender

Packet1

↓

Lost

No ACK.

Timer expires.

Timeout

↓

Sender

Packet1 Again

↓

Receiver

↓

ACK0

Now communication continues.


Suppose ACK is lost.

Sender

Packet0

↓

Receiver

↓

ACK Lost

Timer expires.

Sender sends

Packet0 Again

Receiver recognizes it as duplicate.

It discards it and sends

ACK1




Efficiency of Stop-and-Wait Protocol

Although Stop-and-Wait is simple and reliable, it is not efficient for networks with:

  • High bandwidth
  • Long propagation delay

This is because the sender remains idle while waiting for the ACK.

Example

Suppose

  • Packet transmission time = 1 ms
  • Round-trip delay = 50 ms

Timeline:

Time →

Send Packet (1 ms)

↓

Wait 49 ms

↓

ACK Arrives

↓

Send Next Packet

The sender spends most of its time waiting, leaving the communication channel underutilized.


Bandwidth-Delay Product (BDP)

The inefficiency of Stop-and-Wait becomes more apparent in networks with a large Bandwidth-Delay Product (BDP).

Definition

The Bandwidth-Delay Product is the amount of data that can be present ("in flight") in the network while waiting for an acknowledgment.

It is calculated as:

Analogy

Imagine the communication channel as a water pipe:

  • Bandwidth represents the diameter of the pipe.
  • Round-trip delay represents the length of the pipe.
  • The Bandwidth-Delay Product represents the volume of water the pipe can hold.

With Stop-and-Wait, only one packet is inside the pipe at any time. If the pipe is very long (large delay) or very wide (high bandwidth), most of its capacity remains unused while the sender waits for an ACK. This results in poor channel utilization.


Advantages

  • Very simple implementation.
  • Reliable communication.
  • Prevents receiver overflow.
  • Detects lost packets.
  • Detects corrupted packets.
  • Eliminates duplicate packets.
  • Uses only one-bit sequence numbers.

Disadvantages

  • Low throughput.
  • Poor channel utilization.
  • Sender remains idle while waiting for ACK.
  • Inefficient for high-speed or long-distance networks.
  • Large Bandwidth-Delay Product leads to poor efficiency.

Summary

  • The Stop-and-Wait Protocol is a connection-oriented transport-layer protocol that provides both flow control and error control.
  • It uses a sliding window of size 1, allowing only one outstanding packet at any time.
  • Each packet contains a sequence number and a checksum, while acknowledgments contain the sequence number of the next expected packet.
  • The sender maintains a copy of the transmitted packet and starts a timer. If an ACK is received before the timer expires, the sender transmits the next packet. Otherwise, it retransmits the previous packet.
  • The protocol uses modulo-2 sequence numbers (0 and 1) because only one outstanding packet needs to be distinguished from its retransmission.
  • Although the protocol is simple and reliable, it is inefficient on networks with a large bandwidth-delay product, because the sender remains idle while waiting for acknowledgments.

Solved Problems

Problem


Assume that, in a Stop-and-Wait system, the bandwidth of the line is 1 Mbps, and 1 bit takes 20 milliseconds to make a round trip. What is the bandwidth-delay product? If the system data packets are 1,000 bits in length, what is the utilization percentage of the link?

Solution

Step 1: Calculate the Bandwidth-Delay Product

The Bandwidth-Delay Product (BDP) is given by:

Bandwidth-Delay Product=Bandwidth×Round-Trip Delay\text{Bandwidth-Delay Product} = \text{Bandwidth} \times \text{Round-Trip Delay}

Given:

  • Bandwidth = 1 Mbps=1×1061 \text{ Mbps} = 1 \times 10^6 bits/second
  • Round-trip delay = 2020 ms = 20×10320 \times 10^{-3} seconds

Substituting the values,

BDP=(1×106)×(20×103)\text{BDP} = (1 \times 10^6) \times (20 \times 10^{-3})
=20,000 bits= 20,000 \text{ bits}

Bandwidth-Delay Product = 20,000 bits


Step 2: Calculate the Link Utilization

During one round-trip time, the communication channel is capable of carrying 20,000 bits.

However, in the Stop-and-Wait protocol, the sender transmits only one packet of 1,000 bits before waiting for an acknowledgment.

Therefore,

Link Utilization=Packet SizeBandwidth-Delay Product\text{Link Utilization} = \frac{\text{Packet Size}}{\text{Bandwidth-Delay Product}} =100020000=0.05= \frac{1000}{20000} = 0.05

Converting into percentage,

Link Utilization=0.05×100=5%\text{Link Utilization} = 0.05 \times 100 = 5\%

Link Utilization = 5%


Final Answer

  • Bandwidth-Delay Product = 20,000 bits
  • Link Utilization = 5%

Interpretation

The communication link can hold 20,000 bits while waiting for the acknowledgment to return. However, the Stop-and-Wait protocol transmits only 1,000 bits before stopping to wait for the ACK.

Thus, only 5% of the link capacity is utilized, while the remaining 95% of the bandwidth remains idle.

This example illustrates why the Stop-and-Wait Protocol is inefficient for networks with high bandwidth or long propagation delays, as it wastes a significant portion of the available channel capacity.


Problem

Consider the same communication system as in the previous problem with the following parameters:

  • Bandwidth = 1 Mbps
  • Round-trip delay = 20 ms
  • Data packet size = 1,000 bits

Instead of using the Stop-and-Wait Protocol, assume that the protocol can send up to 15 packets before stopping and waiting for acknowledgments.

Determine the link utilization percentage.


Solution

Step 1: Calculate the Bandwidth-Delay Product

From Example 3.5,

  • Bandwidth = 1×1061 \times 10^6 bits/second
  • Round-trip delay = 20×10320 \times 10^{-3} seconds

The Bandwidth-Delay Product (BDP) is

BDP=Bandwidth×Round-Trip Delay\text{BDP} = \text{Bandwidth} \times \text{Round-Trip Delay}
=(1×106)×(20×103)= (1 \times 10^6) \times (20 \times 10^{-3})
=20,000 bits= 20,000 \text{ bits}

Bandwidth-Delay Product = 20,000 bits


Step 2: Calculate the Total Number of Bits Sent Before Waiting

Since the protocol can send 15 packets before waiting,

Total bits sent=15×1000=15,000 bits\text{Total bits sent} = 15 \times 1000 = 15,000 \text{ bits}


Step 3: Calculate the Link Utilization

The link utilization is given by

Link Utilization=Total bits sent before waitingBandwidth-Delay Product\text{Link Utilization} = \frac{\text{Total bits sent before waiting}}{\text{Bandwidth-Delay Product}} =1500020000=0.75= \frac{15000}{20000} = 0.75

Converting to percentage,

Link Utilization=0.75×100=75%\text{Link Utilization} = 0.75 \times 100 = 75\%


Final Answer

  • Bandwidth-Delay Product = 20,000 bits
  • Total data sent before waiting = 15,000 bits
  • Link Utilization = 75%

Interpretation

Unlike the Stop-and-Wait Protocol, which transmits only one packet (1,000 bits) before waiting for an acknowledgment, this protocol allows the sender to transmit 15 packets (15,000 bits) continuously before waiting.

As a result, the sender utilizes 75% of the available link capacity, compared to only 5% utilization in Stop-and-Wait.

This demonstrates why sliding window protocols (such as Go-Back-N and Selective Repeat) are much more efficient than the Stop-and-Wait protocol, especially in networks with high bandwidth or long propagation delays.

Comments

Popular posts from this blog

Computer Networks PCCST501 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Computer Networks

Introduction to Local Area Network (LAN)