Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

queue-monitor.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 
00002  *
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the MASH Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tools/queue-monitor.h,v 1.24 2003/01/28 23:31:04 sfloyd Exp $ (UCB)
00035  */
00036 
00037 #ifndef ns_queue_monitor_h
00038 #define ns_queue_monitor_h
00039 
00040 #include "config.h"  // for int64_t
00041 #include "integrator.h"
00042 #include "connector.h"
00043 #include "packet.h"
00044 #include "flags.h"
00045 
00046 class QueueMonitor : public TclObject {
00047 public: 
00048         QueueMonitor() : bytesInt_(NULL), pktsInt_(NULL), delaySamp_(NULL),
00049                 size_(0), pkts_(0),
00050                 parrivals_(0), barrivals_(0),
00051                 pdepartures_(0), bdepartures_(0),
00052                 pdrops_(0), pmarks_(0), bdrops_(0), 
00053                 keepRTTstats_(0), maxRTT_(1), numRTTs_(0), binsPerSec_(10),
00054                 keepSeqnoStats_(0), maxSeqno_(1000), 
00055                 numSeqnos_(0), SeqnoBinSize_(1),
00056                 k_(0.1), 
00057                 srcId_(0), dstId_(0), channel_(0), channel1_(0),
00058                 estimate_rate_(0), estRate_(0.0),
00059                 temp_size_(0) {
00060                 
00061                 bind("size_", &size_);
00062                 bind("pkts_", &pkts_);
00063                 bind("parrivals_", &parrivals_);
00064                 bind("barrivals_", &barrivals_);
00065                 bind("pdepartures_", &pdepartures_);
00066                 bind("bdepartures_", &bdepartures_);
00067                 bind("pdrops_", &pdrops_);
00068                 bind("pmarks_", &pmarks_);
00069                 bind("bdrops_", &bdrops_);
00070 
00071                 //for keeping RTT statistics
00072                 bind_bool("keepRTTstats_", &keepRTTstats_);
00073                 bind("maxRTT_", &maxRTT_);
00074                 bind("binsPerSec_", &binsPerSec_);
00075 
00076                 //for keeping sequence number statistics
00077                 bind_bool("keepSeqnoStats_", &keepSeqnoStats_);
00078                 bind("maxSeqno_", &maxSeqno_);
00079                 bind("SeqnoBinSize_", &SeqnoBinSize_);
00080 
00081                 //variable binding for flow rate estimation
00082                 bind_bool("estimate_rate_", &estimate_rate_);
00083                 bind("k_", &k_);
00084                 bind("prevTime_", &prevTime_);
00085                 bind("startTime_", &startTime_);
00086                 bind("estRate_", &estRate_);
00087                 
00088                 startTime_ = Scheduler::instance().clock();
00089                 prevTime_  = startTime_;
00090         };
00091 
00092         int size() const { return (size_); }
00093         int pkts() const { return (pkts_); }
00094 #if defined(HAVE_INT64)
00095         int64_t parrivals() const { return (parrivals_); }      
00096         int64_t barrivals() const { return (barrivals_); }
00097         int64_t pdepartures() const { return (pdepartures_); }
00098         int64_t bdepartures() const { return (bdepartures_); }
00099 #else /* no 64-bit integer */
00100         int parrivals() const { return (parrivals_); }
00101         int barrivals() const { return (barrivals_); }
00102         int pdepartures() const { return (pdepartures_); }
00103         int bdepartures() const { return (bdepartures_); }
00104 #endif
00105         int pdrops() const { return (pdrops_); }
00106         int pmarks() const { return (pmarks_); }
00107         int bdrops() const { return (bdrops_); }
00108         void printRTTs();
00109         void printSeqnos();
00110         void printStats();
00111         virtual void in(Packet*);
00112         virtual void out(Packet*);
00113         virtual void drop(Packet*);
00114         virtual void edrop(Packet*) { abort(); }; // not here
00115         virtual int command(int argc, const char*const* argv);
00116 protected:
00117         Integrator *bytesInt_;          // q-size integrator (bytes)
00118         Integrator *pktsInt_;           // q-size integrator (pkts)
00119         Samples* delaySamp_;            // stat samples of q delay
00120         int size_;                      // current queue size (bytes)
00121         int pkts_;                      // current queue size (packets)
00122         // aggregate counters bytes/packets
00123 #if defined(HAVE_INT64)
00124         int64_t parrivals_;
00125         int64_t barrivals_;
00126         int64_t pdepartures_;
00127         int64_t bdepartures_;
00128 #else /* no 64-bit integer */
00129         int parrivals_;
00130         int barrivals_;
00131         int pdepartures_;
00132         int bdepartures_;
00133 #endif
00134         int pdrops_;
00135         int pmarks_;
00136         int bdrops_;
00137 
00138         int keepRTTstats_;              /* boolean - keeping RTT stats? */
00139         int maxRTT_;                    /* Max RTT to measure, in seconds */
00140         int numRTTs_;                   /* number of RTT measurements */
00141         int binsPerSec_;                /* number of bins per second */
00142         int *RTTbins_;                  /* Number of RTTs in each bin */
00143 
00144         int keepSeqnoStats_;            /* boolean - keeping Seqno stats? */
00145         int maxSeqno_;                  /* Max Seqno to measure */
00146         int numSeqnos_;                 /* number of Seqno measurements */
00147         int SeqnoBinSize_;              /* number of Seqnos per bin */
00148         int *SeqnoBins_;                /* Number of Seqnos in each bin */
00149 
00150         int srcId_;
00151         int dstId_;
00152         Tcl_Channel channel_;
00153         Tcl_Channel channel1_;
00154 
00155         // the estimation of incoming rate using an exponential averaging algorithm due to Stoica
00156         // hence a lot of this stuff is inspired by csfq.cc(Stoica)
00157         // put in here so that it can be used to estimate the arrival rate for both whole queues as 
00158         // well as flows (Flow inherits from EDQueueMonitor);
00159 public:
00160         int estimate_rate_;           /* boolean - whether rate estimation is on or not */
00161         double k_;                    /* averaging interval for rate estimation in seconds*/
00162         double estRate_;              /* current flow's estimated rate in bps */
00163         double prevTime_;             /* time of last packet arrival */
00164         double startTime_;            /* time when the flow started */
00165 
00166 protected:
00167         int temp_size_;               /* keep track of packets that arrive at the same time */
00168 
00169         void estimateRate(Packet *p);
00170         void keepRTTstats(Packet *p);
00171         void keepSeqnoStats(Packet *p);
00172 };
00173 
00174 class SnoopQueue : public Connector {
00175 public: 
00176         SnoopQueue() : qm_(0) {}
00177         int command(int argc, const char*const* argv) {
00178                 if (argc == 3) { 
00179                         if (strcmp(argv[1], "set-monitor") == 0) {
00180                                 qm_ = (QueueMonitor*)
00181                                         TclObject::lookup(argv[2]);
00182                                 if (qm_ == NULL)
00183                                         return (TCL_ERROR);
00184                                 return (TCL_OK);
00185                         }
00186                 }
00187                 return (Connector::command(argc, argv));
00188         }
00189  protected:
00190         QueueMonitor* qm_;
00191 };
00192 
00193 class SnoopQueueIn : public SnoopQueue {
00194 public:
00195         void recv(Packet* p, Handler* h) {
00196                 qm_->in(p);
00197                 send(p, h);
00198         }
00199 };
00200 
00201 class SnoopQueueOut : public SnoopQueue {
00202 public:
00203         void recv(Packet* p, Handler* h) {
00204                 qm_->out(p);
00205                 send(p, h);
00206         }
00207 };
00208 
00209 class SnoopQueueDrop : public SnoopQueue {
00210 public:
00211         void recv(Packet* p, Handler* h) {
00212                 qm_->drop(p);
00213                 send(p, h);
00214         }
00215 };
00216 
00217 /* Tagger, Like a normal FlowMonitor, use SnoopQueueTagger
00218  * to start it.
00219  * By Yun Wang 
00220  */
00221 class SnoopQueueTagger : public SnoopQueue {
00222 public:
00223         void recv(Packet* p, Handler* h) {
00224                 qm_->in(p);
00225                 send(p, h);
00226         }
00227 };
00228 
00229 /*
00230  * "early drop" QueueMonitor.  Like a normal QueueMonitor,
00231  * but also supports the notion of "early" drops
00232  */
00233 
00234 /* 
00235  * The mon* things added to make it work with redpd. 
00236  * I tried more "elegant" ways -- but mulitple inheritance sucks !!.
00237  * -ratul
00238  */
00239 class EDQueueMonitor : public QueueMonitor {
00240 public:
00241         EDQueueMonitor() : ebdrops_(0), epdrops_(0), mon_ebdrops_(0), mon_epdrops_(0) {
00242                 bind("ebdrops_", &ebdrops_);
00243                 bind("epdrops_", &epdrops_);
00244                 bind("mon_ebdrops_", &mon_ebdrops_);
00245                 bind("mon_epdrops_", &mon_epdrops_);
00246         }
00247         void edrop(Packet* p) {
00248                 hdr_cmn* hdr = hdr_cmn::access(p);
00249                 ebdrops_ += hdr->size();
00250                 epdrops_++;
00251                 // remove later - ratul
00252                 // printf("My epdrops = %d\n",epdrops_);
00253                 QueueMonitor::drop(p);
00254         }
00255         
00256         void mon_edrop(Packet *p) {
00257                 hdr_cmn* hdr = hdr_cmn::access(p);
00258                 mon_ebdrops_ += hdr->size();
00259                 mon_epdrops_++;
00260         
00261                 QueueMonitor::drop(p);
00262         }
00263         
00264         int epdrops() const { return (epdrops_); }
00265         int ebdrops() const { return (ebdrops_); }
00266         int mon_epdrops() const { return (mon_epdrops_); }
00267         int mon_ebdrops() const { return (mon_ebdrops_); }
00268 protected:
00269         int     ebdrops_;
00270         int     epdrops_;
00271         int     mon_ebdrops_;
00272         int     mon_epdrops_;
00273 };
00274 
00275 class SnoopQueueEDrop : public SnoopQueue {
00276 public:
00277         void recv(Packet* p, Handler* h) {
00278                 qm_->edrop(p);
00279                 send(p, h);
00280         }
00281 };
00282 
00283 
00284 #ifndef MAXFLOW
00285 #define MAXFLOW 32
00286 #endif
00287 
00288 /*
00289  * a 'QueueMonitorCompat', which is used by the compat
00290  * code to produce the link statistics available in ns-1
00291  */
00292 
00293 class QueueMonitorCompat : public QueueMonitor {
00294 public:
00295         QueueMonitorCompat();
00296         void in(Packet*);
00297         void out(Packet*);
00298         void drop(Packet*);
00299         int command(int argc, const char*const* argv);
00300 protected:
00301         void    flowstats(int flowid);  /* create a flowstats structure */
00302 
00303         int     pkts_[MAXFLOW];
00304         int     bytes_[MAXFLOW];
00305         int     drops_[MAXFLOW];
00306         Samples *flowstats_[MAXFLOW];
00307 };
00308 
00309 #endif
00310 

Generated on Tue Apr 20 12:14:28 2004 for NS2.26SourcesOriginal by doxygen 1.3.3