GreenCloud Simulator
switchenergymodel.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 #include "switchenergymodel.h"
6 #include "scheduler.h"
7 
8 static class SwitchEnergyModelClass : public TclClass {
9 public:
10  SwitchEnergyModelClass() : TclClass("SwitchEnergyModel") {}
11  TclObject* create(int argc, const char*const*argv) {
12  return (new SwitchEnergyModel());
13  }
15 
16 SwitchEnergyModel::SwitchEnergyModel() : eConsumed_(0.0), eChassis_(0.0), eLineCard_(0.0), ePort_(0.0), eSimEnd_(0.0), eDVFS_enabled_(0), eDNS_enabled_(0), eDNS_delay_(0.0), eEnabled_(0), eCurrentRate_(0.0), eActivePorts_(0), eSimDuration_(0.0), classifier_(NULL), energytimer_(this)
17 {
18  bind("eConsumed_", &eConsumed_);
19  bind("eChassis_", &eChassis_);
20  bind("eLineCard_", &eLineCard_);
21  bind("ePort_", &ePort_);
22  bind("eSimEnd_", &eSimEnd_);
23  bind("eDVFS_enabled_", &eDVFS_enabled_); /* ON when DVFS is enabled */
24  bind("eDNS_enabled_", &eDNS_enabled_); /* ON when DNS is enabled */
25  bind("eDNS_delay_", &eDNS_delay_);
26 }
27 
29 {
30 }
31 
33 {
34  eEnabled_ = 1;
35  eLastSample_ = Scheduler::instance().clock();
37 
38  if (classifier_) eActivePorts_ = classifier_->maxslot();
39 
40  if (eDNS_enabled_) eCurrentRate_ = 0.0;
41  else computeCurrentRate();
42 }
43 
45 {
46  updateEnergy(0, 0);
47 }
48 
50 {
52 
53  return eCurrentRate_;
54 }
55 
56 void SwitchEnergyModel::updateEnergy(int curslot, int nports)
57 {
58  if (eEnabled_ == 0) return;
59 
60  /* Compute energy spent since last call */
61  if (nports != eActivePorts_) {
62  eConsumed_ += eCurrentRate_*(Scheduler::instance().clock() - eLastSample_)/3600; // update energy
63  eActivePorts_ = nports; // update number of active ports
65  eLastSample_ = Scheduler::instance().clock();
66 
67  /* if DNS is enabled start sleep-mode timer */
69  }
70 }
71 
72 int SwitchEnergyModel::command(int argc, const char*const* argv)
73 {
74  if (argc == 2) {
75  if (strcmp(argv[1], "start") == 0) {
76  start();
77  return (TCL_OK);
78  }
79  if (strcmp(argv[1], "stop") == 0) {
80  stop();
81  return (TCL_OK);
82  }
83  }
84  return (SwitchEnergyModel::command(argc, argv));
85 }
86 
88 
89  eConsumed_ += eCurrentRate_*(Scheduler::instance().clock() - eLastSample_)/3600; // update energy
90  eCurrentRate_ = 0.0;
91  eLastSample_ = Scheduler::instance().clock();
92 }
93 
95 {
96  em_->timeout();
97 }
virtual int command(int argc, const char *const *argv)
SwitchEnergyTimer energytimer_
TclObject * create(int argc, const char *const *argv)
void updateEnergy(int curSlot, int nports)
void expire(Event *)
SwitchEnergyModelClass class_switchenergymodel
virtual void timeout()
virtual ~SwitchEnergyModel()
Classifier * classifier_