Dear users ,
I have some problem about how to achieve packetsize and packet inter-arrival
time
to follow exponential distribution.
I find a tcl which can accomplish this goal, but here is the next question
How can I modify the expoo.cc(traffic generator/Exponential) to achieve like
that tcl code?
Here is the .tcl and expoo.cc
set ns [new Simulator] set tf [open out.tr w]
$ns trace-all $tf
set lambda 30.0 set mu 33.0
set n1 [$ns node] set n2 [$ns node]
# Since packet sizes will be rounded to an integer
# number of bytes, we should have large packets and
# to have small rounding errors, and so we take large bandwidth
set link [$ns simplex-link $n1 $n2 100kb 0ms DropTail] $ns queue-limit
$n1 $n2 100000
# generate random interarrival times and packet sizes
set InterArrivalTime [new RandomVariable/Exponential] $InterArrivalTime
set avg_ [expr 1/$lambda] set pktSize [new RandomVariable/Exponential]
$pktSize set avg_ [expr 100000.0/(8*$mu)] set src [new Agent/UDP] $ns
attach-agent $n1 $src
# queue monitoring
set qmon [$ns monitor-queue $n1 $n2 [open qm.out w] 0.1] $link
queue-sample-timeout
proc finish {} { global ns tf $ns flush-trace close
$tf exit 0 }
proc sendpacket {} { global ns src InterArrivalTime pktSize
set time [$ns now] $ns at [expr $time + [$InterArrivalTime value]]
"sendpacket" set bytes [expr round ([$pktSize value])] $src send
$bytes
} set sink [new Agent/Null] $ns attach-agent $n2 $sink $ns connect
$src $sink
$ns at 0.0001 "sendpacket" $ns at 1000.0 "finish"
$ns run
expoo.cc
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /cvsroot/nsnam/ns-2/tools/expoo.cc,v 1.15 2005/08/26
05:05:30 tomh Exp $ (Xerox)";
#endif
#include <stdlib.h>
#include "random.h"
#include "trafgen.h"
#include "ranvar.h"
/* implement an on/off source with exponentially distributed on and *
off times. parameterized by average burst time, average idle time, * burst
rate and packet size.*/
class EXPOO_Traffic : public TrafficGenerator { public:
EXPOO_Traffic(); virtual double next_interval(int&);
virtual void timeout(); virtual void call(void);
// Added by Debojyoti Dutta October 12th 2000 int
command(int argc, const char*const* argv); protected:
void init(); double ontime_; /* average
length of burst (sec) */
double offtime_; /* average length of idle time (sec) */
double rate_; /* send rate during on time (bps) */
double interval_; /* packet inter-arrival time during burst
(sec) */ unsigned int rem_;
/* number of packets left in current burst */
/* new stuff using RandomVariable */
ExponentialRandomVariable burstlen_;
ExponentialRandomVariable Offtime_; /*modify*/
ExponentialRandomVariable expSize_;
ExponentialRandomVariable interArrivaltime_;
};
static class EXPTrafficClass : public TclClass { public:
EXPTrafficClass() :
TclClass("Application/Traffic/Exponential") {}
TclObject* create(int, const char*const*) {
return (new EXPOO_Traffic());
}
} class_expoo_traffic;
// Added by Debojyoti Dutta October 12th 2000
// This is a new command that allows us to use
// our own RNG object for random number generation
// when generating application traffic
int EXPOO_Traffic::command(int argc, const char*const* argv){
if(argc==3){
if (strcmp(argv[1], "use-rng") == 0) {
burstlen_.seed((char *)argv[2]);
Offtime_.seed((char *)argv[2]);
/*expSize_.seed((char *)argv[2]);*/
return (TCL_OK);
}
}
return Application::command(argc,argv);
}
EXPOO_Traffic::EXPOO_Traffic() : burstlen_(0.0),
Offtime_(0.0)//,expSize_(123.0)
{ bind_time("burst_time_", &ontime_);
bind_time("idle_time_", Offtime_.avgp());
bind_bw("rate_", &rate_);
bind("packetSize_", &size_);
}
void EXPOO_Traffic::init() { /* compute inter-packet interval
during bursts based on * packet size and burst rate. then compute
average number * of packets in a burst. */
interval_ = (double)(size_ << 3)/(double)rate_;
burstlen_.setavg(ontime_/interval_);
/*修改*/
expSize_.setavg(123.0);
size_ = expSize_.value();
interArrivaltime_.setavg(1.0/lambda_);
/*修改*/ rem_ = 0;
if (agent_) agent_->set_pkttype(PT_EXP); }
double EXPOO_Traffic::next_interval(int& size) {
double t = interval_;
if (rem_ == 0) {
/* compute number of packets in next burst */
rem_ = int(burstlen_.value() + .5);
/* make sure we got at least 1 */
if (rem_ == 0)
rem_ = 1;
/* start of an idle period, compute idle time */
t += Offtime_.value(); } rem_--;
size = size_;
return(t); }
void EXPOO_Traffic::timeout() {
expSize_.setavg(123.0);
size_ = expSize_.value();
interArrivaltime_.setavg(1.0/lambda_); if (!
running_)
return;
/* send a packet */
// The test tcl/ex/test-rcvr.tcl relies on the "NEW_BURST" flag
being // set at the start of any exponential burst
("talkspurt"). if (nextPkttime_ != interval_ ||
nextPkttime_ == -1) agent_->sendmsg(size_, "NEW_BURST");
else
agent_->sendmsg(size_);
/* figure out when to send the next one */
nextPkttime_ = interArrivaltime_.value(); /*
schedule it */
if (nextPkttime_ > 0)
timer_.resched(nextPkttime_);
}
I have tried to add ExponentialRandomVariable expSize_ and interArrival_ in
expoo.cc
but I dont know where I can change the packetsize and interArrival time
even I use the funtion of ExpRandomVariable , .setavg_() and .value() ,
the result seems the same.
Could someone tell me where I can change the fixed packetsize and interArrival
to my ExpRandomVariable?
Should me use the two function above?
Any suggestion will be very appreciate.
Thanks alot!!