Go-Back-N (GBN) ARQ Protocol allows the sender to send multiple frames before receiving individual acknowledgments. It is a flow control protocol used in the data link layer to achieve reliable and efficient data transmission between a sender and a receiver over a noisy channel. In this article, you would learn to code the Go-Back-N Protocol using C++.
You can use any code editor you want to run this program. However, using either Codeblocks or VS Code is recommended. Refer to this article to learn how to setup VScode to compile and run C/C++ code.
/*In Go Back N, there is a window in sender's side but only one unit receiver buffer. So if out of order packet
arrives it's not taken in. There is cumulative acknowledgement. And for a lost data packet or acknowledgement
the entire window is retransmitted.*/
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int noofframes=6,N=4;
int count=0;
srand(time(NULL));
int i=1;
while(i<=noofframes)
{
int x=0;
for(int j=i;j<i+N && j<=noofframes;j++)
{
cout<<"Sending the Frame "<<j<<endl;
count++;
}
for(int j=i;j<i+N && j<=noofframes;j++)
{
int flag = rand()%2;
if(!flag)
{
cout<<"\n Acknowledgment for Window Received whose first packet is "<<j;
x++;
}
else
{ cout<<"\n Data Packet in Cumulative Acknowledgement Not Received whose first packet is "<<j;
cout<<"\n Retransmitting the Same Window \n";
break;
}
}
cout<<endl;
i+=x;
}
cout<<"\n Total number of transmissions : "<<count;
return 0;
}
For the github repository of C implementation of the Go-Back-N Protocol along with other networking and TCP/IP protocol suite protocols, click here.
It is not necessary to try all successively
You are certainly right. In it something is and it is excellent thought. I support you.
I think, to you will help to find the correct decision. Be not afflicted.