21 #include "ns3/basic-energy-source.h" 
   22 #include "ns3/wifi-radio-energy-model.h" 
   23 #include "ns3/basic-energy-source-helper.h" 
   24 #include "ns3/wifi-radio-energy-model-helper.h" 
   25 #include "ns3/energy-source-container.h" 
   26 #include "ns3/device-energy-model-container.h" 
   29 #include "ns3/simulator.h" 
   30 #include "ns3/double.h" 
   31 #include "ns3/config.h" 
   32 #include "ns3/string.h" 
   33 #include "ns3/yans-wifi-helper.h" 
   34 #include "ns3/nqos-wifi-mac-helper.h" 
   78   m_tolerance = 1.0e-13;  
 
   89   m_energySource.SetTypeId (
"ns3::BasicEnergySource");
 
   90   m_deviceEnergyModel.SetTypeId (
"ns3::WifiRadioEnergyModel");
 
   98       std::cerr << 
"Problem with state switch test (WifiPhy idle)." << std::endl;
 
  103       std::cerr << 
"Problem with state switch test (WifiPhy cca busy)." << std::endl;
 
  108       std::cerr << 
"Problem with state switch test (WifiPhy tx)." << std::endl;
 
  113       std::cerr << 
"Problem with state switch test (WifiPhy rx)." << std::endl;
 
  118       std::cerr << 
"Problem with state switch test (WifiPhy switching)." << std::endl;
 
  123       std::cerr << 
"Problem with state switch test (WifiPhy sleep)." << std::endl;
 
  145   source->AppendDeviceEnergyModel (model);
 
  149     source->FindDeviceEnergyModels (
"ns3::WifiRadioEnergyModel");
 
  151   if ((models.
GetN () == 0))
 
  153       std::cerr << 
"Model list is empty!." << std::endl;
 
  158     DynamicCast<WifiRadioEnergyModel> (models.
Get (0));
 
  162       std::cerr << 
"NULL pointer to device model!." << std::endl;
 
  179   double timeDelta = 0.000000001; 
 
  187   double estRemainingEnergy = source->GetInitialEnergy ();
 
  188   double voltage = source->GetSupplyVoltage ();
 
  189   estRemainingEnergy -= devModel->
GetIdleCurrentA () * voltage * m_timeS;
 
  195   double actualTime = m_timeS;
 
  196   actualTime /= source->GetEnergyUpdateInterval ().GetSeconds ();
 
  197   actualTime = floor (actualTime); 
 
  198   actualTime *= source->GetEnergyUpdateInterval ().GetSeconds ();
 
  201   double current = 0.0;
 
  226   estRemainingEnergy -= current * voltage * m_timeS;
 
  229   double remainingEnergy = source->GetRemainingEnergy ();
 
  230   NS_LOG_DEBUG (
"Remaining energy is " << remainingEnergy);
 
  231   NS_LOG_DEBUG (
"Estimated remaining energy is " << estRemainingEnergy);
 
  232   NS_LOG_DEBUG (
"Difference is " << estRemainingEnergy - remainingEnergy);
 
  235   if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) ||
 
  236       (remainingEnergy < (estRemainingEnergy - m_tolerance)))
 
  238       std::cerr << 
"Incorrect remaining energy!" << std::endl;
 
  246   if (endState != state)
 
  248       std::cerr << 
"Incorrect end state!" << std::endl;
 
  278   void DepletionHandler (
void);
 
  287   bool DepletionTestCase (
double simTimeS, 
double updateIntervalS);
 
  304   m_updateIntervalS = 1.5;
 
  319   for (
double simTimeS = 0.0; simTimeS <= m_simTimeS; simTimeS += m_timeStepS)
 
  321       for (
double updateIntervalS = 0.5; updateIntervalS <= m_updateIntervalS;
 
  322            updateIntervalS += m_timeStepS)
 
  324           if (DepletionTestCase (simTimeS, updateIntervalS))
 
  327               std::cerr << 
"Depletion test case problem." << std::endl;
 
  344                                              double updateIntervalS)
 
  350   std::string phyMode (
"DsssRate1Mbps");
 
  385   wifiMac.
SetType (
"ns3::AdhocWifiMac");
 
  395   basicSourceHelper.
Set (
"BasicEnergySourceInitialEnergyJ", 
DoubleValue (0.0));
 
  397   basicSourceHelper.
