12 Go-back-N Algorithm, Program
12 Go-back-N Algorithm, Program
ARQ.
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.
Disadvantages
Algorithm
1.
SF is the sequence number of the first frame in the slide window, SL is
the sequence number of the last frame in the slide window. R is the
sequence number of the excepted frame. W=SL-SF+1=2m-1. Only
when R and sequence number of received frame are matched, frame
accept, otherwise discard it.
Fram
e 0 &1 send, ACK 1 & 2 back to sender. Frame 2 send, ACK 3 back to sender.
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++;
if(!flag)
x++;
else
break;
printf("\n");
i+=x;
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
Go-Back N Client/Server
Implementation in C
gbnclient.c
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<sys/time.h>
#include<sys/wait.h>
#include<string.h>
#include<unistd.h>
#include<arpa/inet.h>
int main() {
int c_sock;
memset(&client, 0, sizeof(client));
client.sin_family = AF_INET;
client.sin_port = htons(9009);
client.sin_addr.s_addr = inet_addr("127.0.0.1");
printf("Connection failed");
return 0;
char msg2[50];
char buff[100];
int flag=1,flg=1;
for(int i=0;i<=9;i++) {
flg=1;
bzero(buff,sizeof(buff));
bzero(msg2,sizeof(msg2));
if(i==8&&flag==1){
flag=0;
read(c_sock,buff,sizeof(buff));
i--;
else{
strcpy(msg2,msg1);
msg2[strlen(msg2)]=i+'0';
write(c_sock,msg2, sizeof(msg2));
close(c_sock);
return 0;
gbnserver.c
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<sys/time.h>
#include<netinet/in.h>
#include<string.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<fcntl.h>
int main() {
memset(&server, 0, sizeof(server));
memset(&other, 0, sizeof(other));
server.sin_family = AF_INET;
server.sin_port = htons(9009);
server.sin_addr.s_addr = INADDR_ANY;
socklen_t add;
printf("Binding failed\n");
return 0;
add = sizeof(other);
time_t t1,t2;
char buff[50];
int flag=0;
fd_set set1,set2,set3;
int rv1,rv2,rv3;
int i=-1;
qq:
i=i+1;
bzero(buff,sizeof(buff));
char buff2[60];
bzero(buff2,sizeof(buff2));
buff2[strlen(buff2)]=i+'0';
buff2[strlen(buff2)]='\0';
usleep(1000);
i=i+1;
bzero(buff2,sizeof(buff2));
strcpy(buff2,msg);
buff2[strlen(msg)]=i+'0';
i=i+1;
usleep(1000);
qqq:
bzero(buff2,sizeof(buff2));
strcpy(buff2,msg);
buff2[strlen(msg)]=i+'0';
FD_ZERO(&set1);
FD_SET(c_sock, &set1);
timeout1.tv_sec = 2;
timeout1.tv_usec = 0;
if(rv1 == -1)
i=i-3;
goto qq;}
else{
if(i<=9)
goto qqq;
qq2:
FD_ZERO(&set2);
FD_SET(c_sock, &set2);
timeout2.tv_sec = 3;
timeout2.tv_usec = 0;
if(rv2 == -1)
i=i-2;
bzero(buff2,sizeof(buff2));
strcpy(buff2,msg);
buff2[strlen(buff2)]=i+'0';
usleep(1000);
bzero(buff2,sizeof(buff2));
i++;
strcpy(buff2,msg);
buff2[strlen(buff2)]=i+'0';
else{
bzero(buff,sizeof(buff));
close(c_sock);
close(s_sock);
return 0;
Output
gcc gbserver.c -o s
cca@labb30:~$ ./s
Server Up
gcc gbclient.c -o c
cca@labb30:~$ ./c
here