| 1 |
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- |
| 2 |
* |
| 3 |
* Copyright (c) 1997 Regents of the University of California. |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 12 |
* notice, this list of conditions and the following disclaimer in the |
| 13 |
* documentation and/or other materials provided with the distribution. |
| 14 |
* 3. All advertising materials mentioning features or use of this software |
| 15 |
* must display the following acknowledgement: |
| 16 |
* This product includes software developed by the MASH Research |
| 17 |
* Group at the University of California Berkeley. |
| 18 |
* 4. Neither the name of the University nor of the Research Group may be |
| 19 |
* used to endorse or promote products derived from this software without |
| 20 |
* specific prior written permission. |
| 21 |
* |
| 22 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 23 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 28 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 29 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 31 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 |
* SUCH DAMAGE. |
| 33 |
* |
| 34 |
* @(#) $Header: /cvsroot/nsnam/ns-2/tools/queue-monitor.h,v 1.26 2005/07/13 03:51:33 tomh Exp $ (UCB) |
| 35 |
*/ |
| 36 |
|
| 37 |
#ifndef ns_queue_monitor_h |
| 38 |
#define ns_queue_monitor_h |
| 39 |
|
| 40 |
#include "config.h" // for int64_t |
| 41 |
#include "integrator.h" |
| 42 |
#include "connector.h" |
| 43 |
#include "packet.h" |
| 44 |
#include "flags.h" |
| 45 |
|
| 46 |
class QueueMonitor : public TclObject { |
| 47 |
public: |
| 48 |
QueueMonitor() : bytesInt_(NULL), pktsInt_(NULL), delaySamp_(NULL), |
| 49 |
size_(0), pkts_(0), |
| 50 |
parrivals_(0), barrivals_(0), |
| 51 |
pdepartures_(0), bdepartures_(0), |
| 52 |
pdrops_(0), pmarks_(0), bdrops_(0), |
| 53 |
qs_pkts_(0), qs_bytes_(0), qs_drops_(0), |
| 54 |
keepRTTstats_(0), maxRTT_(1), numRTTs_(0), binsPerSec_(10), |
| 55 |
keepSeqnoStats_(0), maxSeqno_(1000), |
| 56 |
numSeqnos_(0), SeqnoBinSize_(1), |
| 57 |
srcId_(0), dstId_(0), channel_(0), channel1_(0), |
| 58 |
estimate_rate_(0), |
| 59 |
k_(0.1), |
| 60 |
estRate_(0.0), |
| 61 |
temp_size_(0) { |
| 62 |
|
| 63 |
bind("size_", &size_); |
| 64 |
bind("pkts_", &pkts_); |
| 65 |
bind("parrivals_", &parrivals_); |
| 66 |
bind("barrivals_", &barrivals_); |
| 67 |
bind("pdepartures_", &pdepartures_); |
| 68 |
bind("bdepartures_", &bdepartures_); |
| 69 |
bind("pdrops_", &pdrops_); |
| 70 |
bind("pmarks_", &pmarks_); |
| 71 |
bind("bdrops_", &bdrops_); |
| 72 |
|
| 73 |
bind("qs_pkts_", &qs_pkts_); |
| 74 |
bind("qs_bytes_", &qs_bytes_); |
| 75 |
bind("qs_drops_", &qs_drops_); |
| 76 |
|
| 77 |
bind("first_pkt_", &first_pkt_); |
| 78 |
bind("last_pkt_", &last_pkt_); |
| 79 |
|
| 80 |
//for keeping RTT statistics |
| 81 |
bind_bool("keepRTTstats_", &keepRTTstats_); |
| 82 |
bind("maxRTT_", &maxRTT_); |
| 83 |
bind("binsPerSec_", &binsPerSec_); |
| 84 |
|
| 85 |
//for keeping sequence number statistics |
| 86 |
bind_bool("keepSeqnoStats_", &keepSeqnoStats_); |
| 87 |
bind("maxSeqno_", &maxSeqno_); |
| 88 |
bind("SeqnoBinSize_", &SeqnoBinSize_); |
| 89 |
|
| 90 |
//variable binding for flow rate estimation |
| 91 |
bind_bool("estimate_rate_", &estimate_rate_); |
| 92 |
bind("k_", &k_); |
| 93 |
bind("prevTime_", &prevTime_); |
| 94 |
bind("startTime_", &startTime_); |
| 95 |
bind("estRate_", &estRate_); |
| 96 |
|
| 97 |
startTime_ = Scheduler::instance().clock(); |
| 98 |
prevTime_ = startTime_; |
| 99 |
}; |
| 100 |
|
| 101 |
int size() const { return (size_); } |
| 102 |
int pkts() const { return (pkts_); } |
| 103 |
#if defined(HAVE_INT64) |
| 104 |
int64_t parrivals() const { return (parrivals_); } |
| 105 |
int64_t barrivals() const { return (barrivals_); } |
| 106 |
int64_t pdepartures() const { return (pdepartures_); } |
| 107 |
int64_t bdepartures() const { return (bdepartures_); } |
| 108 |
#else /* no 64-bit integer */ |
| 109 |
int parrivals() const { return (parrivals_); } |
| 110 |
int barrivals() const { return (barrivals_); } |
| 111 |
int pdepartures() const { return (pdepartures_); } |
| 112 |
int bdepartures() const { return (bdepartures_); } |
| 113 |
#endif |
| 114 |
int pdrops() const { return (pdrops_); } |
| 115 |
int pmarks() const { return (pmarks_); } |
| 116 |
int bdrops() const { return (bdrops_); } |
| 117 |
|
| 118 |
int qs_pkts() const { return (qs_pkts_); } |
| 119 |
int qs_bytes() const { return (qs_bytes_); } |
| 120 |
int qs_drops() const { return (qs_drops_); } |
| 121 |
|
| 122 |
double first_pkt() const { return (first_pkt_); } |
| 123 |
|
| 124 |
void printRTTs(); |
| 125 |
void printSeqnos(); |
| 126 |
void printStats(); |
| 127 |
virtual void in(Packet*); |
| 128 |
virtual void out(Packet*); |
| 129 |
virtual void drop(Packet*); |
| 130 |
virtual void edrop(Packet*) { abort(); }; // not here |
| 131 |
virtual int command(int argc, const char*const* argv); |
| 132 |
protected: |
| 133 |
Integrator *bytesInt_; // q-size integrator (bytes) |
| 134 |
Integrator *pktsInt_; // q-size integrator (pkts) |
| 135 |
Samples* delaySamp_; // stat samples of q delay |
| 136 |
int size_; // current queue size (bytes) |
| 137 |
int pkts_; // current queue size (packets) |
| 138 |
// aggregate counters bytes/packets |
| 139 |
#if defined(HAVE_INT64) |
| 140 |
int64_t parrivals_; |
| 141 |
int64_t barrivals_; |
| 142 |
int64_t pdepartures_; |
| 143 |
int64_t bdepartures_; |
| 144 |
#else /* no 64-bit integer */ |
| 145 |
int parrivals_; |
| 146 |
int barrivals_; |
| 147 |
int pdepartures_; |
| 148 |
int bdepartures_; |
| 149 |
#endif |
| 150 |
int pdrops_; |
| 151 |
int pmarks_; |
| 152 |
int bdrops_; |
| 153 |
|
| 154 |
int qs_pkts_; /* Number of Quick-Start packets */ |
| 155 |
int qs_bytes_; /* Number of Quick-Start bytes */ |
| 156 |
int qs_drops_; /* Number of dropped QS packets */ |
| 157 |
|
| 158 |
double first_pkt_; /* Time of first packet arrival */ |
| 159 |
double last_pkt_; /* Time of last packet arrival */ |
| 160 |
|
| 161 |
int keepRTTstats_; /* boolean - keeping RTT stats? */ |
| 162 |
int maxRTT_; /* Max RTT to measure, in seconds */ |
| 163 |
int numRTTs_; /* number of RTT measurements */ |
| 164 |
int binsPerSec_; /* number of bins per second */ |
| 165 |
int *RTTbins_; /* Number of RTTs in each bin */ |
| 166 |
|
| 167 |
int keepSeqnoStats_; /* boolean - keeping Seqno stats? */ |
| 168 |
int maxSeqno_; /* Max Seqno to measure */ |
| 169 |
int numSeqnos_; /* number of Seqno measurements */ |
| 170 |
int SeqnoBinSize_; /* number of Seqnos per bin */ |
| 171 |
int *SeqnoBins_; /* Number of Seqnos in each bin */ |
| 172 |
|
| 173 |
int srcId_; |
| 174 |
int dstId_; |
| 175 |
Tcl_Channel channel_; |
| 176 |
Tcl_Channel channel1_; |
| 177 |
|
| 178 |
// the estimation of incoming rate using an exponential averaging algorithm due to Stoica |
| 179 |
// hence a lot of this stuff is inspired by csfq.cc(Stoica) |
| 180 |
// put in here so that it can be used to estimate the arrival rate for both whole queues as |
| 181 |
// well as flows (Flow inherits from EDQueueMonitor); |
| 182 |
public: |
| 183 |
int estimate_rate_; /* boolean - whether rate estimation is on or not */ |
| 184 |
double k_; /* averaging interval for rate estimation in seconds*/ |
| 185 |
double estRate_; /* current flow's estimated rate in bps */ |
| 186 |
double prevTime_; /* time of last packet arrival */ |
| 187 |
double startTime_; /* time when the flow started */ |
| 188 |
|
| 189 |
protected: |
| 190 |
int temp_size_; /* keep track of packets that arrive at the same time */ |
| 191 |
|
| 192 |
void estimateRate(Packet *p); |
| 193 |
void keepRTTstats(Packet *p); |
| 194 |
void keepSeqnoStats(Packet *p); |
| 195 |
}; |
| 196 |
|
| 197 |
class SnoopQueue : public Connector { |
| 198 |
public: |
| 199 |
SnoopQueue() : qm_(0) {} |
| 200 |
int command(int argc, const char*const* argv) { |
| 201 |
if (argc == 3) { |
| 202 |
if (strcmp(argv[1], "set-monitor") == 0) { |
| 203 |
qm_ = (QueueMonitor*) |
| 204 |
TclObject::lookup(argv[2]); |
| 205 |
if (qm_ == NULL) |
| 206 |
return (TCL_ERROR); |
| 207 |
return (TCL_OK); |
| 208 |
} |
| 209 |
} |
| 210 |
return (Connector::command(argc, argv)); |
| 211 |
} |
| 212 |
protected: |
| 213 |
QueueMonitor* qm_; |
| 214 |
}; |
| 215 |
|
| 216 |
class SnoopQueueIn : public SnoopQueue { |
| 217 |
public: |
| 218 |
void recv(Packet* p, Handler* h) { |
| 219 |
qm_->in(p); |
| 220 |
send(p, h); |
| 221 |
} |
| 222 |
}; |
| 223 |
|
| 224 |
class SnoopQueueOut : public SnoopQueue { |
| 225 |
public: |
| 226 |
void recv(Packet* p, Handler* h) { |
| 227 |
qm_->out(p); |
| 228 |
send(p, h); |
| 229 |
} |
| 230 |
}; |
| 231 |
|
| 232 |
class SnoopQueueDrop : public SnoopQueue { |
| 233 |
public: |
| 234 |
void recv(Packet* p, Handler* h) { |
| 235 |
qm_->drop(p); |
| 236 |
send(p, h); |
| 237 |
} |
| 238 |
}; |
| 239 |
|
| 240 |
/* Tagger, Like a normal FlowMonitor, use SnoopQueueTagger |
| 241 |
* to start it. |
| 242 |
* By Yun Wang |
| 243 |
*/ |
| 244 |
class SnoopQueueTagger : public SnoopQueue { |
| 245 |
public: |
| 246 |
void recv(Packet* p, Handler* h) { |
| 247 |
qm_->in(p); |
| 248 |
send(p, h); |
| 249 |
} |
| 250 |
}; |
| 251 |
|
| 252 |
/* |
| 253 |
* "early drop" QueueMonitor. Like a normal QueueMonitor, |
| 254 |
* but also supports the notion of "early" drops |
| 255 |
*/ |
| 256 |
|
| 257 |
/* |
| 258 |
* The mon* things added to make it work with redpd. |
| 259 |
* I tried more "elegant" ways -- but mulitple inheritance sucks !!. |
| 260 |
* -ratul |
| 261 |
*/ |
| 262 |
class EDQueueMonitor : public QueueMonitor { |
| 263 |
public: |
| 264 |
EDQueueMonitor() : ebdrops_(0), epdrops_(0), mon_ebdrops_(0), mon_epdrops_(0) { |
| 265 |
bind("ebdrops_", &ebdrops_); |
| 266 |
bind("epdrops_", &epdrops_); |
| 267 |
bind("mon_ebdrops_", &mon_ebdrops_); |
| 268 |
bind("mon_epdrops_", &mon_epdrops_); |
| 269 |
} |
| 270 |
void edrop(Packet* p) { |
| 271 |
hdr_cmn* hdr = hdr_cmn::access(p); |
| 272 |
ebdrops_ += hdr->size(); |
| 273 |
epdrops_++; |
| 274 |
// remove later - ratul |
| 275 |
// printf("My epdrops = %d\n",epdrops_); |
| 276 |
QueueMonitor::drop(p); |
| 277 |
} |
| 278 |
|
| 279 |
void mon_edrop(Packet *p) { |
| 280 |
hdr_cmn* hdr = hdr_cmn::access(p); |
| 281 |
mon_ebdrops_ += hdr->size(); |
| 282 |
mon_epdrops_++; |
| 283 |
|
| 284 |
QueueMonitor::drop(p); |
| 285 |
} |
| 286 |
|
| 287 |
int epdrops() const { return (epdrops_); } |
| 288 |
int ebdrops() const { return (ebdrops_); } |
| 289 |
int mon_epdrops() const { return (mon_epdrops_); } |
| 290 |
int mon_ebdrops() const { return (mon_ebdrops_); } |
| 291 |
protected: |
| 292 |
int ebdrops_; |
| 293 |
int epdrops_; |
| 294 |
int mon_ebdrops_; |
| 295 |
int mon_epdrops_; |
| 296 |
}; |
| 297 |
|
| 298 |
class SnoopQueueEDrop : public SnoopQueue { |
| 299 |
public: |
| 300 |
void recv(Packet* p, Handler* h) { |
| 301 |
qm_->edrop(p); |
| 302 |
send(p, h); |
| 303 |
} |
| 304 |
}; |
| 305 |
|
| 306 |
|
| 307 |
#ifndef MAXFLOW |
| 308 |
#define MAXFLOW 32 |
| 309 |
#endif |
| 310 |
|
| 311 |
/* |
| 312 |
* a 'QueueMonitorCompat', which is used by the compat |
| 313 |
* code to produce the link statistics available in ns-1 |
| 314 |
*/ |
| 315 |
|
| 316 |
class QueueMonitorCompat : public QueueMonitor { |
| 317 |
public: |
| 318 |
QueueMonitorCompat(); |
| 319 |
void in(Packet*); |
| 320 |
void out(Packet*); |
| 321 |
void drop(Packet*); |
| 322 |
int command(int argc, const char*const* argv); |
| 323 |
protected: |
| 324 |
void flowstats(int flowid); /* create a flowstats structure */ |
| 325 |
|
| 326 |
int pkts_[MAXFLOW]; |
| 327 |
int bytes_[MAXFLOW]; |
| 328 |
int drops_[MAXFLOW]; |
| 329 |
Samples *flowstats_[MAXFLOW]; |
| 330 |
}; |
| 331 |
|
| 332 |
#endif |
| 333 |
|