Apply energy model changes of http://codereview.appspot.com/1008043/show patchset 13
authorHe Wu <mdzz@u.washington.edu>
Mon, 09 Aug 2010 23:31:57 -0700
changeset 6535 0a90ef2b29a9
parent 6534 f99ae4e06d61
child 6536 2666c1d862ef
Apply energy model changes of http://codereview.appspot.com/1008043/show patchset 13
src/contrib/energy/helper/basic-energy-source-helper.cc
src/contrib/energy/helper/basic-energy-source-helper.h
src/contrib/energy/helper/basic-radio-energy-model-helper.cc
src/contrib/energy/helper/basic-radio-energy-model-helper.h
src/contrib/energy/helper/energy-model-helper.cc
src/contrib/energy/helper/energy-model-helper.h
src/contrib/energy/helper/energy-source-container.cc
src/contrib/energy/helper/energy-source-container.h
src/contrib/energy/helper/wifi-radio-energy-model-helper.cc
src/contrib/energy/helper/wifi-radio-energy-model-helper.h
src/contrib/energy/model/basic-energy-source.cc
src/contrib/energy/model/basic-energy-source.h
src/contrib/energy/model/basic-radio-energy-model.cc
src/contrib/energy/model/basic-radio-energy-model.h
src/contrib/energy/model/device-energy-model-container.cc
src/contrib/energy/model/device-energy-model-container.h
src/contrib/energy/model/device-energy-model.cc
src/contrib/energy/model/device-energy-model.h
src/contrib/energy/model/energy-source.cc
src/contrib/energy/model/energy-source.h
src/contrib/energy/model/radio-energy-model.cc
src/contrib/energy/model/radio-energy-model.h
src/contrib/energy/model/wifi-radio-energy-model.cc
src/contrib/energy/model/wifi-radio-energy-model.h
src/contrib/energy/test/basic-energy-model-test.cc
src/contrib/energy/wscript
--- a/src/contrib/energy/helper/basic-energy-source-helper.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/helper/basic-energy-source-helper.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -39,15 +39,7 @@
 }
 
 Ptr<EnergySource>
-BasicEnergySourceHelper::Create (void) const
-{
-  Ptr<EnergySource> source = m_basicEnergySource.Create<EnergySource> ();
-  NS_ASSERT (source != 0);
-  return source;
-}
-
-void
-BasicEnergySourceHelper::Install (Ptr<Node> node) const
+BasicEnergySourceHelper::DoInstall (Ptr<Node> node) const
 {
   NS_ASSERT (node != NULL);
   // check if energy source already exists
@@ -55,13 +47,11 @@
   if (source != NULL)
     {
       NS_FATAL_ERROR ("Energy source already installed!");
-      return;
     }
-  // create energy source
-  source = Create ();
+  source = m_basicEnergySource.Create<EnergySource> ();
   NS_ASSERT (source != NULL);
-  // aggregate source to node
-  node->AggregateObject (source);
+  source->SetNode (node);
+  return source;
 }
 
 } // namespace ns3
--- a/src/contrib/energy/helper/basic-energy-source-helper.h	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/helper/basic-energy-source-helper.h	Mon Aug 09 23:31:57 2010 -0700
@@ -18,15 +18,14 @@
  * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
  */
 
-#ifndef BASIC_ENERGY_SOURCE_HELPER
-#define BASIC_ENERGY_SOURCE_HELPER
+#ifndef BASIC_ENERGY_SOURCE_HELPER_H
+#define BASIC_ENERGY_SOURCE_HELPER_H
 
 #include "energy-model-helper.h"
+#include "ns3/node.h"
 
 namespace ns3 {
 
-class Node;
-
 /**
  * \brief Creates a BasicEnergySource object.
  */
@@ -38,9 +37,8 @@
 
   void Set (std::string name, const AttributeValue &v);
 
-  Ptr<EnergySource> Create (void) const;
-
-  void Install (Ptr<Node> node) const;
+private:
+  virtual Ptr<EnergySource> DoInstall (Ptr<Node> node) const;
 
 private:
   ObjectFactory m_basicEnergySource;
@@ -49,4 +47,4 @@
 
 } // namespace ns3
 
-#endif  /* BASIC_ENERGY_SOURCE_HELPER */
+#endif  /* BASIC_ENERGY_SOURCE_HELPER_H */
--- a/src/contrib/energy/helper/basic-radio-energy-model-helper.cc	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
- */
-
-#include "basic-radio-energy-model-helper.h"
-#include "basic-energy-source-helper.h"
-#include "ns3/radio-energy-model.h"
-#include "ns3/config.h"
-#include "ns3/names.h"
-#include "ns3/log.h"
-
-namespace ns3 {
-
-NS_LOG_COMPONENT_DEFINE ("BasicRadioEnergyModelHelper");
-
-BasicRadioEnergyModelHelper::BasicRadioEnergyModelHelper ()
-{
-  m_radioEnergy.SetTypeId ("ns3::BasicRadioEnergyModel");
-  m_depletionCallback.Nullify ();
-}
-
-BasicRadioEnergyModelHelper::~BasicRadioEnergyModelHelper ()
-{
-}
-
-void
-BasicRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v)
-{
-  m_radioEnergy.Set (name, v);
-}
-
-Ptr<DeviceEnergyModel>
-BasicRadioEnergyModelHelper::Create (void) const
-{
-  return m_radioEnergy.Create<DeviceEnergyModel> ();
-}
-
-void
-BasicRadioEnergyModelHelper::SetDepletionCallback (
-  BasicRadioEnergyModel::BasicEnergyDepletionCallback callback)
-{
-  m_depletionCallback = callback;
-}
-
-/*
- * Private function starts here.
- */
-
-void
-BasicRadioEnergyModelHelper::DoInstall (Ptr<Node> node) const
-{
-  NS_LOG_FUNCTION (this << node);
-  // check if energy source is installed
-  Ptr<EnergySource> source = node->GetObject<EnergySource> ();
-  if (source != NULL)
-    {
-      Ptr<BasicRadioEnergyModel> model = m_radioEnergy.Create ()->
-        GetObject<BasicRadioEnergyModel> ();
-      if (model == NULL)
-        {
-          NS_FATAL_ERROR ( "The requested radio energy model does not exist: "
-                           << m_radioEnergy.GetTypeId ().GetName ());
-        }
-      else
-        {
-          // set energy source pointer
-          model->SetEnergySource (source);
-          // set energy depletion callback
-          model->SetEnergyDepletionCallback (m_depletionCallback);
-          // add model to device model list in energy source
-          source->AppendDeviceEnergyModel (model);
-        }
-    }
-  else
-    {
-      NS_FATAL_ERROR ("Energy source NOT installed!");
-    }
-}
-
-} // namespace ns3
--- a/src/contrib/energy/helper/basic-radio-energy-model-helper.h	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
-* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License version 2 as
-* published by the Free Software Foundation;
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*
-* Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
-*/
-
-#ifndef BASIC_RADIO_ENERGY_MODEL_HELPER_H
-#define BASIC_RADIO_ENERGY_MODEL_HELPER_H
-
-#include "energy-model-helper.h"
-#include "ns3/device-energy-model.h"
-#include "ns3/basic-radio-energy-model.h"
-
-namespace ns3 {
-
-/**
- * \brief Assign energy model to nodes.
- *
- * This installer is used for BasicRadioEnergyModel.
- */
-class BasicRadioEnergyModelHelper : public DeviceEnergyModelHelper
-{
-public:
-  /**
-   * Construct a helper which is used to add a radio energy model to a node
-   */
-  BasicRadioEnergyModelHelper ();
-
-  /**
-   * Destroy a RadioEnergy Helper
-   */
-  ~BasicRadioEnergyModelHelper ();
-
-  /**
-   * \param name the name of the attribute to set
-   * \param v the value of the attribute
-   *
-   * Sets an attribute of the underlying PHY object.
-   */
-  void Set (std::string name, const AttributeValue &v);
-
-  /**
-   * \returns A newly created RadioEnergySource object.
-   */
-  Ptr<DeviceEnergyModel> Create (void) const;
-
-  /**
-   * \param callback Callback function for energy depletion handling.
-   *
-   * Sets the callback to be invoked when energy is depleted.
-   */
-  void SetDepletionCallback (
-    BasicRadioEnergyModel::BasicEnergyDepletionCallback callback);
-
-
-private:
-  /**
-   * \brief Add an energy model to the specified node.
-   *
-   * \param node The node on which the energy model is to be installed.
-   *
-   * This method creates an instance of a ns3::BasicRadioEnergyModel and
-   * aggregates it to the given node.
-   */
-  void DoInstall (Ptr<Node> node) const;
-
-private:
-  ObjectFactory m_radioEnergy;
-  /// Callback function for energy depletion.
-  BasicRadioEnergyModel::BasicEnergyDepletionCallback m_depletionCallback;
-
-};
-
-} // namespace ns3
-
-#endif /* BASIC_RADIO_ENERGY_MODEL_HELPER_H */
--- a/src/contrib/energy/helper/energy-model-helper.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/helper/energy-model-helper.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -19,7 +19,6 @@
  */
 
 #include "energy-model-helper.h"
-#include "ns3/log.h"
 #include "ns3/config.h"
 #include "ns3/names.h"
 
@@ -32,6 +31,55 @@
 {
 }
 
+EnergySourceContainer
+EnergySourceHelper::Install (Ptr<Node> node) const
+{
+  return Install (NodeContainer (node));
+}
+
+EnergySourceContainer
+EnergySourceHelper::Install (NodeContainer c) const
+{
+  EnergySourceContainer container;
+  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+    {
+      Ptr<EnergySource> src = DoInstall (*i);
+      container.Add (src);
+      /*
+       * Check if EnergySourceContainer is already aggregated to target node. If
+       * not, create a new EnergySourceContainer and aggregate it to node.
+       */
+      Ptr<EnergySourceContainer> EnergySourceContrainerOnNode =
+        (*i)->GetObject<EnergySourceContainer> ();
+      if (EnergySourceContrainerOnNode == NULL)
+        {
+          ObjectFactory fac;
+          fac.SetTypeId ("ns3::EnergySourceContainer");
+          EnergySourceContrainerOnNode = fac.Create<EnergySourceContainer> ();
+          EnergySourceContrainerOnNode->Add (src);
+          (*i)->AggregateObject (EnergySourceContrainerOnNode);
+        }
+      else
+        {
+          EnergySourceContrainerOnNode->Add (src);  // append new EnergySource
+        }
+    }
+  return container;
+}
+
+EnergySourceContainer
+EnergySourceHelper::Install (std::string nodeName) const
+{
+  Ptr<Node> node = Names::Find<Node> (nodeName);
+  return Install (node);
+}
+
+EnergySourceContainer
+EnergySourceHelper::InstallAll (void) const
+{
+  return Install (NodeContainer::GetGlobal ());
+}
+
 /*
  * DeviceEnergyModelHelper
  */
@@ -39,76 +87,34 @@
 {
 }
 
-void
-DeviceEnergyModelHelper::Install (Ptr<Node> node) const
-{
-  NS_ASSERT (node != NULL);
-  DoInstall (node);
-}
-
-void
-DeviceEnergyModelHelper::Install (NodeContainer c) const
+DeviceEnergyModelContainer
+DeviceEnergyModelHelper::Install (Ptr<NetDevice> device,
+                                  Ptr<EnergySource> source) const
 {
-  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
-    {
-      Install (*i);
-    }
-}
-
-void
-DeviceEnergyModelHelper::Install (std::string nodeName) const
-{
-  Ptr<Node> node = Names::Find<Node> (nodeName);
-  Install (node);
-}
-
-void
-DeviceEnergyModelHelper::InstallAll (void) const
-{
-  Install (NodeContainer::GetGlobal ());
+  NS_ASSERT (device != NULL);
+  NS_ASSERT (source != NULL);
+  NS_ASSERT (device->GetNode () == source->GetNode ());
+  DeviceEnergyModelContainer container (DoInstall (device, source));
+  return container;
 }
 
-/*
- * EnergyModelHelper
- */
-EnergyModelHelper::EnergyModelHelper ()
-{
-}
-
-void
-EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper,
-                            const DeviceEnergyModelHelper &modelHelper, Ptr<Node> node) const
+DeviceEnergyModelContainer
+DeviceEnergyModelHelper::Install (NetDeviceContainer deviceContainer,
+                                  EnergySourceContainer sourceContainer) const
 {
-  NS_ASSERT (node != NULL);
-  // install source. source must be installed before installing device model.
-  sourceHelper.Install (node);
-  // install device model
-  modelHelper.Install (node);
-}
-
-void
-EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper,
-                            const DeviceEnergyModelHelper &modelHelper, NodeContainer c) const
-{
-  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+  NS_ASSERT (deviceContainer.GetN () <= sourceContainer.GetN ());
+  DeviceEnergyModelContainer container;
+  NetDeviceContainer::Iterator dev = deviceContainer.Begin ();
+  EnergySourceContainer::Iterator src = sourceContainer.Begin ();
+  while (dev != deviceContainer.End ())
     {
-      Install (sourceHelper, modelHelper, *i);
+      NS_ASSERT ((*dev)->GetNode () == (*src)->GetNode ());
+      Ptr<DeviceEnergyModel> model = DoInstall (*dev, *src);
+      container.Add (model);
+      dev++;
+      src++;
     }
-}
-
-void
-EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper,
-                            const DeviceEnergyModelHelper &modelHelper, std::string nodeName) const
-{
-  Ptr<Node> node = Names::Find<Node> (nodeName);
-  Install (sourceHelper, modelHelper, node);
-}
-
-void
-EnergyModelHelper::InstallAll (const EnergySourceHelper &sourceHelper,
-                               const DeviceEnergyModelHelper &modelHelper) const
-{
-  Install (sourceHelper, modelHelper, NodeContainer::GetGlobal ());
+  return container;
 }
 
 } // namespace ns3
--- a/src/contrib/energy/helper/energy-model-helper.h	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/helper/energy-model-helper.h	Mon Aug 09 23:31:57 2010 -0700
@@ -18,24 +18,27 @@
  * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
  */
 
-#ifndef ENERGY_MODEL_HELPER
-#define ENERGY_MODEL_HELPER
+#ifndef ENERGY_MODEL_HELPER_H
+#define ENERGY_MODEL_HELPER_H
 
 #include "ns3/attribute.h"
 #include "ns3/object-factory.h"
 #include "ns3/node-container.h"
 #include "ns3/ptr.h"
+#include "ns3/net-device.h"
+#include "ns3/net-device-container.h"
 #include "ns3/energy-source.h"
 #include "ns3/device-energy-model.h"
