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 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 /* | 165 /* |
166 * The radio will stay IDLE for m_timeS seconds. Then it will switch into a | 166 * The radio will stay IDLE for m_timeS seconds. Then it will switch into a |
167 * different state. | 167 * different state. |
168 */ | 168 */ |
169 | 169 |
170 // schedule change of state | 170 // schedule change of state |
171 Simulator::Schedule (Seconds (m_timeS), | 171 Simulator::Schedule (Seconds (m_timeS), |
172 &WifiRadioEnergyModel::ChangeState, devModel, state); | 172 &WifiRadioEnergyModel::ChangeState, devModel, state); |
173 | 173 |
174 // Calculate remaining energy at simulation stop time | 174 // Calculate remaining energy at simulation stop time |
175 Simulator::Schedule (Seconds (m_timeS * 2), | 175 Simulator::Schedule (Seconds (m_timeS * 2), |
176 &BasicEnergySource::UpdateEnergySource, source); | 176 &BasicEnergySource::UpdateEnergySource, source); |
177 | 177 |
178 double timeDelta = 0.000000001; // 1 nanosecond | 178 double timeDelta = 0.000000001; // 1 nanosecond |
179 // run simulation; stop just after last scheduled event | 179 // run simulation; stop just after last scheduled event |
180 Simulator::Stop (Seconds (m_timeS * 2 + timeDelta)); | 180 Simulator::Stop (Seconds (m_timeS * 2 + timeDelta)); |
181 Simulator::Run (); | 181 Simulator::Run (); |
182 | 182 |
183 // energy = current * voltage * time | 183 // energy = current * voltage * time |
184 | 184 |
185 // calculate idle power consumption | 185 // calculate idle power consumption |
186 double estRemainingEnergy = source->GetInitialEnergy (); | 186 double estRemainingEnergy = source->GetInitialEnergy (); |
187 double voltage = source->GetSupplyVoltage (); | 187 double voltage = source->GetSupplyVoltage (); |
188 estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS; | 188 estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS; |
189 | 189 |
190 /* | |
191 * Manually calculate the number of periodic updates performed by the source. | |
192 * This is to check if the periodic updates are performed correctly. | |
193 */ | |
194 double actualTime = m_timeS; | |
195 actualTime /= source->GetEnergyUpdateInterval ().GetSeconds (); | |
196 actualTime = floor (actualTime); // rounding for update interval | |
197 actualTime *= source->GetEnergyUpdateInterval ().GetSeconds (); | |
198 | 190 |
199 // calculate new state power consumption | 191 // calculate new state power consumption |
200 double current = 0.0; | 192 double current = 0.0; |
201 switch (state) | 193 switch (state) |
202 { | 194 { |
203 case WifiPhy::IDLE: | 195 case WifiPhy::IDLE: |
204 current = devModel->GetIdleCurrentA (); | 196 current = devModel->GetIdleCurrentA (); |
205 break; | 197 break; |
206 case WifiPhy::CCA_BUSY: | 198 case WifiPhy::CCA_BUSY: |
207 current = devModel->GetCcaBusyCurrentA (); | 199 current = devModel->GetCcaBusyCurrentA (); |
(...skipping 16 matching lines...) Expand all Loading... |
224 } | 216 } |
225 estRemainingEnergy -= current * voltage * m_timeS; | 217 estRemainingEnergy -= current * voltage * m_timeS; |
226 | 218 |
227 // obtain remaining energy from source | 219 // obtain remaining energy from source |
228 double remainingEnergy = source->GetRemainingEnergy (); | 220 double remainingEnergy = source->GetRemainingEnergy (); |
229 NS_LOG_DEBUG ("Remaining energy is " << remainingEnergy); | 221 NS_LOG_DEBUG ("Remaining energy is " << remainingEnergy); |
230 NS_LOG_DEBUG ("Estimated remaining energy is " << estRemainingEnergy); | 222 NS_LOG_DEBUG ("Estimated remaining energy is " << estRemainingEnergy); |
231 NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy); | 223 NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy); |
232 | 224 |
233 // check remaining energy | 225 // check remaining energy |
234 if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) || | 226 if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) |
235 (remainingEnergy < (estRemainingEnergy - m_tolerance))) | 227 || (remainingEnergy < (estRemainingEnergy - m_tolerance))) |
236 { | 228 { |
237 std::cerr << "Incorrect remaining energy!" << std::endl; | 229 std::cerr << "Incorrect remaining energy!" << std::endl; |
238 return true; | 230 return true; |
239 } | 231 } |
240 | 232 |
241 // obtain radio state | 233 // obtain radio state |
242 WifiPhy::State endState = devModel->GetCurrentState (); | 234 WifiPhy::State endState = devModel->GetCurrentState (); |
243 NS_LOG_DEBUG ("Radio state is " << endState); | 235 NS_LOG_DEBUG ("Radio state is " << endState); |
244 // check end state | 236 // check end state |
245 if (endState != state) | 237 if (endState != state) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 431 } |
440 | 432 |
441 BasicEnergyDepletionTest testEnergyDepletion; | 433 BasicEnergyDepletionTest testEnergyDepletion; |
442 if (testEnergyDepletion.DoRun ()) | 434 if (testEnergyDepletion.DoRun ()) |
443 { | 435 { |
444 return 1; | 436 return 1; |
445 } | 437 } |
446 | 438 |
447 return 0; | 439 return 0; |
448 } | 440 } |
LEFT | RIGHT |