0% found this document useful (0 votes)
20 views4 pages

Stop and Wait Algorithm

The document outlines the implementation of the Stop and Wait Protocol and Sliding Window Protocol in data communication. It explains the theory behind each protocol, including error detection and frame management, and provides sample C programs for both protocols. The document concludes with sections for results related to the experiments conducted.

Uploaded by

Pavithra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Stop and Wait Algorithm

The document outlines the implementation of the Stop and Wait Protocol and Sliding Window Protocol in data communication. It explains the theory behind each protocol, including error detection and frame management, and provides sample C programs for both protocols. The document concludes with sections for results related to the experiments conducted.

Uploaded by

Pavithra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CN LAB Sub Code: BEC702

EXPERIMENT NO: 05
STOP AND WAIT PROTOCOL & SLIDING WINDOW PROTOCOL

Aim: To implement Stop and Wait Protocol and Sliding Window Protocol.

Theory:
Stop and Wait:

The Stop-and-Wait Automatic Repeat Request protocol (Stop-and Wait ARQ), is used to detect and
correct erroneous frames. To detect and correct corrupted frames, we need to add redundancy bits to
our data frame. When the frame arrives at the receiver side, it is checked and if it is corrupted, it is
silently discarded. The detection of errors in this protocol is manifested by the silence of the receiver.
Lost frames are more difficult to handle than corrupted ones. The received frame could be the correct
one, or a duplicate, or a frame out of order. The solution is to number the frames. When the receiver
receives a data frame that is out of order, this means that frames were either lost or duplicated. The
corrupted and lost frames need to be re-sent in this protocol. If the receiver does not respond when there
is an error, how can the sender know which frame to re-send? To provide solution to this problem, the
sender keeps a copy of the sent frame. At the same time, it starts a timer. If the timer expires and there
is no ACK for the sent frame, the frame is re-sent, the copy is held, and the timer is restarted.

Sliding Window:

The sliding window protocol is an abstract concept that defines the range of sequence numbers that is
the concern of the sender and receiver. In other words, the sender and receiver need to deal with only
part of the possible sequence numbers. The range which is the concern of the sender is called the send
sliding window; the range that is the concern of the receiver is called the receive sliding window. The
send window is an imaginary box covering the sequence numbers of the data frames which can be in
transit. In each window position, some of these sequence numbers define the frames that have been sent;
others define those that can be sent. The maximum size of the window is 2m – 1. Figure 11.12 shows a
sliding window of size 15 (m =4). The window at any time divides the possible sequence numbers into
four regions. The first region, from the far left to the left wall of the window, defines the sequence
numbers belonging to frames that are already acknowledged. The sender does not worry about these
frames and keeps no copies of them. The second region, colored in Figure 11.12a, defines the range of
sequence numbers belonging to the frames that are sent and have an unknown status. The

Dept. of ECE, EPCET Page 53


CN LAB Sub Code: BEC702

sender needs to wait to find out if these frames have been received or were lost. We call these
outstanding frames. The third range, white in the figure, defines the range of sequence numbers for
frames that can be sent; however, the corresponding data packets have not yet been received from the
network layer. Finally, the fourth region defines sequence numbers that cannot be used until the window
slides.

Program:
Stop and Wait program:

#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,j,noframes,x,x1=10,x2;
noframes=10;
i=1;
j=1;
printf("number of frames is %d ",noframes);

getch();
while(noframes>0)
{
printf("\nsending frames is %d",i);
x=rand()%10;
if(x%10==0)
{
for(x2=1;x2<2;x2++)
{
printf("\n waiting for %d seconds\n",x2);
sleep(x2);
}
printf("\n sending frames %d\n",i);
x=rand()%10;
}
printf("\n ack for frame %d\n",j);
noframes=noframes-1;
i++;
j++;
}
printf("\n end of stop and wait protocol\n");
}

Dept. of ECE, EPCET Page 54


CN LAB Sub Code: BEC702

Sliding Window Program:

#include<stdio.h>
int main()
{
intw,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("\nEnter number of frames to transmit: ");
scanf("%d",&f);
printf("\nEnter %d frames: ",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}

Dept. of ECE, EPCET Page 55


CN LAB Sub Code: BEC702

Result:
Sliding Window:

Stop and wait:

Dept. of ECE, EPCET Page 56

You might also like