GreenCloud Simulator
expclouduser.cc
Go to the documentation of this file.
1 #ifndef lint
2 static const char rcsid[] =
3  "@(#) $Header: /cvsroot/nsnam/ns-2/tools/clouduser.cc,v 1.15 Exp $";
4 #endif
5 
6 #include <stdlib.h>
7 
8 #include "random.h"
9 #include "datacenter.h"
10 #include "trafgen.h"
11 #include "ranvar.h"
12 #include "clouduser.h"
13 
14 
15 /* implement an on/off source with exponentially distributed on and
16  * off times. parameterized by average burst time, average idle time,
17  * burst rate and packet size.
18  */
19 
20 class ExpCloudUser : public TrafficGenerator, public CloudUser {
21 public:
22  ExpCloudUser();
23  virtual double next_interval(int&);
24  virtual void timeout();
25 
26  int command(int argc, const char*const* argv);
27 
28  void addDataCenterPointer(DataCenter *joindc_);
29 
30 protected:
31  void init();
32  double ontime_;
33  double offtime_;
34  double rate_;
35  double interval_;
36  unsigned int rem_;
38  /* new stuff using RandomVariable */
39  ExponentialRandomVariable burstlen_;
40  ExponentialRandomVariable Offtime_;
41 };
42 
43 
44 static class ExpCloudUserClass : public TclClass {
45 public:
46  ExpCloudUserClass() : TclClass("Application/Traffic/ExpCloudUser") {}
47  TclObject* create(int, const char*const*) {
48  return (new ExpCloudUser());
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 ExpCloudUser::command(int argc, const char*const* argv){
58  int result = CloudUser::process_command(argc,argv);
59  if(result==-1){
60  if(argc==3){
61  if (strcmp(argv[1], "use-rng") == 0) {
62  burstlen_.seed((char *)argv[2]);
63  Offtime_.seed((char *)argv[2]);
64  return (TCL_OK);
65  }
66  //ADDED CODE
67  else if (strcmp(argv[1], "set-rate") == 0) {
68  int new_rate = atoi(argv[2]);
69  if(1){
70  rate_=new_rate;
71  interval_ = (double)(size_ << 3)/(double)rate_;
72  return (TCL_OK);
73  }
74  return (TCL_ERROR);
75  }
76  //ADDED CODE
77  }
78  return Application::command(argc,argv);
79  } else {
80  return result;
81  }
82 }
83 
85 {
86 
87  bind_time("random_tskmips_",random_tskmips_.avgp());
88  bind_time("burst_time_", &ontime_);
89  bind_time("idle_time_", Offtime_.avgp());
90  bind_bw("rate_", &rate_);
91  bind("packetSize_", &size_);
92 
93  // Bind CloudUser variables
94  bind("id_", &id_);
95  bind("tskmips_", &tskmips_);
96  bind("memory_", &memory_);
97  bind("storage_", &storage_);
98  bind("tsksize_", &tsksize_);
99  bind("tskmaxduration_", &tskmaxduration_);
100  bind("toutputsize_", &toutputsize_);
101  bind("tintercom_", &tintercom_);
102  bind("mean_response_time_", &mean_response_time_);
103  bind("sd_response_time_", &sd_response_time_);
104  bind("unfinished_tasks_", &unfinished_tasks_);
105 }
106 
108 {
109  /* compute inter-packet interval during bursts based on
110  * packet size and burst rate. then compute average number
111  * of packets in a burst.
112  */
113  interval_ = (double)(size_ << 3)/(double)rate_;
114  burstlen_.setavg(ontime_/interval_);
115  rem_ = 0;
116 }
117 
119 {
120  double t = interval_;
121 
122  if (rem_ == 0) {
123  /* compute number of packets in next burst */
124  rem_ = int(burstlen_.value() + .5);
125  /* make sure we got at least 1 */
126  if (rem_ == 0)
127  rem_ = 1;
128  /* start of an idle period, compute idle time */
129  t += Offtime_.value();
130  }
131  rem_--;
132 
133  size = size_;
134  //TODO: add change factor (for decay the change should be >1):interval_ = interval_ * change_ ;
135  // OR: use change by constant term as below:
136  // interval_ = interval_ + 0.000005;
137  // if(interval_<=0) interval_ = 0.000005;
138  return(t);
139 }
140 
142 {
143  if (! running_)
144  return;
145 
146  if (nextPkttime_ != interval_ || nextPkttime_ == -1){
147  dc_->receivedTsk(size_, createTask(), "NEW_BURST");
148  }
149  else {
150  dc_->receivedTsk(size_, createTask());
151  }
152 
153 
154  /* figure out when to send the next one */
155  nextPkttime_ = next_interval(size_);
156  /* schedule it */
157  if (nextPkttime_ > 0)
158  timer_.resched(nextPkttime_);
159 }
160 
161 
CloudTask * createTask()
Definition: clouduser.cc:19
double interval_
Definition: expclouduser.cc:35
unsigned int rem_
Definition: expclouduser.cc:36
ExponentialRandomVariable random_tskmips_
Definition: clouduser.h:47
double sd_response_time_
Definition: clouduser.h:41
int tintercom_
Definition: clouduser.h:36
int id_
Definition: clouduser.h:26
int process_command(int argc, const char *const *argv)
Definition: clouduser.cc:73
double mean_response_time_
Definition: clouduser.h:40
int toutputsize_
Definition: clouduser.h:35
ExponentialRandomVariable burstlen_
Definition: expclouduser.cc:39
double tskmips_
Definition: clouduser.h:29
virtual double next_interval(int &)
double tskmaxduration_
Definition: clouduser.h:33
virtual void receivedTsk(int tsksize, CloudTask *pTask, const char *flags=0)
Definition: datacenter.cc:161
double ontime_
Definition: expclouduser.cc:32
void addDataCenterPointer(DataCenter *joindc_)
virtual void timeout()
ExpCloudUserClass class_exp_cloud_user
ExponentialRandomVariable Offtime_
Definition: expclouduser.cc:40
double offtime_
Definition: expclouduser.cc:33
TclObject * create(int, const char *const *)
Definition: expclouduser.cc:47
double storage_
Definition: clouduser.h:31
int unfinished_tasks_
Definition: clouduser.h:42
static const char rcsid[]
Definition: expclouduser.cc:2
int command(int argc, const char *const *argv)
Definition: expclouduser.cc:57
double memory_
Definition: clouduser.h:30
unsigned int tsksize_
Definition: clouduser.h:32
DataCenter * dc_
Definition: clouduser.h:45