pareto.cc

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) Xerox Corporation 1997. All rights reserved.
00004  *  
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU General Public License as published by the
00007  * Free Software Foundation; either version 2 of the License, or (at your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  * Linking this file statically or dynamically with other modules is making
00020  * a combined work based on this file.  Thus, the terms and conditions of
00021  * the GNU General Public License cover the whole combination.
00022  *
00023  * In addition, as a special exception, the copyright holders of this file
00024  * give you permission to combine this file with free software programs or
00025  * libraries that are released under the GNU LGPL and with code included in
00026  * the standard release of ns-2 under the Apache 2.0 license or under
00027  * otherwise-compatible licenses with advertising requirements (or modified
00028  * versions of such code, with unchanged license).  You may copy and
00029  * distribute such a system following the terms of the GNU GPL for this
00030  * file and the licenses of the other code concerned, provided that you
00031  * include the source code of that other code when and as the GNU GPL
00032  * requires distribution of source code.
00033  *
00034  * Note that people who make modified versions of this file are not
00035  * obligated to grant this special exception for their modified versions;
00036  * it is their choice whether to do so.  The GNU General Public License
00037  * gives permission to release a modified version without this exception;
00038  * this exception also makes it possible to release a modified version
00039  * which carries forward this exception.
00040  */
00041 
00042 #ifndef lint
00043 static const char rcsid[] =
00044     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tools/pareto.cc,v 1.9 2005/08/26 05:05:31 tomh Exp $ (Xerox)";
00045 #endif
00046  
00047 #include "random.h"
00048 #include "trafgen.h"
00049 
00050 /* implement an on/off source with average on and off times taken
00051  * from a pareto distribution.  (enough of these sources multiplexed
00052  * produces aggregate traffic that is LRD).  It is parameterized
00053  * by the average burst time, average idle time, burst rate, and
00054  * pareto shape parameter and packet size.
00055  */
00056 
00057 class POO_Traffic : public TrafficGenerator {
00058  public:
00059     POO_Traffic();
00060     virtual double next_interval(int&);
00061     int on()  { return on_ ; }
00062     // Added by Debojyoti Dutta October 12th 2000
00063     int command(int argc, const char*const* argv);
00064 protected:
00065     void init();
00066     double ontime_;  /* average length of burst (sec) */
00067     double offtime_; /* average idle period (sec) */
00068     double rate_;    /* send rate during burst (bps) */
00069     double interval_; /* inter-packet time at burst rate */
00070     double burstlen_; /* average # packets/burst */
00071     double shape_;    /* pareto shape parameter */
00072     unsigned int rem_; /* number of packets remaining in current burst */
00073     double p1_;       /* parameter for pareto distribution to compute
00074                * number of packets in burst.
00075                    */
00076     double p2_;       /* parameter for pareto distribution to compute
00077                    * length of idle period.
00078                    */
00079     int on_;          /* denotes whether in the on or off state */
00080 
00081     // Added by Debojyoti Dutta 13th October 2000
00082     RNG * rng_; /* If the user wants to specify his own RNG object */
00083 };
00084 
00085 
00086 static class POOTrafficClass : public TclClass {
00087  public:
00088     POOTrafficClass() : TclClass("Application/Traffic/Pareto") {}
00089     TclObject* create(int, const char*const*) {
00090         return (new POO_Traffic());
00091     }
00092 } class_poo_traffic;
00093 
00094 // Added by Debojyoti Dutta October 12th 2000
00095 // This is a new command that allows us to use 
00096 // our own RNG object for random number generation
00097 // when generating application traffic
00098 
00099 int POO_Traffic::command(int argc, const char*const* argv){
00100         
00101     Tcl& tcl = Tcl::instance();
00102         if(argc==3){
00103                 if (strcmp(argv[1], "use-rng") == 0) {
00104             rng_ = (RNG*)TclObject::lookup(argv[2]);
00105             if (rng_ == 0) {
00106                 tcl.resultf("no such RNG %s", argv[2]);
00107                 return(TCL_ERROR);
00108             }                        
00109             return (TCL_OK);
00110                 }
00111         }
00112         return Application::command(argc,argv);
00113 }
00114 
00115 POO_Traffic::POO_Traffic() : rng_(NULL)
00116 {
00117     bind_time("burst_time_", &ontime_);
00118     bind_time("idle_time_", &offtime_);
00119     bind_bw("rate_", &rate_);
00120     bind("shape_", &shape_);
00121     bind("packetSize_", &size_);
00122 }
00123 
00124 void POO_Traffic::init()
00125 {
00126     interval_ = (double)(size_ << 3)/(double)rate_;
00127     burstlen_ = ontime_/interval_;
00128     rem_ = 0;
00129     on_ = 0;
00130     p1_ = burstlen_ * (shape_ - 1.0)/shape_;
00131     p2_ = offtime_ * (shape_ - 1.0)/shape_;
00132     if (agent_)
00133         agent_->set_pkttype(PT_PARETO);
00134 }
00135 
00136 double POO_Traffic::next_interval(int& size)
00137 {
00138 
00139     double t = interval_;
00140 
00141     on_ = 1;
00142     if (rem_ == 0) {
00143         /* compute number of packets in next burst */
00144         if(rng_ == 0){
00145             rem_ = int(Random::pareto(p1_, shape_) + .5);
00146         }
00147         else{
00148             // Added by Debojyoti Dutta 13th October 2000
00149             rem_ = int(rng_->pareto(p1_, shape_) + .5);
00150         }
00151         /* make sure we got at least 1 */
00152         if (rem_ == 0)
00153             rem_ = 1;   
00154         /* start of an idle period, compute idle time */
00155         if(rng_ == 0){
00156             t += Random::pareto(p2_, shape_);
00157         }
00158         else{
00159             // Added by Debojyoti Dutta 13th October 2000
00160             t += rng_->pareto(p2_, shape_);
00161         }
00162         on_ = 0;
00163     }   
00164     rem_--;
00165 
00166     size = size_;
00167     return(t);
00168 
00169 }
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 

Generated on Tue Mar 6 16:47:49 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6