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 #include "ns3/wifi-phy.h"
25 
26 namespace ns3 {
27 
29 {
30  m_radioEnergy.SetTypeId ("ns3::WifiRadioEnergyModel");
33 }
34 
36 {
37 }
38 
39 void
40 WifiRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v)
41 {
42  m_radioEnergy.Set (name, v);
43 }
44 
45 void
48 {
49  m_depletionCallback = callback;
50 }
51 
52 void
55 {
56  m_rechargedCallback = callback;
57 }
58 
59 void
61  std::string n0, const AttributeValue& v0,
62  std::string n1, const AttributeValue& v1,
63  std::string n2, const AttributeValue& v2,
64  std::string n3, const AttributeValue& v3,
65  std::string n4, const AttributeValue& v4,
66  std::string n5, const AttributeValue& v5,
67  std::string n6, const AttributeValue& v6,
68  std::string n7, const AttributeValue& v7)
69 {
70  ObjectFactory factory;
71  factory.SetTypeId (name);
72  factory.Set (n0, v0);
73  factory.Set (n1, v1);
74  factory.Set (n2, v2);
75  factory.Set (n3, v3);
76  factory.Set (n4, v4);
77  factory.Set (n5, v5);
78  factory.Set (n6, v6);
79  factory.Set (n7, v7);
80  m_txCurrentModel = factory;
81 }
82 
83 
84 /*
85  * Private function starts here.
86  */
87 
90  Ptr<EnergySource> source) const
91 {
92  NS_ASSERT (device != NULL);
93  NS_ASSERT (source != NULL);
94  // check if device is WifiNetDevice
95  std::string deviceName = device->GetInstanceTypeId ().GetName ();
96  if (deviceName.compare ("ns3::WifiNetDevice") != 0)
97  {
98  NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!");
99  }
100  Ptr<Node> node = device->GetNode ();
102  NS_ASSERT (model != NULL);
103 
104  // set energy depletion callback
105  // if none is specified, make a callback to WifiPhy::SetOffMode
106  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
107  Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy ();
108  wifiPhy->SetWifiRadioEnergyModel (model);
110  {
111  model->SetEnergyDepletionCallback (MakeCallback (&WifiPhy::SetOffMode, wifiPhy));
112  }
113  else
114  {
115  model->SetEnergyDepletionCallback (m_depletionCallback);
116  }
117  // set energy recharged callback
118  // if none is specified, make a callback to WifiPhy::ResumeFromOff
120  {
121  model->SetEnergyRechargedCallback (MakeCallback (&WifiPhy::ResumeFromOff, wifiPhy));
122  }
123  else
124  {
125  model->SetEnergyRechargedCallback (m_rechargedCallback);
126  }
127  // add model to device model list in energy source
128  source->AppendDeviceEnergyModel (model);
129  // set energy source pointer
130  model->SetEnergySource (source);
131  // create and register energy model phy listener
132  wifiPhy->RegisterListener (model->GetPhyListener ());
133  //
135  {
137  model->SetTxCurrentModel (txcurrent);
138  }
139  return model;
140 }
141 
142 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
void ResumeFromOff(void)
Resume from off mode.
Definition: wifi-phy.cc:1609
Hold a value for an Attribute.
Definition: attribute.h:68
#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
void SetOffMode(void)
Put in off mode.
Definition: wifi-phy.cc:1557
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
virtual Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const
uint16_t GetUid(void) const
Get the internal id of this TypeId.
Definition: type-id.cc:1183
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Set(std::string name, const AttributeValue &v)
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
A WiFi radio energy model.
TypeId GetTypeId(void) const
Get the TypeId which will be created by this ObjectFactory.
Instantiate subclasses of ns3::Object.
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.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
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