Signup/Sign In
PUBLISHED ON: APRIL 30, 2021

Stop-and-Wait Protocol

In this tutorial, we will be covering another protocol used in the Noiseless channels in the Data link layer.

Stop-and-wait Protocol is used in the data link layer for the transmission in the noiseless channels. Let us first understand why there is a need to use this protocol then we will cover this protocol in detail.

We have studied the simplest protocol in the previous tutorial, suppose there is a scenario in which the data frames arrive at the receiver's site faster than they can be processed means the rate of transmission is more than the processing rate of the frames. Also, it is normal that the receiver does not have enough space, and the data is also coming from multiple sources. Then due to all these, there may occur discarding of frames or denial of service.

In order to prevent the receiver from overwhelming, there is a need to tell the sender to slow down the transmission of frames. We can make use of feedback from the receiver to the sender.

Now from the next section, we will cover the concept of the Stop-and-wait protocol.

As the name suggests, when we use this protocol during transmission, then the sender sends one frame, then stops until it receives the confirmation from the receiver, after receiving the confirmation sender sends the next frame.

  • There is unidirectional communication for the data frames, but the acknowledgment or ACK frames travel from the other direction. Thus the flow control is added here.

  • Thus the stop-and-wait is one of the flow control protocol which makes the use of flow control service provided by the data link layer.

  • For every sent frame, the acknowledgment is needed and it takes the same amount of time for propagation in order to get back to the sender.

  • In order to end up the transmission, the sender transmits an end of transmission that means(EOT frame).

Design of the Stop-and-Wait protocol

Datalink layer at the sender side waits for its network layer in order to send the data packet. After that data link checks that it can send the frame or not. In case of receiving a positive notification from the physical layer; the data link layer makes the frame out of the data provided by the network layer and then sends it to the physical layer. After sending the data it will then wait for the acknowledgment before sending the next frame.

The data link layer on the receiver side waits for the frame to arrive. When the frame arrives then the receiver processes the frame and then delivers it to the network layer. After that, it will send the acknowledgment or we can say that ACK frame back to the sender.

The algorithm used at the sender site for the stop-and-wait protocol

This is an algorithm used at the sender site for the stop-and-wait protocol. Applications can have its implementation in its own programming lamguage.

while(true)                //Repeat forever
canSend=true                 //It will allow the first frame to go.
{
  WaitForEvent();                  //sleep until the occurrence of an event
  if(Event(RequestToSend) AND canSend)
   {
      GetData();
      MakeFrame();
      SendFrame();   //Send the data frame
      canSend=false;   //cannot send until the acknowledgement arrives.
}

WaitForEvent();   //sleep until the occurrence of an event
if(Event(ArrivalNotification))  //indicates the arrival of the acknowledgement
   {
     ReceiveFrame();     //Means the ACK frame received
     canSend=true;
   }
}

Algorithm At the Receiver Side

This is an algorithm used at the receiver side for the stop-and-wait protocol. Applications can have their implementation in their own programming language.

while(true)   //means Repeat forever
{
   WaitForEvent();  //sleep until the occurrence of an event
   if(Event(ArrivalNotification)) //indicates arrival of the data frame
   {
      ReceiveFrame();
      ExtractData();
      Deliver(data); //delivers the data to the network layer.
      SendFrame(); //Send the ACK frame
   }
}

Flow diagram of the stop-and-wait protocol

Given below is the flow diagram of the stop-and-wait protocol:

Advantages

One of the main advantages of the stop-and-wait protocol is the accuracy provided. As the transmission of the next frame is only done after receiving the acknowledgment of the previous frame. Thus there is no chance for data loss.

Disadvantages

Given below are some of the drawbacks of using the stop-and-wait Protocol:

  • Using this protocol only one frame can be transmitted at a time.

  • Suppose in a case, the frame is sent by the sender but it gets lost during the transmission and then the receiver can neither get it nor can send an acknowledgment back to the sender. Upon not receiving the acknowledgment the sender will not send the next frame. Thus there will occur two situations and these are: The receiver has to wait for an infinite amount of time for the data and the sender has to wait for an infinite amount of time in order to send the next frame.

  • In the case of the transmission over a long distance, this is not suitable because the propagation delay becomes much longer than the transmission delay.

  • In case the sender sends the data and this data has also been received by the receiver. After receiving the data the receiver then sends the acknowledgment but due to some reasons, this acknowledgment is received by the sender after the timeout period. Now as this acknowledgment is received too late; thus it can be wrongly considered as the acknowledgment of another data packet.

  • The time spent waiting for the acknowledgment for each frame also adds up in the total transmission time.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.