13 Go-back-N Algorithm, Program
13 Go-back-N Algorithm, Program
Aim:- write a program to perform simulation on sliding window protocol using Go-back-N
ARQ for noisy channel.
Description:-
● In Go-Back-N ARQ, the size of the sender window is N and the size of the receiver
window is always 1.
● This protocol makes the use of cumulative acknowledgements means here the
receiver maintains an acknowledgement timer.
● If the receiver receives a corrupted frame, then it silently discards that corrupted
frame and the correct frame is retransmitted by the sender after the timeout timer
expires.
● In case if the receiver receives the out of order frame then it simply discards all the
frames.
● In case if the sender does not receive any acknowledgement then the frames in the
entire window will be retransmitted again.
SF is the sequence number of the first frame in the sliding window, S L is
the sequence number of the last frame in the sliding window. R is the
sequence number of the expected frame. W=S L-SF+1=N itself, indicating
the number of frames. Only when R and sequence number of
received frame are matched, frame is accepted, otherwise discard
frame. Receiver window size is 1.
Consequently, the size of the sending window is 2^n1. Thus in order to accommodate a sending window
2^3 - 1 = 7 i.e window will carry frames from 0 to 6 which are 7 in number. If window
size is 3, we use a 2-bit sequence number to transmit frames, i.e 2^2-1=3.
Frame 0 &1 send, ACK 1 & 2 back to sender. Frame 2 send, ACK 3 back to sender.
Algorithm to be written in record
GoBackN.c
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
int nf,N;
int tr=0;
srand(time(NULL));
scanf("%d",&nf);
scanf("%d",&N);
int i=1;
while(i<=nf)
{
int x=0;
tr++; //After each frame is send, increment tr by 1 to track total number of transmissions
if(!flag)
else
break;
printf("\n");
return 0; }
Output
gcc goBackN.c
net@inlab:~$ ./a.out
Enter the number of
frames : 5
Enter the Window Size : 2
Sent Frame 1
Sent Frame 2
1 : Acknowledged!
Frame 2 Not Received
Retransmitting Window
Sent Frame 2
Sent Frame 3
2 : Acknowledged!
3 : Acknowledged!
Sent Frame 4
Sent Frame 5
4 : Acknowledged!
5 : Acknowledged!
Total number of
transmissions : 6
gbns.c
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
#include<string.h>
#include<unistd.h>
numberString[1] = '\0';
int main()
char buffer[100];
socklen_t len;
server.sin_family = AF_INET;
server.sin_port = 3033;
server.sin_addr.s_addr = INADDR_ANY;
printf("\nStarting up...");
int k;
k=bind(sockfd, (struct sockaddr *)&server, sizeof(server)); //bind socket with ip addr of server
if(k==-1)
printf("Error in binding");
len = sizeof(client);
listen(sockfd,1);
do
if(windowCurrent != windowEnd)
printf("\nPacket Sent: %d\n",windowCurrent); //show which window number the transmitted frame
was
else if(buffer[0] == 'A') //check if incoming buffer contained acknowledgement denoted by ‘A’
while(windowCurrent!= 10);
close(sockfd);
close(newSockFd);
return(0);
gbnc.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include<unistd.h>
int main()
client.sin_family = AF_INET;
client.sin_port = 3033;
client.sin_addr.s_addr = INADDR_ANY;
printf("\nStarting up...");
size = sizeof(client);
sprintf(data, "REQUEST");
firstTime =0;
else
{ wait--; //wait time is initialized as 3ms. we can reduce wait time till 0
if(!wait)
sprintf(data, "A");
digit[1] = '\0';
strcat(data, digit); //concatenate A and packet number together for each packet
send(sockfd, data,strlen(data),0); //send acknowledgement to server
while(currentPacket != 9);
close(sockfd);
return(0);
labb04@labb04:~/Desktop$ ./s1
Starting up...
Packet Sent: 1
Packet Sent: 2
Packet Sent: 3
Packet Sent: 2
Packet Sent: 3
Packet Sent: 4
Packet Sent: 5
Packet Sent: 6
Packet Sent: 7
Packet Sent: 8
Packet Sent: 9
labb04@labb04:~/Desktop$ ./c1
Starting up...
Establishing Connection...
Got packet: 1
Got packet: 2
Got packet: 3
Got packet: 1
Got packet: 2
Got packet: 3
Got packet: 4
Got packet: 5
Got packet: 6
Got packet: 7
Got packet: 8
Got packet: 9