CN Stop and Wait Protocol

You are on page 1of 3

1

Stop and Wait communication protocol

Priyadarshini Rajendran, Section B, ECE, Reg.No 160907060


Abstract— Stop and wait, (sometimes known as "positive III. DISADVANTAGES
acknowledgement with retransmission") is the fundamental
technique to provide reliable transfer under unreliable packet A. Bandwith wastage
delivery system. This particular algorithm has been implemented The main disadvantage of this method is that it is inefficient.
for a noiseless channel. There is no error control, making this one
The sender needs to wait for the ACK after every frame it
of the simplest communication protocols present. The sender
transmits a data frame, but cannot send any further frames till it transmits. This is a source of inefficiency, and is particularly
receives an acknowledgement from the receiver. Similarly, at the bad when the propagation delay is much longer than the
receiver’s side, the data received is acknowledged by sending the transmission delay. In this method single frame travels from
appropriate frame to the sender. Hence the sender sends a source to destination and single acknowledgment travels from
frame,then stops, and waits for an acknowledgement; and this destination to source. As a result each frame sent and received
process continues till there is data to transmit. The main uses the entire time needed to traverse the link. Moreover, if
shortcoming of the stop-and-wait algorithm is that it allows the two devices are distance apart, a lot of time is wasted waiting
sender to have only one outstanding frame on the link at a time. for ACKs that leads to increase in total transmission time.
The sender should wait till it gets an ACK of previous frame before
it sends next frame. As a result, it wastes a substantial amount of
network bandwidth.
B. Inefficiency
Index Terms—Acknowledgement, communication, network, Stop and wait can also create inefficiencies when sending
protocol, sender, stop, receiver, wait. longer transmissions. The receiver has a limited buffer and
requires flow control techniques. When longer transmissions
are sent there is more likely chance for error in this protocol. If
I. INTRODUCTION the messages are short the errors are more likely to be detected
early. More inefficiency is created when single messages are
I N this method of flow control, the sender sends a single
frame to receiver & waits for an acknowledgment. The next
frame is sent by sender only when acknowledgment of previous
broken into separate frames because it makes the transmission
longer. It makes the transmission process slow.
frame is received. This process of sending a frame & waiting
for an acknowledgment continues as long as the sender has data IV. OPERATIONS
to send. It is the simplest form of flow control. The receiver
indicates its readiness to receive data for each frame, the A. Sender: Transmits a single frame at a time, ie allow the
message is broken into multiple frames. The sender waits for an first frame to go, and wait till the next data packet arrives.
ACK (acknowledgement) after every frame for specified time
(called time out). It is sent to ensure that the receiver has B. Receiver: Sleeps until an event occurs, then transmits
received the frame correctly. It will then send the next frame acknowledgement (ACK) as it receives a frame.
only after the ACK has been received. To end up the
transmission sender transmits end of transmission (EOT) frame. C. Check to see if sender receives ACK within time out-
cannot send next data packet till previous acknowledgement
II. ADVANTAGES has been received.
The main advantage of stop & wait protocols is its accuracy.
Next frame is transmitted only when the first frame is D. Once ACK received, go to step A.
acknowledged. So there is no chance of frame being lost. The
other advantage of this method is its simplicity.

Submitted on 23rd October 2018.


The author is with the Electronics and Communication Department,
Manipal Institute of Technology, Manipal, Karnataka, India (e-mail:
[email protected]).
2

Fig 1. Pictorial representation of the Stop and Wait protocol. Fig 2. State diagram of the Stop and Wait protocol.

V. IMPLEMENTATION
VI. CODE
A. Objective Language used for implementation is C and MATLAB.
To write a program to simulate stop and wait protocol.
B. Algorithm steps A. Code in C
1) Start the program. #include<stdio.h>
#include<conio.h>
2) Generate a random that gives the total number of frames
#include<stdlib.h>
to be transmitted.
void main()
{ int i,j,noframes,x,x1=10,x2;
3) Transmit the first frame.
Fig. 1. clrscr();
for(i=0;i<200;i++)
4) Receive the acknowledgement for the first frame.
rand();
noframes=rand()/200;
5) Transmit the next frame.
i=1;
j=1;
6) Find the remaining frames to be sent.
noframes = noframes / 8;
printf("\n number of frames is %d",noframes);
7) If an acknowledgement is not received for a particular
getch();
frame retransmit that frame alone again.
while(noframes>0)
{
8) Repeat the steps 5 to 7 till the number of remaining frames
printf("\nsending frame %d",i);
to be send becomes zero.
srand(x1++);
x = rand()%10;
9) Stop the program.
if(x%2 == 0)
{
for (x2=1; x2<2; x2++)
{
printf("waiting for %d seconds\n", x2);
sleep(x2);
}
printf("\nsending frame %d",i);
srand(x1++);
x = rand()%10;
}
3

printf("\nack for frame %d",j); B. In MATLAB


noframes-=1;
i++;
j++;
}
printf("\n end of stop and wait protocol");
getch();
}

B. Code in MATLAB
clc;
clear all;
disp('SAMPLE INPUT AND OUTPUT: ');
n=input('Number of Frames: ');
frame=1;
while frame<=n
fprintf('Transmitting Frame %d\n',frame);
s=randint(1,1,15);
if s<3
fprintf('TIME OUT\n Re-');
elseif s>6
fprintf('PAK of Frame %d Received\n',frame);
frame=frame+1;
else
fprintf('NAK of Frame %d Received\n Re-',frame); REFERENCES
end
end
[1] Behrouz A. Forouzan, Data Communications and
Networking. , pp. 1.
VII. RESULTS
[2] F. Argenti ; G. Benelli ; A. Garzelli, “Generalised stop-and-
A. In C wait protocol,” 23 April 1992.

You might also like