0% found this document useful (0 votes)
1K views

Program - : AIM: Write C Program To Implement Selective Repeat Sliding Window Protocol Description

The document describes an implementation of the selective repeat sliding window protocol. It contains: 1) An overview of the selective repeat protocol and negative acknowledgement approach. 2) Details of the implementation including buffers in the receiver for each sequence number, checking if numbers are within the window, and storing accepted frames. 3) Example code showing the sender and receiver functions, including transmitting data, simulating errors, retransmitting lost packets, and acknowledging received packets. 4) Sample outputs showing the transmission of 3 packets with an error on one packet, its retransmission, and the received packets stored in the receiver window.

Uploaded by

Lavanya Diet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Program - : AIM: Write C Program To Implement Selective Repeat Sliding Window Protocol Description

The document describes an implementation of the selective repeat sliding window protocol. It contains: 1) An overview of the selective repeat protocol and negative acknowledgement approach. 2) Details of the implementation including buffers in the receiver for each sequence number, checking if numbers are within the window, and storing accepted frames. 3) Example code showing the sender and receiver functions, including transmitting data, simulating errors, retransmitting lost packets, and acknowledging received packets. 4) Sample outputs showing the transmission of 3 packets with an error on one packet, its retransmission, and the received packets stored in the receiver window.

Uploaded by

Lavanya Diet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

You might also like