Energy Model Update in ns-2


To support simulations of S-MAC and other energy-efficient protocols, we have extended the energy model in ns-2. The old energy model did not have a sleep state. We added the sleep state. In addition, we also added energy consumption during state transition from sleep to idle (active). To help analyzing energy consumption in different states, we enhanced the energy traces on individual states: sleep, idle, transmit and receive.

The above changes were implemented by Vijay Kakadia as Directed Research under Dr. Wei Ye. Padma Haldar provided insights about ns-2 internals and integrated Vijay's code into ns-2. The code is checked into ns-2 on June 14, 2005. To use it, get the latest ns-2 release.

IMPORTANT NOTICE: The detailed energy tracing was accidentally removed by an ns developer. To use it, you need to install the most recent ns release (ns-2.29), and replace the following file with this one.


Changes to ns-2

Major changes have been made in the physical layer (ns-2/mac/wireless-phy.{h,cc}) and the energy model (ns-2/mobile/energy-model.{h,cc} ). Now the physical layer has full control over radio states, and provides interfaces to put radio into sleep state and wake it up. It also keeps track of radio energy consumption at all times. Whenever the radio state changes, it updates the energy model to subtract the appropriate amount for the previous state. The new wireless-phy provides accurate energy measurement no matter what MAC is running on top of it.

The energy model only maintains the total energy and does not maintain radio states. It is generic enough for future simulations such as the CPU power consumption. Please note that the old energy model indeed maintains some radio states, and have some methods to manipulate them, and they are only used by the adaptive fidelity module. This approach may cause inconsistency with wireless-phy. To keep adaptive fidelity work, we did not remove it from the energy model, but it is obsolete, and should not be used further. Now all access to the energy model should go through wireless-phy.

Energy Model API

The energy model is used through the node-config API. An example is shown as follows
      $ns_ node-config -adhocRouting DumbAgent \
			 -llType $opt(ll) \
			 -macType Mac/SMAC \
			 -ifqType $opt(ifq) \
			 -ifqLen $opt(ifqlen) \
			 -antType $opt(ant) \
			 -propType $opt(prop) \
			 -phyType $opt(netif) \
			 -channelType $opt(chan) \
			 -topoInstance $topo_ \
			 -agentTrace ON \
			 -routerTrace ON \
			 -macTrace ON \
			 -energyModel $opt(energymodel) \
			 -idlePower 1.0 \
			 -rxPower 1.0 \
			 -txPower 2.0 \
          		 -sleepPower 0.001 \
          		 -transitionPower 0.2 \
          		 -transitionTime 0.005 \
			 -initialEnergy $opt(initialenergy)
The following parameters are newly added:
-sleepPower: power consumption (Watt) in sleep state
-transitionPower: power consumption (Watt) in state transition from sleep to idle (active)
-transitionTime: time (second) used in state transition from sleep to idle (active)

Energy Analysis Through Trace Files

We have added energy breakdown in each state in the traces to support detailed energy analysis. In addition to the total energy, now users will be able to see the energy consumption in different states at a given time. Following is an example from a trace file on energy.
 [energy 979.917000 ei 20.074 es 0.000 et 0.003 er 0.006]
The meaning of each item is as follows:
energy: total remaining energy
ei: energy consumption in IDLE state
es: energy consumption in SLEEP state
et: energy consumed in transmitting packets
er: energy consumed in receiving packets

Example Script

The following simulations script is provided by Vijay Kakadia in his testing. It uses S-MAC with the new energy model.


Other Notes

A user reported that the example script MyTest.tcl works with IEEE 802.11 MAC if you simply change Mac/SMAC to Mac/802_11. The trace will include detailed energy consumption of the 802.11 MAC.

Please send comments to Wei Ye.
Last modified on May 24, 2007.