-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomqueue.cpp
52 lines (42 loc) · 1.2 KB
/
randomqueue.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
45
46
47
48
49
50
51
52
#include "randomqueue.h"
RandomQueue::RandomQueue(linkspeed_bps bitrate, mem_b maxsize, QueueLogger *logger, mem_b drop)
: Queue(bitrate, maxsize, logger), _drop(drop), _buffer_drops(0)
{
_drop_th = _maxsize - _drop;
_plr = 0.0;
}
void
RandomQueue::set_packet_loss_rate(double l)
{
_plr = l;
}
void
RandomQueue::receivePacket(Packet &pkt)
{
double drop_prob = 0;
mem_b crt = _queuesize + pkt.size();
if (_plr > 0.0 && drand() < _plr) {
pkt.free();
return;
}
if (crt > _drop_th)
drop_prob = 1100.0 / _drop_th;
if (crt > _maxsize || drand() < drop_prob) {
if (_logger) _logger->logQueue(*this, QueueLogger::PKT_DROP, pkt);
pkt.flow().logTraffic(pkt,*this,TrafficLogger::PKT_DROP);
if (crt > _maxsize) {
_buffer_drops ++;
}
pkt.free();
return;
}
pkt.flow().logTraffic(pkt,*this,TrafficLogger::PKT_ARRIVE);
bool queueWasEmpty = _enqueued.empty();
_enqueued.push_front(&pkt);
_queuesize += pkt.size();
if (_logger) _logger->logQueue(*this, QueueLogger::PKT_ENQUEUE, pkt);
if (queueWasEmpty) {
assert(_enqueued.size()==1);
beginService();
}
}