LAB CYCLE- Date: -04-13
PROGRAM -
AIM: Write c program to implement selective repeat sliding window protocol
Description:
Select Repeat Protocol:
Receiver stores correct frames following the bad one
Sender retransmits the bad one after noticing
Receiver passes data to network layer and acknowledge with the highest number
Receiving window > 1 (i.e., any frame within the window may be accepted and buffered until all
the preceding one passed to the network layer
Might need large memory
Negative Acknowledgement (NAK):
SRP is often combined with NAK
When error is suspected by receiver, receiver request retransmission of a frame
Arrival of a damaged frame
Arrival of a frame other than the expected
Selective Repeat ARQ, lost frame
Dept of CSE, K L UNIVERSITY 21 Reg no-12203008
LAB CYCLE- Date: -04-13
Select Repeat Protocol Implementation
o Receiver has a buffer for each sequence number within receiving window
o Each buffer is associated with an "arrived" bit
o Check whether sequence number of an arriving frame within window or not
If so, accept and store
o Select Repeat Protocol - Window Size:
o Suppose 3-bit window is used and window size = MAX_SEQ = 7
sender receiver
0 1 2 3 4 5 6 sent 0 1 2 3 4 5 6 accepted
0 through 6 to network layer
all acknowledgements lost
0 retransmitted 0 accepted
acknowledgement 6 received
7 sent 7 accepted
7 and 0 to network layer
Program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sendfunc();
int recvfunc(int,int);
static int rec[3];
int main()
{
char ch;
int i;
Dept of CSE, K L UNIVERSITY 22 Reg no-12203008
LAB CYCLE- Date: -04-13
printf("\n********* SELECTIVE REPEAT SLIDING WINDOW PROTOCAL ***********\n");
while(1)
{
printf("\nDo you want to send data to receiver(y/n) : ");
scanf("%s",&ch);
if(ch=='y' || ch=='Y')
{
sendfunc();
printf("\nData in receiver side window: ");
for(i=0;i<3;i++)
printf("%d ",rec[i]);
printf("\n");
}
else
break;
}
return 0;
}
void sendfunc()
{
int data[3],re[3];
int count=0,i,j,k,tem;
for(i=0;i<3;i++)
{
printf("\nEnter the %d packet to be send : ",i);
scanf("%d",&data[i]);
}
printf("\nSOURCE SIDE DESTINATION SIDE\n");
printf("--------------------- -------------------------\n");
for(j=0;j<3;j++)
printf("\n%d data is transmiting\n",j);
for(j=0;j<3;j++)
{
if(data[j]<50)
re[j]=0;
else
{
printf("\n --- TRANSMITION ERROR AT %d DATA------ \n",j);
re[j]=1;
}
}
for(i=0;i<3;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<3;i++)
{
Dept of CSE, K L UNIVERSITY 23 Reg no-12203008
LAB CYCLE- Date: -04-13
if(re[i]==1)
{
count++;
printf("\n%d Data is retransmitting\n",i);
re[i]=0;
tem=recvfunc(data[i],i);
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);
rec[seq]=data;
printf("\n -----ACK is transmitting- - - - \n");
return seq;
}
Output 1:
********* SELECTIVE REPEAT SLIDING WINDOW PROTOCAL ***********
Do you want to send data to receiver(y/n) : y
Enter the 0 packet to be send : 45
Enter the 1 packet to be send : 56
Enter the 2 packet to be send : 48
SOURCE SIDE DESTINATION SIDE
---------------------- ---------------------------
0 data is transmiting
1 data is transmiting
2 data is transmiting
--- TRANSMITION ERROR AT 1 DATA------
0 DATA RECEIVED
-----ACK is transmitting- - - -
ACK of pkt 0 is received ACK sent
2 DATA RECEIVED
-----ACK is transmitting- - - -
Dept of CSE, K L UNIVERSITY 24 Reg no-12203008
LAB CYCLE- Date: -04-13
ACK of pkt 2 is received ACK sent
1 Data is retransmitting
1 DATA RECEIVED
-----ACK is transmitting- - - -
ACK of pkt 1 is received ACK sent
Data in receiver side window: 45 56 48
Do you want to send data to receiver(y/n) : n
Output 2:
********* SELECTIVE REPEAT SLIDING WINDOW PROTOCAL ***********
Do you want to send data to receiver(y/n) : y
Enter the 0 packet to be send : 23
Enter the 1 packet to be send : 34
Enter the 2 packet to be send : 38
SOURCE DESTINATION
--------- --------------------
0 data is transmiting
1 data is transmiting
2 data is transmiting
0 DATA RECEIVED
-----ACK is transmitting- - - -
ACK of pkt 0 is received ACK sent
1 DATA RECEIVED
-----ACK is transmitting- - - -
ACK of pkt 1 is received ACK sent
2 DATA RECEIVED
-----ACK is transmitting- - - -
Dept of CSE, K L UNIVERSITY 25 Reg no-12203008
LAB CYCLE- Date: -04-13
ACK of pkt 2 is received ACK sent
Data in receiver side window: 23 34 38
Do you want to send data to receiver(y/n) : n
Dept of CSE, K L UNIVERSITY 26 Reg no-12203008