IMPLEMENT SELECTIVE REPEAT SLIDING WINDOW PROTOCOL
SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int f,N;
printf("Enter the no. of bits for the sequence no. : ");
scanf("%d",&N);
f=pow(2,N-1);
for(int j=0;j<f;j++)
{
printf("\nSENDER : Frame %d is sent ",j);
}
for(int i=0;i<f;i++)
{
printf("\n");
int flag = rand()%2; //TESTCASE-2 //int flag = rand()%1; // for no
corruption/retransmission of frames
if(!flag)
{
printf("RECEIVER:Frame %d received correctly\n(acknowledgement %d
received)\n ",i,i);
}
else
{ printf("RECEIVER:Frame %d received correctly\n(acknowledgement %d
lost)\n ",i,i);
printf("(sender timeouts-->Resend the frame)\n");
printf("\n Want to continue");
return 0;
}
EXECUTION:
TESTCASE 1:
Enter the no. of bits for the sequence no. : 4
SENDER : Frame 0 is sent
SENDER : Frame 1 is sent
SENDER : Frame 2 is sent
SENDER : Frame 3 is sent
SENDER : Frame 4 is sent
SENDER : Frame 5 is sent
SENDER : Frame 6 is sent
SENDER : Frame 7 is sent
RECEIVER:Frame 0 received correctly
(acknowledgement 0 lost)
(sender timeouts-->Resend the frame)
RECEIVER:Frame 1 received correctly
(acknowledgement 1 received)
RECEIVER:Frame 2 received correctly
(acknowledgement 2 lost)
(sender timeouts-->Resend the frame)
RECEIVER:Frame 3 received correctly
(acknowledgement 3 lost)
(sender timeouts-->Resend the frame)
RECEIVER:Frame 4 received correctly
(acknowledgement 4 lost)
(sender timeouts-->Resend the frame)
RECEIVER:Frame 5 received correctly
(acknowledgement 5 lost)
(sender timeouts-->Resend the frame)
RECEIVER:Frame 6 received correctly
(acknowledgement 6 received)
RECEIVER:Frame 7 received correctly
(acknowledgement 7 received)
Want to continue
TESTCASE 2:
Enter the no. of bits for the sequence no. : 5
SENDER : Frame 0 is sent
SENDER : Frame 1 is sent
SENDER : Frame 2 is sent
SENDER : Frame 3 is sent
SENDER : Frame 4 is sent
SENDER : Frame 5 is sent
SENDER : Frame 6 is sent
SENDER : Frame 7 is sent
SENDER : Frame 8 is sent
SENDER : Frame 9 is sent
SENDER : Frame 10 is sent
SENDER : Frame 11 is sent
SENDER : Frame 12 is sent
SENDER : Frame 13 is sent
SENDER : Frame 14 is sent
SENDER : Frame 15 is sent
RECEIVER:Frame 0 received correctly
(acknowledgement 0 received)
RECEIVER:Frame 1 received correctly
(acknowledgement 1 received)
RECEIVER:Frame 2 received correctly
(acknowledgement 2 received)
RECEIVER:Frame 3 received correctly
(acknowledgement 3 received)
RECEIVER:Frame 4 received correctly
(acknowledgement 4 received)
RECEIVER:Frame 5 received correctly
(acknowledgement 5 received)
RECEIVER:Frame 6 received correctly
(acknowledgement 6 received)
RECEIVER:Frame 7 received correctly
(acknowledgement 7 received)
RECEIVER:Frame 8 received correctly
(acknowledgement 8 received)
RECEIVER:Frame 9 received correctly
(acknowledgement 9 received)
RECEIVER:Frame 10 received correctly
(acknowledgement 10 received)
RECEIVER:Frame 11 received correctly
(acknowledgement 11 received)
RECEIVER:Frame 12 received correctly
(acknowledgement 12 received)
RECEIVER:Frame 13 received correctly
(acknowledgement 13 received)
RECEIVER:Frame 14 received correctly
(acknowledgement 14 received)
RECEIVER:Frame 15 received correctly
(acknowledgement 15 received)
Want to continue