--- a/RELEASE_NOTES Mon Jan 29 21:29:02 2018 -0600
+++ b/RELEASE_NOTES Tue Oct 24 22:04:13 2017 +0200
@@ -38,6 +38,7 @@
- Bug 2764 - wifi: WifiSpectrumModelId doesn't distinguish 11ax from legacy
- Bug 2766 - core: Modify logging for int64x64 to avoid stack overflow
- Bug 2768 - lte: LteUeNetDevice has a null MAC address
+- Bug 2807 - energy: GetTotalEnergyConsumption is not updated correctly
- Bug 2820 - wifi: segmentation fault when Rrpaa wifi manager is used
- Bug 2824 - ICMP opcode fr fragment timeout drop is wrong
- Bug 2828 - OLSR simple P2P example produces wrong results
--- a/src/energy/model/simple-device-energy-model.cc Mon Jan 29 21:29:02 2018 -0600
+++ b/src/energy/model/simple-device-energy-model.cc Tue Oct 24 22:04:13 2017 +0200
@@ -85,7 +85,15 @@
SimpleDeviceEnergyModel::GetTotalEnergyConsumption (void) const
{
NS_LOG_FUNCTION (this);
- return m_totalEnergyConsumption;
+ Time duration = Simulator::Now () - m_lastUpdateTime;
+
+ double energyToDecrease = 0.0;
+ double supplyVoltage = m_source->GetSupplyVoltage ();
+ energyToDecrease = duration.GetSeconds () * m_actualCurrentA * supplyVoltage;
+
+ m_source->UpdateEnergySource ();
+
+ return m_totalEnergyConsumption + energyToDecrease;
}
void
--- a/src/wifi/model/wifi-radio-energy-model.cc Mon Jan 29 21:29:02 2018 -0600
+++ b/src/wifi/model/wifi-radio-energy-model.cc Tue Oct 24 22:04:13 2017 +0200
@@ -119,7 +119,41 @@
WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const
{
NS_LOG_FUNCTION (this);
- return m_totalEnergyConsumption;
+
+ Time duration = Simulator::Now () - m_lastUpdateTime;
+ NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
+
+ // energy to decrease = current * voltage * time
+ double energyToDecrease = 0.0;
+ double supplyVoltage = m_source->GetSupplyVoltage ();
+ switch (m_currentState)
+ {
+ case WifiPhy::IDLE:
+ energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage;
+ break;
+ case WifiPhy::CCA_BUSY:
+ energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVoltage;
+ break;
+ case WifiPhy::TX:
+ energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage;
+ break;
+ case WifiPhy::RX:
+ energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage;
+ break;
+ case WifiPhy::SWITCHING:
+ energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVoltage;
+ break;
+ case WifiPhy::SLEEP:
+ energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltage;
+ break;
+ default:
+ NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state: " << m_currentState);
+ }
+
+ // notify energy source
+ m_source->UpdateEnergySource ();
+
+ return m_totalEnergyConsumption + energyToDecrease;
}
double