LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. | 3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> | 18 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
19 */ | 19 */ |
20 | 20 |
21 #ifndef DEVICE_ENERGY_MODEL_H | 21 #ifndef DEVICE_ENERGY_MODEL_H |
22 #define DEVICE_ENERGY_MODEL_H | 22 #define DEVICE_ENERGY_MODEL_H |
23 | 23 |
24 #include "ns3/object.h" | 24 #include "ns3/object.h" |
25 #include "ns3/ptr.h" | 25 #include "ns3/ptr.h" |
26 #include "ns3/type-id.h" | 26 #include "ns3/type-id.h" |
27 #include "ns3/node.h" | 27 #include "ns3/node.h" |
28 #include "energy-source.h" | |
29 | 28 |
30 namespace ns3 { | 29 namespace ns3 { |
31 | 30 |
32 class EnergySource; | 31 class EnergySource; |
33 | 32 |
34 /** | 33 /** |
35 * \brief Base class for device energy models. | 34 * \brief Base class for device energy models. |
36 * | 35 * |
37 * A device energy model should represent the energy consumption behavior of a | 36 * A device energy model should represent the energy consumption behavior of a |
38 * specific device. It will update remaining energy stored in the EnergySource | 37 * specific device. It will update remaining energy stored in the EnergySource |
39 * object installed on node. When energy is depleted, each DeviceEnergyModel | 38 * object installed on node. When energy is depleted, each DeviceEnergyModel |
40 * object installed on the same node will be informed by the EnergySource. | 39 * object installed on the same node will be informed by the EnergySource. |
41 */ | 40 */ |
42 class DeviceEnergyModel : public Object | 41 class DeviceEnergyModel : public Object |
43 { | 42 { |
44 public: | 43 public: |
45 /** | 44 /** |
46 * Callback type for ChangeState function. Devices uses this state to notify | 45 * Callback type for ChangeState function. Devices uses this state to notify |
47 * DeviceEnergyModel of a state change. | 46 * DeviceEnergyModel of a state change. |
48 */ | 47 */ |
49 typedef Callback<void, int> ChangeStateCallback; | 48 typedef Callback<void, int> ChangeStateCallback; |
50 | 49 |
51 public: | 50 public: |
52 static TypeId GetTypeId (void); | 51 static TypeId GetTypeId (void); |
53 DeviceEnergyModel (); | 52 DeviceEnergyModel (); |
54 virtual ~DeviceEnergyModel (); | 53 virtual ~DeviceEnergyModel (); |
55 | 54 |
56 /** | 55 /** |
57 * \brief Sets pointer to node containing this EnergySource. | |
58 * | |
59 * \param node Pointer to node containing this EnergySource. | |
60 */ | |
61 void SetNode (Ptr<Node> node); | |
62 | |
63 /** | |
64 * \returns Pointer to node containing this EnergySource. | |
65 * | |
66 * When a subclass needs to get access to the underlying node base class to | |
67 * print the nodeId for example, it can invoke this method. | |
68 */ | |
69 Ptr<Node> GetNode (void) const; | |
70 | |
71 /** | |
72 * \param source Pointer to energy source installed on node. | 56 * \param source Pointer to energy source installed on node. |
73 * | 57 * |
74 * This function sets the pointer to energy source installed on node. Should | 58 * This function sets the pointer to energy source installed on node. Should |
75 * be called only by DeviceEnergyModel helper classes. | 59 * be called only by DeviceEnergyModel helper classes. |
76 */ | 60 */ |
77 void SetEnergySource (Ptr<EnergySource> source); | 61 virtual void SetEnergySource (Ptr<EnergySource> source) = 0; |
| 62 |
| 63 /** |
| 64 * \returns Total energy consumption of the device. |
| 65 * |
| 66 * DeviceEnergyModel records its own energy consumption during simulation. |
| 67 */ |
| 68 virtual double GetTotalEnergyConsumption (void) const = 0; |
78 | 69 |
79 /** | 70 /** |
80 * \param newState New state the device is in. | 71 * \param newState New state the device is in. |
81 * | 72 * |
82 * DeviceEnergyModel is a state based model. This function is implemented by | 73 * DeviceEnergyModel is a state based model. This function is implemented by |
83 * all child of DeviceEnergyModel to change the model's state. States are to | 74 * all child of DeviceEnergyModel to change the model's state. States are to |
84 * be defined by each child using an enum (int). | 75 * be defined by each child using an enum (int). |
85 */ | 76 */ |
86 void ChangeState (int newState); | 77 virtual void ChangeState (int newState) = 0; |
| 78 |
| 79 /** |
| 80 * \returns Current draw of the device, in Ampere. |
| 81 * |
| 82 * This function returns the current draw at the device in its current state. |
| 83 * This function is called from the EnergySource to obtain the total current |
| 84 * draw at any given time during simulation. |
| 85 */ |
| 86 double GetCurrentA (void) const; |
87 | 87 |
88 /** | 88 /** |
89 * This function is called by the EnergySource object when energy stored in | 89 * This function is called by the EnergySource object when energy stored in |
90 * the energy source is depleted. Should be implemented by child classes. | 90 * the energy source is depleted. Should be implemented by child classes. |
91 */ | 91 */ |
92 void HandleEnergyDepletion (void); | 92 virtual void HandleEnergyDepletion (void) = 0; |
93 | 93 |
94 | 94 |
95 private: | 95 private: |
96 /* | 96 /** |
97 * Do not include DoStart in any child of this base class. DeviceEnergyModel | 97 * \returns 0.0 as the current value, in Ampere. |
98 * is *not* aggregated to the node hence DoStart will *not* be called. | 98 * |
| 99 * Child class does not have to implement this method if current draw for its |
| 100 * states are not know. This default method will always return 0.0A. For the |
| 101 * devices who does know the current draw of its states, this method must be |
| 102 * overwritten. |
99 */ | 103 */ |
100 | 104 virtual double DoGetCurrentA (void) const; |
101 /** | |
102 * All child's implementation must call BreakSourceRefCycle to ensure | |
103 * reference cycle to EnergySource object is broken. | |
104 */ | |
105 void DoDispose (void); | |
106 | |
107 /** | |
108 * \param newState New state the device is in. | |
109 * | |
110 * Implements ChangeState. | |
111 */ | |
112 virtual void DoChangeState (int newState) = 0; | |
113 | |
114 /** | |
115 * Implements HandleEnergyDepletion. | |
116 */ | |
117 virtual void DoHandleEnergyDepletion (void) = 0; | |
118 | |
119 private: | |
120 /** | |
121 * Pointer to EnergySource. | |
122 */ | |
123 Ptr<EnergySource> m_energySourcePtr; | |
124 | |
125 /** | |
126 * Pointer to node where the DeviceEnergyModel resides. | |
127 */ | |
128 Ptr<Node> m_node; | |
129 | |
130 | |
131 protected: | |
132 /** | |
133 * \param energyJ Amount of energy to decrease from energy source, in Joules. | |
134 * | |
135 * This function decreases energy from the energy source. | |
136 */ | |
137 void DecreaseRemainingEnergy (double energyJ); | |
138 | |
139 /** | |
140 * \param energyJ Amount of energy to increase from energy source. in Joules. | |
141 * | |
142 * This function increases energy from the energy source. | |
143 */ | |
144 void IncreaseRemainingEnergy (double energyJ); | |
145 | |
146 /** | |
147 * This function is called to break reference cycle between DeviceEnergyModel | |
148 * and EnergySource. Child of the DeviceEnergyModel base class must call this | |
149 * function in their implementation of DoDispose to make sure the reference | |
150 * cycle is broken. | |
151 * | |
152 * Normally this work will be completed by the DoDispose function. However it | |
153 * will be overridden in the child class. Hence we introduced this function. | |
154 */ | |
155 void BreakSourceRefCycle (void); | |
156 | 105 |
157 }; | 106 }; |
158 | 107 |
159 } | 108 } |
160 | 109 |
161 #endif /* DEVICE_ENERGY_MODEL_H */ | 110 #endif /* DEVICE_ENERGY_MODEL_H */ |
LEFT | RIGHT |