File: queue-monitor.h

package info (click to toggle)
ns2 2.35%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 78,756 kB
  • ctags: 27,476
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 812; awk: 525; csh: 355
file content (319 lines) | stat: -rw-r--r-- 9,701 bytes parent folder | download | duplicates (7)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 
 *
 * Copyright (c) 1997 Regents of the University of California.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the MASH Research
 *      Group at the University of California Berkeley.
 * 4. Neither the name of the University nor of the Research Group may be
 *    used to endorse or promote products derived from this software without
 *    specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#) $Header: /cvsroot/nsnam/ns-2/tools/queue-monitor.h,v 1.26 2005/07/13 03:51:33 tomh Exp $ (UCB)
 */

#ifndef ns_queue_monitor_h
#define ns_queue_monitor_h

#include "config.h"  // for int64_t
#include "integrator.h"
#include "connector.h"
#include "packet.h"
#include "flags.h"

class QueueMonitor : public TclObject {
public: 
	QueueMonitor() : bytesInt_(NULL), pktsInt_(NULL), delaySamp_(NULL),
		size_(0), pkts_(0),
		parrivals_(0), barrivals_(0),
		pdepartures_(0), bdepartures_(0),
		pdrops_(0), pmarks_(0), bdrops_(0), 
			 qs_pkts_(0), qs_bytes_(0), qs_drops_(0),
		keepRTTstats_(0), maxRTT_(1), numRTTs_(0), binsPerSec_(10),
		keepSeqnoStats_(0), maxSeqno_(1000), 
		numSeqnos_(0), SeqnoBinSize_(1),
		srcId_(0), dstId_(0), channel_(0), channel1_(0),
		estimate_rate_(0), 
		k_(0.1), 
		estRate_(0.0),
		temp_size_(0) {
		
		bind("size_", &size_);
		bind("pkts_", &pkts_);
		bind("parrivals_", &parrivals_);
		bind("barrivals_", &barrivals_);
		bind("pdepartures_", &pdepartures_);
		bind("bdepartures_", &bdepartures_);
		bind("pdrops_", &pdrops_);
		bind("pmarks_", &pmarks_);
		bind("bdrops_", &bdrops_);

		bind("qs_pkts_", &qs_pkts_);
		bind("qs_bytes_", &qs_bytes_);
		bind("qs_drops_", &qs_drops_);

		bind("first_pkt_", &first_pkt_);
		bind("last_pkt_", &last_pkt_);

		//for keeping RTT statistics
                bind_bool("keepRTTstats_", &keepRTTstats_);
		bind("maxRTT_", &maxRTT_);
		bind("binsPerSec_", &binsPerSec_);

		//for keeping sequence number statistics
                bind_bool("keepSeqnoStats_", &keepSeqnoStats_);
		bind("maxSeqno_", &maxSeqno_);
		bind("SeqnoBinSize_", &SeqnoBinSize_);

		//variable binding for flow rate estimation
		bind_bool("estimate_rate_", &estimate_rate_);
		bind("k_", &k_);
		bind("prevTime_", &prevTime_);
		bind("startTime_", &startTime_);
 		bind("estRate_", &estRate_);
		
		startTime_ = Scheduler::instance().clock();
		prevTime_  = startTime_;
	};

	int size() const { return (size_); }
	int pkts() const { return (pkts_); }
	int parrivals() const { return (parrivals_); }
	int barrivals() const { return (barrivals_); }
	int pdepartures() const { return (pdepartures_); }
	int bdepartures() const { return (bdepartures_); }
	int pdrops() const { return (pdrops_); }
	int pmarks() const { return (pmarks_); }
	int bdrops() const { return (bdrops_); }

	int qs_pkts() const { return (qs_pkts_); }
	int qs_bytes() const { return (qs_bytes_); }
	int qs_drops() const { return (qs_drops_); }

	double first_pkt() const { return (first_pkt_); }

	void printRTTs();
	void printSeqnos();
	void printStats();
	virtual void in(Packet*);
	virtual void out(Packet*);
	virtual void drop(Packet*);
	virtual void edrop(Packet*) { abort(); }; // not here
	virtual int command(int argc, const char*const* argv);
protected:
	Integrator *bytesInt_;		// q-size integrator (bytes)
	Integrator *pktsInt_;		// q-size integrator (pkts)
	Samples* delaySamp_;		// stat samples of q delay
	int size_;			// current queue size (bytes)
	int pkts_;			// current queue size (packets)
	// aggregate counters bytes/packets
	int parrivals_;
	int barrivals_;
	int pdepartures_;
	int bdepartures_;
	int pdrops_;
	int pmarks_;
	int bdrops_;

	int qs_pkts_;			/* Number of Quick-Start packets */
	int qs_bytes_;			/* Number of Quick-Start bytes */
	int qs_drops_;			/* Number of dropped QS packets */

	double first_pkt_;		/* Time of first packet arrival */
	double last_pkt_;		/* Time of last packet arrival */

        int keepRTTstats_;		/* boolean - keeping RTT stats? */
	int maxRTT_;			/* Max RTT to measure, in seconds */
	int numRTTs_;			/* number of RTT measurements */
	int binsPerSec_;		/* number of bins per second */
	int *RTTbins_;			/* Number of RTTs in each bin */

