avoid decrementing by too many backoff slots
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 19 Nov 2007 14:22:45 +0100
changeset 2142 63c08450a4da
parent 2141 bb6670fc71cb
child 2143 c3c874d850a1
avoid decrementing by too many backoff slots
src/devices/wifi/dcf-manager.cc
--- a/src/devices/wifi/dcf-manager.cc	Mon Nov 19 14:20:19 2007 +0100
+++ b/src/devices/wifi/dcf-manager.cc	Mon Nov 19 14:22:45 2007 +0100
@@ -57,8 +57,7 @@
 void 
 DcfState::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
 {
-  uint32_t n = std::min (nSlots, m_backoffSlots);
-  m_backoffSlots -= n;
+  m_backoffSlots -= nSlots;
   m_backoffStart = backoffUpdateBound;
   MY_DEBUG ("update slots="<<nSlots<<" slots, backoff="<<m_backoffSlots);
 }
@@ -229,7 +228,8 @@
               if (otherState->NeedsAccess () &&
                   GetBackoffEndFor (otherState) <= Simulator::Now ())
                 {
-                  MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision.");
+                  MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision. slots=" << 
+                            otherState->GetBackoffSlots ());
                   /**
                    * all other dcfs with a lower priority whose backoff
                    * has expired and which needed access to the medium
@@ -334,9 +334,10 @@
            */
           if (nIntSlots >= state->GetAifsn ())
             {
-              MY_DEBUG ("dcf " << k << " dec backoff slots=" << nIntSlots);
-              Time backoffUpdateBound = backoffStart + Scalar (nIntSlots) * m_slotTime;
-              state->UpdateBackoffSlotsNow (nIntSlots, backoffUpdateBound);
+              uint32_t n = std::min (nIntSlots, state->GetBackoffSlots ());
+              MY_DEBUG ("dcf " << k << " dec backoff slots=" << n);
+              Time backoffUpdateBound = backoffStart + Scalar (n) * m_slotTime;
+              state->UpdateBackoffSlotsNow (n, backoffUpdateBound);
             }
         }
     }