+#include "ns3/device-energy-model-container.h"
+#include "energy-source-container.h"
 
 namespace ns3 {
 
 /**
  * \brief Creates EnergySource objects.
  *
- * This class creates and installs an energy source onto network nodes. This
- * base class must be implemented by new EnergySource implementation which wish
- * to integrate with the \ref ns3::EnergyModelHelper class.
+ * This class creates and installs an energy source onto network nodes. Only a
+ * single source can exist on a network node.
  */
 class EnergySourceHelper
 {
@@ -43,31 +46,65 @@
   virtual ~EnergySourceHelper ();
 
   /**
-   * \returns A newly created EnergySource object.
-   * Subclasses must implement this methods to allow the ns3::EnergySource class
-   * to create DeviceEnergyModel object for installation.
+   * \param name Name of attribute to set.
+   * \param v Value of the attribute.
+   *
+   * Sets one of the attributes of underlying EnergySource.
    */
-  virtual Ptr<EnergySource> Create (void) const = 0;
+  virtual void Set (std::string name, const AttributeValue &v) = 0;
+
+  /**
+   * \param node Pointer to the node where EnergySource will be installed.
+   * \returns An EnergySourceContainer which contains all the EnergySources.
+   *
+   * This function installs an EnergySource onto a node.
+   */
+  EnergySourceContainer Install (Ptr<Node> node) const;
+
+  /**
+   * \param c List of nodes where EnergySource will be installed.
+   * \returns An EnergySourceContainer which contains all the EnergySources.
+   *
+   * This function installs an EnergySource onto a list of nodes.
+   */
+  EnergySourceContainer Install (NodeContainer c) const;
 
   /**
-   * \param node Pointer to the node where EnergySource will be installed on.
+   * \param nodeName Name of node where EnergySource will be installed.
+   * \returns An EnergySourceContainer which contains all the EnergySources.
+   *
+   * This function installs an EnergySource onto a node.
+   */
+  EnergySourceContainer Install (std::string nodeName) const;
+
+  /**
+   * \brief This function installs an EnergySource on all nodes in simulation.
    *
-   * This method installs an EnergySource onto a node. Must be implemented by
-   * subclasses.
+   * \returns An EnergySourceContainer which contains all the EnergySources.
    */
-  virtual void Install (Ptr<Node> node) const = 0;
+  EnergySourceContainer InstallAll (void) const;
+
+
+private:
+  /**
+   * \param node Pointer to node where the energy source is to be installed.
+   * \returns Pointer to the created EnergySource.
+   *
+   * Child classes of EnergySourceHelper only have to implement this function,
+   * to create and aggregate an EnergySource object onto a single node. Rest of
+   * the installation process (eg. installing EnergySource on set of nodes) is
+   * implemented in the EnergySourceHelper base class.
+   */
+  virtual Ptr<EnergySource> DoInstall (Ptr<Node> node) const = 0;
 
 };
 
 
 /**
- * \brief Creates DeviceEnergyModel objects
+ * \brief Creates DeviceEnergyModel objects.
  *
- * This class can help to create and install an DeviceEnergyModel onto network
- * nodes. It can be called separately to install extra DeviceEnergyModels onto
- * the same nodes. This base class must be implemented by new DeviceEnergyModel
- * which wishes to integrate with the \ref ns3::EnergyModelHelper class.
- *
+ * This class helps to create and install DeviceEnergyModel onto NetDevice. A
+ * DeviceEnergyModel is connected to a NetDevice (or PHY object) by callbacks.
  * Note that DeviceEnergyModel objects are *not* aggregated onto the node. They
  * can be accessed through the EnergySource object, which *is* aggregated onto
  * the node.
@@ -78,14 +115,6 @@
   virtual ~DeviceEnergyModelHelper ();
 
   /**
-   * \returns A newly created DeviceEnergySource object.
-   *
-   * Subclasses must implement this method to allow the ns3::DeviceEnergyModel
-   * class to create DeviceEnergyModel object for installation.
-   */
-  virtual Ptr<DeviceEnergyModel> Create (void) const = 0;
-
-  /**
    * \param name Name of attribute to set.
    * \param v Value of the attribute.
    *
@@ -94,95 +123,46 @@
   virtual void Set (std::string name, const AttributeValue &v) = 0;
 
   /**
-   * \param node The node on which a DeviceEnergyModel object must be created.
+   * \param device Pointer to the NetDevice to install DeviceEnergyModel.
+   * \param source The EnergySource the DeviceEnergyModel will be using.
+   * \returns An DeviceEnergyModelContainer contains all the DeviceEnergyModels.
    *
-   * Installs an DeviceEnergyModel onto a node. Subclasses must implement this
-   * method.
+   * Installs an DeviceEnergyModel with a specified EnergySource onto a
+   * xNetDevice.
    */
-  void Install (Ptr<Node> node) const;
+  DeviceEnergyModelContainer Install (Ptr<NetDevice> device,
+                                      Ptr<EnergySource> source) const;
 
   /**
-   * \param c The set of nodes on which a jammer object must be created.
+   * \param deviceContainer List of NetDevices to be install DeviceEnergyModel
+   * objects.
+   * \param sourceContainer List of EnergySource the DeviceEnergyModel will be
+   * using.
+   * \returns An DeviceEnergyModelContainer contains all the DeviceEnergyModels.
    *
-   * Installs DeviceEnergyModel onto a list of nodes. Calls Install (Ptr<Node>
-   * node).
+   * Installs DeviceEnergyModels with specified EnergySources onto a list of
+   * NetDevices.
    */
-  void Install (NodeContainer c) const;
-
-  /**
-   * \param nodeName The name of node.
-   *
-   * Calls Install (Ptr<Node> node).
-   */
-  void Install (std::string nodeName) const;
-
-  /**
-   * Install on *ALL* nodes exists in simulation.
-   */
-  void InstallAll (void) const;
+  DeviceEnergyModelContainer Install (NetDeviceContainer deviceContainer,
+                                      EnergySourceContainer sourceContainer) const;
 
 
 private:
   /**
-   * \param node The node on which a DeviceEnergyModel object must be created.
+   * \param device The net device corresponding to DeviceEnergyModel object.
+   * \param source The EnergySource the DeviceEnergyModel will be using.
+   * \returns Pointer to the created DeviceEnergyModel.
    *
-   * Implements Install (Ptr<Node>). Subclasses must implement this method.
-   */
-  virtual void DoInstall (Ptr<Node> node) const = 0;
-
-};
-
-
-/**
- * \brief Creates EnergySource and DeviceEnergyModel objects.
- *
- * This class helps to create EnergySource and DeviceEnergyModel objects. Note
- * that only a single EnergySource can exist on the same node where multiple
- * DeviceEnergyModel can coexist on the same node. Extra DeviceEnergyModels can
- * be installed by DeviceEnergyModelHelper.
- */
-class EnergyModelHelper
-{
-public:
-  /**
-   * Create an EnergyModelHelper in an empty state: all its parameters must be
-   * set before calling ns3::EnergyModelHelper::Install.
+   * Child classes of DeviceEnergyModelHelper only have to implement this
+   * function, to create and aggregate an DeviceEnergyModel object onto a single
+   * node. The rest of the installation process (eg. installing EnergySource on
+   * set of nodes) is implemented in the DeviceEnergyModelHelper base class.
    */
-  EnergyModelHelper ();
-
-  /**
-   * \param sourceHelper The EnergySourceHelper to create EnergySource.
-   * \param modelHelper The DeviceEnergyModelHelper to create DeviceEnergyModel.
-   * \param node The node on which the energy model will be installed on.
-   */
-  void Install (const EnergySourceHelper &sourceHelper,
-                const DeviceEnergyModelHelper &modelHelper, Ptr<Node> node) const;
-
-  /**
-   * \param sourceHelper The EnergySourceHelper to create EnergySource.
-   * \param modelHelper The DeviceEnergyModelHelper to create DeviceEnergyModel.
-   * \param c List of node on which the energy model will be installed on.
-   */
-  void Install (const EnergySourceHelper &sourceHelper,
-                const DeviceEnergyModelHelper &modelHelper, NodeContainer c) const;
-
-  /**
-   * \param sourceHelper The EnergySourceHelper to create EnergySource.
-   * \param modelHelper The DeviceEnergyModelHelper to create DeviceEnergyModel.
-   * \param nodeName name of node on which the energy model will be installed on.
-   */
-  void Install (const EnergySourceHelper &sourceHelper,
-                const DeviceEnergyModelHelper &modelHelper, std::string nodeName) const;
-
-  /**
-   * \param sourceHelper The EnergySourceHelper to create EnergySource.
-   * \param modelHelper The DeviceEnergyModelHelper to create DeviceEnergyModel.
-   */
-  void InstallAll (const EnergySourceHelper &sourceHelper,
-                   const DeviceEnergyModelHelper &modelHelper) const;
+  virtual Ptr<DeviceEnergyModel> DoInstall (Ptr<NetDevice> device,
+                                            Ptr<EnergySource> source) const = 0;
 
 };
 
 } // namespace ns3
 
