-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathred.cpp
34 lines (28 loc) · 844 Bytes
/
red.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
#include <iostream>
#include <time.h>
using namespace std;
int MAX_PACKETS = 20;
int QUEUE_SIZE = 10;
double MAX_PROBABILITY = 0.7;
double MIN_PROBABILITY = 0.3;
int main(){
srand(time(0));
int queue_length=0;
double drop_probability = MIN_PROBABILITY;
for(int i=0; i<MAX_PACKETS; i++){
if (queue_length==QUEUE_SIZE){
cout << "Packet dropped (QUEUE FULL)" <<endl;
drop_probability = MIN_PROBABILITY;
}
else if ((double)rand()/RAND_MAX < drop_probability){
cout << "Packet dropped (RANDOM)" <<endl;
drop_probability += (MAX_PROBABILITY - MIN_PROBABILITY)/(MAX_PACKETS - 1);
}
else{
cout << "Packet accepted" <<endl;
queue_length++;
drop_probability = MIN_PROBABILITY;
}
}
return 0;
}