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

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 cbr_traffic.cc file.
00006  *
00007  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00008  *  
00009  * License is granted to copy, to use, and to make and to use derivative
00010  * works for research and evaluation purposes, provided that Xerox is
00011  * acknowledged in all documentation pertaining to any such copy or derivative
00012  * work. Xerox grants no other licenses expressed or implied. The Xerox trade
00013  * name should not be used in any advertising without its written permission.
00014  *  
00015  * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00016  * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00017  * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00018  * express or implied warranty of any kind.
00019  *  
00020  * These notices must be retained in any copies of any part of this software.
00021  */
00022 
00023 #include <stdlib.h>
00024  
00025 #include "random.h"
00026 #include "trafgen.h"
00027 #include "ranvar.h"
00028 
00029 
00030 /* 
00031  * Constant bit rate traffic source.   Parameterized by interval, (optional)
00032  * random noise in the interval, and packet size.  
00033  */
00034 
00035 class CBR_PP_Traffic : public TrafficGenerator {
00036  public:
00037         CBR_PP_Traffic();
00038         virtual double next_interval(int&);
00039         //HACK so that udp agent knows interpacket arrival time within a burst
00040         inline double interval() { return (interval_); }
00041  protected:
00042         virtual void start();
00043         void init();
00044         void timeout();
00045         double rate_;     /* send rate during on time (bps) */
00046         double interval_; /* packet inter-arrival time during burst (sec) */
00047         double random_;
00048         int seqno_;
00049         int maxpkts_;
00050         int PP_;
00051         int PBM_;         /*size of the packets bunch*/
00052 };
00053 
00054 
00055 static class CBR_PP_TrafficClass : public TclClass {
00056  public:
00057         CBR_PP_TrafficClass() : TclClass("Application/Traffic/CBR_PP") {}
00058         TclObject* create(int, const char*const*) {
00059                 return (new CBR_PP_Traffic());
00060         }
00061 } class_cbr_PP_traffic;
00062 
00063 CBR_PP_Traffic::CBR_PP_Traffic() : seqno_(0)
00064 {
00065         bind_bw("rate_", &rate_);
00066         bind("random_", &random_);
00067         bind("packetSize_", &size_);
00068         bind("maxpkts_", &maxpkts_);
00069         bind("PBM_", &PBM_);
00070 }
00071 
00072 void CBR_PP_Traffic::init()
00073 {
00074         // compute inter-packet interval 
00075          interval_ = PBM_*(double)(size_ << 3)/(double)rate_;
00076         //interval_ = 1e-100;
00077         PP_ = 0;
00078         if (agent_)
00079                 agent_->set_pkttype(PT_CBR);
00080 }
00081 
00082 void CBR_PP_Traffic::start()
00083 {
00084         init();
00085         running_ = 1;
00086         timeout();
00087 }
00088 
00089 double CBR_PP_Traffic::next_interval(int& size)
00090 {
00091         // Recompute interval in case rate_ or size_ has changes
00092         if (PP_ >= (PBM_ - 1)){         
00093                 interval_ = PBM_*(double)(size_ << 3)/(double)rate_;
00094                 PP_ = 0;
00095         }
00096         else {
00097                 interval_ = 1e-100;
00098                 PP_ += 1 ;
00099         }
00100         double t = interval_;
00101         if (random_==1)
00102                 t += interval_ * Random::uniform(-0.5, 0.5);    
00103         if (random_==2)
00104                 t += interval_ * Random::uniform(-0.000001, 0.000001);  
00105         size = size_;
00106         if (++seqno_ < maxpkts_)
00107                 return(t);
00108         else
00109                 return(-1); 
00110 }
00111 
00112 void CBR_PP_Traffic::timeout()
00113 {
00114         if (! running_)
00115                 return;
00116 
00117         /* send a packet */
00118         // The test tcl/ex/test-rcvr.tcl relies on the "NEW_BURST" flag being 
00119         // set at the start of any exponential burst ("talkspurt").  
00120         if (PP_ == 0) 
00121                 agent_->sendmsg(size_, "NEW_BURST");
00122         else 
00123                 agent_->sendmsg(size_);
00124 
00125         /* figure out when to send the next one */
00126         nextPkttime_ = next_interval(size_);
00127         /* schedule it */
00128         if (nextPkttime_ > 0)
00129                 timer_.resched(nextPkttime_);
00130 }
00131 

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