C++ Program To Implement Go Back N

  • Go Back N is an implementation of sliding window protocol
  • Go-Back-N ARQ is a particular instance of the automatic repeat request (ARQ) protocol, in which the sending process continues to send the number of frames determined by a window size even without receiving an acknowledgment (ACK) packet from the beneficiary. 
  • It is an uncommon instance of the general sliding window protocol with the transmit window size of N and get window size of 1. It can transmit N frames to the destination before requiring an ACK. 
  • The receiver process monitors the sequence number of the next edge it hopes to get and sends that number with each ACK it sends.
  •  The receiver will dispose of any casing that does not have the definite sequence number it expects and will resend an ACK for the last right in-request outline. 
  • Once the sender has sent the majority of the frames in its window, it will identify that the majority of the frames since the main lost edge are outstanding, and will go back to the sequence number of the last ACK it got from the receiver process and fill its window starting with that frame and continue the process over again. 
  •  be spent waiting, more packets are being sent. Nonetheless, this strategy likewise brings about sending frames on numerous occasions – if any edge was lost or harmed, or the ACK acknowledging them was lost or harmed, then that frame and every single following frame in the window will be re-sent. To maintain a strategic distance from this, Selective Repeat ARQ can be utilized.

Here you get Go back N sliding window protocol program in C++.

C++ Program To Implement Go Back N
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int nf,N;
int no_tr=0;
srand(time(NULL));
cout<<"Enter the number of frames : ";
cin>>nf;
cout<<"Enter the Window Size : ";
cin>>N;
int i=1;
while(i<=nf)
{
    int x=0;
    for(int j=i;j<i+N && j<=nf;j++)
    {
        cout<<"Sent Frame "<<j<<endl;
        no_tr++;
    }
    for(int j=i;j<i+N && j<=nf;j++)
    {
        int flag = rand()%2;
        if(!flag)
            {
                cout<<"Acknowledgment for Frame "<<j<<endl;
                x++;
            }
        else
            {   cout<<"Frame "<<j<<" Not Received"<<endl;
                cout<<"Retransmitting Window"<<endl;
                break;
            }
    }
    cout<<endl;
    i+=x;
}
cout<<"Total number of transmissions : "<<no_tr<<endl;
return 0;
}


OUTPUT:
Enter the number of frames: 10
Enter the Window Size : 3
Sent Frame 1
Sent Frame 2
Sent Frame 3
Acknowledgment for Frame 1
Acknowledgment for Frame 2
Acknowledgment for Frame 3


Sent Frame 4
Sent Frame 5
Sent Frame 6
Frame 4 Not Received
Retransmitting Window


Sent Frame 4
Sent Frame 5
Sent Frame 6
Acknowledgment for Frame 4
Acknowledgment for Frame 5
Acknowledgment for Frame 6


Sent Frame 7
Sent Frame 8
Sent Frame 9
Acknowledgment for Frame 7
Acknowledgment for Frame 8
Acknowledgment for Frame 9


Sent Frame 10
Acknowledgment for Frame 10


Total number of transmissions: 13

tags: sliding window protocol, go back n, window size, packets, packets size, programming language, learn programming, computer networks, go back n sliding window protocol,

2 Comments

  1. Sir can you please send opengl code for Go back N protocol
    Email : shreyashet200@gmail.com

    ReplyDelete
  2. Hey there is one small error in your code. Whenever any acknowledgement is received the sender can send the next frame. But in your code the sender can send all the frames only when all the acknowledgment are received, this will affect the total transmission count.

    ReplyDelete
Previous Post Next Post