Go-Back-N Protocol
Description
Go-Back-N is a sliding window protocol used in network communications to achieve reliable data transmission over an unreliable network. It allows multiple frames to be in transit between sender and receiver, where the sender can send multiple frames before receiving an acknowledgment (ACK) from the receiver. If an ACK is not received within a specified timeout period, the sender retransmits all frames starting from the unacknowledged frame.
C++ Code (without comments)
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
using namespace std;
const int WINDOW_SIZE = 4;
const int TIMEOUT = 3;
bool sendData(int frameNumber) {
srand(time(0));
bool ackReceived = (rand() % 10 < 8);
if (ackReceived) {
cout << "Frame " << frameNumber << " sent successfully." << endl;
return true;
} else {
cout << "Frame " << frameNumber << " not acknowledged. Retransmitting all frames in window..." << endl;
return false;
}
}
int main() {
int base = 1;
int nextSeqNum = 1;
while (base <= 5) {
while (nextSeqNum < base + WINDOW_SIZE && nextSeqNum <= 5) {
bool ack = sendData(nextSeqNum);
if (ack) {
nextSeqNum++;
}
}
sleep(TIMEOUT);
}
cout << "Data transmission completed." << endl;
return 0;
}
Time and Space Complexity
Operation | Time Complexity | Space Complexity |
---|---|---|
Go-Back-N Protocol | O(n) | O(1) |
Where:
- n: Number of frames to be transmitted.