We have roamed on the ground floor of the sliding window protocol in the earlier post. If you haven’t gone through it, here is the route. There are two major sliding window protocols. Now, we shall look at the implementation of one of the sliding window protocols, GoBackN.
Go Back N (GBN):
The sender window size is N in GBN. For example, if it is Go Back 10 (GB10) it indicates that the window size of the sender is 10. In GBN, the window size of the receiver is always equal to 1 irrespective of the size of the sender. GBN uses cumulative acknowledgments. At the receiver’s end, it starts an acknowledgment timer. The receiver sends an acknowledgment for the set of finite frames received once the timer ends. If the acknowledgment is not sent, then the set of frames has to be retransmitted from the sender.
The acknowledgment timer will not start once the earlier timer expires. It starts once it receives a packet or a frame.
It will be more clear once we take an example.
Let’s say it is GB3 with a sequence number field of 2 bits. The size of the sender window=3 (since N=3). We require a minimum of 3 sequence numbers to represent the frames.

Now the sender sends three frames at once (window size=3). Then the window slides to the left of three frames. The receiver responds with an increased value of the acknowledgment number stating that it is waiting for the “acknowledgment number” frame. Suppose if frames 0,1,2 are transmitted. If there is no loss of packets, then the receiver responds with ACK=3 (n+1) asking for the transmission of frame 3. With reference to Fig 1.
If there is any loss in the frame, say 1 is lost when 0,1, and 2 are transmitted. The window is slid to the next three frames at the sender’s side. Since the frame 1 is lost, the receiver waits for the frame 1 until the timer expires. When the timer expires, the acknowledgment number sent is 1, as only the frame 0 is received at the receiver side and the other frames are simply discarded. Then the “window slides back to the frame 1” or “window go back to frame 1” and transmit all the frames starting from frame 1 i.e. 1,2, and 3.
The frames are now transmitted completely with no loss and the acknowledgment number would be ACK+1 i.e. 4. Now, what if the ACK packet is lost??

The sender waits for the acknowledgment until the timer expires. If the acknowledgment is not received, then the window slides to the initial or the earlier set of frames and retransmits them. As the receiver is now waiting for frame 3 (assuming 0,1, and 2 frames are transmitted earlier), it simply discards them and sends the acknowledgment number 3 again. This process continues until the reception of respective packets take place at both ends of the communication. With reference to Fig 2.
Simulation of GoBackN:
/*File: GoBackN.java*/
import java.io.*;
public class GoBackN {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the Window Size: ");
int window = Integer.parseInt(br.readLine());
boolean loop = true;
int sent = 0;
while(loop){
for(int i = 0; i < window; i++){
System.out.println("Frame " + sent + " has been transmitted.");
sent++;
if(sent == window)
break;
}
System.out.println("Please enter the last Acknowledgement received.");
int ack = Integer.parseInt(br.readLine());
if(ack == window)
loop = false;
else
sent = ack;
}
}
}
/* Source code from:
http://campuscoke.blogspot.com/2015/01/go-back-n-protocol-in-java.html
*/
If you have any queries or suggestions, you are free to contact us or simply transmit your views to the comment section. We are glad to assist you!😀
2 thoughts on “Go Back N”