Left: | ||
Right: |
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 &WifiRadioEnergyModel::GetSleepCurrentA), | 75 &WifiRadioEnergyModel::GetSleepCurrentA), |
76 MakeDoubleChecker<double> ()) | 76 MakeDoubleChecker<double> ()) |
77 .AddAttribute ("TxCurrentModel", "A pointer to the attached tx current model .", | 77 .AddAttribute ("TxCurrentModel", "A pointer to the attached tx current model .", |
78 PointerValue (), | 78 PointerValue (), |
79 MakePointerAccessor (&WifiRadioEnergyModel::m_txCurrentModel) , | 79 MakePointerAccessor (&WifiRadioEnergyModel::m_txCurrentModel) , |
80 MakePointerChecker<WifiTxCurrentModel> ()) | 80 MakePointerChecker<WifiTxCurrentModel> ()) |
81 .AddTraceSource ("TotalEnergyConsumption", | 81 .AddTraceSource ("TotalEnergyConsumption", |
82 "Total energy consumption of the radio device.", | 82 "Total energy consumption of the radio device.", |
83 MakeTraceSourceAccessor (&WifiRadioEnergyModel::m_totalEner gyConsumption), | 83 MakeTraceSourceAccessor (&WifiRadioEnergyModel::m_totalEner gyConsumption), |
84 "ns3::TracedValueCallback::Double") | 84 "ns3::TracedValueCallback::Double") |
85 ; | 85 ; |
86 return tid; | 86 return tid; |
87 } | 87 } |
88 | 88 |
89 WifiRadioEnergyModel::WifiRadioEnergyModel () | 89 WifiRadioEnergyModel::WifiRadioEnergyModel () |
90 : m_source (0), | 90 : m_source (0), |
91 m_currentState (WifiPhy::IDLE), | 91 m_currentState (WifiPhyState::IDLE), |
92 m_lastUpdateTime (Seconds (0.0)), | 92 m_lastUpdateTime (Seconds (0.0)), |
93 m_nPendingChangeState (0) | 93 m_nPendingChangeState (0) |
94 { | 94 { |
95 NS_LOG_FUNCTION (this); | 95 NS_LOG_FUNCTION (this); |
96 m_energyDepletionCallback.Nullify (); | 96 m_energyDepletionCallback.Nullify (); |
97 // set callback for WifiPhy listener | 97 // set callback for WifiPhy listener |
98 m_listener = new WifiRadioEnergyModelPhyListener; | 98 m_listener = new WifiRadioEnergyModelPhyListener; |
99 m_listener->SetChangeStateCallback (MakeCallback (&DeviceEnergyModel::ChangeSt ate, this)); | 99 m_listener->SetChangeStateCallback (MakeCallback (&DeviceEnergyModel::ChangeSt ate, this)); |
100 // set callback for updating the tx current | 100 // set callback for updating the tx current |
101 m_listener->SetUpdateTxCurrentCallback (MakeCallback (&WifiRadioEnergyModel::S etTxCurrentFromModel, this)); | 101 m_listener->SetUpdateTxCurrentCallback (MakeCallback (&WifiRadioEnergyModel::S etTxCurrentFromModel, this)); |
102 } | 102 } |
103 | 103 |
104 WifiRadioEnergyModel::~WifiRadioEnergyModel () | 104 WifiRadioEnergyModel::~WifiRadioEnergyModel () |
105 { | 105 { |
106 NS_LOG_FUNCTION (this); | 106 NS_LOG_FUNCTION (this); |
107 m_txCurrentModel = 0; | |
107 delete m_listener; | 108 delete m_listener; |
108 } | 109 } |
109 | 110 |
110 void | 111 void |
111 WifiRadioEnergyModel::SetEnergySource (const Ptr<EnergySource> source) | 112 WifiRadioEnergyModel::SetEnergySource (const Ptr<EnergySource> source) |
112 { | 113 { |
113 NS_LOG_FUNCTION (this << source); | 114 NS_LOG_FUNCTION (this << source); |
114 NS_ASSERT (source != NULL); | 115 NS_ASSERT (source != NULL); |
115 m_source = source; | 116 m_source = source; |
116 m_switchToOffEvent.Cancel (); | 117 m_switchToOffEvent.Cancel (); |
117 Time durationToOff = GetMaximumTimeInState (m_currentState); | 118 Time durationToOff = GetMaximumTimeInState (m_currentState); |
118 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel ::ChangeState, this, WifiPhy::OFF); | 119 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel ::ChangeState, this, WifiPhyState::OFF); |
119 } | 120 } |
120 | 121 |
121 double | 122 double |
122 WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const | 123 WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const |
123 { | 124 { |
124 NS_LOG_FUNCTION (this); | 125 NS_LOG_FUNCTION (this); |
125 | 126 |
126 Time duration = Simulator::Now () - m_lastUpdateTime; | 127 Time duration = Simulator::Now () - m_lastUpdateTime; |
127 NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid | 128 NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid |
128 | 129 |
129 // energy to decrease = current * voltage * time | 130 // energy to decrease = current * voltage * time |
130 double energyToDecrease = 0.0; | 131 double energyToDecrease = 0.0; |
131 double supplyVoltage = m_source->GetSupplyVoltage (); | 132 double supplyVoltage = m_source->GetSupplyVoltage (); |
132 switch (m_currentState) | 133 switch (m_currentState) |
133 { | 134 { |
134 case WifiPhy::IDLE: | 135 case WifiPhyState::IDLE: |
135 energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage ; | 136 energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage ; |
136 break; | 137 break; |
137 case WifiPhy::CCA_BUSY: | 138 case WifiPhyState::CCA_BUSY: |
138 energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVolt age; | 139 energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVolt age; |
139 break; | 140 break; |
140 case WifiPhy::TX: | 141 case WifiPhyState::TX: |
141 energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage; | 142 energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage; |
142 break; | 143 break; |
143 case WifiPhy::RX: | 144 case WifiPhyState::RX: |
144 energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage; | 145 energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage; |
145 break; | 146 break; |
146 case WifiPhy::SWITCHING: | 147 case WifiPhyState::SWITCHING: |
147 energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVo ltage; | 148 energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVo ltage; |
148 break; | 149 break; |
149 case WifiPhy::SLEEP: | 150 case WifiPhyState::SLEEP: |
150 energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltag e; | 151 energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltag e; |
151 break; | 152 break; |
152 case WifiPhy::OFF: | 153 case WifiPhyState::OFF: |
153 energyToDecrease = 0; | 154 energyToDecrease = 0; |
154 break; | 155 break; |
155 default: | 156 default: |
156 NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state: " << m_curren tState); | 157 NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state: " << m_curren tState); |
157 } | 158 } |
158 | 159 |
159 // notify energy source | 160 // notify energy source |
160 m_source->UpdateEnergySource (); | 161 m_source->UpdateEnergySource (); |
161 | 162 |
162 return m_totalEnergyConsumption + energyToDecrease; | 163 return m_totalEnergyConsumption + energyToDecrease; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 return m_sleepCurrentA; | 240 return m_sleepCurrentA; |
240 } | 241 } |
241 | 242 |
242 void | 243 void |
243 WifiRadioEnergyModel::SetSleepCurrentA (double sleepCurrentA) | 244 WifiRadioEnergyModel::SetSleepCurrentA (double sleepCurrentA) |
244 { | 245 { |
245 NS_LOG_FUNCTION (this << sleepCurrentA); | 246 NS_LOG_FUNCTION (this << sleepCurrentA); |
246 m_sleepCurrentA = sleepCurrentA; | 247 m_sleepCurrentA = sleepCurrentA; |
247 } | 248 } |
248 | 249 |
249 WifiPhy::State | 250 WifiPhyState |
250 WifiRadioEnergyModel::GetCurrentState (void) const | 251 WifiRadioEnergyModel::GetCurrentState (void) const |
251 { | 252 { |
252 NS_LOG_FUNCTION (this); | 253 NS_LOG_FUNCTION (this); |
253 return m_currentState; | 254 return m_currentState; |
254 } | 255 } |
255 | 256 |
256 void | 257 void |
257 WifiRadioEnergyModel::SetEnergyDepletionCallback ( | 258 WifiRadioEnergyModel::SetEnergyDepletionCallback ( |
258 WifiRadioEnergyDepletionCallback callback) | 259 WifiRadioEnergyDepletionCallback callback) |
259 { | 260 { |
(...skipping 29 matching lines...) Expand all Loading... | |
289 if (m_txCurrentModel) | 290 if (m_txCurrentModel) |
290 { | 291 { |
291 m_txCurrentA = m_txCurrentModel->CalcTxCurrent (txPowerDbm); | 292 m_txCurrentA = m_txCurrentModel->CalcTxCurrent (txPowerDbm); |
292 } | 293 } |
293 } | 294 } |
294 | 295 |
295 Time | 296 Time |
296 WifiRadioEnergyModel::GetMaximumTimeInState (int state) const | 297 WifiRadioEnergyModel::GetMaximumTimeInState (int state) const |
297 { | 298 { |
298 Time remainingTime; | 299 Time remainingTime; |
299 double remainingEnergy = m_source->GetRemainingEnergy(); | 300 double remainingEnergy = m_source->GetRemainingEnergy (); |
300 double supplyVoltage = m_source->GetSupplyVoltage (); | 301 double supplyVoltage = m_source->GetSupplyVoltage (); |
301 switch (state) | 302 switch (state) |
302 { | 303 { |
303 case WifiPhy::IDLE: | 304 case WifiPhyState::IDLE: |
304 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_idleCurrentA * su pplyVoltage))); | 305 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_idleCurrentA * supplyVoltage)))); |
305 break; | 306 break; |
306 case WifiPhy::CCA_BUSY: | 307 case WifiPhyState::CCA_BUSY: |
307 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_ccaBusyCurrentA * supplyVoltage))); | 308 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_ccaBusyCurrentA * supplyVoltage)))); |
308 break; | 309 break; |
309 case WifiPhy::TX: | 310 case WifiPhyState::TX: |
310 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_txCurrentA * supp lyVoltage))); | 311 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_txCurrentA * supplyVoltage)))); |
311 break; | 312 break; |
312 case WifiPhy::RX: | 313 case WifiPhyState::RX: |
313 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_rxCurrentA * supp lyVoltage))); | 314 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_rxCurrentA * supplyVoltage)))); |
314 break; | 315 break; |
315 case WifiPhy::SWITCHING: | 316 case WifiPhyState::SWITCHING: |
316 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_switchingCurrentA * supplyVoltage))); | 317 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_switchingCurrentA * supplyVoltage)))); |
317 break; | 318 break; |
318 case WifiPhy::SLEEP: | 319 case WifiPhyState::SLEEP: |
319 remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_sleepCurrentA * s upplyVoltage))); | 320 remainingTime = NanoSeconds (static_cast<uint64_t> (1e9 * (remainingEnergy / (m_sleepCurrentA * supplyVoltage)))); |
S. Deronne
2018/05/11 14:46:06
indeed, if it expects uint64_t, I think we should
| |
320 break; | 321 break; |
321 default: | 322 default: |
322 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << state); | 323 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << state); |
323 } | 324 } |
324 return remainingTime; | 325 return remainingTime; |
325 } | 326 } |
326 | 327 |
327 void | 328 void |
328 WifiRadioEnergyModel::ChangeState (int newState) | 329 WifiRadioEnergyModel::ChangeState (int newState) |
329 { | 330 { |
330 NS_LOG_FUNCTION (this << newState); | 331 NS_LOG_FUNCTION (this << newState); |
331 | 332 |
332 m_nPendingChangeState++; | 333 m_nPendingChangeState++; |
333 | 334 |
334 if (m_nPendingChangeState > 1 && newState == WifiPhy::OFF) | 335 if (m_nPendingChangeState > 1 && newState == WifiPhyState::OFF) |
335 { | 336 { |
336 SetWifiRadioState ((WifiPhy::State) newState); | 337 SetWifiRadioState ((WifiPhyState) newState); |
337 m_nPendingChangeState--; | 338 m_nPendingChangeState--; |
338 return; | 339 return; |
339 } | 340 } |
340 | 341 |
341 if (newState != WifiPhy::OFF) | 342 if (newState != WifiPhyState::OFF) |
342 { | 343 { |
343 m_switchToOffEvent.Cancel (); | 344 m_switchToOffEvent.Cancel (); |
344 Time durationToOff = GetMaximumTimeInState (newState); | 345 Time durationToOff = GetMaximumTimeInState (newState); |
345 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyM odel::ChangeState, this, WifiPhy::OFF); | 346 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyM odel::ChangeState, this, WifiPhyState::OFF); |
346 } | 347 } |
347 | 348 |
348 Time duration = Simulator::Now () - m_lastUpdateTime; | 349 Time duration = Simulator::Now () - m_lastUpdateTime; |
349 NS_ASSERT (duration.IsPositive ()); // check if duration is valid | 350 NS_ASSERT (duration.IsPositive ()); // check if duration is valid |
350 | 351 |
351 // energy to decrease = current * voltage * time | 352 // energy to decrease = current * voltage * time |
352 double energyToDecrease = 0.0; | 353 double energyToDecrease = 0.0; |
353 double supplyVoltage = m_source->GetSupplyVoltage (); | 354 double supplyVoltage = m_source->GetSupplyVoltage (); |
354 switch (m_currentState) | 355 switch (m_currentState) |
355 { | 356 { |
356 case WifiPhy::IDLE: | 357 case WifiPhyState::IDLE: |
357 energyToDecrease = (duration.GetNanoSeconds () * m_idleCurrentA * supplyVo ltage) / 1e9; | 358 energyToDecrease = (duration.GetNanoSeconds () * m_idleCurrentA * supplyVo ltage) / 1e9; |
358 break; | 359 break; |
359 case WifiPhy::CCA_BUSY: | 360 case WifiPhyState::CCA_BUSY: |
360 energyToDecrease = (duration.GetNanoSeconds () * m_ccaBusyCurrentA * suppl yVoltage) / 1e9; | 361 energyToDecrease = (duration.GetNanoSeconds () * m_ccaBusyCurrentA * suppl yVoltage) / 1e9; |
361 break; | 362 break; |
362 case WifiPhy::TX: | 363 case WifiPhyState::TX: |
363 energyToDecrease = (duration.GetNanoSeconds () * m_txCurrentA * supplyVolt age) / 1e9; | 364 energyToDecrease = (duration.GetNanoSeconds () * m_txCurrentA * supplyVolt age) / 1e9; |
364 break; | 365 break; |
365 case WifiPhy::RX: | 366 case WifiPhyState::RX: |
366 energyToDecrease = (duration.GetNanoSeconds () * m_rxCurrentA * supplyVolt age) / 1e9; | 367 energyToDecrease = (duration.GetNanoSeconds () * m_rxCurrentA * supplyVolt age) / 1e9; |
367 break; | 368 break; |
368 case WifiPhy::SWITCHING: | 369 case WifiPhyState::SWITCHING: |
369 energyToDecrease = (duration.GetNanoSeconds () * m_switchingCurrentA * sup plyVoltage) / 1e9; | 370 energyToDecrease = (duration.GetNanoSeconds () * m_switchingCurrentA * sup plyVoltage) / 1e9; |
370 break; | 371 break; |
371 case WifiPhy::SLEEP: | 372 case WifiPhyState::SLEEP: |
372 energyToDecrease = (duration.GetNanoSeconds () * m_sleepCurrentA * supplyV oltage) / 1e9; | 373 energyToDecrease = (duration.GetNanoSeconds () * m_sleepCurrentA * supplyV oltage) / 1e9; |
373 break; | 374 break; |
374 case WifiPhy::OFF: | 375 case WifiPhyState::OFF: |
375 energyToDecrease = 0.0; | 376 energyToDecrease = 0.0; |
376 break; | 377 break; |
377 default: | 378 default: |
378 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << m_curren tState); | 379 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << m_curren tState); |
379 } | 380 } |
380 | 381 |
381 // update total energy consumption | 382 // update total energy consumption |
382 m_totalEnergyConsumption += energyToDecrease; | 383 m_totalEnergyConsumption += energyToDecrease; |
383 NS_ASSERT (m_totalEnergyConsumption <= m_source->GetInitialEnergy ()); | 384 NS_ASSERT (m_totalEnergyConsumption <= m_source->GetInitialEnergy ()); |
384 | 385 |
385 // update last update time stamp | 386 // update last update time stamp |
386 m_lastUpdateTime = Simulator::Now (); | 387 m_lastUpdateTime = Simulator::Now (); |
387 | 388 |
388 // notify energy source | 389 // notify energy source |
389 m_source->UpdateEnergySource (); | 390 m_source->UpdateEnergySource (); |
390 | 391 |
391 // in case the energy source is found to be depleted during the last update, a callback might be | 392 // in case the energy source is found to be depleted during the last update, a callback might be |
392 // invoked that might cause a change in the Wifi PHY state (e.g., the PHY is p ut into SLEEP mode). | 393 // invoked that might cause a change in the Wifi PHY state (e.g., the PHY is p ut into SLEEP mode). |
393 // This in turn causes a new call to this member function, with the consequenc e that the previous | 394 // This in turn causes a new call to this member function, with the consequenc e that the previous |
394 // instance is resumed after the termination of the new instance. In particula r, the state set | 395 // instance is resumed after the termination of the new instance. In particula r, the state set |
395 // by the previous instance is erroneously the final state stored in m_current State. The check below | 396 // by the previous instance is erroneously the final state stored in m_current State. The check below |
396 // ensures that previous instances do not change m_currentState. | 397 // ensures that previous instances do not change m_currentState. |
397 | 398 |
398 if (m_nPendingChangeState <= 1 && m_currentState != WifiPhy::OFF) | 399 if (m_nPendingChangeState <= 1 && m_currentState != WifiPhyState::OFF) |
399 { | 400 { |
400 // update current state & last update time stamp | 401 // update current state & last update time stamp |
401 SetWifiRadioState ((WifiPhy::State) newState); | 402 SetWifiRadioState ((WifiPhyState) newState); |
402 | 403 |
403 // some debug message | 404 // some debug message |
404 NS_LOG_DEBUG ("WifiRadioEnergyModel:Total energy consumption is " << | 405 NS_LOG_DEBUG ("WifiRadioEnergyModel:Total energy consumption is " << |
405 m_totalEnergyConsumption << "J"); | 406 m_totalEnergyConsumption << "J"); |
406 } | 407 } |
407 | 408 |
408 m_nPendingChangeState--; | 409 m_nPendingChangeState--; |
409 } | 410 } |
410 | 411 |
411 void | 412 void |
(...skipping 18 matching lines...) Expand all Loading... | |
430 { | 431 { |
431 m_energyRechargedCallback (); | 432 m_energyRechargedCallback (); |
432 } | 433 } |
433 } | 434 } |
434 | 435 |
435 void | 436 void |
436 WifiRadioEnergyModel::HandleEnergyChanged (void) | 437 WifiRadioEnergyModel::HandleEnergyChanged (void) |
437 { | 438 { |
438 NS_LOG_FUNCTION (this); | 439 NS_LOG_FUNCTION (this); |
439 NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is changed!"); | 440 NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is changed!"); |
440 if (m_currentState != WifiPhy::OFF) | 441 if (m_currentState != WifiPhyState::OFF) |
441 { | 442 { |
442 m_switchToOffEvent.Cancel (); | 443 m_switchToOffEvent.Cancel (); |
443 Time durationToOff = GetMaximumTimeInState (m_currentState); | 444 Time durationToOff = GetMaximumTimeInState (m_currentState); |
444 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyM odel::ChangeState, this, WifiPhy::OFF); | 445 m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyM odel::ChangeState, this, WifiPhyState::OFF); |
445 } | 446 } |
446 } | 447 } |
447 | 448 |
448 WifiRadioEnergyModelPhyListener * | 449 WifiRadioEnergyModelPhyListener * |
449 WifiRadioEnergyModel::GetPhyListener (void) | 450 WifiRadioEnergyModel::GetPhyListener (void) |
450 { | 451 { |
451 NS_LOG_FUNCTION (this); | 452 NS_LOG_FUNCTION (this); |
452 return m_listener; | 453 return m_listener; |
453 } | 454 } |
454 | 455 |
455 /* | 456 /* |
456 * Private functions start here. | 457 * Private functions start here. |
457 */ | 458 */ |
458 | 459 |
459 void | 460 void |
460 WifiRadioEnergyModel::DoDispose (void) | 461 WifiRadioEnergyModel::DoDispose (void) |
461 { | 462 { |
462 NS_LOG_FUNCTION (this); | 463 NS_LOG_FUNCTION (this); |
463 m_source = NULL; | 464 m_source = NULL; |
464 m_energyDepletionCallback.Nullify (); | 465 m_energyDepletionCallback.Nullify (); |
465 } | 466 } |
466 | 467 |
467 double | 468 double |
468 WifiRadioEnergyModel::DoGetCurrentA (void) const | 469 WifiRadioEnergyModel::DoGetCurrentA (void) const |
469 { | 470 { |
470 NS_LOG_FUNCTION (this); | |
S. Deronne
2018/02/18 14:52:57
not needed
| |
471 switch (m_currentState) | 471 switch (m_currentState) |
472 { | 472 { |
473 case WifiPhy::IDLE: | 473 case WifiPhyState::IDLE: |
474 return m_idleCurrentA; | 474 return m_idleCurrentA; |
475 case WifiPhy::CCA_BUSY: | 475 case WifiPhyState::CCA_BUSY: |
476 return m_ccaBusyCurrentA; | 476 return m_ccaBusyCurrentA; |
477 case WifiPhy::TX: | 477 case WifiPhyState::TX: |
478 return m_txCurrentA; | 478 return m_txCurrentA; |
479 case WifiPhy::RX: | 479 case WifiPhyState::RX: |
480 return m_rxCurrentA; | 480 return m_rxCurrentA; |
481 case WifiPhy::SWITCHING: | 481 case WifiPhyState::SWITCHING: |
482 return m_switchingCurrentA; | 482 return m_switchingCurrentA; |
483 case WifiPhy::SLEEP: | 483 case WifiPhyState::SLEEP: |
484 return m_sleepCurrentA; | 484 return m_sleepCurrentA; |
485 case WifiPhy::OFF: | 485 case WifiPhyState::OFF: |
486 return 0.0; | 486 return 0.0; |
487 default: | 487 default: |
488 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << m_curren tState); | 488 NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << m_curren tState); |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 void | 492 void |
493 WifiRadioEnergyModel::SetWifiRadioState (const WifiPhy::State state) | 493 WifiRadioEnergyModel::SetWifiRadioState (const WifiPhyState state) |
494 { | 494 { |
495 NS_LOG_FUNCTION (this << state); | 495 NS_LOG_FUNCTION (this << state); |
496 m_currentState = state; | 496 m_currentState = state; |
497 std::string stateName; | 497 std::string stateName; |
498 switch (state) | 498 switch (state) |
499 { | 499 { |
500 case WifiPhy::IDLE: | 500 case WifiPhyState::IDLE: |
501 stateName = "IDLE"; | 501 stateName = "IDLE"; |
502 break; | 502 break; |
503 case WifiPhy::CCA_BUSY: | 503 case WifiPhyState::CCA_BUSY: |
504 stateName = "CCA_BUSY"; | 504 stateName = "CCA_BUSY"; |
505 break; | 505 break; |
506 case WifiPhy::TX: | 506 case WifiPhyState::TX: |
507 stateName = "TX"; | 507 stateName = "TX"; |
508 break; | 508 break; |
509 case WifiPhy::RX: | 509 case WifiPhyState::RX: |
510 stateName = "RX"; | 510 stateName = "RX"; |
511 break; | 511 break; |
512 case WifiPhy::SWITCHING: | 512 case WifiPhyState::SWITCHING: |
513 stateName = "SWITCHING"; | 513 stateName = "SWITCHING"; |
514 break; | 514 break; |
515 case WifiPhy::SLEEP: | 515 case WifiPhyState::SLEEP: |
516 stateName = "SLEEP"; | 516 stateName = "SLEEP"; |
517 break; | 517 break; |
518 case WifiPhy::OFF: | 518 case WifiPhyState::OFF: |
519 stateName = "OFF"; | 519 stateName = "OFF"; |
520 break; | 520 break; |
521 } | 521 } |
522 NS_LOG_DEBUG ("WifiRadioEnergyModel:Switching to state: " << stateName << | 522 NS_LOG_DEBUG ("WifiRadioEnergyModel:Switching to state: " << stateName << |
523 " at time = " << Simulator::Now ()); | 523 " at time = " << Simulator::Now ()); |
524 } | 524 } |
525 | 525 |
526 // -------------------------------------------------------------------------- // | 526 // -------------------------------------------------------------------------- // |
527 | 527 |
528 WifiRadioEnergyModelPhyListener::WifiRadioEnergyModelPhyListener () | 528 WifiRadioEnergyModelPhyListener::WifiRadioEnergyModelPhyListener () |
(...skipping 25 matching lines...) Expand all Loading... | |
554 } | 554 } |
555 | 555 |
556 void | 556 void |
557 WifiRadioEnergyModelPhyListener::NotifyRxStart (Time duration) | 557 WifiRadioEnergyModelPhyListener::NotifyRxStart (Time duration) |
558 { | 558 { |
559 NS_LOG_FUNCTION (this << duration); | 559 NS_LOG_FUNCTION (this << duration); |
560 if (m_changeStateCallback.IsNull ()) | 560 if (m_changeStateCallback.IsNull ()) |
561 { | 561 { |
562 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 562 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
563 } | 563 } |
564 m_changeStateCallback (WifiPhy::RX); | 564 m_changeStateCallback (WifiPhyState::RX); |
565 m_switchToIdleEvent.Cancel (); | 565 m_switchToIdleEvent.Cancel (); |
566 } | 566 } |
567 | 567 |
568 void | 568 void |
569 WifiRadioEnergyModelPhyListener::NotifyRxEndOk (void) | 569 WifiRadioEnergyModelPhyListener::NotifyRxEndOk (void) |
570 { | 570 { |
571 NS_LOG_FUNCTION (this); | 571 NS_LOG_FUNCTION (this); |
572 if (m_changeStateCallback.IsNull ()) | 572 if (m_changeStateCallback.IsNull ()) |
573 { | 573 { |
574 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 574 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
575 } | 575 } |
576 m_changeStateCallback (WifiPhy::IDLE); | 576 m_changeStateCallback (WifiPhyState::IDLE); |
577 } | 577 } |
578 | 578 |
579 void | 579 void |
580 WifiRadioEnergyModelPhyListener::NotifyRxEndError (void) | 580 WifiRadioEnergyModelPhyListener::NotifyRxEndError (void) |
581 { | 581 { |
582 NS_LOG_FUNCTION (this); | 582 NS_LOG_FUNCTION (this); |
583 if (m_changeStateCallback.IsNull ()) | 583 if (m_changeStateCallback.IsNull ()) |
584 { | 584 { |
585 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 585 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
586 } | 586 } |
587 m_changeStateCallback (WifiPhy::IDLE); | 587 m_changeStateCallback (WifiPhyState::IDLE); |
588 } | 588 } |
589 | 589 |
590 void | 590 void |
591 WifiRadioEnergyModelPhyListener::NotifyTxStart (Time duration, double txPowerDbm ) | 591 WifiRadioEnergyModelPhyListener::NotifyTxStart (Time duration, double txPowerDbm ) |
592 { | 592 { |
593 NS_LOG_FUNCTION (this << duration << txPowerDbm); | 593 NS_LOG_FUNCTION (this << duration << txPowerDbm); |
594 if (m_updateTxCurrentCallback.IsNull ()) | 594 if (m_updateTxCurrentCallback.IsNull ()) |
595 { | 595 { |
596 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Update tx current callbac k not set!"); | 596 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Update tx current callbac k not set!"); |
597 } | 597 } |
598 m_updateTxCurrentCallback (txPowerDbm); | 598 m_updateTxCurrentCallback (txPowerDbm); |
599 if (m_changeStateCallback.IsNull ()) | 599 if (m_changeStateCallback.IsNull ()) |
600 { | 600 { |
601 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 601 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
602 } | 602 } |
603 m_changeStateCallback (WifiPhy::TX); | 603 m_changeStateCallback (WifiPhyState::TX); |
604 // schedule changing state back to IDLE after TX duration | 604 // schedule changing state back to IDLE after TX duration |
605 m_switchToIdleEvent.Cancel (); | 605 m_switchToIdleEvent.Cancel (); |
606 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); | 606 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); |
607 } | 607 } |
608 | 608 |
609 void | 609 void |
610 WifiRadioEnergyModelPhyListener::NotifyMaybeCcaBusyStart (Time duration) | 610 WifiRadioEnergyModelPhyListener::NotifyMaybeCcaBusyStart (Time duration) |
611 { | 611 { |
612 NS_LOG_FUNCTION (this << duration); | 612 NS_LOG_FUNCTION (this << duration); |
613 if (m_changeStateCallback.IsNull ()) | 613 if (m_changeStateCallback.IsNull ()) |
614 { | 614 { |
615 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 615 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
616 } | 616 } |
617 m_changeStateCallback (WifiPhy::CCA_BUSY); | 617 m_changeStateCallback (WifiPhyState::CCA_BUSY); |
618 // schedule changing state back to IDLE after CCA_BUSY duration | 618 // schedule changing state back to IDLE after CCA_BUSY duration |
619 m_switchToIdleEvent.Cancel (); | 619 m_switchToIdleEvent.Cancel (); |
620 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); | 620 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); |
621 } | 621 } |
622 | 622 |
623 void | 623 void |
624 WifiRadioEnergyModelPhyListener::NotifySwitchingStart (Time duration) | 624 WifiRadioEnergyModelPhyListener::NotifySwitchingStart (Time duration) |
625 { | 625 { |
626 NS_LOG_FUNCTION (this << duration); | 626 NS_LOG_FUNCTION (this << duration); |
627 if (m_changeStateCallback.IsNull ()) | 627 if (m_changeStateCallback.IsNull ()) |
628 { | 628 { |
629 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 629 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
630 } | 630 } |
631 m_changeStateCallback (WifiPhy::SWITCHING); | 631 m_changeStateCallback (WifiPhyState::SWITCHING); |
632 // schedule changing state back to IDLE after CCA_BUSY duration | 632 // schedule changing state back to IDLE after CCA_BUSY duration |
633 m_switchToIdleEvent.Cancel (); | 633 m_switchToIdleEvent.Cancel (); |
634 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); | 634 m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyL istener::SwitchToIdle, this); |
635 } | 635 } |
636 | 636 |
637 void | 637 void |
638 WifiRadioEnergyModelPhyListener::NotifySleep (void) | 638 WifiRadioEnergyModelPhyListener::NotifySleep (void) |
639 { | 639 { |
640 NS_LOG_FUNCTION (this); | 640 NS_LOG_FUNCTION (this); |
641 if (m_changeStateCallback.IsNull ()) | 641 if (m_changeStateCallback.IsNull ()) |
642 { | 642 { |
643 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 643 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
644 } | 644 } |
645 m_changeStateCallback (WifiPhy::SLEEP); | 645 m_changeStateCallback (WifiPhyState::SLEEP); |
646 m_switchToIdleEvent.Cancel (); | 646 m_switchToIdleEvent.Cancel (); |
647 } | 647 } |
648 | 648 |
649 void | 649 void |
650 WifiRadioEnergyModelPhyListener::NotifyWakeup(void) | 650 WifiRadioEnergyModelPhyListener::NotifyWakeup (void) |
651 { | 651 { |
652 NS_LOG_FUNCTION (this); | 652 NS_LOG_FUNCTION (this); |
653 if (m_changeStateCallback.IsNull ()) | 653 if (m_changeStateCallback.IsNull ()) |
654 { | 654 { |
655 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 655 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
656 } | 656 } |
657 m_changeStateCallback (WifiPhy::IDLE); | 657 m_changeStateCallback (WifiPhyState::IDLE); |
658 } | 658 } |
659 | 659 |
660 void | 660 void |
661 WifiRadioEnergyModelPhyListener::NotifyOff (void) | 661 WifiRadioEnergyModelPhyListener::NotifyOff (void) |
662 { | 662 { |
663 NS_LOG_FUNCTION (this); | 663 NS_LOG_FUNCTION (this); |
664 if (m_changeStateCallback.IsNull ()) | 664 if (m_changeStateCallback.IsNull ()) |
665 { | 665 { |
666 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 666 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
667 } | 667 } |
668 m_changeStateCallback (WifiPhy::OFF); | 668 m_changeStateCallback (WifiPhyState::OFF); |
669 m_switchToIdleEvent.Cancel (); | 669 m_switchToIdleEvent.Cancel (); |
670 } | 670 } |
671 | 671 |
672 void | 672 void |
673 WifiRadioEnergyModelPhyListener::NotifyOn (void) | |
674 { | |
675 NS_LOG_FUNCTION (this); | |
676 if (m_changeStateCallback.IsNull ()) | |
677 { | |
678 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | |
679 } | |
680 m_changeStateCallback (WifiPhyState::IDLE); | |
681 } | |
682 | |
683 void | |
673 WifiRadioEnergyModelPhyListener::SwitchToIdle (void) | 684 WifiRadioEnergyModelPhyListener::SwitchToIdle (void) |
674 { | 685 { |
675 NS_LOG_FUNCTION (this); | 686 NS_LOG_FUNCTION (this); |
676 if (m_changeStateCallback.IsNull ()) | 687 if (m_changeStateCallback.IsNull ()) |
677 { | 688 { |
678 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); | 689 NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
679 } | 690 } |
680 m_changeStateCallback (WifiPhy::IDLE); | 691 m_changeStateCallback (WifiPhyState::IDLE); |
681 } | 692 } |
682 | 693 |
683 } // namespace ns3 | 694 } // namespace ns3 |
LEFT | RIGHT |