expoo.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/expoo.cc,v 1.15 2005/08/26 05:05:30 tomh Exp $ (Xerox)";
00045 #endif
00046 
00047 #include <stdlib.h>
00048  
00049 #include "random.h"
00050 #include "trafgen.h"
00051 #include "ranvar.h"
00052 
00053 
00054 /* implement an on/off source with exponentially distributed on and
00055  * off times.  parameterized by average burst time, average idle time,
00056  * burst rate and packet size.
00057  */
00058 
00059 class EXPOO_Traffic : public TrafficGenerator {
00060  public:
00061     EXPOO_Traffic();
00062     virtual double next_interval(int&);
00063         virtual void timeout();
00064     // Added by Debojyoti Dutta October 12th 2000
00065     int command(int argc, const char*const* argv);
00066  protected:
00067     void init();
00068     double ontime_;   /* average length of burst (sec) */
00069     double offtime_;  /* average length of idle time (sec) */
00070     double rate_;     /* send rate during on time (bps) */
00071     double interval_; /* packet inter-arrival time during burst (sec) */
00072     unsigned int rem_; /* number of packets left in current burst */
00073 
00074     /* new stuff using RandomVariable */
00075     ExponentialRandomVariable burstlen_;
00076     ExponentialRandomVariable Offtime_;
00077 
00078 };
00079 
00080 
00081 static class EXPTrafficClass : public TclClass {
00082  public:
00083     EXPTrafficClass() : TclClass("Application/Traffic/Exponential") {}
00084     TclObject* create(int, const char*const*) {
00085         return (new EXPOO_Traffic());
00086     }
00087 } class_expoo_traffic;
00088 
00089 // Added by Debojyoti Dutta October 12th 2000
00090 // This is a new command that allows us to use 
00091 // our own RNG object for random number generation
00092 // when generating application traffic
00093 
00094 int EXPOO_Traffic::command(int argc, const char*const* argv){
00095         
00096         if(argc==3){
00097                 if (strcmp(argv[1], "use-rng") == 0) {
00098                         burstlen_.seed((char *)argv[2]);
00099                         Offtime_.seed((char *)argv[2]);
00100                         return (TCL_OK);
00101                 }
00102         }
00103         return Application::command(argc,argv);
00104 }
00105 
00106 
00107 EXPOO_Traffic::EXPOO_Traffic() : burstlen_(0.0), Offtime_(0.0)
00108 {
00109     bind_time("burst_time_", &ontime_);
00110     bind_time("idle_time_", Offtime_.avgp());
00111     bind_bw("rate_", &rate_);
00112     bind("packetSize_", &size_);
00113 }
00114 
00115 void EXPOO_Traffic::init()
00116 {
00117         /* compute inter-packet interval during bursts based on
00118      * packet size and burst rate.  then compute average number
00119      * of packets in a burst.
00120      */
00121     interval_ = (double)(size_ << 3)/(double)rate_;
00122     burstlen_.setavg(ontime_/interval_);
00123     rem_ = 0;
00124     if (agent_)
00125         agent_->set_pkttype(PT_EXP);
00126 }
00127 
00128 double EXPOO_Traffic::next_interval(int& size)
00129 {
00130     double t = interval_;
00131 
00132     if (rem_ == 0) {
00133         /* compute number of packets in next burst */
00134         rem_ = int(burstlen_.value() + .5);
00135         /* make sure we got at least 1 */
00136         if (rem_ == 0)
00137             rem_ = 1;
00138         /* start of an idle period, compute idle time */
00139         t += Offtime_.value();
00140     }   
00141     rem_--;
00142 
00143     size = size_;
00144     return(t);
00145 }
00146 
00147 void EXPOO_Traffic::timeout()
00148 {
00149     if (! running_)
00150         return;
00151 
00152     /* send a packet */
00153     // The test tcl/ex/test-rcvr.tcl relies on the "NEW_BURST" flag being 
00154     // set at the start of any exponential burst ("talkspurt").  
00155     if (nextPkttime_ != interval_ || nextPkttime_ == -1) 
00156         agent_->sendmsg(size_, "NEW_BURST");
00157     else 
00158         agent_->sendmsg(size_);
00159     /* figure out when to send the next one */
00160     nextPkttime_ = next_interval(size_);
00161     /* schedule it */
00162     if (nextPkttime_ > 0)
00163         timer_.resched(nextPkttime_);
00164 }
00165 
00166 
00167 

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