-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo_back_n.cc
47 lines (42 loc) · 885 Bytes
/
go_back_n.cc
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
45
46
47
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int n,ws,tr=0;
// tr -> total nuber of transmissions
cout<<"Enter number of frames to be transmitted = ";
cin>>n;
cout<<"Enter sender window size = ";
cin>>ws;
int i=1;
while(i<=n)
{
int x = 0;
// send frames from current frame to (current frame + window size)
for(int j=i;j<i+ws && j<=n;j++)
{
cout<<"Sent Frame ["<<j<<"]\n";
tr++;
}
for(int j=i;j<i+ws && j<=n;j++)
{
int flag = rand()%2;
if(flag != 0)
{
cout<<"Ack for Frame["<<j<<"]\n";
x++;
}
else
{
cout<<"Frame["<<j<<"] not received\n\n";
cout<<"Retransmitting Window\n";
break;
}
}
cout<<endl;
i = i+x;
}
cout<<"Total number of transmissions = "<<tr<<endl;
return 0;
}