Set (
"PeriodicEnergyUpdateInterval",
 
  417   NS_LOG_DEBUG (
"Update interval = " << updateIntervalS << 
"s");
 
  418   NS_LOG_DEBUG (
"Expected callback count is " << m_numOfNodes);
 
  419   NS_LOG_DEBUG (
"Actual callback count is " << m_callbackCount);
 
  422   if (m_numOfNodes != m_callbackCount)
 
  424       std::cerr << 
"Not all callbacks are invoked!" << std::endl;
 
  434 main (
int argc, 
char **argv)
 
  437   if (testEnergyUpdate.
DoRun ())
 
  443   if (testEnergyDepletion.
DoRun ())
 
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const 
 
Assign WifiRadioEnergyModel to wifi devices. 
 
Holds a vector of ns3::EnergySource pointers. 
 
ObjectFactory m_deviceEnergyModel
 
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
 
Ptr< YansWifiChannel > Create(void) const 
 
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
 
Hold variables of type string. 
 
Make it easy to create and manage PHY objects for the yans model. 
 
The PHY layer has sense the medium busy through the CCA mechanism. 
 
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
 
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together. 
 
static void Run(void)
Run the simulation. 
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
BasicEnergySource decreases/increases remaining energy stored in itself in linearly. 
 
virtual void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode. 
 
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used. 
 
The PHY layer is sleeping. 
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate. 
 
virtual void UpdateEnergySource(void)
Implements UpdateEnergySource. 
 
Test case of update remaining energy for BasicEnergySource and WifiRadioEnergyModel. 
 
void Set(std::string name, const AttributeValue &v)
 
double GetSleepCurrentA(void) const 
 
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state. 
 
helps to create WifiNetDevice objects 
 
Include Radiotap link layer information. 
 
Holds a vector of ns3::DeviceEnergyModel pointers. 
 
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const 
 
BasicEnergyDepletionTest()
 
void SetChannel(Ptr< YansWifiChannel > channel)
 
double GetCcaBusyCurrentA(void) const 
 
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay. 
 
AttributeValue implementation for Time. 
 
Creates a BasicEnergySource object. 
 
holds a vector of ns3::NetDevice pointers 
 
virtual void SetStandard(enum WifiPhyStandard standard)
 
The PHY layer is receiving a packet. 
 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
 
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state. 
 
WifiPhy::State GetCurrentState(void) const 
 
The PHY layer is sending a packet. 
 
bool StateSwitchTest(WifiPhy::State state)
 
create non QoS-enabled MAC layers for a ns3::WifiNetDevice. 
 
The PHY layer is switching to other channel. 
 
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy(). 
 
Ptr< DeviceEnergyModel > Get(uint32_t i) const 
Get the i-th Ptr stored in this container. 
 
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
keep track of a set of node pointers. 
 
bool DoRun(void)
Performs some tests involving state updates and the relative energy consumption. 
 
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18) 
 
EnergySourceContainer Install(Ptr< Node > node) const 
 
double GetTxCurrentA(void) const 
 
bool DoRun(void)
Performs some tests involving energy depletion. 
 
Test case of energy depletion handling for BasicEnergySource and WifiRadioEnergyModel. 
 
double GetRxCurrentA(void) const 
 
manage and create wifi channel objects for the yans model. 
 
A WiFi radio energy model. 
 
virtual ~BasicEnergyUpdateTest()
 
Instantiate subclasses of ns3::Object. 
 
static void Stop(void)
Tell the Simulator the calling event should be the last one executed. 
 
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG. 
 
virtual ~BasicEnergyDepletionTest()
 
Time Seconds(double value)
Construct a Time in the indicated unit. 
 
void SetDefault(std::string name, const AttributeValue &value)
 
void Set(std::string name, const AttributeValue &v)
 
double GetIdleCurrentA(void) const 
 
uint32_t GetN(void) const 
Get the number of Ptr stored in this container. 
 
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer. 
 
ObjectFactory m_energySource
 
void SetPropagationDelay(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
 
State
The state of the PHY layer. 
 
This class can be used to hold variables of floating point type such as 'double' or 'float'...
 
bool DepletionTestCase(double simTimeS, double updateIntervalS)
 
void DepletionHandler(void)
Callback invoked when energy is drained from source. 
 
double GetSwitchingCurrentA(void) const