12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 19Energy Model in <strong>ns</strong>Energy Model, as implemented in <strong>ns</strong>, is a node <strong>at</strong>tribute. <strong>The</strong> energy model represents level of energy in a mobile host.<strong>The</strong> energy model in a node has a initial value which is the level of energy the node has <strong>at</strong> the beginning of the simul<strong>at</strong>ion.This is known as initialEnergy_. It also has a given energy usage for every packet it tra<strong>ns</strong>mits <strong>and</strong> receives. <strong>The</strong>seare called txPower_ <strong>and</strong> rxPower_. <strong>The</strong> files where the energy model is defined are <strong>ns</strong>/energymodel[.cc <strong>and</strong>.h]. Otherfunctio<strong>ns</strong>/methods described in this chapter may be found in <strong>ns</strong>/wireless-phy.cc, <strong>ns</strong>/cmu-trace.cc, <strong>ns</strong>/tcl/lib[<strong>ns</strong>-lib.tcl, <strong>ns</strong>node.tcl,<strong>ns</strong>-mobilenode.tcl].19.1 <strong>The</strong> C++ EnergyModel Class<strong>The</strong> basic energy model is very simple <strong>and</strong> is defined by class EnergyModel as shown below:class EnergyModel : public TclObjectpublic: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 thelevel of energy in the node <strong>at</strong> any given time. <strong>The</strong> co<strong>ns</strong>tructor EnergyModel(energy) requires the initial-energy to be passedalong as a parameter. <strong>The</strong> other class methods are used to decrease the energy level of the node for every packet tra<strong>ns</strong>mitted( DecrTxEnergy(txtime, P_tx)) <strong>and</strong> every packet received ( DecrRcvEnergy (rcvtime, P_rcv)) by thenode. P_tx <strong>and</strong> P_rcv are the tra<strong>ns</strong>mitting <strong>and</strong> receiving power (respectively) required by the node’s interface or PHY. Atthe beginning of simul<strong>at</strong>ion, energy_ is set to initialEnergy_ which is then decremented for every tra<strong>ns</strong>mission <strong>and</strong>192

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!