wifi: (fixes #2820) Correct power levels in rrpaa wifi manager
authorMatias Richart <mrichart@fing.edu.uy>
Wed, 27 Dec 2017 09:21:58 +0100
changeset 13233 d1ed8ca3b295
parent 13232 896e8dc8bd93
child 13234 3c57aff5d965
wifi: (fixes #2820) Correct power levels in rrpaa wifi manager
RELEASE_NOTES
src/wifi/model/rrpaa-wifi-manager.cc
src/wifi/model/rrpaa-wifi-manager.h
--- a/RELEASE_NOTES	Sat Dec 23 20:21:45 2017 +0100
+++ b/RELEASE_NOTES	Wed Dec 27 09:21:58 2017 +0100
@@ -34,7 +34,8 @@
 - Bug 2505 - network:  Avoid asserts in Header/Trailer deserialization
 - Bug 2653 - tcp: Avoid saving smaller TS in case of packet reordering
 - Bug 2764 - wifi: WifiSpectrumModelId doesn't distinguish 11ax from legacy
-- Bug 2766 - core:  Modify logging for int64x64 to avoid stack overflow
+- Bug 2766 - core: Modify logging for int64x64 to avoid stack overflow
+- 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
 - Bug 2827 - wifi: Active scanning not working with 802.11n/ac/ax
--- a/src/wifi/model/rrpaa-wifi-manager.cc	Sat Dec 23 20:21:45 2017 +0100
+++ b/src/wifi/model/rrpaa-wifi-manager.cc	Wed Dec 27 09:21:58 2017 +0100
@@ -154,9 +154,9 @@
 RrpaaWifiManager::SetupPhy (const Ptr<WifiPhy> phy)
 {
   NS_LOG_FUNCTION (this);
-  m_minPower = phy->GetTxPowerStart ();
-  m_maxPower = phy->GetTxPowerEnd ();
-  m_nPower = m_maxPower - m_minPower + 1;
+  m_nPowerLevels = phy->GetNTxPower ();
+  m_maxPowerLevel = m_nPowerLevels  - 1;
+  m_minPowerLevel = 0;
   uint8_t nModes = phy->GetNModes ();
   for (uint8_t i = 0; i < nModes; i++)
     {
@@ -246,20 +246,20 @@
       //Initialize at minimal rate and maximal power.
       station->m_prevRateIndex = 0;
       station->m_rateIndex = 0;
-      station->m_prevPowerLevel = m_maxPower;
-      station->m_powerLevel = m_maxPower;
+      station->m_prevPowerLevel = m_maxPowerLevel;
+      station->m_powerLevel = m_maxPowerLevel;
       WifiMode mode = GetSupported (station, 0);
       uint8_t channelWidth = GetChannelWidth (station);
       DataRate rate = DataRate (mode.GetDataRate (channelWidth));
-      double power = GetPhy ()->GetPowerDbm (m_maxPower);
+      double power = GetPhy ()->GetPowerDbm (station->m_powerLevel);
       m_rateChange (rate, rate, station->m_state->m_address);
       m_powerChange (power, power, station->m_state->m_address);
 
-      station->m_pdTable = RrpaaProbabilitiesTable (station->m_nRate, std::vector<double> (m_nPower));
+      station->m_pdTable = RrpaaProbabilitiesTable (station->m_nRate, std::vector<double> (m_nPowerLevels));
       NS_LOG_DEBUG ("Initializing pdTable");
       for (uint8_t i = 0; i < station->m_nRate; i++)
         {
-          for (uint8_t j = 0; j < m_nPower; j++)
+          for (uint8_t j = 0; j < m_nPowerLevels; j++)
             {
               station->m_pdTable[i][j] = 1;
             }
@@ -470,7 +470,7 @@
   NS_LOG_DEBUG ("Worst loss prob= " << wploss);
   if (bploss >= thresholds.m_mtl)
     {
-      if (station->m_powerLevel < m_maxPower)
+      if (station->m_powerLevel < m_maxPowerLevel)
         {
           NS_LOG_DEBUG ("bploss >= MTL and power < maxPower => Increase Power");
           station->m_pdTable[station->m_rateIndex][station->m_powerLevel] /= m_gamma;
@@ -505,7 +505,7 @@
                 {
                   station->m_pdTable[i][station->m_powerLevel] = 1;
                 }
-              NS_LOG_DEBUG ("pdTable[" << i << "][" << station->m_powerLevel << "] = " << station->m_pdTable[i][station->m_powerLevel]);
+              NS_LOG_DEBUG ("pdTable[" << i << "][" << (int)station->m_powerLevel << "] = " << station->m_pdTable[i][station->m_powerLevel]);
             }
           double rand = m_uniformRandomVariable->GetValue (0,1);
           if (rand < station->m_pdTable[station->m_rateIndex + 1][station->m_powerLevel])
@@ -514,12 +514,12 @@
               station->m_rateIndex++;
             }
         }
-      else if (station->m_powerLevel > m_minPower)
+      else if (station->m_powerLevel > m_minPowerLevel)
         {
           NS_LOG_DEBUG ("wploss <= ORI and rate = maxRate => Probabilistic Power Decrease");
 
           // Recalculate probabilities of higher powers.
-          for (uint32_t i = m_maxPower; i > station->m_powerLevel; i--)
+          for (uint32_t i = m_maxPowerLevel; i > station->m_powerLevel; i--)
             {
               station->m_pdTable[station->m_rateIndex][i] *= m_delta;
               if (station->m_pdTable[station->m_rateIndex][i] > 1)
@@ -539,12 +539,12 @@
     }
   else if (bploss > thresholds.m_ori && wploss < thresholds.m_mtl)
     {
-      if (station->m_powerLevel > m_minPower)
+      if (station->m_powerLevel > m_minPowerLevel)
         {
-          NS_LOG_DEBUG ("loss between ORI and MTL and power > minPower => Probabilistic Power Decrease");
+          NS_LOG_DEBUG ("loss between ORI and MTL and power > minPowerLevel => Probabilistic Power Decrease");
 
           // Recalculate probabilities of higher powers.
-          for (uint32_t i = m_maxPower; i >= station->m_powerLevel; i--)
+          for (uint32_t i = m_maxPowerLevel; i >= station->m_powerLevel; i--)
             {
               station->m_pdTable[station->m_rateIndex][i] *= m_delta;
               if (station->m_pdTable[station->m_rateIndex][i] > 1)
--- a/src/wifi/model/rrpaa-wifi-manager.h	Sat Dec 23 20:21:45 2017 +0100
+++ b/src/wifi/model/rrpaa-wifi-manager.h	Wed Dec 27 09:21:58 2017 +0100
@@ -218,9 +218,9 @@
    * Differently form rate, power levels do not depend on the remote station.
    * The levels depend only on the physical layer of the device.
    */
-  uint32_t m_minPower;     //!< Minimal power level.
-  uint32_t m_maxPower;     //!< Maximal power level.
-  uint32_t m_nPower;       //!< Number of power levels.
+  uint32_t m_minPowerLevel;     //!< Minimal power level.
+  uint32_t m_maxPowerLevel;     //!< Maximal power level.
+  uint32_t m_nPowerLevels;      //!< Number of power levels.
 
   /**
    * The trace source fired when the transmission power change