        int keepSeqnoStats_;		/* boolean - keeping Seqno stats? */
	int maxSeqno_;			/* Max Seqno to measure */
	int numSeqnos_;			/* number of Seqno measurements */
	int SeqnoBinSize_;		/* number of Seqnos per bin */
	int *SeqnoBins_;		/* Number of Seqnos in each bin */

	int srcId_;
	int dstId_;
	Tcl_Channel channel_;
	Tcl_Channel channel1_;

	// the estimation of incoming rate using an exponential averaging algorithm due to Stoica
	// hence a lot of this stuff is inspired by csfq.cc(Stoica)
	// put in here so that it can be used to estimate the arrival rate for both whole queues as 
	// well as flows (Flow inherits from EDQueueMonitor);
public:
	int estimate_rate_;           /* boolean - whether rate estimation is on or not */
	double k_;                    /* averaging interval for rate estimation in seconds*/
	double estRate_;              /* current flow's estimated rate in bps */
	double prevTime_;             /* time of last packet arrival */
	double startTime_;            /* time when the flow started */

protected:
	int temp_size_;               /* keep track of packets that arrive at the same time */

	void estimateRate(Packet *p);
	void keepRTTstats(Packet *p);
	void keepSeqnoStats(Packet *p);
};

class SnoopQueue : public Connector {
public: 
	SnoopQueue() : qm_(0) {}
	int command(int argc, const char*const* argv) {
		if (argc == 3) { 
			if (strcmp(argv[1], "set-monitor") == 0) {
				qm_ = (QueueMonitor*)
					TclObject::lookup(argv[2]);
				if (qm_ == NULL)
					return (TCL_ERROR);
				return (TCL_OK);
			}
		}
		return (Connector::command(argc, argv));
	}
 protected:
	QueueMonitor* qm_;
};

class SnoopQueueIn : public SnoopQueue {
public:
	void recv(Packet* p, Handler* h) {
		qm_->in(p);
		send(p, h);
	}
};

class SnoopQueueOut : public SnoopQueue {
public:
	void recv(Packet* p, Handler* h) {
		qm_->out(p);
		send(p, h);
	}
};

class SnoopQueueDrop : public SnoopQueue {
public:
	void recv(Packet* p, Handler* h) {
		qm_->drop(p);
		send(p, h);
	}
};

/* Tagger, Like a normal FlowMonitor, use SnoopQueueTagger
 * to start it.
 * By Yun Wang 
 */
class SnoopQueueTagger : public SnoopQueue {
public:
        void recv(Packet* p, Handler* h) {
                qm_->in(p);
                send(p, h);
        }
};

/*
 * "early drop" QueueMonitor.  Like a normal QueueMonitor,
 * but also supports the notion of "early" drops
 */

/* 
 * The mon* things added to make it work with redpd. 
 * I tried more "elegant" ways -- but mulitple inheritance sucks !!.
 * -ratul
 */
class EDQueueMonitor : public QueueMonitor {
public:
	EDQueueMonitor() : ebdrops_(0), epdrops_(0), mon_ebdrops_(0), mon_epdrops_(0) {
		bind("ebdrops_", &ebdrops_);
		bind("epdrops_", &epdrops_);
		bind("mon_ebdrops_", &mon_ebdrops_);
		bind("mon_epdrops_", &mon_epdrops_);
	}
	void edrop(Packet* p) {
		hdr_cmn* hdr = hdr_cmn::access(p);
		ebdrops_ += hdr->size();
		epdrops_++;
		// remove later - ratul
		// printf("My epdrops = %d\n",epdrops_);
		QueueMonitor::drop(p);
	}
	
	void mon_edrop(Packet *p) {
		hdr_cmn* hdr = hdr_cmn::access(p);
		mon_ebdrops_ += hdr->size();
		mon_epdrops_++;
	
		QueueMonitor::drop(p);
	}
	
	int epdrops() const { return (epdrops_); }
	int ebdrops() const { return (ebdrops_); }
	int mon_epdrops() const { return (mon_epdrops_); }
	int mon_ebdrops() const { return (mon_ebdrops_); }
protected:
	int	ebdrops_;
	int	epdrops_;
	int	mon_ebdrops_;
	int	mon_epdrops_;
};

class SnoopQueueEDrop : public SnoopQueue {
public:
	void recv(Packet* p, Handler* h) {
		qm_->edrop(p);
		send(p, h);
	}
};


#ifndef	MAXFLOW
#define	MAXFLOW	32
#endif

/*
 * a 'QueueMonitorCompat', which is used by the compat
 * code to produce the link statistics available in ns-1
 */

class QueueMonitorCompat : public QueueMonitor {
public:
	QueueMonitorCompat();
	void in(Packet*);
	void out(Packet*);
	void drop(Packet*);
	int command(int argc, const char*const* argv);
protected:
	void	flowstats(int flowid);	/* create a flowstats structure */

	int	pkts_[MAXFLOW];
	int	bytes_[MAXFLOW];
	int	drops_[MAXFLOW];
	Samples *flowstats_[MAXFLOW];
};

#endif