19.1 The C++ EnergyModel Class

The basic energy model is very simple and is defined by class EnergyModel as shown below:

class EnergyModel : public TclObject {
public:
  EnergyModel(double energy) { energy_ = energy; }
  inline double energy() { return energy_; }
  inline void setenergy(double e) {energy_ = e;}
  virtual void DecrTxEnergy(double txtime, double P_tx) {
    energy_ -= (P_tx * txtime);
  }
  virtual void DecrRcvEnergy(double rcvtime, double P_rcv) {
    energy_ -= (P_rcv * rcvtime);
  }
protected:
  double energy_;
};

As seen from the EnergyModel Class definition above, there is only a single class variable energy_ which represents the level of energy in the node at any given time. The constructor EnergyModel(energy) requires the initial-energy to be passed along as a parameter. The other class methods are used to decrease the energy level of the node for every packet transmitted ( DecrTxEnergy(txtime, P_tx)) and every packet received ( DecrRcvEnergy (rcvtime, P_rcv)) by the node. P_tx and P_rcv are the transmitting and receiving power (respectively) required by the node's interface or PHY. At the beginning of simulation, energy_ is set to initialEnergy_ which is then decremented for every transmission and reception of packets at the node. When the energy level at the node goes down to zero, no more packets can be received or transmitted by the node. If tracing is turned on, line DEBUG: node node-id dropping pkts due to energy = 0 is printed in the tracefile.

Tom Henderson 2011-11-05