-#endif  /* ENERGY_MODEL_HELPER */
+#endif  /* ENERGY_MODEL_HELPER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/helper/energy-source-container.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,135 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ *          Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#include "energy-source-container.h"
+#include "ns3/names.h"
+
+namespace ns3 {
+
+TypeId
+EnergySourceContainer::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::EnergySourceContainer")
+    .SetParent<Object> ()
+    .AddConstructor<EnergySourceContainer> ()
+  ;
+  return tid;
+}
+
+EnergySourceContainer::EnergySourceContainer ()
+{
+}
+
+EnergySourceContainer::~EnergySourceContainer ()
+{
+}
+
+EnergySourceContainer::EnergySourceContainer (Ptr<EnergySource> source)
+{
+  NS_ASSERT (source != NULL);
+  m_sources.push_back (source);
+}
+
+EnergySourceContainer::EnergySourceContainer (std::string sourceName)
+{
+  Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
+  NS_ASSERT (source != NULL);
+  m_sources.push_back (source);
+}
+
+EnergySourceContainer::EnergySourceContainer (const EnergySourceContainer &a,
+                                              const EnergySourceContainer &b)
+{
+  *this = a;
+  Add (b);
+}
+
+EnergySourceContainer::Iterator
+EnergySourceContainer::Begin (void) const
+{
+  return m_sources.begin ();
+}
+
+EnergySourceContainer::Iterator
+EnergySourceContainer::End (void) const
+{
+  return m_sources.end ();
+}
+
+uint32_t
+EnergySourceContainer::GetN (void) const
+{
+  return m_sources.size ();
+}
+
+Ptr<EnergySource>
+EnergySourceContainer::Get (uint32_t i) const
+{
+  return m_sources[i];
+}
+
+void
+EnergySourceContainer::Add (EnergySourceContainer container)
+{
+  for (Iterator i = container.Begin (); i != container.End (); i++)
+    {
+      m_sources.push_back (*i);
+    }
+}
+
+void
+EnergySourceContainer::Add (Ptr<EnergySource> source)
+{
+  NS_ASSERT (source != NULL);
+  m_sources.push_back (source);
+}
+
+void
+EnergySourceContainer::Add (std::string sourceName)
+{
+  Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
+  NS_ASSERT (source != NULL);
+  m_sources.push_back (source);
+}
+
+/*
+ * Private functions start here.
+ */
+
+void
+EnergySourceContainer::DoDispose (void)
+{
+  m_sources.clear ();
+}
+
+void
+EnergySourceContainer::DoStart (void)
+{
+  // call Object::Start for all EnergySource objects
+  for (std::vector< Ptr<EnergySource> >::iterator i = m_sources.begin ();
+      i != m_sources.end (); i++)
+    {
+      (*i)->Start ();
+    }
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/helper/energy-source-container.h	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,180 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ *          Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#ifndef ENERGY_SOURCE_CONTAINER_H
+#define ENERGY_SOURCE_CONTAINER_H
+
+#include "ns3/energy-source.h"
+#include "ns3/object.h"
+#include <vector>
+#include <stdint.h>
+
+namespace ns3 {
+
+/**
+ * \brief Holds a vector of ns3::EnergySource pointers.
+ *
+ * EnergySourceHelper returns a list of EnergySource pointers installed onto a
+ * node. Users can use this list to access EnergySource objects to obtain total
+ * energy consumption on a node easily.
+ *
+ * \see NetDeviceContainer
+ */
+class EnergySourceContainer : public Object
+{
+public:
+  typedef std::vector< Ptr<EnergySource> >::const_iterator Iterator;
+
+public:
+  static TypeId GetTypeId (void);
+  /**
+   * Creates an empty EnergySourceContainer.
+   */
+  EnergySourceContainer ();
+  ~EnergySourceContainer ();
+
+  /**
+   * \param source Pointer to an EnergySource.
+   *
+   * Creates an EnergySourceContianer with exactly one EnergySource previously
+   * instantiated.
+   */
+  EnergySourceContainer (Ptr<EnergySource> source);
+
+  /**
+   * \param sourceName Name of EnergySource.
+   *
+   * Creates an EnergySourceContainer with exactly one EnergySource previously
+   * instantiated and assigned a name using the Object name service. This
+   * EnergySource is specified by its assigned name.
+   */
+  EnergySourceContainer (std::string sourceName);
+
+  /**
+   * \param a A EnergySourceContainer.
+   * \param b Another EnergySourceContainer.
+   *
+   * Creates an EnergySourceContainer by concatenating EnergySourceContainer b
+   * to EnergySourceContainer a.
+   *
+   * \note Can be used to concatenate 2 Ptr<EnergySource> directly. C++ will be
+   * calling EnergySourceContainer constructor with Ptr<EnergySource> first.
+   */
+  EnergySourceContainer (const EnergySourceContainer &a,
+                         const EnergySourceContainer &b);
+
+  /**
+   * \brief Get an iterator which refers to the first EnergySource pointer in
+   * the container.
+   *
+   * \returns An iterator which refers to the first EnergySource in container.
+   *
+   * EnergySources can be retrieved from the container in two ways. First,
+   * directly by an index into the container, and second, using an iterator.
+   * This method is used in the iterator method and is typically used in a
+   * for-loop to run through the EnergySources.
+   *
+   * \code
+   *   EnergySourceContainer::Iterator i;
+   *   for (i = container.Begin (); i != container.End (); ++i)
+   *     {
+   *       (*i)->method ();  // some EnergySource method
+   *     }
+   * \endcode
+   */
+  Iterator Begin (void) const;
+
+  /**
+   * \brief Get an iterator which refers to the last EnergySource pointer in
+   * the container.
+   *
+   * \returns An iterator which refers to the last EnergySource in container.
+   *
+   * EnergySources can be retrieved from the container in two ways. First,
+   * directly by an index into the container, and second, using an iterator.
+   * This method is used in the iterator method and is typically used in a
+   * for-loop to run through the EnergySources.
+   *
+   * \code
+   *   EnergySourceContainer::Iterator i;
+   *   for (i = container.Begin (); i != container.End (); ++i)
+   *     {
+   *       (*i)->method ();  // some EnergySource method
+   *     }
+   * \endcode
+   */
+  Iterator End (void) const;
+
+  /**
+   * \brief Get the number of Ptr<EnergySource> stored in this container.
+   *
+   * \returns The number of Ptr<EnergySource> stored in this container.
+   */
+  uint32_t GetN (void) const;
+
+  /**
+   * \brief Get the i-th Ptr<EnergySource> stored in this container.
+   *
+   * \param i Index of the requested Ptr<EnergySource>.
+   * \returns The requested Ptr<EnergySource>.
+   */
+  Ptr<EnergySource> Get (uint32_t i) const;
+
+  /**
+   * \param container Another EnergySourceContainer to append.
+   *
+   * Appends the contents of another EnergySourceContainer to the end of this
+   * EnergySourceContainer.
+   */
+  void Add (EnergySourceContainer container);
+
+  /**
+   * \brief Append a single Ptr<EnergySource> to the end of this container.
+   *
+   * \param source Pointer to an EnergySource.
+   */
+  void Add (Ptr<EnergySource> source);
+
+  /**
+   * \brief Append a single Ptr<EnergySource> referred to by its object name to
+   * the end of this container.
+   *
+   * \param sourceName Name of EnergySource object.
+   */
+  void Add (std::string sourceName);
+
+private:
+  virtual void DoDispose (void);
+
+  /**
+   * \brief Calls Object::Start () for all EnergySource objects.
+   */
+  virtual void DoStart (void);
+
+private:
+  std::vector< Ptr<EnergySource> > m_sources;
+
+};
+
+} // namespace ns3
+
+#endif /* ENERGY_SOURCE_CONTAINER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/helper/wifi-radio-energy-model-helper.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,90 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#include "wifi-radio-energy-model-helper.h"
+#include "basic-energy-source-helper.h"
+#include "ns3/wifi-phy.h"
+#include "ns3/wifi-net-device.h"
+#include "ns3/config.h"
+#include "ns3/names.h"
+
+namespace ns3 {
+
+WifiRadioEnergyModelHelper::WifiRadioEnergyModelHelper ()
+{
+  m_radioEnergy.SetTypeId ("ns3::WifiRadioEnergyModel");
+  m_depletionCallback.Nullify ();
+}
+
+WifiRadioEnergyModelHelper::~WifiRadioEnergyModelHelper ()
+{
+}
+
+void
+WifiRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v)
+{
+  m_radioEnergy.Set (name, v);
+}
+
+void
+WifiRadioEnergyModelHelper::SetDepletionCallback (
+  WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
+{
+  m_depletionCallback = callback;
+}
+
+/*
+ * Private function starts here.
+ */
+
+Ptr<DeviceEnergyModel>
+WifiRadioEnergyModelHelper::DoInstall (Ptr<NetDevice> device,
+                                       Ptr<EnergySource> source) const
+{
+  NS_ASSERT (device != NULL);
+  NS_ASSERT (source != NULL);
+  // check if device is WifiNetDevice
+  std::string deviceName = device->GetInstanceTypeId ().GetName ();
+  if (deviceName.compare ("ns3::WifiNetDevice") != 0)
+    {
+      NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!");
+    }
+  Ptr<Node> node = device->GetNode ();
+  Ptr<WifiRadioEnergyModel> model = m_radioEnergy.Create ()->
+    GetObject<WifiRadioEnergyModel> ();
+  NS_ASSERT (model != NULL);
+  // set node pointer
+  model->SetNode (node);
+  // set energy source pointer
+  model->SetEnergySource (source);
+  // set energy depletion callback
+  model->SetEnergyDepletionCallback (m_depletionCallback);
+  // add model to device model list in energy source
+  source->AppendDeviceEnergyModel (model);
+  // create and install energy model callback
+  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
+  Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy ();
+  DeviceEnergyModel::ChangeStateCallback callback;
+  callback = MakeCallback (&DeviceEnergyModel::ChangeState, model);
+  //wifiPhy->SetEnergyModelCallback (callback);
+  return model;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/helper/wifi-radio-energy-model-helper.h	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,81 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation;
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*
+* Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+*/
+
+#ifndef WIFI_RADIO_ENERGY_MODEL_HELPER_H
+#define WIFI_RADIO_ENERGY_MODEL_HELPER_H
+
+#include "energy-model-helper.h"
+#include "ns3/wifi-radio-energy-model.h"
+
+namespace ns3 {
+
+/**
+ * \brief Assign WifiRadioEnergyModel to wifi devices.
+ *
+ * This installer installs WifiRadioEnergyModel for only WifiNetDevice objects.
+ */
+class WifiRadioEnergyModelHelper : public DeviceEnergyModelHelper
+{
+public:
+  /**
+   * Construct a helper which is used to add a radio energy model to a node
+   */
+  WifiRadioEnergyModelHelper ();
+
+  /**
+   * Destroy a RadioEnergy Helper
+   */
+  ~WifiRadioEnergyModelHelper ();
+
+  /**
+   * \param name the name of the attribute to set
+   * \param v the value of the attribute
+   *
+   * Sets an attribute of the underlying PHY object.
+   */
+  void Set (std::string name, const AttributeValue &v);
+
+  /**
+   * \param callback Callback function for energy depletion handling.
+   *
+   * Sets the callback to be invoked when energy is depleted.
+   */
+  void SetDepletionCallback (
+    WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback);
+
+
+private:
+  /**
+   * \param device Pointer to the NetDevice to install DeviceEnergyModel.
+   *
+   * Implements DeviceEnergyModel::Install.
+   */
+  virtual Ptr<DeviceEnergyModel> DoInstall (Ptr<NetDevice> device,
+                                            Ptr<EnergySource> source) const;
+
+private:
+  ObjectFactory m_radioEnergy;
+  WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback m_depletionCallback;
+
+};
+
+} // namespace ns3
+
+#endif /* WIFI_RADIO_ENERGY_MODEL_HELPER_H */
--- a/src/contrib/energy/model/basic-energy-source.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/basic-energy-source.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -23,6 +23,7 @@
 #include "ns3/assert.h"
 #include "ns3/double.h"
 #include "ns3/trace-source-accessor.h"
+#include "ns3/simulator.h"
 
 NS_LOG_COMPONENT_DEFINE ("BasicEnergySource");
 
@@ -40,8 +41,20 @@
                    "Initial energy stored in basic energy source.",
                    DoubleValue (10),  // in Joules
                    MakeDoubleAccessor (&BasicEnergySource::SetInitialEnergy,
-                                       &BasicEnergySource::DoGetInitialEnergy),
+                                       &BasicEnergySource::GetInitialEnergy),
                    MakeDoubleChecker<double> ())
+    .AddAttribute ("BasicEnergySupplyVoltageV",
+                   "Initial supply voltage for basic energy source.",
+                   DoubleValue (3.0), // in Volts
+                   MakeDoubleAccessor (&BasicEnergySource::SetSupplyVoltage,
+                                       &BasicEnergySource::GetSupplyVoltage),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("PeriodicEnergyUpdateInterval",
+                   "Time between two consecutive periodic energy updates.",
+                   TimeValue (Seconds (1.0)),
+                   MakeTimeAccessor (&BasicEnergySource::SetEnergyUpdateInterval,
+                                     &BasicEnergySource::GetEnergyUpdateInterval),
+                   MakeTimeChecker ())
     .AddTraceSource ("RemainingEnergy",
                      "Remaining energy at BasicEnergySource.",
                      MakeTraceSourceAccessor (&BasicEnergySource::m_remainingEnergyJ))
@@ -51,6 +64,7 @@
 
 BasicEnergySource::BasicEnergySource ()
 {
+  m_lastUpdateTime = Seconds (0.0);
 }
 
 BasicEnergySource::~BasicEnergySource ()
@@ -63,37 +77,64 @@
   NS_LOG_FUNCTION (this << initialEnergyJ);
   NS_ASSERT (initialEnergyJ >= 0);
   m_initialEnergyJ = initialEnergyJ;
-  // set remaining energy to be initial energy
   m_remainingEnergyJ = m_initialEnergyJ;
 }
 
-/*
- * Private functions start here.
- */
+void
+BasicEnergySource::SetSupplyVoltage (double supplyVoltageV)
+{
+  NS_LOG_FUNCTION (this << supplyVoltageV);
+  m_supplyVoltageV = supplyVoltageV;
+}
 
 void
-BasicEnergySource::DoDispose (void)
+BasicEnergySource::SetEnergyUpdateInterval (Time interval)
 {
   NS_LOG_FUNCTION (this);
-  BreakDeviceEnergyModelRefCycle ();  // break reference cycle
+  m_energyUpdateInterval = interval;
+}
+
+Time
+BasicEnergySource::GetEnergyUpdateInterval (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_energyUpdateInterval;
 }
 
 double
-BasicEnergySource::DoGetInitialEnergy (void) const
+BasicEnergySource::GetSupplyVoltage (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_supplyVoltageV;
+}
+
+double
+BasicEnergySource::GetInitialEnergy (void) const
 {
   NS_LOG_FUNCTION (this);
   return m_initialEnergyJ;
 }
 
 double
-BasicEnergySource::DoGetRemainingEnergy (void) const
+BasicEnergySource::GetRemainingEnergy (void)
 {
   NS_LOG_FUNCTION (this);
+  // update energy source to get the latest remaining energy.
+  UpdateEnergySource ();
   return m_remainingEnergyJ;
 }
 
+double
+BasicEnergySource::GetEnergyFraction (void)
+{
+  NS_LOG_FUNCTION (this);
+  // update energy source to get the latest remaining energy.
+  UpdateEnergySource ();
+  return m_remainingEnergyJ / m_initialEnergyJ;
+}
+
 void
-BasicEnergySource::DoDecreaseRemainingEnergy (double energyJ)
+BasicEnergySource::DecreaseRemainingEnergy (double energyJ)
 {
   NS_LOG_FUNCTION (this << energyJ);
   NS_ASSERT (energyJ >= 0);
@@ -106,28 +147,84 @@
 }
 
 void
-BasicEnergySource::HandleEnergyDrainedEvent (void)
-{
-  NS_LOG_FUNCTION (this);
-  NS_LOG_DEBUG ("BasicEnergySource:Energy depleted!");
-  NotifyEnergyDrained (); // notify DeviceEnergyModel objects
-  // energy never goes below 0
-  m_remainingEnergyJ = 0;
-}
-
-void
-BasicEnergySource::DoIncreaseRemainingEnergy (double energyJ)
+BasicEnergySource::IncreaseRemainingEnergy (double energyJ)
 {
   NS_LOG_FUNCTION (this << energyJ);
   NS_ASSERT (energyJ >= 0);
   m_remainingEnergyJ += energyJ;
 }
 
-double
-BasicEnergySource::DoGetEnergyFraction (void) const
+void
+BasicEnergySource::UpdateEnergySource (void)
 {
   NS_LOG_FUNCTION (this);
-  return m_remainingEnergyJ / m_initialEnergyJ;
+  NS_LOG_DEBUG ("BasicEnergySource:Updating remaining energy at node #" <<
+                GetNode ()->GetId ());
+
+  // do not update if simulation has finished
+  if (Simulator::IsFinished ())
+    {
+      return;
+    }
+
+  m_energyUpdateEvent.Cancel ();
+
+  CalculateRemainingEnergy ();
+
+  if (m_remainingEnergyJ <= 0)
+    {
+      HandleEnergyDrainedEvent ();
+      return; // stop periodic update
+    }
+
+  m_lastUpdateTime = Simulator::Now ();
+
+  m_energyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
+                                             &BasicEnergySource::UpdateEnergySource,
+                                             this);
+}
+
+/*
+ * Private functions start here.
+ */
+
+void
+BasicEnergySource::DoStart (void)
+{
+  NS_LOG_FUNCTION (this);
+  UpdateEnergySource ();  // start periodic update
+}
+
+void
+BasicEnergySource::DoDispose (void)
+{
+  NS_LOG_FUNCTION (this);
+  // calculate remaining energy at the end of simulation
+  CalculateRemainingEnergy ();
+  BreakDeviceEnergyModelRefCycle ();  // break reference cycle
+}
+
+void
+BasicEnergySource::HandleEnergyDrainedEvent (void)
+{
+  NS_LOG_FUNCTION (this);
+  NS_LOG_DEBUG ("BasicEnergySource:Energy depleted at node #" <<
+                GetNode ()->GetId ());
+  NotifyEnergyDrained (); // notify DeviceEnergyModel objects
+  m_remainingEnergyJ = 0; // energy never goes below 0
+}
+
+void
+BasicEnergySource::CalculateRemainingEnergy (void)
+{
+  NS_LOG_FUNCTION (this);
+  double totalCurrentA = CalculateTotalCurrent ();
+  Time duration = Simulator::Now () - m_lastUpdateTime;
+  NS_ASSERT (duration.GetSeconds () >= 0);
+  // energy = current * voltage * time
+  double energyToDecreaseJ = totalCurrentA * m_supplyVoltageV * duration.GetSeconds ();
+  m_remainingEnergyJ -= energyToDecreaseJ;
+  NS_LOG_DEBUG ("BasicEnergySource:Remaining energy = " << m_remainingEnergyJ);
 }
 
 } // namespace ns3
--- a/src/contrib/energy/model/basic-energy-source.h	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/basic-energy-source.h	Mon Aug 09 23:31:57 2010 -0700
@@ -18,14 +18,20 @@
  * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
  */
 
-#ifndef BASIC_ENERGY_SOURCE
-#define BASIC_ENERGY_SOURCE
+#ifndef BASIC_ENERGY_SOURCE_H
+#define BASIC_ENERGY_SOURCE_H
 
 #include "ns3/traced-value.h"
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
 #include "energy-source.h"
 
 namespace ns3 {
 
+/**
+ * BasicEnergySource decreases/increases remaining energy stored in itself in
+ * linearly.
+ */
 class BasicEnergySource : public EnergySource
 {
 public:
@@ -33,39 +39,85 @@
   BasicEnergySource ();
   virtual ~BasicEnergySource ();
 
-
-  /**
-   * \param initialEnergyJ Initial energy, in Joules
-   *
-   * Implements SetInitialEnergy. Note that initial energy is assumed to be set
-   * before simulation starts and is set only once per simulation.
-   */
-  void SetInitialEnergy (double initialEnergyJ);
-
-
-private:
-  void DoDispose (void);
-
   /**
    * \return Initial energy stored in energy source, in Joules.
    *
    * Implements GetInitialEnergy.
    */
-  double DoGetInitialEnergy (void) const;
+  virtual double GetInitialEnergy (void) const;
+
+  /**
+   * \returns Supply voltage at the energy source.
+   *
+   * Implements GetSupplyVoltage.
+   */
+  virtual double GetSupplyVoltage (void) const;
 
   /**
    * \return Remaining energy in energy source, in Joules
    *
    * Implements GetRemainingEnergy.
    */
-  double DoGetRemainingEnergy (void) const;
+  virtual double GetRemainingEnergy (void);
+
+  /**
+   * \returns Energy fraction.
+   *
+   * Implements GetEnergyFraction.
+   */
+  virtual double GetEnergyFraction (void);
 
   /**
    * \param energy Amount of energy (in Joules) to decrease from energy source.
    *
    * Implements DecreaseRemainingEnergy.
    */
-  void DoDecreaseRemainingEnergy (double energyJ);
+  virtual void DecreaseRemainingEnergy (double energyJ);
+
+  /**
+   * \param energy Amount of energy (in Joules) to increase from energy source.
+   *
+   * Implements IncreaseRemainingEnergy.
+   */
+  virtual void IncreaseRemainingEnergy (double energyJ);
+
+  /**
+   * Implements UpdateEnergySource.
+   */
+  virtual void UpdateEnergySource (void);
+
+  /**
+   * \param initialEnergy Initial energy, in Joules
+   *
+   * Sets initial energy stored in the energy source. Note that initial energy
+   * is assumed to be set before simulation starts and is set only once per
+   * simulation.
+   */
+  void SetInitialEnergy (double initialEnergyJ);
+
+  /**
+   * \param supplyVoltage Supply voltage at the energy source, in Volts.
+   *
+   * Sets supply voltage of the energy source.
+   */
+  void SetSupplyVoltage (double supplyVoltageV);
+
+  /**
+   * \param interval Energy update interval.
+   *
+   * This function sets the interval between each energy update.
+   */
+  void SetEnergyUpdateInterval (Time interval);
+
+  /**
+   * \returns The interval between each energy update.
+   */
+  Time GetEnergyUpdateInterval (void) const;
+
+
+private:
+  void DoStart (void);
+  void DoDispose (void);
 
   /**
    * Handles the remaining energy going to zero event. This function notifies
@@ -75,21 +127,25 @@
   void HandleEnergyDrainedEvent (void);
 
   /**
-   * \param energy Amount of energy (in Joules) to increase from energy source.
-   *
-   * Implements IncreaseRemainingEnergy.
+   * Calculates remaining energy. This function uses the total current from all
+   * device models to calculate the amount of energy to decrease. The energy to
+   * decrease is given by:
+   *    energy to decrease = total current * supply voltage * time duration
+   * This function subtracts the calculated energy to decrease from remaining
+   * energy.
    */
-  void DoIncreaseRemainingEnergy (double energyJ);
-
-  /// Implements GetEnergyFraction.
-  double DoGetEnergyFraction (void) const;
+  void CalculateRemainingEnergy (void);
 
 private:
   double m_initialEnergyJ;                // initial energy, in Joules
+  double m_supplyVoltageV;                // supply voltage, in Volts
   TracedValue<double> m_remainingEnergyJ; // remaining energy, in Joules
+  EventId m_energyUpdateEvent;            // energy update event
+  Time m_lastUpdateTime;                  // last update time
+  Time m_energyUpdateInterval;            // energy update interval
 
 };
 
 } // namespace ns3
 
