-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfairqueue.h
69 lines (55 loc) · 1.67 KB
/
fairqueue.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef FAIR_QUEUE_H
#define FAIR_QUEUE_H
/*
* A fair-queue that emulates byte-by-byte round robin.
*/
#include "queue.h"
#include <set>
class CompareFqPackets
{
public:
bool operator() (std::pair<uint64_t,Packet*> a,
std::pair<uint64_t,Packet*> b)
{
if (a.first < b.first) {
return true;
} else if (a.first > b.first) {
return false;
} else {
if (a.second->id() < b.second->id()) {
return true;
} else {
return false;
}
}
}
};
class FairQueue : public Queue
{
public:
FairQueue(linkspeed_bps bitrate, mem_b maxsize, QueueLogger *logger);
void receivePacket(Packet &pkt);
void printStats();
protected:
void beginService();
void completeService();
private:
// Updates the current round number based on time elapsed and active flows.
void updateRoundNumber();
// Multi-set of all packets, to transmit from head or drop from tail.
std::multiset<std::pair<uint64_t,Packet*>, CompareFqPackets> _packets;
// Finish round number of each active flow.
std::unordered_map<uint32_t, uint64_t> _flowRound;
// Number of packets enqueued for each active flow.
std::unordered_map<uint32_t, uint32_t> _nPackets;
simtime_picosec _roundUpdate; // Last round update time.
uint32_t _nActiveFlows; // Number of active flows.
uint64_t _roundNumber; // Current round number.
double _exactRoundNumber; // Current round number in decimals.
Packet *_currentPkt; // Current packet being serviced.
enum Mode {
PRECISE,
LAZY
} _mode;
};
#endif