cbr-traffic-PP.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * This code is a contribution of Arnaud Legout, Institut Eurecom, France.
00004  * This code is highly inspired from the code of the CBR sources.
00005  * The following copyright is the original copyright included in the 
00006  * cbr_traffic.cc file.
00007  *
00008  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00009  *  
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU General Public License as published by the
00012  * Free Software Foundation; either version 2 of the License, or (at your
00013  * option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  * Linking this file statically or dynamically with other modules is making
00025  * a combined work based on this file.  Thus, the terms and conditions of
00026  * the GNU General Public License cover the whole combination.
00027  *
00028  * In addition, as a special exception, the copyright holders of this file
00029  * give you permission to combine this file with free software programs or
00030  * libraries that are released under the GNU LGPL and with code included in
00031  * the standard release of ns-2 under the Apache 2.0 license or under
00032  * otherwise-compatible licenses with advertising requirements (or modified
00033  * versions of such code, with unchanged license).  You may copy and
00034  * distribute such a system following the terms of the GNU GPL for this
00035  * file and the licenses of the other code concerned, provided that you
00036  * include the source code of that other code when and as the GNU GPL
00037  * requires distribution of source code.
00038  *
00039  * Note that people who make modified versions of this file are not
00040  * obligated to grant this special exception for their modified versions;
00041  * it is their choice whether to do so.  The GNU General Public License
00042  * gives permission to release a modified version without this exception;
00043  * this exception also makes it possible to release a modified version
00044  * which carries forward this exception.
00045  */
00046 
00047 #include <stdlib.h>
00048  
00049 #include "random.h"
00050 #include "trafgen.h"
00051 #include "ranvar.h"
00052 
00053 
00054 /* 
00055  * Constant bit rate traffic source.   Parameterized by interval, (optional)
00056  * random noise in the interval, and packet size.  
00057  */
00058 
00059 class CBR_PP_Traffic : public TrafficGenerator {
00060  public:
00061     CBR_PP_Traffic();
00062     virtual double next_interval(int&);
00063     //HACK so that udp agent knows interpacket arrival time within a burst
00064     inline double interval() { return (interval_); }
00065  protected:
00066     virtual void start();
00067     void init();
00068     void timeout();
00069     double rate_;     /* send rate during on time (bps) */
00070     double interval_; /* packet inter-arrival time during burst (sec) */
00071     double random_;
00072     int seqno_;
00073     int maxpkts_;
00074     int PP_;
00075     int PBM_;         /*size of the packets bunch*/
00076 };
00077 
00078 
00079 static class CBR_PP_TrafficClass : public TclClass {
00080  public:
00081     CBR_PP_TrafficClass() : TclClass("Application/Traffic/CBR_PP") {}
00082     TclObject* create(int, const char*const*) {
00083         return (new CBR_PP_Traffic());
00084     }
00085 } class_cbr_PP_traffic;
00086 
00087 CBR_PP_Traffic::CBR_PP_Traffic() : seqno_(0)
00088 {
00089     bind_bw("rate_", &rate_);
00090     bind("random_", &random_);
00091     bind("packetSize_", &size_);
00092     bind("maxpkts_", &maxpkts_);
00093     bind("PBM_", &PBM_);
00094 }
00095 
00096 void CBR_PP_Traffic::init()
00097 {
00098         // compute inter-packet interval 
00099      interval_ = PBM_*(double)(size_ << 3)/(double)rate_;
00100     //interval_ = 1e-100;
00101     PP_ = 0;
00102     if (agent_)
00103         agent_->set_pkttype(PT_CBR);
00104 }
00105 
00106 void CBR_PP_Traffic::start()
00107 {
00108         init();
00109         running_ = 1;
00110         timeout();
00111 }
00112 
00113 double CBR_PP_Traffic::next_interval(int& size)
00114 {
00115     // Recompute interval in case rate_ or size_ has changes
00116     if (PP_ >= (PBM_ - 1)){     
00117         interval_ = PBM_*(double)(size_ << 3)/(double)rate_;
00118         PP_ = 0;
00119     }
00120     else {
00121         interval_ = 1e-100;
00122         PP_ += 1 ;
00123     }
00124     double t = interval_;
00125     if (random_==1)
00126         t += interval_ * Random::uniform(-0.5, 0.5);    
00127     if (random_==2)
00128         t += interval_ * Random::uniform(-0.000001, 0.000001);  
00129     size = size_;
00130     if (++seqno_ < maxpkts_)
00131         return(t);
00132     else
00133         return(-1); 
00134 }
00135 
00136 void CBR_PP_Traffic::timeout()
00137 {
00138         if (! running_)
00139                 return;
00140 
00141         /* send a packet */
00142         // The test tcl/ex/test-rcvr.tcl relies on the "NEW_BURST" flag being 
00143         // set at the start of any exponential burst ("talkspurt").  
00144         if (PP_ == 0) 
00145                 agent_->sendmsg(size_, "NEW_BURST");
00146         else 
00147                 agent_->sendmsg(size_);
00148 
00149         /* figure out when to send the next one */
00150         nextPkttime_ = next_interval(size_);
00151         /* schedule it */
00152         if (nextPkttime_ > 0)
00153                 timer_.resched(nextPkttime_);
00154 }
00155 

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