-
Notifications
You must be signed in to change notification settings - Fork 1
/
GoBackN.cpp
44 lines (42 loc) · 1.18 KB
/
GoBackN.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*This code is contributed by Sourajita Dewasi. */
/*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;
}