A Discrete-Event Network Simulator
API
wifi-radio-energy-model-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
19  */
20 
22 #include "ns3/basic-energy-source-helper.h"
23 #include "ns3/wifi-phy.h"
24 #include "ns3/wifi-net-device.h"
25 #include "ns3/config.h"
26 #include "ns3/names.h"
27 #include "ns3/wifi-tx-current-model.h"
28 
29 namespace ns3 {
30 
32 {
33  m_radioEnergy.SetTypeId ("ns3::WifiRadioEnergyModel");
36 }
37 
39 {
40 }
41 
42 void
43 WifiRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v)
44 {
45  m_radioEnergy.Set (name, v);
46 }
47 
48 void
51 {
52  m_depletionCallback = callback;
53 }
54 
55 void
58 {
59  m_rechargedCallback = callback;
60 }
61 
62 void
64  std::string n0, const AttributeValue& v0,
65  std::string n1, const AttributeValue& v1,
66  std::string n2, const AttributeValue& v2,
67  std::string n3, const AttributeValue& v3,
68  std::string n4, const AttributeValue& v4,
69  std::string n5, const AttributeValue& v5,
70  std::string n6, const AttributeValue& v6,
71  std::string n7, const AttributeValue& v7)
72 {
73  ObjectFactory factory;
74  factory.SetTypeId (name);
75  factory.Set (n0, v0);
76  factory.Set (n1, v1);
77  factory.Set (n2, v2);
78  factory.Set (n3, v3);
79  factory.Set (n4, v4);
80  factory.Set (n5, v5);
81  factory.Set (n6, v6);
82  factory.Set (n7, v7);
83  m_txCurrentModel = factory;
84 }
85 
86 
87 /*
88  * Private function starts here.
89  */
90 
93  Ptr<EnergySource> source) const
94 {
95  NS_ASSERT (device != NULL);
96  NS_ASSERT (source != NULL);
97  // check if device is WifiNetDevice
98  std::string deviceName = device->GetInstanceTypeId ().GetName ();
99  if (deviceName.compare ("ns3::WifiNetDevice") != 0)
100  {
101  NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!");
102  }
103  Ptr<Node> node = device->GetNode ();
105  NS_ASSERT (model != NULL);
106  // set energy source pointer
107  model->SetEnergySource (source);
108  // set energy depletion callback
109  // if none is specified, make a callback to WifiPhy::SetSleepMode
110  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
111  Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy ();
113  {
114  model->SetEnergyDepletionCallback (MakeCallback (&WifiPhy::SetSleepMode, wifiPhy));
115  }
116  else
117  {
118  model->SetEnergyDepletionCallback (m_depletionCallback);
119  }
120  // set energy recharged callback
121  // if none is specified, make a callback to WifiPhy::ResumeFromSleep
123  {
124  model->SetEnergyRechargedCallback (MakeCallback (&WifiPhy::ResumeFromSleep, wifiPhy));
125  }
126  else
127  {
128  model->SetEnergyRechargedCallback (m_rechargedCallback);
129  }
130  // add model to device model list in energy source
131  source->AppendDeviceEnergyModel (model);
132  // create and register energy model phy listener
133  wifiPhy->RegisterListener (model->GetPhyListener ());
134  //
136  {
138  model->SetTxCurrentModel (txcurrent);
139  }
140  return model;
141 }
142 
143 } // namespace ns3
TypeId GetTypeId(void) const
Get the TypeId which will be created by this ObjectFactory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
Hold a value for an Attribute.
Definition: attribute.h:68
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback m_rechargedCallback
virtual void ResumeFromSleep(void)=0
Resume from sleep mode.
WifiRadioEnergyModelHelper()
Construct a helper which is used to add a radio energy model to a node.
~WifiRadioEnergyModelHelper()
Destroy a RadioEnergy Helper.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback m_depletionCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Set(std::string name, const AttributeValue &v)
virtual Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1172
A WiFi radio energy model.
Instantiate subclasses of ns3::Object.
virtual void SetSleepMode(void)=0
Put in sleep mode.
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1274
Modelize the transmit current as a function of the transmit power and mode.
void SetTxCurrentModel(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())
void SetRechargedCallback(WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback callback)