0% found this document useful (0 votes)
3K views5 pages

Program - : AIM: Write A C Program To Implement Goback N Sliding Window Protocol Description

The document describes a C program to implement the Go Back N sliding window protocol. The program simulates data transmission between a sender and receiver with a fixed window size of 3. It introduces errors to test retransmission of lost packets. When an error occurs, subsequent packets are discarded until an ACK is received, and lost packets are retransmitted. The program outputs show sample runs demonstrating normal operation and error handling via retransmission.

Uploaded by

Lavanya Diet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views5 pages

Program - : AIM: Write A C Program To Implement Goback N Sliding Window Protocol Description

The document describes a C program to implement the Go Back N sliding window protocol. The program simulates data transmission between a sender and receiver with a fixed window size of 3. It introduces errors to test retransmission of lost packets. When an error occurs, subsequent packets are discarded until an ACK is received, and lost packets are retransmitted. The program outputs show sample runs demonstrating normal operation and error handling via retransmission.

Uploaded by

Lavanya Diet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB CYCLE- Date:22-02-13

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

Go Back n Protocol Implementation


 Sender has to buffer unacknowledged frames
 Acknowledge n means frames n,n-1,n-2, ... are acknowledged (i.e., received correctly) and those
buffers can be released
 One timer for each outstanding frame in sending window

Go-Back-N ARQ, lost frame

Dept of CSE, K L UNIVERSITY 16 Reg no-12203008


LAB CYCLE- Date:22-02-13

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++)
{

Dept of CSE, K L UNIVERSITY 17 Reg no-12203008


LAB CYCLE- Date:22-02-13

printf("\nEnter the %d packet to be send:",i);


scanf("%d",&data[i]);
}
printf("\n SOURCE SIDE DESTINATION SIDE\n");
printf("\n ----------- -------------------\n");
for(i=0;i<size;i++)
printf("\n%d Data is transmiting\n",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)
{

Dept of CSE, K L UNIVERSITY 18 Reg no-12203008


LAB CYCLE- Date:22-02-13

int i;
sleep(5);
printf("\n %d DATA RECEIVED\n",seq);
printf("\n ---- ACK is transmitting ----- \n");
return seq;
}
Output 1:

************* GO BACK N SLIDING WINDOW PROTOCAL ****************

size of sender window is fixed to 3 size

Enter the 0 packet to be send:13

Enter the 1 packet to be send:56

Enter the 2 packet to be send:14

SOURCE SIDE DESTINATION SIDE

-------------------- ---------------------------

0 Data is transmiting

1 Data is transmiting

2 Data is transmiting

------ TRANSMISSION ERROR AT 1 DATA ----

2 DATA DISCARDED

0 DATA RECEIVED

-------- ACK is transmitting ---------

ACK of pkt 0 is received ACK sent

1 data is retransmiting

2 data is retransmiting

1 DATA RECEIVED

-------- ACK is transmitting ----------

ACK of pkt 1 is received ACK sent

2 DATA RECEIVED

Dept of CSE, K L UNIVERSITY 19 Reg no-12203008


LAB CYCLE- Date:22-02-13

-------- ACK is transmitting --------

ACK of pkt 2 is received ACK sent

Do you want to send data to receiver (y/n):n

Output 2:

************* GO BACK N SLIDING WINDOW PROTOCAL ****************

size of sender window is fixed to 3 size

Enter the 0 packet to be send:12

Enter the 1 packet to be send:13

Enter the 2 packet to be send:14

SOURCE SIDE DESTINATION SIDE

------------------- ---------------------------

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 -----

ACK of pkt 2 is received ACK sent

Do you want to send data to receiver (y/n):n

Dept of CSE, K L UNIVERSITY 20 Reg no-12203008

You might also like