-#endif /* BASIC_ENERGY_SOURCE */
+#endif /* BASIC_ENERGY_SOURCE_H */
--- a/src/contrib/energy/model/basic-radio-energy-model.cc	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,312 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
- */
-
-#include "ns3/log.h"
-#include "ns3/double.h"
-#include "ns3/simulator.h"
-#include "ns3/trace-source-accessor.h"
-#include "basic-radio-energy-model.h"
-
-NS_LOG_COMPONENT_DEFINE ("BasicRadioEnergyModel");
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (BasicRadioEnergyModel);
-
-TypeId
-BasicRadioEnergyModel::GetTypeId (void)
-{
-  static TypeId tid = TypeId ("ns3::BasicRadioEnergyModel")
-    .SetParent<RadioEnergyModel> ()
-    .AddConstructor<BasicRadioEnergyModel> ()
-    .AddAttribute ("TxPowerW",
-                   "The radio Tx power in Watts.",
-                   DoubleValue (0.0435),    // typical CC2420 value
-                   MakeDoubleAccessor (&BasicRadioEnergyModel::SetTxPowerW,
-                                       &BasicRadioEnergyModel::GetTxPowerW),
-                   MakeDoubleChecker<double> ())
-    .AddAttribute ("RxPowerW",
-                   "The radio Rx power in Watts.",
-                   DoubleValue (0.047),     // typical CC2420 value
-                   MakeDoubleAccessor (&BasicRadioEnergyModel::SetRxPowerW,
-                                       &BasicRadioEnergyModel::GetRxPowerW),
-                   MakeDoubleChecker<double> ())
-    .AddAttribute ("IdlePowerW",
-                   "The default radio Idle power in Watts.",
-                   DoubleValue (0.001065),  // typical CC2420 value
-                   MakeDoubleAccessor (&BasicRadioEnergyModel::SetIdlePowerW,
-                                       &BasicRadioEnergyModel::GetIdlePowerW),
-                   MakeDoubleChecker<double> ())
-    .AddAttribute ("SleepPowerW",
-                   "The default radio Sleep power in Watts.",
-                   DoubleValue (0.00005),   // typical CC2420 value
-                   MakeDoubleAccessor (&BasicRadioEnergyModel::SetSleepPowerW,
-                                       &BasicRadioEnergyModel::GetSleepPowerW),
-                   MakeDoubleChecker<double> ())
-    .AddAttribute ("PeriodicEnergyUpdateInterval",
-                   "Time between two consecutive periodic energy updates.",
-                   TimeValue (Seconds (1.0)),
-                   MakeTimeAccessor (&BasicRadioEnergyModel::SetEnergyUpdateInterval,
-                                     &BasicRadioEnergyModel::GetEnergyUpdateInterval),
-                   MakeTimeChecker ())
-    .AddTraceSource ("TotalEnergyConsumption",
-                     "Total energy consumption of the radio device.",
-                     MakeTraceSourceAccessor (&BasicRadioEnergyModel::m_totalEnergyConsumption))
-  ; 
-  return tid;
-}
-
-BasicRadioEnergyModel::BasicRadioEnergyModel ()
-{
-  NS_LOG_FUNCTION (this);
-  m_currentState = IDLE;
-  m_lastUpdateTime = Seconds (0.0);
-  m_energyDepletionCallback.Nullify ();
-  /*
-   * Start scheduling the periodic energy update event. BasicRadioEnergyModel
-   * is *not* aggregated to the node. Hence we have to schedule this in the
-   * constructor instead of calling it in DoStart.
-   */
-  m_periodicEnergyUpdateEvent = Simulator::Schedule (Seconds (0.0),
-                                                     &BasicRadioEnergyModel::DoUpdateRemainingEnergy, this, m_currentState);
-}
-
-BasicRadioEnergyModel::~BasicRadioEnergyModel ()
-{
-}
-
-BasicRadioEnergyModel::RadioState
-BasicRadioEnergyModel::GetCurrentState (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_currentState;
-}
-
-void
-BasicRadioEnergyModel::SetCurrentState (const RadioState currentState)
-{
-  NS_LOG_FUNCTION (this);
-  if (currentState != m_currentState)
-    {
-      m_currentState = currentState;
-      std::string stateName;
-      switch (currentState)
-        {
-        case TX:
-          stateName = "TX";
-          break;
-        case RX:
-          stateName = "RX";
-          break;
-        case IDLE:
-          stateName = "IDLE";
-          break;
-        case SLEEP:
-          stateName = "SLEEP";
-          break;
-        }
-      NS_LOG_DEBUG ("BasicRadioEnergyModel: Switching to state: "
-                    << stateName << " at time = " << Simulator::Now ());
-    }
-}
-
-Time
-BasicRadioEnergyModel::GetEnergyUpdateInterval (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_energyUpdateInterval;
-}
-
-void
-BasicRadioEnergyModel::SetEnergyUpdateInterval (const Time interval)
-{
-  NS_LOG_FUNCTION (this);
-  NS_ASSERT (interval.GetSeconds () > 0);
-  m_energyUpdateInterval = interval;
-}
-
-void
-BasicRadioEnergyModel::SetEnergyDepletionCallback (
-  BasicEnergyDepletionCallback callback)
-{
-  NS_LOG_FUNCTION (this);
-  if (callback.IsNull ())
-    {
-      NS_LOG_DEBUG ("BasicRadioEnergyModel:Setting NULL energy depletion callback!");
-    }
-  m_energyDepletionCallback = callback;
-}
-
-bool
-BasicRadioEnergyModel::IsStateTransitionValid (const RadioState destState)
-{
-  NS_LOG_FUNCTION (this << destState);
-  bool returnValue = true;
-
-  /*
-   * This is a placeholder function to specify if some of the radio state
-   * transitions are prohibited. For example, if transition TX -> RX is not
-   * allowed, and must go through IDLE as TX -> IDLE -> RX, then this method
-   * can be used to raise an ns3 error. Initial state is m_currentState.
-   */
-
-  return returnValue;
-}
-
-/*
- * Private functions start here.
- */
-
-void
-BasicRadioEnergyModel::DoDispose (void)
-{
-  NS_LOG_FUNCTION (this);
-  BreakSourceRefCycle (); // break reference cycle to energy source
-  m_energyDepletionCallback.Nullify ();
-}
-
-void
-BasicRadioEnergyModel::DoHandleEnergyDepletion (void)
-{
-  NS_LOG_FUNCTION (this);
-  NS_LOG_DEBUG ("BasicRadioEnergyModel:Energy is depleted!");
-  // invoke energy depletion callback, if set.
-  if (!m_energyDepletionCallback.IsNull ())
-    {
-      m_energyDepletionCallback ();
-    }
-}
-
-double
-BasicRadioEnergyModel::DoGetTotalEnergyConsumption (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_totalEnergyConsumption;
-}
-
-double
-BasicRadioEnergyModel::DoGetTxPowerW (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_txPower;
-}
-
-void 
-BasicRadioEnergyModel::DoSetTxPowerW (double txPowerW)
-{
-  NS_LOG_FUNCTION (this << txPowerW);
-  m_txPower = txPowerW;
-}
-
-double
-BasicRadioEnergyModel::DoGetRxPowerW (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_rxPower;
-}
-
-void 
-BasicRadioEnergyModel::DoSetRxPowerW (double rxPowerW)
-{
-  NS_LOG_FUNCTION (this << rxPowerW);
-  m_rxPower = rxPowerW;
-}
-
-double
-BasicRadioEnergyModel::DoGetIdlePowerW (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_idlePower;
-}
-
-void 
-BasicRadioEnergyModel::DoSetIdlePowerW (double idlePowerW)
-{
-  NS_LOG_FUNCTION (this << idlePowerW);
-  m_idlePower = idlePowerW;
-}
-
-double
-BasicRadioEnergyModel::DoGetSleepPowerW (void) const
-{
-  NS_LOG_FUNCTION (this);
-  return m_sleepPower;
-}
-
-void 
-BasicRadioEnergyModel::DoSetSleepPowerW (double sleepPowerW)
-{
-  NS_LOG_FUNCTION (this << sleepPowerW);
-  m_sleepPower = sleepPowerW;
-}
-
-void
-BasicRadioEnergyModel::DoUpdateRemainingEnergy (const RadioState destState)
-{
-  NS_LOG_FUNCTION (this << destState);
-  NS_ASSERT (IsStateTransitionValid (destState));
-
-  // Cancel the currently scheduled periodic event, if any
-  m_periodicEnergyUpdateEvent.Cancel ();
-
-  Time duration = Simulator::Now () - m_lastUpdateTime;
-  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
-
-  // update remaining energy accordingly
-  double energyToDecrease = 0.0;
-  switch (m_currentState)
-    {
-    case TX:
-      energyToDecrease = duration.GetSeconds () * m_txPower;
-      DecreaseRemainingEnergy (energyToDecrease);
-      break;
-    case RX:
-      energyToDecrease = duration.GetSeconds () * m_rxPower;
-      DecreaseRemainingEnergy (energyToDecrease);
-      break;
-    case IDLE:
-      energyToDecrease = duration.GetSeconds () * m_idlePower;
-      DecreaseRemainingEnergy (energyToDecrease);
-      break;
-    case SLEEP:
-      energyToDecrease = duration.GetSeconds () * m_sleepPower;
-      DecreaseRemainingEnergy (energyToDecrease);
-      break;
-    }
-
-  // update total energy consumption
-  m_totalEnergyConsumption += energyToDecrease;
-
-  // update last update time stamp
-  m_lastUpdateTime = Simulator::Now ();
-
-  // update current state & last update time stamp
-  SetCurrentState (destState);
-
-  // Schedule the next periodic energy update event
-  m_periodicEnergyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
-                                                     &BasicRadioEnergyModel::DoUpdateRemainingEnergy, this, m_currentState);
-
-  // some debug message
-  NS_LOG_DEBUG ("BasicRadioEnergyModel:Total energy consumption is "
-                << m_totalEnergyConsumption << "J");
-}
-
-} // namespace ns3
--- a/src/contrib/energy/model/basic-radio-energy-model.h	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
- */
-
-#ifndef BASIC_RADIO_ENERGY_MODEL_H
-#define BASIC_RADIO_ENERGY_MODEL_H
-
-#include "radio-energy-model.h"
-#include "ns3/nstime.h"
-#include "ns3/event-id.h"
-#include "ns3/traced-value.h"
-
-namespace ns3 {
-
-/**
- * \brief a basic radio energy model
- *
- * This is a child class of the RadioEnergyModel class.
- * 
- * 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is
- * IDLE.
- * The different types of transactions that are defined are: 
- *  1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration,
- *     then state goes from TX to IDLE.
- *  2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration,
- *     then state goes from RX to IDLE.
- *  3. Go_to_Sleep: State goes from IDLE to SLEEP.
- *  4. End_of_Sleep: State goes from SLEEP to IDLE.
- * The class keeps track of what state the radio is currently in.
- *
- * Energy calculation: For each transaction, we see how much time the radio
- * spent in each state and calculate energy consumption accordingly.
- *
- * Energy update: Remaining energy =
- *                Previous remaining energy - Energy_transaction.
- *
- * Default values for power consumption are based on CC2420 radio chip, with
- * supply voltage as 2.5V and currents as 17.4 mA (TX), 18.8 mA (RX), 20 uA
- * (sleep) and 426 uA (idle).
- *
- * TODO change default values to wifi radio chip numbers.
- */
-class BasicRadioEnergyModel : public RadioEnergyModel
-{
-public:
-  /// Callback type for energy depletion handling.
-  typedef Callback<void> BasicEnergyDepletionCallback;
-
-public:
-  static TypeId GetTypeId (void);
-  BasicRadioEnergyModel ();
-  virtual ~BasicRadioEnergyModel ();
-
-  /**
-   * For current state, the getter is public, but the setter method should be
-   * private.
-   */
-  RadioState GetCurrentState (void) const;
-
-  /**
-   * \param interval Energy update interval.
-   *
-   * Setter for the energy update interval - time between two consecutive energy
-   * updates.
-   */
-  void SetEnergyUpdateInterval (const Time interval);
-
-  /**
-   * Getter for the energy update interval - time between two consecutive energy
-   * updates.
-   */
-  Time GetEnergyUpdateInterval (void) const;
-
-  /**
-   * \param callback Callback function.
-   *
-   * Sets callback for energy depletion handling.
-   */
-  void SetEnergyDepletionCallback (BasicEnergyDepletionCallback callback);
-
-  /**
-   * \param destState Radio state to switch to.
-   * \return True if the transition is allowed.
-   *
-   * This function checks if a given radio state transition is allowed.
-   */
-  bool IsStateTransitionValid (const RadioState destState);
-
-
-private:
-  void DoDispose (void);
-
-  /// Handles energy depletion.
-  void DoHandleEnergyDepletion (void);
-
-  /// Implements GetTotalEnergyConsumption.
-  double DoGetTotalEnergyConsumption (void) const;
-
-  double DoGetTxPowerW (void) const;
-  void DoSetTxPowerW (double txPowerW);
-  double DoGetRxPowerW (void) const;
-  void DoSetRxPowerW (double rxPowerW);
-  double DoGetIdlePowerW (void) const;
-  void DoSetIdlePowerW (double idlePowerW);
-  double DoGetSleepPowerW (void) const;
-  void DoSetSleepPowerW (double sleepPowerW);
-
-  void DoUpdateRemainingEnergy (const RadioState destState);
-
-  /**
-   * \param currentState New state the radio device is currently in.
-   *
-   * Sets current state. This function is private so that only the energy model
-   * can change its own state.
-   */
-  void SetCurrentState (const RadioState currentState);
-
-private:
-  /*
-   * Member variables for the power consumption in different radio modes.
-   * Power = (supply voltage * current draw)
-   */
-  double m_txPower;
-  double m_rxPower;
-  double m_idlePower;
-  double m_sleepPower;
-
-  // This variable keeps track of the total energy consumed by this particular model.
-  TracedValue<double> m_totalEnergyConsumption;
-
-  // State variables.
-  RadioState m_currentState;  // current state the radio is in
-  Time m_lastUpdateTime;      // time stamp of previous energy update
-  EventId m_periodicEnergyUpdateEvent;  // scheduled event to update remaining energy periodically
-  Time m_energyUpdateInterval;  // Time between consecutive periodic energy updates.
-
-  // energy depletion callback
-  BasicEnergyDepletionCallback m_energyDepletionCallback;
-};
-
-} // namespace ns3
-
-#endif /* BASIC_RADIO_ENERGY_MODEL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/model/device-energy-model-container.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,106 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ *          Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#include "device-energy-model-container.h"
+#include "ns3/names.h"
+
+namespace ns3 {
+
+DeviceEnergyModelContainer::DeviceEnergyModelContainer ()
+{
+}
+
+DeviceEnergyModelContainer::DeviceEnergyModelContainer (Ptr<DeviceEnergyModel> model)
+{
+  NS_ASSERT (model != NULL);
+  m_models.push_back (model);
+}
+
+DeviceEnergyModelContainer::DeviceEnergyModelContainer (std::string modelName)
+{
+  Ptr<DeviceEnergyModel> model = Names::Find<DeviceEnergyModel> (modelName);
+  NS_ASSERT (model != NULL);
+  m_models.push_back (model);
+}
+
+DeviceEnergyModelContainer::DeviceEnergyModelContainer (const DeviceEnergyModelContainer &a,
+                                                        const DeviceEnergyModelContainer &b)
+{
+  *this = a;
+  Add (b);
+}
+
+DeviceEnergyModelContainer::Iterator
+DeviceEnergyModelContainer::Begin (void) const
+{
+  return m_models.begin ();
+}
+
+DeviceEnergyModelContainer::Iterator
+DeviceEnergyModelContainer::End (void) const
+{
+  return m_models.end ();
+}
+
+uint32_t
+DeviceEnergyModelContainer::GetN (void) const
+{
+  return m_models.size ();
+}
+
+Ptr<DeviceEnergyModel>
+DeviceEnergyModelContainer::Get (uint32_t i) const
+{
+  return m_models[i];
+}
+
+void
+DeviceEnergyModelContainer::Add (DeviceEnergyModelContainer container)
+{
+  for (Iterator i = container.Begin (); i != container.End (); i++)
+    {
+      m_models.push_back (*i);
+    }
+}
+
+void
+DeviceEnergyModelContainer::Add (Ptr<DeviceEnergyModel> model)
+{
+  NS_ASSERT (model != NULL);
+  m_models.push_back (model);
+}
+
+void
+DeviceEnergyModelContainer::Add (std::string modelName)
+{
+  Ptr<DeviceEnergyModel> model = Names::Find<DeviceEnergyModel> (modelName);
+  NS_ASSERT (model != NULL);
+  m_models.push_back (model);
+}
+
+void
+DeviceEnergyModelContainer::Clear (void)
+{
+  m_models.clear ();
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/model/device-energy-model-container.h	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,175 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ *          Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#ifndef DEVICE_ENERGY_MODEL_CONTAINER_H
+#define DEVICE_ENERGY_MODEL_CONTAINER_H
+
+#include "ns3/device-energy-model.h"
+#include <vector>
+#include <stdint.h>
+
+namespace ns3 {
+
+/**
+ * \brief Holds a vector of ns3::DeviceEnergyModel pointers.
+ *
+ * DeviceEnergyModelContainer returns a list of DeviceEnergyModel pointers
+ * installed on a node. Users can use this list to access DeviceEnergyModel
+ * objects to obtain total device energy consumption on a node easily.
+ *
+ * \see NetDeviceContainer
+ */
+class DeviceEnergyModelContainer
+{
+public:
+  typedef std::vector< Ptr<DeviceEnergyModel> >::const_iterator Iterator;
+
+public:
+  /**
+   * Creates an empty DeviceEnergyModelContainer.
+   */
+  DeviceEnergyModelContainer ();
+
+  /**
+   * \param model Pointer to a DeviceEnergyModel.
+   *
+   * Creates a DeviceEnergyModelContainer with exactly one DeviceEnergyModel
+   * previously instantiated.
+   */
+  DeviceEnergyModelContainer (Ptr<DeviceEnergyModel> model);
+
+  /**
+   * \param modelName Name of DeviceEnergyModel.
+   *
+   * Creates an DeviceEnergyModelContainer with exactly one DeviceEnergyModel
+   * previously instantiated and assigned a name using the Object name service.
+   * This DeviceEnergyModel is specified by its assigned name.
+   */
+  DeviceEnergyModelContainer (std::string modelName);
+
+  /**
+   * \param a A DeviceEnergyModelContainer.
+   * \param b Another DeviceEnergyModelContainer.
+   *
+   * Creates a DeviceEnergyModelContainer by concatenating DeviceEnergyModelContainer b
+   * to DeviceEnergyModelContainer a.
+   *
+   * \note Can be used to concatenate 2 Ptr<DeviceEnergyModel> directly. C++
+   * will be calling DeviceEnergyModelContainer constructor with Ptr<DeviceEnergyModel>
+   * first.
+   */
+  DeviceEnergyModelContainer (const DeviceEnergyModelContainer &a,
+                              const DeviceEnergyModelContainer &b);
+
+  /**
+   * \brief Get an iterator which refers to the first DeviceEnergyModel pointer
+   * in the container.
+   *
+   * \returns An iterator which refers to the first DeviceEnergyModel in container.
+   *
+   * DeviceEnergyModels can be retrieved from the container in two ways. First,
+   * directly by an index into the container, and second, using an iterator.
+   * This method is used in the iterator method and is typically used in a
+   * for-loop to run through the DeviceEnergyModels.
+   *
+   * \code
+   *   DeviceEnergyModelContainer::Iterator i;
+   *   for (i = container.Begin (); i != container.End (); ++i)
+   *     {
+   *       (*i)->method ();  // some DeviceEnergyModel method
+   *     }
+   * \endcode
+   */
+  Iterator Begin (void) const;
+
+  /**
+   * \brief Get an iterator which refers to the last DeviceEnergyModel pointer
+   * in the container.
+   *
+   * \returns An iterator which refers to the last DeviceEnergyModel in container.
+   *
+   * DeviceEnergyModels can be retrieved from the container in two ways. First,
+   * directly by an index into the container, and second, using an iterator.
+   * This method is used in the iterator method and is typically used in a
+   * for-loop to run through the DeviceEnergyModels.
+   *
+   * \code
+   *   DeviceEnergyModelContainer::Iterator i;
+   *   for (i = container.Begin (); i != container.End (); ++i)
+   *     {
+   *       (*i)->method ();  // some DeviceEnergyModel method
+   *     }
+   * \endcode
+   */
+  Iterator End (void) const;
+
+  /**
+   * \brief Get the number of Ptr<DeviceEnergyModel> stored in this container.
+   *
+   * \returns The number of Ptr<DeviceEnergyModel> stored in this container.
+   */
+  uint32_t GetN (void) const;
+
+  /**
+   * \brief Get the i-th Ptr<DeviceEnergyModel> stored in this container.
+   *
+   * \param i Index of the requested Ptr<DeviceEnergyModel>.
+   * \returns The requested Ptr<DeviceEnergyModel>.
+   */
+  Ptr<DeviceEnergyModel> Get (uint32_t i) const;
+
+  /**
+   * \param container Another DeviceEnergyModelContainer.
+   *
+   * Appends the contents of another DeviceEnergyModelContainer to the end of
+   * this DeviceEnergyModelContainer.
+   */
+  void Add (DeviceEnergyModelContainer container);
+
+  /**
+   * \brief Append a single Ptr<DeviceEnergyModel> to the end of this container.
+   *
+   * \param model Pointer to an DeviceEnergyModel.
+   */
+  void Add (Ptr<DeviceEnergyModel> model);
+
+  /**
+   * \brief Append a single Ptr<DeviceEnergyModel> referred to by its object
+   * name to the end of this container.
+   *
+   * \param modelName Name of DeviceEnergyModel object.
+   */
+  void Add (std::string modelName);
+
+  /**
+   * \brief Removes all elements in the container.
+   */
+  void Clear (void);
+
+private:
+  std::vector< Ptr<DeviceEnergyModel> > m_models;
+
+};
+
+} // namespace ns3
+
+#endif /* DEVICE_ENERGY_MODEL_CONTAINER_H */
--- a/src/contrib/energy/model/device-energy-model.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/device-energy-model.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -19,9 +19,6 @@
  */
 
 #include "device-energy-model.h"
-#include "ns3/log.h"
-
-NS_LOG_COMPONENT_DEFINE ("DeviceEnergyModel");
 
 namespace ns3 {
 
@@ -44,56 +41,20 @@
 {
 }
 
-void
-DeviceEnergyModel::HandleEnergyDepletion (void)
+double
+DeviceEnergyModel::GetCurrentA (void) const
 {
-  DoHandleEnergyDepletion ();
-}
-
-void
-DeviceEnergyModel::SetEnergySource (Ptr<EnergySource> source)
-{
-  NS_LOG_FUNCTION (this << source);
-  NS_ASSERT (source != NULL);  // energy source must exist
-  m_energySourcePtr = source;
+  return DoGetCurrentA ();
 }
 
 /*
  * Private function starts here.
  */
 
-void
-DeviceEnergyModel::DoDispose (void)
-{
-  NS_LOG_FUNCTION (this);
-  m_energySourcePtr = NULL;
-}
-
-/*
- * Protected functions start here.
- */
-
-void
-DeviceEnergyModel::DecreaseRemainingEnergy (double energyJ)
+double
+DeviceEnergyModel::DoGetCurrentA (void) const
 {
-  NS_LOG_FUNCTION (this << energyJ);
-  NS_ASSERT (m_energySourcePtr != NULL);  // energy source must exist
-  m_energySourcePtr->DecreaseRemainingEnergy (energyJ);
-}
-
-void
-DeviceEnergyModel::IncreaseRemainingEnergy (double energyJ)
-{
-  NS_LOG_FUNCTION (this << energyJ);
-  NS_ASSERT (m_energySourcePtr != NULL);  // energy source must exist
-  m_energySourcePtr->IncreaseRemainingEnergy (energyJ);
-}
-
-void
-DeviceEnergyModel::BreakSourceRefCycle (void)
-{
-  NS_LOG_FUNCTION (this);
-  m_energySourcePtr = NULL;
+  return 0.0;
 }
 
 } // namespace ns3
--- a/src/contrib/energy/model/device-energy-model.h	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/device-energy-model.h	Mon Aug 09 23:31:57 2010 -0700
@@ -18,11 +18,13 @@
  * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
  */
 
-#ifndef DEVICE_ENERGY_MODEL
-#define DEVICE_ENERGY_MODEL
+#ifndef DEVICE_ENERGY_MODEL_H
+#define DEVICE_ENERGY_MODEL_H
 
 #include "ns3/object.h"
-#include "energy-source.h"
+#include "ns3/ptr.h"
+#include "ns3/type-id.h"
+#include "ns3/node.h"
 
 namespace ns3 {
 
@@ -39,58 +41,84 @@
 class DeviceEnergyModel : public Object
 {
 public:
+  /**
+   * Callback type for ChangeState function. Devices uses this state to notify
+   * DeviceEnergyModel of a state change.
+   */
+  typedef Callback<void, int> ChangeStateCallback;
+
+public:
   static TypeId GetTypeId (void);
   DeviceEnergyModel ();
   virtual ~DeviceEnergyModel ();
 
   /**
+   * \brief Sets pointer to node containing this EnergySource.
+   *
+   * \param node Pointer to node containing this EnergySource.
+   */
+  virtual void SetNode (Ptr<Node> node) = 0;
+
+  /**
+   * \brief Gets pointer to node containing this EnergySource.
+   *
+   * \returns Pointer to node containing this EnergySource.
+   */
+  virtual Ptr<Node> GetNode (void) const = 0;
+
+  /**
+   * \param source Pointer to energy source installed on node.
+   *
+   * This function sets the pointer to energy source installed on node. Should
+   * be called only by DeviceEnergyModel helper classes.
+   */
+  virtual void SetEnergySource (Ptr<EnergySource> source) = 0;
+
+  /**
+   * \returns Total energy consumption of the device.
+   *
+   * DeviceEnergyModel records its own energy consumption during simulation.
+   */
+  virtual double GetTotalEnergyConsumption (void) const = 0;
+
+  /**
+   * \param newState New state the device is in.
+   *
+   * DeviceEnergyModel is a state based model. This function is implemented by
+   * all child of DeviceEnergyModel to change the model's state. States are to
+   * be defined by each child using an enum (int).
+   */
+  virtual void ChangeState (int newState) = 0;
+
+  /**
+   * \returns Current draw of the device, in Ampere.
+   *
+   * This function returns the current draw at the device in its current state.
+   * This function is called from the EnergySource to obtain the total current
+   * draw at any given time during simulation.
+   */
+  double GetCurrentA (void) const;
+
+  /**
    * This function is called by the EnergySource object when energy stored in
    * the energy source is depleted. Should be implemented by child classes.
    */
-  void HandleEnergyDepletion (void);
-
-  /// Sets the pointer to node energy source.
-  void SetEnergySource (Ptr<EnergySource> source);
+  virtual void HandleEnergyDepletion (void) = 0;
 
-private:
-  /*
-   * Do not include DoStart in any child of this base class. DeviceEnergyModel
-   * is *not* aggregated to the node hence DoStart will *not* be called.
-   */
-
-  /**
-   * All child's implementation must call BreakSourceRefCycle to ensure
-   * reference cycle to EnergySource object is broken.
-   */
-  void DoDispose (void);
-
-  /// Implements HandleEnergyDepletion.
-  virtual void DoHandleEnergyDepletion (void) = 0;
 
 private:
-  /// Pointer to EnergySource object
-  Ptr<EnergySource> m_energySourcePtr;
-
-protected:
-  /// This function is used to access the private energy source pointer.
-  void DecreaseRemainingEnergy (double energyJ);
-
-  /// This function is used to access the private energy source pointer.
-  void IncreaseRemainingEnergy (double energyJ);
-
   /**
-   * This function is called to break reference cycle between DeviceEnergyModel
-   * and EnergySource. Child of the DeviceEnergyModel base class must call this
-   * function in their implementation of DoDispose to make sure the reference
-   * cycle is broken.
+   * \returns 0.0 as the current value, in Ampere.
    *
-   * Normally this work will be completed by the DoDispose function. However it
-   * will be overridden in the child class. Hence we introduced this function.
+   * Child class does not have to implement this method if current draw for its
+   * states are not know. This default method will always return 0.0A. For the
+   * devices who does know the current draw of its states, this method must be
+   * overwritten.
    */
-  void BreakSourceRefCycle (void);
+  virtual double DoGetCurrentA (void) const;
 
 };
 
 }
 
-#endif /* DEVICE_ENERGY_MODEL */
+#endif /* DEVICE_ENERGY_MODEL_H */
--- a/src/contrib/energy/model/energy-source.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/energy-source.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -44,77 +44,59 @@
 {
 }
 
-double
-EnergySource::GetInitialEnergy (void) const
+void
+EnergySource::SetNode (Ptr<Node> node)
 {
-  return DoGetInitialEnergy ();
+  NS_LOG_FUNCTION (this << node);
+  NS_ASSERT (node != NULL);
+  m_node = node;
 }
 
-double
-EnergySource::GetRemainingEnergy (void) const
+Ptr<Node>
+EnergySource::GetNode (void) const
 {
-  return DoGetRemainingEnergy ();
+  NS_LOG_FUNCTION (this);
+  return m_node;
 }
 
 void
-EnergySource::DecreaseRemainingEnergy (double energyJ)
-{
-  DoDecreaseRemainingEnergy (energyJ);
-}
-
-void
-EnergySource::IncreaseRemainingEnergy (double energyJ)
-{
-  DoIncreaseRemainingEnergy (energyJ);
-}
-
-double
-EnergySource::GetEnergyFraction (void) const
-{
-  return DoGetEnergyFraction ();
-}
-
-void
-EnergySource::AppendDeviceEnergyModel (
-  Ptr<DeviceEnergyModel> deviceEnergyModelPtr)
+EnergySource::AppendDeviceEnergyModel (Ptr<DeviceEnergyModel> deviceEnergyModelPtr)
 {
   NS_LOG_FUNCTION (this << deviceEnergyModelPtr);
   NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist
-  m_deviceEnergyModelList.push_back (deviceEnergyModelPtr);
+  m_models.Add (deviceEnergyModelPtr);
 }
 
-EnergySource::DeviceEnergyModelList
+DeviceEnergyModelContainer
 EnergySource::FindDeviceEnergyModels (TypeId tid)
 {
   NS_LOG_FUNCTION (this << tid);
-  DeviceEnergyModelList list;
-  DeviceEnergyModelList::iterator listItr;
-  for (listItr = m_deviceEnergyModelList.begin ();
-       listItr != m_deviceEnergyModelList.end (); listItr++)
+  DeviceEnergyModelContainer container;
+  DeviceEnergyModelContainer::Iterator i;
+  for (i = m_models.Begin (); i != m_models.End (); i++)
     {
-      if ((*listItr)->GetInstanceTypeId () == tid)
+      if ((*i)->GetInstanceTypeId () == tid)
         {
-          list.push_back (*listItr);
+          container.Add (*i);
         }
     }
-  return list;
+  return container;
 }
 
-EnergySource::DeviceEnergyModelList
+DeviceEnergyModelContainer
 EnergySource::FindDeviceEnergyModels (std::string name)
 {
   NS_LOG_FUNCTION (this << name);
-  DeviceEnergyModelList list;
-  DeviceEnergyModelList::iterator listItr;
-  for (listItr = m_deviceEnergyModelList.begin ();
-       listItr != m_deviceEnergyModelList.end (); listItr++)
+  DeviceEnergyModelContainer container;
+  DeviceEnergyModelContainer::Iterator i;
+  for (i = m_models.Begin (); i != m_models.End (); i++)
     {
-      if ((*listItr)->GetInstanceTypeId ().GetName ().compare (name) == 0)
+      if ((*i)->GetInstanceTypeId ().GetName ().compare (name) == 0)
         {
-          list.push_back (*listItr);
+          container.Add (*i);
         }
     }
-  return list;
+  return container;
 }
 
 /*
@@ -125,25 +107,35 @@
 EnergySource::DoDispose (void)
 {
   NS_LOG_FUNCTION (this);
-  m_deviceEnergyModelList.clear (); // break reference cycle
+  m_models.Clear ();
 }
 
 /*
  * Protected functions start here.
  */
 
+double
+EnergySource::CalculateTotalCurrent (void)
+{
+  NS_LOG_FUNCTION (this);
+  double totalCurrentA = 0.0;
+  DeviceEnergyModelContainer::Iterator i;
+  for (i = m_models.Begin (); i != m_models.End (); i++)
+    {
+      totalCurrentA += (*i)->GetCurrentA ();
+    }
+  return totalCurrentA;
+}
+
 void
 EnergySource::NotifyEnergyDrained (void)
 {
   NS_LOG_FUNCTION (this);
   // notify all device energy models installed on node
-  DeviceEnergyModelList::iterator listItr;
-  for (listItr = m_deviceEnergyModelList.begin ();
-       listItr != m_deviceEnergyModelList.end (); listItr++)
+  DeviceEnergyModelContainer::Iterator i;
+  for (i = m_models.Begin (); i != m_models.End (); i++)
     {
-      NS_LOG_DEBUG ("BasicEnergySource:Notifying device energy model: "
-                    << (*listItr)->GetInstanceTypeId ());
-      (*listItr)->HandleEnergyDepletion ();
+      (*i)->HandleEnergyDepletion ();
     }
 }
 
@@ -151,7 +143,8 @@
 EnergySource::BreakDeviceEnergyModelRefCycle (void)
 {
   NS_LOG_FUNCTION (this);
-  m_deviceEnergyModelList.clear (); // break reference cycle
+  m_models.Clear ();
+  m_node = NULL;
 }
 
 } // namespace ns3
--- a/src/contrib/energy/model/energy-source.h	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/model/energy-source.h	Mon Aug 09 23:31:57 2010 -0700
@@ -24,12 +24,11 @@
 #include "ns3/object.h"
 #include "ns3/ptr.h"
 #include "ns3/type-id.h"
-#include "device-energy-model.h"
+#include "ns3/node.h"
+#include "device-energy-model-container.h"  // #include "device-energy-model.h"
 
 namespace ns3 {
 
-class DeviceEnergyModel;
-
 /**
  * \brief Energy source base class.
  *
@@ -40,6 +39,23 @@
  * the same node. When the remaining energy level reaches 0, the energy source
  * will notify all device energy models stored in the list.
  *
+ * EnergySource provides 2 types of interfaces for DeviceEnergyModels to update
+ * the remaining energy stored in EnergySource:
+ *  -Direct energy update interface (Joules):
+ *    DecreaseRemainingEnergy
+ *    IncreaseRemainingEnergy
+ *  -Indirect energy update interface (Current):
+ *    UpdateEnergySource
+ * Direct energy update interface will decrease/increase energy from the source
+ * directly (in Joules). Direct energy update interface is typically used by
+ * simple DeviceEnergyModel which knows only average power consumption for each
+ * of its state.
+ * Indirect energy update interface uses the total current cumulated from all
+ * DeviceEnergyModel to calculate energy to decrease from the source. Indirect
+ * energy update interface is typically used by DeviceEnergyModel who knows its
+ * current draw for each of its states. Nonlinear EnergySource also uses this
+ * interface.
+ *
  * Unit of energy is chosen as Joules since energy models typically calculate
  * energy as (time in seconds * power in Watts). If the energy source stores
  * energy in different units (eg. kWh), a simple converter function should
@@ -48,45 +64,79 @@
 class EnergySource : public Object
 {
 public:
-  /// List of pointers to DeviceEnergyModel objects.
-  typedef std::vector< Ptr<DeviceEnergyModel> > DeviceEnergyModelList;
-
-public:
   static TypeId GetTypeId (void);
   EnergySource ();
   virtual ~EnergySource ();
 
-  /// This function returns initial energy stored in energy source.
-  double GetInitialEnergy (void) const;
-
-  /// This function returns the remaining energy stored in the energy source.
-  double GetRemainingEnergy (void) const;
+  /**
+   * \returns Supply voltage of the energy source.
+   *
+   * Set method is to be defined in child class only if necessary. For sources
+   * with a fixed supply voltage, set method is not needed.
+   */
+  virtual double GetSupplyVoltage (void) const = 0;
 
   /**
-   * \param energyJ Amount of energy to decrease (in Joules)
+   * \returns Initial energy (capacity) of the energy source.
    *
-   * This function decreases the remaining energy in the energy source by the
-   * specified amount.
+   * Set method is to be defined in child class only if necessary. For sources
+   * with a fixed initial energy (energy capacity), set method is not needed.
    */
-  void DecreaseRemainingEnergy (double energyJ);
+  virtual double GetInitialEnergy (void) const = 0;
 
   /**
-   * \param energyJ Amount of energy to increase (in Joules)
-   *
-   * This function increases the remaining energy in the energy source by the
-   * specified amount. Provided for supporting re-charging or scavenging.
+   * \returns Remaining energy at the energy source.
    */
-  void IncreaseRemainingEnergy (double energyJ);
+  virtual double GetRemainingEnergy (void) = 0;
 
   /**
    * \return Energy fraction = remaining energy / initial energy [0, 1]
    *
    * This function returns the percentage of energy left in the energy source.
    */
-  double GetEnergyFraction (void) const;
+  virtual double GetEnergyFraction (void) = 0;
+
+  /**
+   * \param energy Amount of energy to decrease (in Joules)
+   *
+   * This function decreases the remaining energy in the energy source by the
+   * specified amount. Provides linear interface for direct energy deduction.
+   */
+  virtual void DecreaseRemainingEnergy (double energyJ) = 0;
+
+  /**
+   * \param energy Amount of energy to increase (in Joules)
+   *
+   * This function increases the remaining energy in the energy source by the
+   * specified amount. Provides linear interface for direct energy increase.
+   */
+  virtual void IncreaseRemainingEnergy (double energyJ) = 0;
+
+  /**
+   * This function goes through the list of DeviceEnergyModels to obtain total
+   * current draw at the energy source and updates remaining energy. Called by
+   * DeviceEnergyModels to inform EnergySource of a state change.
+   */
+  virtual void UpdateEnergySource (void) = 0;
+
+  /**
+   * \brief Sets pointer to node containing this EnergySource.
+   *
+   * \param node Pointer to node containing this EnergySource.
+   */
+  void SetNode (Ptr<Node> node);
+
+  /**
+   * \returns Pointer to node containing this EnergySource.
+   *
+   * When a subclass needs to get access to the underlying node base class to
+   * print the nodeId for example, it can invoke this method.
+   */
+  Ptr<Node> GetNode (void) const;
 
   /**
    * \param deviceEnergyModelPtr Pointer to device energy model.
+   * \param tid TypeId of the specific device energy model.
    *
    * This function appends a device energy model to the end of a list of
    * DeviceEnergyModelInfo structs.
@@ -97,12 +147,13 @@
    * \param tid TypeId of the DeviceEnergyModel we are searching for.
    * \returns List of pointers to DeviceEnergyModel objects installed on node.
    */
-  DeviceEnergyModelList FindDeviceEnergyModels (TypeId tid);
+  DeviceEnergyModelContainer FindDeviceEnergyModels (TypeId tid);
+
   /**
    * \param name name of the DeviceEnergyModel we are searching for.
    * \returns List of pointers to DeviceEnergyModel objects installed on node.
    */
-  DeviceEnergyModelList FindDeviceEnergyModels (std::string name);
+  DeviceEnergyModelContainer FindDeviceEnergyModels (std::string name);
 
 
 private:
@@ -110,30 +161,27 @@
    * All child's implementation must call BreakDeviceEnergyModelRefCycle to
    * ensure reference cycles to DeviceEnergyModel objects are broken.
    */
-  void DoDispose (void);
-
-  /// Implements GetInitialEnergy.
-  virtual double DoGetInitialEnergy (void) const = 0;
-
-  /// Implements GetRemainingEnergy.
-  virtual double DoGetRemainingEnergy (void) const = 0;
-
-  /// Implements DecreaseRemainingEnergy.
-  virtual void DoDecreaseRemainingEnergy (double energyJ) = 0;
-
-  /// Implements IncreaseRemainingEnergy.
-  virtual void DoIncreaseRemainingEnergy (double energyJ) = 0;
-
-  /// Implements GetEnergyFraction.
-  virtual double DoGetEnergyFraction (void) const = 0;
+  virtual void DoDispose (void);
 
 private:
-  /// List of device energy models installed on the same node.
-  DeviceEnergyModelList m_deviceEnergyModelList;
+  /**
+   * List of device energy models installed on the same node.
+   */
+  DeviceEnergyModelContainer m_models;
+
+  /**
+   * Pointer to node containing this EnergySource.
+   */
+  Ptr<Node> m_node;
 
 
 protected:
   /**
+   * \returns Total current draw from all DeviceEnergyModels.
+   */
+  double CalculateTotalCurrent (void);
+
+  /**
    * This function notifies all DeviceEnergyModel of energy depletion event. It
    * is called by the child EnergySource class when energy depletion happens.
    */
--- a/src/contrib/energy/model/radio-energy-model.cc	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
- */
-
-#include "radio-energy-model.h"
-#include "ns3/log.h"
-
-NS_LOG_COMPONENT_DEFINE ("RadioEnergyModel");
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (RadioEnergyModel);
-
-TypeId 
-RadioEnergyModel::GetTypeId (void)
-{
-  static TypeId tid = TypeId ("ns3::RadioEnergyModel")
-    .SetParent<DeviceEnergyModel> ()
-  ;
-  return tid;
-}
-
-RadioEnergyModel::RadioEnergyModel ()
-{
-}
-
-RadioEnergyModel::~RadioEnergyModel ()
-{
-}
-
-double
-RadioEnergyModel::GetTxPowerW (void) const
-{
-  return DoGetTxPowerW ();
-}
-double
-RadioEnergyModel::GetRxPowerW (void) const
-{
-  return DoGetRxPowerW ();
-}
-
-double
-RadioEnergyModel::GetIdlePowerW (void) const
-{
-  return DoGetIdlePowerW ();
-}
-
-double
-RadioEnergyModel::GetSleepPowerW (void) const
-{
-  return DoGetSleepPowerW ();
-}
-
-void 
-RadioEnergyModel::SetTxPowerW (double txPowerW)
-{
-  DoSetTxPowerW (txPowerW);
-}
-
-void 
-RadioEnergyModel::SetRxPowerW (double rxPowerW)
-{
-  DoSetRxPowerW (rxPowerW);
-}
-
-void 
-RadioEnergyModel::SetIdlePowerW (double idlePowerW)
-{
-  DoSetIdlePowerW (idlePowerW);
-}
-
-void 
-RadioEnergyModel::SetSleepPowerW (double sleepPowerW)
-{
-  DoSetSleepPowerW (sleepPowerW);
-}
-
-void
-RadioEnergyModel::UpdateRemainingEnergy (const RadioState destState)
-{
-  DoUpdateRemainingEnergy (destState);
-}
-
-} // namespace ns3
--- a/src/contrib/energy/model/radio-energy-model.h	Mon Aug 09 22:23:57 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
- */
-
-#ifndef RADIO_ENERGY_MODEL_H
-#define RADIO_ENERGY_MODEL_H
-
-#include "device-energy-model.h"
-
-namespace ns3 {
-
-/**
- * \brief Keep track of energy consumption at a radio of a node.
- *
- * Assumption is that the radio is responsible for a significantly higher 
- * percentage of energy consumption than the computation at the node. 
- *
- * The units used are: Joules (J) for energy, Watts (W) for power.
- *
- * This is a base class, which should be inherited and implemented by children
- * classes.
- */
-class RadioEnergyModel : public DeviceEnergyModel
-{
-public:
-  /**
-   * The states of the PHY layer.
-   */
-  enum RadioState
-  {
-    /**
-     * The radio is transmitting.
-     */
-    TX = 0,
-    /**
-     * The radio is receiving.
-     */
-    RX,
-    /**
-     * The radio is idle.
-     */
-    IDLE,
-    /**
-     * The radio is in sleep mode.
-     */
-    SLEEP
-  };
-
-public:
-  static TypeId GetTypeId (void);
-  RadioEnergyModel ();
-  virtual ~RadioEnergyModel ();
-
-  /**
-   * \returns the radio TX power in W.
-   */
-  double GetTxPowerW (void) const;
-
-  /**
-   * \param txPowerW the radio TX power in W
-   */
-  void SetTxPowerW (double txPowerW);
-
-  /**
-   * \returns the radio Rx power in W
-   */
-  double GetRxPowerW (void) const;
-
-  /**
-   * \param rxPowerW the radio RX power in W
-   */
-  void SetRxPowerW (double rxPowerW);
-
-  /**
-   * \returns the radio IDLE power in W
-   */
-  double GetIdlePowerW (void) const;
-
-  /**
-   * \param idlePowerW the radio IDLE power in W
-   */
-  void SetIdlePowerW (double idlePowerW);
-
-  /**
-   * \returns the radio SLEEP power in W
-   */
-  double GetSleepPowerW (void) const;
-
-  /**
-   * \param sleepPowerW the radio SLEEP power in W.
-   */
-  void SetSleepPowerW (double sleepPowerW);
-
-  /**
-   * \param destState Radio state to switch to.
-   *
-   * This function will update the remaining energy. Its implementation will be
-   * completed in child classes.
-   */
-  void UpdateRemainingEnergy (const RadioState destState);
-
-
-private:
-  /**
-   * \returns the radio TX power in W.
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual double DoGetTxPowerW (void) const = 0;
-
-  /**
-   * \param the radio TX power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual void DoSetTxPowerW (double txPowerW) = 0;
-
-  /**
-   * \returns the radio RX power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual double DoGetRxPowerW (void) const = 0;
-
-  /**
-   * \param the radio RX power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual void DoSetRxPowerW (double rxPowerW) = 0;
-
-  /**
-   * \returns the radio IDLE power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual double DoGetIdlePowerW (void) const = 0;
-
-  /**
-   * \param idlePowerW the radio IDLE power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual void DoSetIdlePowerW (double idlePowerW) = 0;
-
-  /**
-   * \returns the radio SLEEP power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual double DoGetSleepPowerW (void) const = 0;
-
-  /**
-   * \param sleepPowerW the radio SLEEP power in W
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual void DoSetSleepPowerW (double sleepPowerW) = 0;
-
-  /**
-   * \param destState Radio state to switch to.
-   *
-   * Concrete subclasses of this base class must implement this method.
-   */
-  virtual void DoUpdateRemainingEnergy (const RadioState destState) = 0;
-};
-
-}; // namespace ns3
-
-#endif /* RADIO_ENERGY_MODEL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/model/wifi-radio-energy-model.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,328 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#include "ns3/log.h"
+#include "ns3/double.h"
+#include "ns3/simulator.h"
+#include "ns3/trace-source-accessor.h"
+#include "energy-source.h"
+#include "wifi-radio-energy-model.h"
+
+NS_LOG_COMPONENT_DEFINE ("WifiRadioEnergyModel");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (WifiRadioEnergyModel);
+
+TypeId
+WifiRadioEnergyModel::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::WifiRadioEnergyModel")
+    .SetParent<DeviceEnergyModel> ()
+    .AddConstructor<WifiRadioEnergyModel> ()
+    .AddAttribute ("TxCurrentA",
+                   "The radio Tx current in Ampere.",
+                   DoubleValue (0.0174),    // transmit at 0dBm = 17.4mA
+                   MakeDoubleAccessor (&WifiRadioEnergyModel::SetTxCurrentA,
+                                       &WifiRadioEnergyModel::GetTxCurrentA),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("RxCurrentA",
+                   "The radio Rx current in Ampere.",
+                   DoubleValue (0.0197),    // receive mode = 19.7mA
+                   MakeDoubleAccessor (&WifiRadioEnergyModel::SetRxCurrentA,
+                                       &WifiRadioEnergyModel::GetRxCurrentA),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("IdleCurrentA",
+                   "The default radio Idle current in Ampere.",
+                   DoubleValue (0.000426),  // idle mode = 426uA
+                   MakeDoubleAccessor (&WifiRadioEnergyModel::SetIdleCurrentA,
+                                       &WifiRadioEnergyModel::GetIdleCurrentA),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("SleepCurrentA",
+                   "The default radio Sleep current in Ampere.",
+                   DoubleValue (0.00002),   // power down mode = 20uA
+                   MakeDoubleAccessor (&WifiRadioEnergyModel::SetSleepCurrentA,
+                                       &WifiRadioEnergyModel::GetSleepCurrentA),
+                   MakeDoubleChecker<double> ())
+    .AddTraceSource ("TotalEnergyConsumption",
+                     "Total energy consumption of the radio device.",
+                     MakeTraceSourceAccessor (&WifiRadioEnergyModel::m_totalEnergyConsumption))
+  ; 
+  return tid;
+}
+
+WifiRadioEnergyModel::WifiRadioEnergyModel ()
+{
+  NS_LOG_FUNCTION (this);
+  m_currentState = IDLE;  // initially IDLE
+  m_lastUpdateTime = Seconds (0.0);
+  m_energyDepletionCallback.Nullify ();
+  m_node = NULL;
+  m_source = NULL;
+}
+
+WifiRadioEnergyModel::~WifiRadioEnergyModel ()
+{
+}
+
+void
+WifiRadioEnergyModel::SetNode (Ptr<Node> node)
+{
+  NS_LOG_FUNCTION (this << node);
+  NS_ASSERT (node != NULL);
+  m_node = node;
+}
+
+Ptr<Node>
+WifiRadioEnergyModel::GetNode (void) const
+{
+  return m_node;
+}
+
+void
+WifiRadioEnergyModel::SetEnergySource (Ptr<EnergySource> source)
+{
+  NS_LOG_FUNCTION (this << source);
+  NS_ASSERT (source != NULL);
+  m_source = source;
+}
+
+double
+WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_totalEnergyConsumption;
+}
+
+double
+WifiRadioEnergyModel::GetTxCurrentA (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_txCurrentA;
+}
+
+void
+WifiRadioEnergyModel::SetTxCurrentA (double txCurrentA)
+{
+  NS_LOG_FUNCTION (this << txCurrentA);
+  m_txCurrentA = txCurrentA;
+}
+
+double
+WifiRadioEnergyModel::GetRxCurrentA (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_rxCurrentA;
+}
+
+void
+WifiRadioEnergyModel::SetRxCurrentA (double rxCurrentA)
+{
+  NS_LOG_FUNCTION (this << rxCurrentA);
+  m_rxCurrentA = rxCurrentA;
+}
+
+double
+WifiRadioEnergyModel::GetIdleCurrentA (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_idleCurrentA;
+}
+
+void
+WifiRadioEnergyModel::SetIdleCurrentA (double idleCurrentA)
+{
+  NS_LOG_FUNCTION (this << idleCurrentA);
+  m_idleCurrentA = idleCurrentA;
+}
+
+double
+WifiRadioEnergyModel::GetSleepCurrentA (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_sleepCurrentA;
+}
+
+void
+WifiRadioEnergyModel::SetSleepCurrentA (double sleepCurrentA)
+{
+  NS_LOG_FUNCTION (this << sleepCurrentA);
+  m_sleepCurrentA = sleepCurrentA;
+}
+
+WifiRadioEnergyModel::WifiRadioState
+WifiRadioEnergyModel::GetCurrentState (void) const
+{
+  NS_LOG_FUNCTION (this);
+  return m_currentState;
+}
+
+void
+WifiRadioEnergyModel::SetEnergyDepletionCallback (
+    WifiRadioEnergyDepletionCallback callback)
+{
+  NS_LOG_FUNCTION (this);
+  if (callback.IsNull ())
+    {
+      NS_LOG_DEBUG ("WifiRadioEnergyModel:Setting NULL energy depletion callback!");
+    }
+  m_energyDepletionCallback = callback;
+}
+
+void
+WifiRadioEnergyModel::ChangeState (int newState)
+{
+  NS_LOG_FUNCTION (this << newState);
+  NS_ASSERT (IsStateTransitionValid ((WifiRadioState) newState));
+
+  Time duration = Simulator::Now () - m_lastUpdateTime;
+  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
+
+  // energy to decrease = current * voltage * time
+  double energyToDecrease = 0.0;
+  double supplyVoltage = m_source->GetSupplyVoltage ();
+  switch (m_currentState)
+    {
+    case TX:
+      energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage;
+      break;
+    case RX:
+      energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage;
+      break;
+    case IDLE:
+      energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage;
+      break;
+    case SLEEP:
+      energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltage;
+      break;
+    default:
+      NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state!");
+    }
+
+  // update total energy consumption
+  m_totalEnergyConsumption += energyToDecrease;
+
+  // update last update time stamp
+  m_lastUpdateTime = Simulator::Now ();
+
+  // notify energy source
+  m_source->UpdateEnergySource ();
+
+  // update current state & last update time stamp
+  SetWifiRadioState ((WifiRadioState) newState);
+
+  // some debug message
+  NS_LOG_DEBUG ("WifiRadioEnergyModel:Total energy consumption at node #"
+      << m_node->GetId () << " is " << m_totalEnergyConsumption << "J");
+}
+
+void
+WifiRadioEnergyModel::HandleEnergyDepletion (void)
+{
+  NS_LOG_FUNCTION (this);
+  NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is depleted at node #" <<
+                m_node->GetId ());
+  // invoke energy depletion callback, if set.
+  if (!m_energyDepletionCallback.IsNull ())
+    {
+      m_energyDepletionCallback ();
+    }
+}
+
+/*
+ * Private functions start here.
+ */
+
+void
+WifiRadioEnergyModel::DoDispose (void)
+{
+  NS_LOG_FUNCTION (this);
+  m_node = NULL;
+  m_source = NULL;
+  m_energyDepletionCallback.Nullify ();
+}
+
+double
+WifiRadioEnergyModel::DoGetCurrentA (void) const
+{
+  NS_LOG_FUNCTION (this);
+  switch (m_currentState)
+    {
+    case TX:
+      return m_txCurrentA;
+    case RX:
+      return m_rxCurrentA;
+    case IDLE:
+      return m_idleCurrentA;
+    case SLEEP:
+      return m_sleepCurrentA;
+    default:
+      NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state!");
+    }
+}
+
+bool
+WifiRadioEnergyModel::IsStateTransitionValid (const WifiRadioState destState)
+{
+  NS_LOG_FUNCTION (this << destState);
+
+  /*
+   * This is a placeholder function to specify if some of the radio state
+   * transitions are prohibited. For example, if transition TX -> RX is not
+   * allowed, and must go through IDLE as TX -> IDLE -> RX, then this method
+   * can be used to raise an ns3 error.
+   */
+
+  return true;
+}
+
+void
+WifiRadioEnergyModel::SetWifiRadioState (const WifiRadioState state)
+{
+  NS_LOG_FUNCTION (this);
+  if (IsStateTransitionValid (state))
+    {
+      m_currentState = state;
+      std::string stateName;
+      switch (state)
+        {
+        case TX:
+          stateName = "TX";
+          break;
+        case RX:
+          stateName = "RX";
+          break;
+        case IDLE:
+          stateName = "IDLE";
+          break;
+        case SLEEP:
+          stateName = "SLEEP";
+          break;
+        }
+      NS_LOG_DEBUG ("WifiRadioEnergyModel:Switching to state: " << stateName <<
+                    " at time = " << Simulator::Now ());
+    }
+  else
+    {
+      NS_FATAL_ERROR ("WifiRadioEnergyModel:Invalid state transition!");
+    }
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/energy/model/wifi-radio-energy-model.h	Mon Aug 09 23:31:57 2010 -0700
@@ -0,0 +1,211 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#ifndef WIFI_RADIO_ENERGY_MODEL_H
+#define WIFI_RADIO_ENERGY_MODEL_H
+
+#include "ns3/device-energy-model.h"
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+#include "ns3/traced-value.h"
+
+namespace ns3 {
+
+/**
+ * \brief A WiFi radio energy model.
+ * 
+ * 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is
+ * IDLE.
+ * The different types of transactions that are defined are: 
+ *  1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration,
+ *     then state goes from TX to IDLE.
+ *  2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration,
+ *     then state goes from RX to IDLE.
+ *  3. Go_to_Sleep: State goes from IDLE to SLEEP.
+ *  4. End_of_Sleep: State goes from SLEEP to IDLE.
+ * The class keeps track of what state the radio is currently in.
+ *
+ * Energy calculation: For each transaction, this model notifies EnergySource
+ * object. The EnergySource object will query this model for the total current.
+ * Then the EnergySource object uses the total current to calculate energy.
+ *
+ * Default values for power consumption are based on CC2420 radio chip, with
+ * supply voltage as 2.5V and currents as 17.4 mA (TX), 18.8 mA (RX), 20 uA
+ * (sleep) and 426 uA (idle).
+ */
+class WifiRadioEnergyModel : public DeviceEnergyModel
+{
+public:
+  /**
+   * Wifi radio states.
+   */
+  enum WifiRadioState
+  {
+    /**
+     * Radio is transmitting.
+     */
+    TX = 0,
+    /**
+     * Radio is receiving.
+     */
+    RX,
+    /**
+     * Radio is idling.
+     */
+    IDLE,
+    /**
+     * Radio is asleep.
+     */
+    SLEEP
+  };
+
+  /**
+   * Callback type for energy depletion handling.
+   */
+  typedef Callback<void> WifiRadioEnergyDepletionCallback;
+
+public:
+  static TypeId GetTypeId (void);
+  WifiRadioEnergyModel ();
+  virtual ~WifiRadioEnergyModel ();
+
+  /**
+   * \brief Sets pointer to node.
+   *
+   * \param node Pointer to node.
+   *
+   * Implements DeviceEnergyModel::SetNode.
+   */
+  virtual void SetNode (Ptr<Node> node);
+
+  /**
+   * \brief Gets pointer to node.
+   *
+   * \returns Pointer to node.
+   *
+   * Implements DeviceEnergyModel::GetNode.
+   */
+  virtual Ptr<Node> GetNode (void) const;
+
+  /**
+   * \brief Sets pointer to EnergySouce installed on node.
+   *
+   * \param source Pointer to EnergySource installed on node.
+   *
+   * Implements DeviceEnergyModel::SetEnergySource.
+   */
+  virtual void SetEnergySource (Ptr<EnergySource> source);
+
+  /**
+   * \returns Total energy consumption of the wifi device.
+   *
+   * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
+   */
+  virtual double GetTotalEnergyConsumption (void) const;
+
+  // Setter & getters for state power consumption.
+  double GetTxCurrentA (void) const;
+  void SetTxCurrentA (double txCurrentA);
+  double GetRxCurrentA (void) const;
+  void SetRxCurrentA (double rxCurrentA);
+  double GetIdleCurrentA (void) const;
+  void SetIdleCurrentA (double idleCurrentA);
+  double GetSleepCurrentA (void) const;
+  void SetSleepCurrentA (double sleepCurrentA);
+
+  /**
+   * \returns Current state.
+   */
+  WifiRadioState GetCurrentState (void) const;
+
+  /**
+   * \param callback Callback function.
+   *
+   * Sets callback for energy depletion handling.
+   */
+  void SetEnergyDepletionCallback (WifiRadioEnergyDepletionCallback callback);
+
+  /**
+   * \brief Changes state of the WifiRadioEnergyMode.
+   *
+   * \param newState New state the wifi radio is in.
+   *
+   * Implements DeviceEnergyModel::ChangeState.
+   */
+  virtual void ChangeState (int newState);
+
+  /**
+   * \brief Handles energy depletion.
+   *
+   * Implements DeviceEnergyModel::HandleEnergyDepletion
+   */
+  virtual void HandleEnergyDepletion (void);
+
+
+private:
+  void DoDispose (void);
+
+  /**
+   * \returns Current draw of device, at current state.
+   *
+   * Implements DeviceEnergyModel::GetCurrentA.
+   */
+  virtual double DoGetCurrentA (void) const;
+
+  /**
+   * \param destState Radio state to switch to.
+   * \return True if the transition is allowed.
+   *
+   * This function checks if a given radio state transition is allowed.
+   */
+  bool IsStateTransitionValid (const WifiRadioState destState);
+
+  /**
+   * \param currentState New state the radio device is currently in.
+   *
+   * Sets current state. This function is private so that only the energy model
+   * can change its own state.
+   */
+  void SetWifiRadioState (const WifiRadioState state);
+
+private:
+  Ptr<Node> m_node;
+  Ptr<EnergySource> m_source;
+
+  // Member variables for current draw in different radio modes.
+  double m_txCurrentA;
+  double m_rxCurrentA;
+  double m_idleCurrentA;
+  double m_sleepCurrentA;
+
+  // This variable keeps track of the total energy consumed by this model.
+  TracedValue<double> m_totalEnergyConsumption;
+
+  // State variables.
+  WifiRadioState m_currentState;  // current state the radio is in
+  Time m_lastUpdateTime;          // time stamp of previous energy update
+
+  // energy depletion callback
+  WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
+};
+
+} // namespace ns3
+
+#endif /* WIFI_RADIO_ENERGY_MODEL_H */
--- a/src/contrib/energy/test/basic-energy-model-test.cc	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/test/basic-energy-model-test.cc	Mon Aug 09 23:31:57 2010 -0700
@@ -19,23 +19,29 @@
  */
 
 #include "ns3/basic-energy-source.h"
-#include "ns3/basic-radio-energy-model.h"
+#include "ns3/wifi-radio-energy-model.h"
 #include "ns3/basic-energy-source-helper.h"
-#include "ns3/basic-radio-energy-model-helper.h"
+#include "ns3/wifi-radio-energy-model-helper.h"
+#include "ns3/energy-source-container.h"
+#include "ns3/device-energy-model-container.h"
 #include "ns3/log.h"
 #include "ns3/test.h"
 #include "ns3/node.h"
 #include "ns3/simulator.h"
 #include "ns3/double.h"
+#include "ns3/config.h"
+#include "ns3/string.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/nqos-wifi-mac-helper.h"
 #include <math.h>
 
-using namespace ns3;
+namespace ns3 {
 
 NS_LOG_COMPONENT_DEFINE ("BasicEnergyModelTestSuite");
 
 /**
  * Test case of update remaining energy for BasicEnergySource and
- * BasicRadioEnergyModel.
+ * WifiRadioEnergyModel.
  */
 class BasicEnergyUpdateTest : public TestCase
 {
@@ -53,7 +59,7 @@
    * Runs simulation for a while, check if final state & remaining energy is
    * correctly updated.
    */
-  bool StateSwitchTest (RadioEnergyModel::RadioState state);
+  bool StateSwitchTest (WifiRadioEnergyModel::WifiRadioState state);
 
 private:
   double m_timeS;     // in seconds
@@ -79,22 +85,22 @@
 {
   // set types
   m_energySource.SetTypeId ("ns3::BasicEnergySource");
-  m_deviceEnergyModel.SetTypeId ("ns3::BasicRadioEnergyModel");
+  m_deviceEnergyModel.SetTypeId ("ns3::WifiRadioEnergyModel");
 
   // run state switch tests
-  if (StateSwitchTest (RadioEnergyModel::TX))
+  if (StateSwitchTest (WifiRadioEnergyModel::TX))
     {
       return true;
     }
-  if (StateSwitchTest (RadioEnergyModel::RX))
+  if (StateSwitchTest (WifiRadioEnergyModel::RX))
     {
       return true;
     }
-  if (StateSwitchTest (RadioEnergyModel::IDLE))
+  if (StateSwitchTest (WifiRadioEnergyModel::IDLE))
     {
       return true;
     }
-  if (StateSwitchTest (RadioEnergyModel::SLEEP))
+  if (StateSwitchTest (WifiRadioEnergyModel::SLEEP))
     {
       return true;
     }
@@ -105,84 +111,100 @@
 
 bool
 BasicEnergyUpdateTest::StateSwitchTest (
-  RadioEnergyModel::RadioState state)
+    WifiRadioEnergyModel::WifiRadioState state)
 {
   // create node
   Ptr<Node> node = CreateObject<Node> ();
 
   // create energy source
-  Ptr<EnergySource> source = m_energySource.Create<EnergySource> ();
+  Ptr<BasicEnergySource> source = m_energySource.Create<BasicEnergySource> ();
   // aggregate energy source to node
   node->AggregateObject (source);
+  // set update interval in source
+  source->SetEnergyUpdateInterval (Seconds (1.0));
 
   // create device energy model
-  Ptr<BasicRadioEnergyModel> model =
-    m_deviceEnergyModel.Create<BasicRadioEnergyModel> ();
+  Ptr<WifiRadioEnergyModel> model =
+    m_deviceEnergyModel.Create<WifiRadioEnergyModel> ();
   // set energy source pointer
   model->SetEnergySource (source);
   // add device energy model to model list in energy source
   source->AppendDeviceEnergyModel (model);
 
   // retrieve device energy model from energy source
-  EnergySource::DeviceEnergyModelList modelList =
-    source->FindDeviceEnergyModels ("ns3::BasicRadioEnergyModel");
+  DeviceEnergyModelContainer models =
+    source->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel");
   // check list
-  NS_TEST_ASSERT_MSG_EQ (false, modelList.empty (), "Model list is empty!");
+  NS_TEST_ASSERT_MSG_EQ (false, (models.GetN () == 0), "Model list is empty!");
   // get pointer
-  Ptr<BasicRadioEnergyModel> devModel =
-    DynamicCast<BasicRadioEnergyModel> (modelList[0]);
+  Ptr<WifiRadioEnergyModel> devModel =
+      DynamicCast<WifiRadioEnergyModel> (models.Get (0));
   // check pointer
-  NS_TEST_ASSERT_MSG_NE (0, devModel, "NULL pointer to device model!");
+  NS_TEST_ASSERT_MSG_NE (NULL, devModel, "NULL pointer to device model!");
+
+  /*
+   * The radio will stay IDLE for m_timeS seconds. Then it will switch into a
+   * different state.
+   */
 
   // schedule change of state
   Simulator::Schedule (Seconds (m_timeS),
-                       &BasicRadioEnergyModel::UpdateRemainingEnergy, devModel, state);
+                       &WifiRadioEnergyModel::ChangeState, devModel, state);
 
   // run simulation
-  Simulator::Stop (Seconds (m_timeS * 2));  // run twice as long
+  Simulator::Stop (Seconds (m_timeS * 2));
   Simulator::Run ();
   Simulator::Destroy ();
 
-  // calculate estimated remaining energy
+  // energy = current * voltage * time
+
+  // calculate idle power consumption
   double estRemainingEnergy = source->GetInitialEnergy ();
-  estRemainingEnergy -= devModel->GetIdlePowerW () * m_timeS;
+  double voltage = source->GetSupplyVoltage ();
+  estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS;
+
   /*
-   * Energy is updated periodically, hence we have to take into account of the
-   * update interval.
+   * Manually calculate the number of periodic updates performed by the source.
+   * This is to check if the periodic updates are performed correctly.
    */
   double actualTime = m_timeS;
-  actualTime /= devModel->GetEnergyUpdateInterval ().GetSeconds ();
+  actualTime /= source->GetEnergyUpdateInterval ().GetSeconds ();
   actualTime = floor (actualTime); // rounding for update interval
-  actualTime *= devModel->GetEnergyUpdateInterval ().GetSeconds ();
+  actualTime *= source->GetEnergyUpdateInterval ().GetSeconds ();
+
+  // calculate new state power consumption
+  double current = 0.0;
   switch (state)
     {
-    case RadioEnergyModel::TX:
-      estRemainingEnergy -= devModel->GetTxPowerW () * actualTime;
+    case WifiRadioEnergyModel::TX:
+      current = devModel->GetTxCurrentA ();
       break;
-    case RadioEnergyModel::RX:
-      estRemainingEnergy -= devModel->GetRxPowerW () * actualTime;
+    case WifiRadioEnergyModel::RX:
+      current = devModel->GetRxCurrentA ();
       break;
-    case RadioEnergyModel::IDLE:
-      estRemainingEnergy -= devModel->GetIdlePowerW () * actualTime;
+    case WifiRadioEnergyModel::IDLE:
+      current = devModel->GetIdleCurrentA ();
       break;
-    case RadioEnergyModel::SLEEP:
-      estRemainingEnergy -= devModel->GetSleepPowerW () * actualTime;
+    case WifiRadioEnergyModel::SLEEP:
+      current = devModel->GetSleepCurrentA ();
       break;
     default:
+      NS_FATAL_ERROR ("Undefined radio state: " << state);
       break;
     }
-  // obtain remaining energy
+  estRemainingEnergy -= current * voltage * m_timeS;
+
+  // obtain remaining energy from source
   double remainingEnergy = source->GetRemainingEnergy ();
-  NS_LOG_UNCOND ("Remaining energy is " << remainingEnergy << "\n"
-                                        << "Estimated remaining energy is " << estRemainingEnergy << "\n"
-                                        << "Difference is " << estRemainingEnergy - remainingEnergy);
+  NS_LOG_UNCOND ("Remaining energy is " << remainingEnergy);
+  NS_LOG_UNCOND ("Estimated remaining energy is " << estRemainingEnergy);
+  NS_LOG_UNCOND ("Difference is " << estRemainingEnergy - remainingEnergy);
   // check remaining energy
   NS_TEST_ASSERT_MSG_EQ_TOL (remainingEnergy, estRemainingEnergy, m_tolerance,
                              "Incorrect remaining energy!");
 
-
   // obtain radio state
-  RadioEnergyModel::RadioState endState = devModel->GetCurrentState ();
+  WifiRadioEnergyModel::WifiRadioState endState = devModel->GetCurrentState ();
   NS_LOG_UNCOND ("Radio state is " << endState);
   // check end state
   NS_TEST_ASSERT_MSG_EQ (endState, state,  "Incorrect end state!");
@@ -190,11 +212,11 @@
   return false; // no error
 }
 
-// ----------------------------------------------------------------------------//
+// -------------------------------------------------------------------------- //
 
 /**
  * Test case of energy depletion handling for BasicEnergySource and
- * BasicRadioEnergyModel.
+ * WifiRadioEnergyModel.
  */
 class BasicEnergyDepletionTest : public TestCase
 {
@@ -205,7 +227,9 @@
 private:
   bool DoRun (void);
 
-  // / Callback invoked when energy is drained from source.
+  /**
+   * Callback invoked when energy is drained from source.
+   */
   void DepletionHandler (void);
 
   /**
@@ -218,7 +242,7 @@
   bool DepletionTestCase (double simTimeS, double updateIntervalS);
 
 private:
-  int m_numOfModels;        // number of BasicRadioEnergyModel to install
+  int m_numOfNodes;         // number of nodes in simulation
   int m_callbackCount;      // counter for # of callbacks invoked
   double m_simTimeS;        // maximum simulation time, in seconds
   double m_timeStepS;       // simulation time step size, in seconds
@@ -229,7 +253,7 @@
 BasicEnergyDepletionTest::BasicEnergyDepletionTest ()
   : TestCase ("Basic energy model energy depletion test case")
 {
-  m_numOfModels = 10;
+  m_numOfNodes = 10;
   m_callbackCount = 0;
   m_simTimeS = 4.5;
   m_timeStepS = 0.5;
@@ -274,7 +298,46 @@
                                              double updateIntervalS)
 {
   // create node
-  Ptr<Node> node = CreateObject<Node> ();
+  NodeContainer c;
+  c.Create (m_numOfNodes);
+
+  std::string phyMode ("DsssRate1Mbps");
+
+  // disable fragmentation for frames below 2200 bytes
+  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
+                      StringValue ("2200"));
+  // turn off RTS/CTS for frames below 2200 bytes
+  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
+                      StringValue ("2200"));
+  // Fix non-unicast data rate to be the same as that of unicast
+  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+                      StringValue (phyMode));
+
+  // install YansWifiPhy
+  WifiHelper wifi;
+  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+
+  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
+  /*
+   * This is one parameter that matters when using FixedRssLossModel, set it to
+   * zero; otherwise, gain will be added.
+   */
+  wifiPhy.Set ("RxGain", DoubleValue (0));
+  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
+  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
+
+  YansWifiChannelHelper wifiChannel ;
+  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+  wifiPhy.SetChannel (wifiChannel.Create ());
+
+  // Add a non-QoS upper MAC, and disable rate control
+  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+                                "DataMode", StringValue(phyMode),
+                                "ControlMode", StringValue(phyMode));
+  // Set it to ad-hoc mode
+  wifiMac.SetType ("ns3::AdhocWifiMac");
+  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
 
   /*
    * Create and install energy source and a single basic radio energy model on
@@ -284,57 +347,41 @@
   BasicEnergySourceHelper basicSourceHelper;
   // set energy to 0 so that we deplete energy at the beginning of simulation
   basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (0.0));
-  // device energy model helper
-  BasicRadioEnergyModelHelper radioEnergyHelper;
   // set update interval
   Time updateInterval = Seconds (1.0);
-  radioEnergyHelper.Set ("PeriodicEnergyUpdateInterval",
+  basicSourceHelper.Set ("PeriodicEnergyUpdateInterval",
                          TimeValue (Seconds (updateIntervalS)));
+  // install source
+  EnergySourceContainer sources = basicSourceHelper.Install (c);
+
+  // device energy model helper
+  WifiRadioEnergyModelHelper radioEnergyHelper;
   // set energy depletion callback
-  BasicRadioEnergyModel::BasicEnergyDepletionCallback callback =
+  WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback =
     MakeCallback (&BasicEnergyDepletionTest::DepletionHandler, this);
   radioEnergyHelper.SetDepletionCallback (callback);
-  // energy model helper
-  EnergyModelHelper energyHelper;
   // install on node
-  energyHelper.Install (basicSourceHelper, radioEnergyHelper, node);
-
-  // Install more basic radio energy models onto the same node, using helper
-  for (int i = 1; i < m_numOfModels; i++)
-    {
-      radioEnergyHelper.Install (node);
-    }
+  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices,
+                                                                       sources);
 
   // run simulation
   Simulator::Stop (Seconds (simTimeS));
   Simulator::Run ();
   Simulator::Destroy ();
 
-  /*
-   * Calculate total number of callbacks invoked. Taking the ceiling instead of
-   * the floor here because initial update is at time = 0.
-   */
-  double tmp = ceil (simTimeS / updateIntervalS);
-  int numOfUpdates = (tmp == 0) ? 1 : static_cast<int> (tmp);
-  /*
-   * Every update will trigger *all* DeviceEnergyModels to react, therefore the
-   * total count should be numOfUpdates * m_numOfModels ^ 2
-   */
-  int totalCallbackCount = numOfUpdates * m_numOfModels * m_numOfModels;
+  NS_LOG_UNCOND ("Simulation time = " << simTimeS << "s");
+  NS_LOG_UNCOND ("Update interval = " << updateIntervalS << "s");
+  NS_LOG_UNCOND ("Expected callback count is " << m_numOfNodes);
+  NS_LOG_UNCOND ("Actual callback count is " << m_callbackCount);
 
-  NS_LOG_UNCOND ("Simulation time = " << simTimeS << "s\n"
-                                      << "Update interval = " << updateIntervalS << "s\n"
-                                      << "Calculated callback count is " << totalCallbackCount << "\n"
-                                      << "Actual callback count is " << m_callbackCount);
-
-  // check result
-  NS_TEST_ASSERT_MSG_EQ (totalCallbackCount, m_callbackCount,
+  // check result, call back should only be invoked once
+  NS_TEST_ASSERT_MSG_EQ (m_numOfNodes, m_callbackCount,
                          "Not all callbacks are invoked!");
 
   return false;
 }
 
-// ----------------------------------------------------------------------------//
+// -------------------------------------------------------------------------- //
 
 /**
  * Unit test suite for energy model. Although the test suite involves 2 modules
@@ -348,11 +395,13 @@
 };
 
 BasicEnergyModelTestSuite::BasicEnergyModelTestSuite ()
-  : TestSuite ("devices-basic-energy-model", UNIT)
+  : TestSuite ("basic-energy-model", UNIT)
 {
   AddTestCase (new BasicEnergyUpdateTest);
-  AddTestCase (new BasicEnergyDepletionTest);
+  //AddTestCase (new BasicEnergyDepletionTest);
 }
 
 // create an instance of the test suite
 BasicEnergyModelTestSuite g_energyModelTestSuite;
+
+} // namespace ns3
--- a/src/contrib/energy/wscript	Mon Aug 09 22:23:57 2010 -0400
+++ b/src/contrib/energy/wscript	Mon Aug 09 23:31:57 2010 -0700
@@ -3,26 +3,27 @@
 def build(bld):
     obj = bld.create_ns3_module('energy', ['node'])
     obj.source = [
-        'model/radio-energy-model.cc',
-        'model/basic-radio-energy-model.cc',
+        'model/wifi-radio-energy-model.cc',
         'model/energy-source.cc',
         'model/basic-energy-source.cc',
         'model/device-energy-model.cc',
+        'model/device-energy-model-container.cc',
+        'helper/energy-source-container.cc',
         'helper/energy-model-helper.cc',
         'helper/basic-energy-source-helper.cc',
-        'helper/basic-radio-energy-model-helper.cc',
+        'helper/wifi-radio-energy-model-helper.cc',
         'test/basic-energy-model-test.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'energy'
     headers.source = [
-        'model/radio-energy-model.h',
-        'model/basic-radio-energy-model.h',
+        'model/wifi-radio-energy-model.h',
         'model/energy-source.h',
         'model/basic-energy-source.h',
         'model/device-energy-model.h',
+        'model/device-energy-model-container.h',
+        'helper/energy-source-container.h',
         'helper/energy-model-helper.h',
         'helper/basic-energy-source-helper.h',
-        'helper/basic-radio-energy-model-helper.h',
+        'helper/wifi-radio-energy-model-helper.h',
         ]
-