Professional Documents
Culture Documents
Selective Repeat SWP Program
Selective Repeat SWP Program
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");
EXECUTION:
TESTCASE 1:
Enter the no. of bits for the sequence no. : 4
(acknowledgement 0 lost)
(acknowledgement 1 received)
(acknowledgement 2 lost)
(acknowledgement 3 lost)
(acknowledgement 4 lost)
(acknowledgement 5 lost)
(acknowledgement 6 received)
Want to continue
TESTCASE 2:
(acknowledgement 0 received)
(acknowledgement 1 received)
(acknowledgement 2 received)
RECEIVER:Frame 3 received correctly
(acknowledgement 3 received)
(acknowledgement 4 received)
(acknowledgement 5 received)
(acknowledgement 6 received)
(acknowledgement 7 received)
(acknowledgement 8 received)
(acknowledgement 9 received)
(acknowledgement 10 received)
(acknowledgement 11 received)
(acknowledgement 12 received)
RECEIVER:Frame 13 received correctly
(acknowledgement 13 received)
(acknowledgement 14 received)
(acknowledgement 15 received)
Want to continue