Program - : AIM: Write A C Program To Implement Goback N Sliding Window Protocol Description
Program - : AIM: Write A C Program To Implement Goback N Sliding Window Protocol Description
PROGRAM -
AIM: Write a c program to implement goback n sliding window protocol
Description:
Go Back n Protocol
Receiver discards all subsequent frames following an error one, and sends no acknowledgement
for those discarded
Receiving window size = 1 (i.e., frames must be accepted in the order they were sent)
Sending window might get full
If so, re-transmitting unacknowledged frames
Wasting a lot of bandwidth if error rate is high
Go-Back-N ARQ, normal operation
Program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define size 3
void sendfunc();
int recvfunc(int,int);
int main()
{
char ch;
printf("\n************* GO BACK N SLIDING WINDOW PROTOCAL ****************\n");
printf("\n size of sender window is fixed to %d size \n",size);
while(1)
{
sendfunc();
printf("\nDo you want to send data to receiver (y/n):");
scanf("%s",&ch);
if(ch=='Y' || ch=='y')
sendfunc();
else
break;
}
system("PAUSE");
return 0;
}
void sendfunc()
{
int data[size],re[size];
int count=0,i,j,k,tem;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(data[j]<50&&count==0)
re[j]=0;
else if(data[j]>50 ||count>=1)
{
count++;
if(count==1)
printf("\n ------ TRANSMISSION ERROR AT %d DATA ---- \n",j);
else
printf(" %d DATA DISCARDED\n",j);
re[j]=1;
}
}
for(i=0;i<size;i++)
{
if(re[i]==0)
{
tem=recvfunc(data[i],i);
printf("\nACK of pkt %d is received ACK sent\n",tem);
}
}
for(i=0;i<size;i++)
if(re[i]==1)
break;
for(j=i;j<size;j++)
{
sleep(5);
printf("\n%d data is retransmiting\n",j);
re[j]=0;
}
for(j=i;j<size;j++)
if(re[j]==0)
{
tem=recvfunc(data[j],j);
printf("\nACK of pkt %d is received ACK sent\n",tem);
}
}
int recvfunc(int data,int seq)
{
int i;
sleep(5);
printf("\n %d DATA RECEIVED\n",seq);
printf("\n ---- ACK is transmitting ----- \n");
return seq;
}
Output 1:
-------------------- ---------------------------
0 Data is transmiting
1 Data is transmiting
2 Data is transmiting
2 DATA DISCARDED
0 DATA RECEIVED
1 data is retransmiting
2 data is retransmiting
1 DATA RECEIVED
2 DATA RECEIVED
Output 2:
------------------- ---------------------------
0 Data is transmiting
1 Data is transmiting
2 Data is transmiting
0 DATA RECEIVED
1 DATA RECEIVED
2 DATA RECEIVED