• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tools/queue-monitor.h

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: /cvsroot/nsnam/ns-2/tools/queue-monitor.h,v 1.26 2005/07/13 03:51:33 tomh 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                          qs_pkts_(0), qs_bytes_(0), qs_drops_(0),
00054                 keepRTTstats_(0), maxRTT_(1), numRTTs_(0), binsPerSec_(10),
00055                 keepSeqnoStats_(0), maxSeqno_(1000), 
00056                 numSeqnos_(0), SeqnoBinSize_(1),
00057                 srcId_(0), dstId_(0), channel_(0), channel1_(0),
00058                 estimate_rate_(0), 
00059                 k_(0.1), 
00060                 estRate_(0.0),
00061                 temp_size_(0) {
00062                 
00063                 bind("size_", &size_);
00064                 bind("pkts_", &pkts_);
00065                 bind("parrivals_", &parrivals_);
00066                 bind("barrivals_", &barrivals_);
00067                 bind("pdepartures_", &pdepartures_);
00068                 bind("bdepartures_", &bdepartures_);
00069                 bind("pdrops_", &pdrops_);
00070                 bind("pmarks_", &pmarks_);
00071                 bind("bdrops_", &bdrops_);
00072 
00073                 bind("qs_pkts_", &qs_pkts_);
00074                 bind("qs_bytes_", &qs_bytes_);
00075                 bind("qs_drops_", &qs_drops_);
00076 
00077                 bind("first_pkt_", &first_pkt_);
00078                 bind("last_pkt_", &last_pkt_);
00079 
00080                 //for keeping RTT statistics
00081                 bind_bool("keepRTTstats_", &keepRTTstats_);
00082                 bind("maxRTT_", &maxRTT_);
00083                 bind("binsPerSec_", &binsPerSec_);
00084 
00085                 //for keeping sequence number statistics
00086                 bind_bool("keepSeqnoStats_", &keepSeqnoStats_);
00087                 bind("maxSeqno_", &maxSeqno_);
00088                 bind("SeqnoBinSize_", &SeqnoBinSize_);
00089 
00090                 //variable binding for flow rate estimation
00091                 bind_bool("estimate_rate_", &estimate_rate_);
00092                 bind("k_", &k_);
00093                 bind("prevTime_", &prevTime_);
00094                 bind("startTime_", &startTime_);
00095                 bind("estRate_", &estRate_);
00096                 
00097                 startTime_ = Scheduler::instance().clock();
00098                 prevTime_  = startTime_;
00099         };
00100 
00101         int size() const { return (size_); }
00102         int pkts() const { return (pkts_); }
00103 #if defined(HAVE_INT64)
00104         int64_t parrivals() const { return (parrivals_); }      
00105         int64_t barrivals() const { return (barrivals_); }
00106         int64_t pdepartures() const { return (pdepartures_); }
00107         int64_t bdepartures() const { return (bdepartures_); }
00108 #else /* no 64-bit integer */
00109         int parrivals() const { return (parrivals_); }
00110         int barrivals() const { return (barrivals_); }
00111         int pdepartures() const { return (pdepartures_); }
00112         int bdepartures() const { return (bdepartures_); }
00113 #endif
00114         int pdrops() const { return (pdrops_); }
00115         int pmarks() const { return (pmarks_); }
00116         int bdrops() const { return (bdrops_); }
00117 
00118         int qs_pkts() const { return (qs_pkts_); }
00119         int qs_bytes() const { return (qs_bytes_); }
00120         int qs_drops() const { return (qs_drops_); }
00121 
00122         double first_pkt() const { return (first_pkt_); }
00123 
00124         void printRTTs();
00125         void printSeqnos();
00126         void printStats();
00127         virtual void in(Packet*);
00128         virtual void out(Packet*);
00129         virtual void drop(Packet*);
00130         virtual void edrop(Packet*) { abort(); }; // not here
00131         virtual int command(int argc, const char*const* argv);
00132 protected:
00133         Integrator *bytesInt_;          // q-size integrator (bytes)
00134         Integrator *pktsInt_;           // q-size integrator (pkts)
00135         Samples* delaySamp_;            // stat samples of q delay
00136         int size_;                      // current queue size (bytes)
00137         int pkts_;                      // current queue size (packets)
00138         // aggregate counters bytes/packets
00139 #if defined(HAVE_INT64)
00140         int64_t parrivals_;
00141         int64_t barrivals_;
00142         int64_t pdepartures_;
00143         int64_t bdepartures_;
00144 #else /* no 64-bit integer */
00145         int parrivals_;
00146         int barrivals_;
00147         int pdepartures_;
00148         int bdepartures_;
00149 #endif
00150         int pdrops_;
00151         int pmarks_;
00152         int bdrops_;
00153 
00154         int qs_pkts_;                   /* Number of Quick-Start packets */
00155         int qs_bytes_;                  /* Number of Quick-Start bytes */
00156         int qs_drops_;                  /* Number of dropped QS packets */
00157 
00158         double first_pkt_;              /* Time of first packet arrival */
00159         double last_pkt_;               /* Time of last packet arrival */
00160 
00161         int keepRTTstats_;              /* boolean - keeping RTT stats? */
00162         int maxRTT_;                    /* Max RTT to measure, in seconds */
00163         int numRTTs_;                   /* number of RTT measurements */
00164         int binsPerSec_;                /* number of bins per second */
00165         int *RTTbins_;                  /* Number of RTTs in each bin */
00166 
00167         int keepSeqnoStats_;            /* boolean - keeping Seqno stats? */
00168         int maxSeqno_;                  /* Max Seqno to measure */
00169         int numSeqnos_;                 /* number of Seqno measurements */
00170         int SeqnoBinSize_;              /* number of Seqnos per bin */
00171         int *SeqnoBins_;                /* Number of Seqnos in each bin */
00172 
00173         int srcId_;
00174         int dstId_;
00175         Tcl_Channel channel_;
00176         Tcl_Channel channel1_;
00177 
00178         // the estimation of incoming rate using an exponential averaging algorithm due to Stoica
00179         // hence a lot of this stuff is inspired by csfq.cc(Stoica)
00180         // put in here so that it can be used to estimate the arrival rate for both whole queues as 
00181         // well as flows (Flow inherits from EDQueueMonitor);
00182 public:
00183         int estimate_rate_;           /* boolean - whether rate estimation is on or not */
00184         double k_;                    /* averaging interval for rate estimation in seconds*/
00185         double estRate_;              /* current flow's estimated rate in bps */
00186         double prevTime_;             /* time of last packet arrival */
00187         double startTime_;            /* time when the flow started */
00188 
00189 protected:
00190         int temp_size_;               /* keep track of packets that arrive at the same time */
00191 
00192         void estimateRate(Packet *p);
00193         void keepRTTstats(Packet *p);
00194         void keepSeqnoStats(Packet *p);
00195 };
00196 
00197 class SnoopQueue : public Connector {
00198 public: 
00199         SnoopQueue() : qm_(0) {}
00200         int command(int argc, const char*const* argv) {
00201                 if (argc == 3) { 
00202                         if (strcmp(argv[1], "set-monitor") == 0) {
00203                                 qm_ = (QueueMonitor*)
00204                                         TclObject::lookup(argv[2]);
00205                                 if (qm_ == NULL)
00206                                         return (TCL_ERROR);
00207                                 return (TCL_OK);
00208                         }
00209                 }
00210                 return (Connector::command(argc, argv));
00211         }
00212  protected:
00213         QueueMonitor* qm_;
00214 };
00215 
00216 class SnoopQueueIn : public SnoopQueue {
00217 public:
00218         void recv(Packet* p, Handler* h) {
00219                 qm_->in(p);
00220                 send(p, h);
00221         }
00222 };
00223 
00224 class SnoopQueueOut : public SnoopQueue {
00225 public:
00226         void recv(Packet* p, Handler* h) {
00227                 qm_->out(p);
00228                 send(p, h);
00229         }
00230 };
00231 
00232 class SnoopQueueDrop : public SnoopQueue {
00233 public:
00234         void recv(Packet* p, Handler* h) {
00235                 qm_->drop(p);
00236                 send(p, h);
00237         }
00238 };
00239 
00240 /* Tagger, Like a normal FlowMonitor, use SnoopQueueTagger
00241  * to start it.
00242  * By Yun Wang 
00243  */
00244 class SnoopQueueTagger : public SnoopQueue {
00245 public:
00246         void recv(Packet* p, Handler* h) {
00247                 qm_->in(p);
00248                 send(p, h);
00249         }
00250 };
00251 
00252 /*
00253  * "early drop" QueueMonitor.  Like a normal QueueMonitor,
00254  * but also supports the notion of "early" drops
00255  */
00256 
00257 /* 
00258  * The mon* things added to make it work with redpd. 
00259  * I tried more "elegant" ways -- but mulitple inheritance sucks !!.
00260  * -ratul
00261  */
00262 class EDQueueMonitor : public QueueMonitor {
00263 public:
00264         EDQueueMonitor() : ebdrops_(0), epdrops_(0), mon_ebdrops_(0), mon_epdrops_(0) {
00265                 bind("ebdrops_", &ebdrops_);
00266                 bind("epdrops_", &epdrops_);
00267                 bind("mon_ebdrops_", &mon_ebdrops_);
00268                 bind("mon_epdrops_", &mon_epdrops_);
00269         }
00270         void edrop(Packet* p) {
00271                 hdr_cmn* hdr = hdr_cmn::access(p);
00272                 ebdrops_ += hdr->size();
00273                 epdrops_++;
00274                 // remove later - ratul
00275                 // printf("My epdrops = %d\n",epdrops_);
00276                 QueueMonitor::drop(p);
00277         }
00278         
00279         void mon_edrop(Packet *p) {
00280                 hdr_cmn* hdr = hdr_cmn::access(p);
00281                 mon_ebdrops_ += hdr->size();
00282                 mon_epdrops_++;
00283         
00284                 QueueMonitor::drop(p);
00285         }
00286         
00287         int epdrops() const { return (epdrops_); }
00288         int ebdrops() const { return (ebdrops_); }
00289         int mon_epdrops() const { return (mon_epdrops_); }
00290         int mon_ebdrops() const { return (mon_ebdrops_); }
00291 protected:
00292         int     ebdrops_;
00293         int     epdrops_;
00294         int     mon_ebdrops_;
00295         int     mon_epdrops_;
00296 };
00297 
00298 class SnoopQueueEDrop : public SnoopQueue {
00299 public:
00300         void recv(Packet* p, Handler* h) {
00301                 qm_->edrop(p);
00302                 send(p, h);
00303         }
00304 };
00305 
00306 
00307 #ifndef MAXFLOW
00308 #define MAXFLOW 32
00309 #endif
00310 
00311 /*
00312  * a 'QueueMonitorCompat', which is used by the compat
00313  * code to produce the link statistics available in ns-1
00314  */
00315 
00316 class QueueMonitorCompat : public QueueMonitor {
00317 public:
00318         QueueMonitorCompat();
00319         void in(Packet*);
00320         void out(Packet*);
00321         void drop(Packet*);
00322         int command(int argc, const char*const* argv);
00323 protected:
00324         void    flowstats(int flowid);  /* create a flowstats structure */
00325 
00326         int     pkts_[MAXFLOW];
00327         int     bytes_[MAXFLOW];
00328         int     drops_[MAXFLOW];
00329         Samples *flowstats_[MAXFLOW];
00330 };
00331 
00332 #endif
00333 

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1