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/wifi-net-device.h"
23 #include "ns3/wifi-tx-current-model.h"
24 
25 namespace ns3 {
26 
28 {
29  m_radioEnergy.SetTypeId ("ns3::WifiRadioEnergyModel");
32 }
33 
35 {
36 }
37 
38 void
39 WifiRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v)
40 {
41  m_radioEnergy.Set (name, v);
42 }
43 
44 void
47 {
48  m_depletionCallback = callback;
49 }
50 
51 void
54 {
55  m_rechargedCallback = callback;
56 }
57 
58 void
60  std::string n0, const AttributeValue& v0,
61  std::string n1, const AttributeValue& v1,
62  std::string n2, const AttributeValue& v2,
63  std::string n3, const AttributeValue& v3,
64  std::string n4, const AttributeValue& v4,
65  std::string n5, const AttributeValue& v5,
66  std::string n6, const AttributeValue& v6,
67  std::string n7, const AttributeValue& v7)
68 {
69  ObjectFactory factory;
70  factory.SetTypeId (name);
71  factory.Set (n0, v0);
72  factory.Set (n1, v1);
73  factory.Set (n2, v2);
74  factory.Set (n3, v3);
75  factory.Set (n4, v4);
76  factory.Set (n5, v5);
77  factory.Set (n6, v6);
78  factory.Set (n7, v7);
79  m_txCurrentModel = factory;
80 }
81 
82 
83 /*
84  * Private function starts here.
85  */
86 
89  Ptr<EnergySource> source) const
90 {
91  NS_ASSERT (device != NULL);
92  NS_ASSERT (source != NULL);
93  // check if device is WifiNetDevice
94  std::string deviceName = device->GetInstanceTypeId ().GetName ();
95  if (deviceName.compare ("ns3::WifiNetDevice") != 0)
96  {
97  NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!");
98  }
99  Ptr<Node> node = device->GetNode ();
101  NS_ASSERT (model != NULL);
102  // set energy source pointer
103  model->SetEnergySource (source);
104  // set energy depletion callback
105  // if none is specified, make a callback to WifiPhy::SetSleepMode
106  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
107  Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy ();
109  {
110  model->SetEnergyDepletionCallback (MakeCallback (&WifiPhy::SetSleepMode, wifiPhy));
111  }
112  else
113  {
114  model->SetEnergyDepletionCallback (m_depletionCallback);
115  }
116  // set energy recharged callback
117  // if none is specified, make a callback to WifiPhy::ResumeFromSleep
119  {
120  model->SetEnergyRechargedCallback (MakeCallback (&WifiPhy::ResumeFromSleep, wifiPhy));
121  }
122  else
123  {
124  model->SetEnergyRechargedCallback (m_rechargedCallback);
125  }
126  // add model to device model list in energy source
127  source->AppendDeviceEnergyModel (model);
128  // create and register energy model phy listener
129  wifiPhy->RegisterListener (model->GetPhyListener ());
130  //
132  {
134  model->SetTxCurrentModel (txcurrent);
135  }
136  return model;
137 }
138 
139 } // 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:459
void ResumeFromSleep(void)
Resume from sleep mode.
Definition: wifi-phy.cc:1638
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
radio energy recharged callback
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
radio energy depletion callback
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:1182
A WiFi radio energy model.
Instantiate subclasses of ns3::Object.
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1274
void SetSleepMode(void)
Put in sleep mode.
Definition: wifi-phy.cc:1606
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)
ObjectFactory m_txCurrentModel
transmit current model