-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggers.cpp
203 lines (171 loc) · 5.56 KB
/
loggers.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* Loggers
*/
#include "loggers.h"
#include "prof.h"
using namespace std;
QueueLoggerSampling::QueueLoggerSampling(simtime_picosec period)
: EventSource("QueueLogSampling"),
_queue(NULL),
_lastlook(0),
_period(period),
_lastq(0),
_seenQueueInD(false),
_cumidle(0),
_cumarr(0),
_cumdrop(0),
_bytesInD(0),
_printed(false)
{
EventList::Get().sourceIsPendingRel(*this, 0);
}
void
QueueLoggerSampling::doNextEvent()
{
EventList::Get().sourceIsPendingRel(*this, _period);
if (_queue == NULL) {
return;
}
if (!_seenQueueInD) { // queue size hasn't changed in the past D time units
_logfile->writeRecord(QUEUE_APPROX, _queue->id, QUEUE_RANGE, (double)_lastq, (double)_lastq, (double)_lastq);
_logfile->writeRecord(QUEUE_APPROX, _queue->id, QUEUE_OVERFLOW, 0, 0, _bytesInD/timeAsSec(_period));
}
else { // queue size has changed
_logfile->writeRecord(QUEUE_APPROX, _queue->id, QUEUE_RANGE,
(double)_lastq, (double)_minQueueInD, (double)_maxQueueInD);
_logfile->writeRecord(QUEUE_APPROX, _queue->id, QUEUE_OVERFLOW,
-(double)_lastIdledInD, (double)_lastDroppedInD, _bytesInD/timeAsSec(_period));
}
_seenQueueInD = false;
simtime_picosec now = EventList::Get().now();
simtime_picosec dt_ps = now - _lastlook;
_lastlook = now;
_bytesInD = 0;
_printed = false;
// if the queue is empty, we've just been idling
if ((_queue != NULL) && (_queue->_queuesize == 0)) {
_cumidle += timeAsSec(dt_ps);
}
_logfile->writeRecord(QUEUE_RECORD, _queue->id, CUM_TRAFFIC, _cumarr, _cumidle, _cumdrop);
#if MING_PROF
_queue->printStats();
#endif
}
void
QueueLoggerSampling::logQueue(Queue& queue,
QueueEvent ev,
Packet &pkt)
{
if (_queue == NULL) {
_queue = &queue;
} else {
assert(&queue == _queue);
}
_lastq = queue._queuesize;
if (!_seenQueueInD) {
_seenQueueInD = true;
_minQueueInD = queue._queuesize;
_maxQueueInD = _minQueueInD;
_lastDroppedInD = 0;
_lastIdledInD = 0;
_numIdledInD = 0;
_numDropsInD = 0;
} else {
_minQueueInD = min(_minQueueInD, queue._queuesize);
_maxQueueInD = max(_maxQueueInD, queue._queuesize);
}
simtime_picosec now = EventList::Get().now();
simtime_picosec dt_ps = now - _lastlook;
_lastlook = now;
double dt = timeAsSec(dt_ps);
switch (ev) {
case PKT_SERVICE: // we've just been working
_bytesInD += pkt.size();
break;
case PKT_ENQUEUE:
_cumarr += timeAsSec(queue.drainTime(&pkt));
if (queue._queuesize > pkt.size()) {
// we've just been working
} else { // we've just been idling
mem_b idledwork = queue.serviceCapacity(dt_ps);
_cumidle += dt;
_lastIdledInD = idledwork;
_numIdledInD++;
}
break;
case PKT_DROP: // assume we've just been working
assert(queue._queuesize >= pkt.size());
// it is possible to drop when queue is idling, but this logger can't make sense of it
double localdroptime = timeAsSec(queue.drainTime(&pkt));
_cumarr += localdroptime;
_cumdrop += localdroptime;
_lastDroppedInD += pkt.size();
_numDropsInD++;
break;
}
//if (!_printed && queue._queuesize > 50000) {
// queue.printStats();
// _printed = true;
//}
}
AggregateTcpLogger::AggregateTcpLogger(simtime_picosec period)
: EventSource("bunchofflows"),
_period(period)
{
EventList::Get().sourceIsPendingRel(*this, period);
}
void
AggregateTcpLogger::monitorTcp(TcpSrc& tcp)
{
_monitoredTcps.push_back(&tcp);
}
void
AggregateTcpLogger::doNextEvent()
{
EventList::Get().sourceIsPendingRel(*this, _period);
double totunacked = 0;
double totcwnd = 0;
int numflows = 0;
for (tcplist_t::iterator i = _monitoredTcps.begin(); i != _monitoredTcps.end(); i++) {
TcpSrc* tcp = *i;
uint32_t cwnd = tcp->_cwnd;
uint32_t unacked = tcp->_highest_sent - tcp->_last_acked;
totcwnd += cwnd;
totunacked += unacked;
numflows++;
}
_logfile->writeRecord(TcpLogger::TCP_RECORD, id, TcpLogger::AVE_CWND,
totcwnd/numflows, totunacked/numflows, 0);
}
SinkLoggerSampling::SinkLoggerSampling(simtime_picosec period):
EventSource("SinkSampling"),
_period(period)
{
EventList::Get().sourceIsPendingRel(*this, 0);
}
void
SinkLoggerSampling::monitorSink(DataSink* sink)
{
_sinks.push_back(sink);
_last_seq.push_back(sink->cumulative_ack());
_last_rate.push_back(0);
}
void
SinkLoggerSampling::doNextEvent()
{
EventList::Get().sourceIsPendingRel(*this, _period);
simtime_picosec now = EventList::Get().now();
simtime_picosec delta = now - _last_time;
_last_time = now;
for (uint64_t i = 0; i < _sinks.size(); i++) {
// this deals with resets for periodic sources
if (_last_seq[i] <= _sinks[i]->cumulative_ack()) {
DataAck::seq_t deltaB = _sinks[i]->cumulative_ack() - _last_seq[i];
double rate = deltaB / timeAsSec(delta); // In Bps
_logfile->writeRecord(TcpLogger::TCP_SINK, _sinks[i]->id, TcpLogger::RATE,
rate, _sinks[i]->drops(), _sinks[i]->cumulative_ack());
_last_rate[i] = rate;
}
_last_seq[i] = _sinks[i]->cumulative_ack();
}
}