GreenCloud Simulator
paretoclouduser.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
2 /*
3  */
4 
5 #ifndef lint
6 static const char rcsid[] =
7  "@(#) $Header: /cvsroot/nsnam/ns-2/tools/pareto.cc,v 1.9 2005/08/26 05:05:31 tomh Exp $";
8 #endif
9 
10 #include "random.h"
11 #include "trafgen.h"
12 #include "clouduser.h"
13 
14 class ParetoCloudUser : public TrafficGenerator, CloudUser {
15 public:
17  virtual double next_interval(int&);
18  virtual void timeout();
19  int on() { return on_ ; }
20  // Added by Debojyoti Dutta October 12th 2000
21  int command(int argc, const char*const* argv);
22 protected:
23  void init();
24  double ontime_; /* average length of burst (sec) */
25  double offtime_; /* average idle period (sec) */
26  double rate_; /* send rate during burst (bps) */
27  double interval_; /* inter-packet time at burst rate */
28  double burstlen_; /* average # packets/burst */
29  double shape_; /* pareto shape parameter */
30  unsigned int rem_; /* number of packets remaining in current burst */
31  double p1_; /* parameter for pareto distribution to compute
32  * number of packets in burst.
33  */
34  double p2_; /* parameter for pareto distribution to compute
35  * length of idle period.
36  */
37  int on_; /* denotes whether in the on or off state */
38 
39  // Added by Debojyoti Dutta 13th October 2000
40  RNG * rng_; /* If the user wants to specify his own RNG object */
41 };
42 
43 
44 static class POOTrafficClass : public TclClass {
45 public:
46  POOTrafficClass() : TclClass("Application/Traffic/ParetoCloudUser") {}
47  TclObject* create(int, const char*const*) {
48  return (new ParetoCloudUser());
49  }
51 
52 // Added by Debojyoti Dutta October 12th 2000
53 // This is a new command that allows us to use
54 // our own RNG object for random number generation
55 // when generating application traffic
56 
57 int ParetoCloudUser::command(int argc, const char*const* argv){
58 
59  Tcl& tcl = Tcl::instance();
60  if(argc==3){
61  if (strcmp(argv[1], "use-rng") == 0) {
62  rng_ = (RNG*)TclObject::lookup(argv[2]);
63  if (rng_ == 0) {
64  tcl.resultf("no such RNG %s", argv[2]);
65  return(TCL_ERROR);
66  }
67  return (TCL_OK);
68  }
69  //ADDED CODE
70  else if (strcmp(argv[1], "join-datacenter") == 0) {
71  DataCenter *dc = dynamic_cast<DataCenter*> (TclObject::lookup(argv[2]));
72  if(dc){
73  dc_ = dc;
74  return (TCL_OK);
75  }
76  return (TCL_ERROR);
77  }
78  //ADDED CODE
79  }
80  return Application::command(argc,argv);
81 }
82 
84 {
85  bind_time("burst_time_", &ontime_);
86  bind_time("idle_time_", &offtime_);
87  bind_bw("rate_", &rate_);
88  bind("shape_", &shape_);
89  bind("packetSize_", &size_);
90 }
91 
93 {
94  interval_ = (double)(size_ << 3)/(double)rate_;
96  rem_ = 0;
97  on_ = 0;
98  p1_ = burstlen_ * (shape_ - 1.0)/shape_;
99  p2_ = offtime_ * (shape_ - 1.0)/shape_;
100 }
101 
103 {
104 
105  double t = interval_;
106 
107  on_ = 1;
108  if (rem_ == 0) {
109  /* compute number of packets in next burst */
110  if(rng_ == 0){
111  rem_ = int(Random::pareto(p1_, shape_) + .5);
112  }
113  else{
114  // Added by Debojyoti Dutta 13th October 2000
115  rem_ = int(rng_->pareto(p1_, shape_) + .5);
116  }
117  /* make sure we got at least 1 */
118  if (rem_ == 0)
119  rem_ = 1;
120  /* start of an idle period, compute idle time */
121  if(rng_ == 0){
122  t += Random::pareto(p2_, shape_);
123  }
124  else{
125  // Added by Debojyoti Dutta 13th October 2000
126  t += rng_->pareto(p2_, shape_);
127  }
128  on_ = 0;
129  }
130  rem_--;
131 
132  size = size_;
133  return(t);
134 
135 }
136 
138 {
139  if (! running_)
140  return;
141 
142  /* send a packet */
143  dc_->receivedTsk(size_, createTask());
144  /* figure out when to send the next one */
145  nextPkttime_ = next_interval(size_);
146  /* schedule it */
147  if (nextPkttime_ > 0)
148  timer_.resched(nextPkttime_);
149  else
150  running_ = 0;
151 }
152 
153 
154 
155 
156 
157 
158 
159 
CloudTask * createTask()
Definition: clouduser.cc:19
POOTrafficClass class_pareto_clouduser
unsigned int rem_
int command(int argc, const char *const *argv)
static const char rcsid[]
virtual void receivedTsk(int tsksize, CloudTask *pTask, const char *flags=0)
Definition: datacenter.cc:161
virtual double next_interval(int &)
TclObject * create(int, const char *const *)
virtual void timeout()
DataCenter * dc_
Definition: clouduser.h:45