From dada8dc1db2e591100ae4c8f8438b700e97e22e0 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 14 Nov 2007 13:50:19 +0100 Subject: [PATCH] improve debugging output. introduce GetBackoffStartFor and GetBackoffEndFor --- src/devices/wifi/dcf-manager.cc | 97 ++++++++++++++++++--------------- src/devices/wifi/dcf-manager.h | 2 + 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 74fd21605..1c8fa8ddb 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -10,6 +10,9 @@ NS_LOG_COMPONENT_DEFINE ("DcfManager"); +#define MY_DEBUG(x) \ + NS_LOG_DEBUG (Simulator::Now () << " " x) + namespace ns3 { /**************************************************************** @@ -185,7 +188,7 @@ DcfManager::RequestAccess (DcfState *state) /* we don't need to do anything because we have an access * timer which will expire soon. */ - NS_LOG_DEBUG ("access timer running. will be notified"); + MY_DEBUG ("access timer running. will be notified"); return; } /** @@ -196,7 +199,7 @@ DcfManager::RequestAccess (DcfState *state) if (state->GetBackoffSlots () == 0 && IsBusy ()) { - NS_LOG_DEBUG ("medium is busy: collision"); + MY_DEBUG ("medium is busy: collision"); /* someone else has accessed the medium. * generate a backoff. */ @@ -210,26 +213,30 @@ DcfManager::RequestAccess (DcfState *state) void DcfManager::DoGrantAccess (void) { + Time accessGrantStart = GetAccessGrantStart (); + uint32_t k = 0; for (States::const_iterator i = m_states.begin (); i != m_states.end (); k++) { DcfState *state = *i; - if (state->GetBackoffSlots () == 0 && state->NeedsAccess ()) + if (state->GetBackoffSlots () == 0 && state->NeedsAccess () && + GetBackoffStartFor (state) < Simulator::Now ()) { /** * This is the first dcf we find with an expired backoff and which * needs access to the medium. i.e., it has data to send. */ - NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired. access granted."); + MY_DEBUG ("dcf " << k << " needs access. backoff expired. access granted."); state->NotifyAccessGranted (); i++; // go to the next item in the list. k++; for (States::const_iterator j = i; j != m_states.end (); j++, k++) { DcfState *state = *j; - if (state->GetBackoffSlots () == 0 && state->NeedsAccess ()) + if (state->GetBackoffSlots () == 0 && state->NeedsAccess () && + GetBackoffStartFor (state) < Simulator::Now ()) { - NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision."); + MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision."); /** * all other dcfs with a lower priority whose backoff * has expired and which needed access to the medium @@ -276,7 +283,7 @@ DcfManager::GetAccessGrantStart (void) const busyAccessStart, txAccessStart, navAccessStart); - NS_LOG_DEBUG ("access grant start=" << accessGrantedStart << + MY_DEBUG ("access grant start=" << accessGrantedStart << ", rx access start=" << rxAccessStart << ", busy access start=" << busyAccessStart << ", tx access start=" << txAccessStart << @@ -284,6 +291,21 @@ DcfManager::GetAccessGrantStart (void) const return accessGrantedStart; } +Time +DcfManager::GetBackoffStartFor (DcfState *state) +{ + Time mostRecentEvent = MostRecent (state->GetBackoffStart (), + GetAccessGrantStart () + Scalar (state->GetAifsn ()) * m_slotTime); + + return mostRecentEvent; +} + +Time +DcfManager::GetBackoffEndFor (DcfState *state) +{ + return GetBackoffStartFor (state) + Scalar (state->GetBackoffSlots ()) * m_slotTime; +} + void DcfManager::UpdateBackoff (void) { @@ -292,11 +314,11 @@ DcfManager::UpdateBackoff (void) { DcfState *state = *i; - Time mostRecentEvent = MostRecent (state->GetBackoffStart (), - GetAccessGrantStart ()); - if (mostRecentEvent < Simulator::Now ()) + Time backoffStart = GetBackoffStartFor (state); + if (backoffStart <= Simulator::Now ()) { - Scalar nSlots = (Simulator::Now () - mostRecentEvent) / m_slotTime; + Scalar nSlots = (Simulator::Now () - backoffStart) / m_slotTime; + // XXX: rounding should be nicer. uint32_t nIntSlots = lrint (nSlots.GetDouble ()); /** * For each DcfState, calculate how many backoff slots elapsed since @@ -306,8 +328,8 @@ DcfManager::UpdateBackoff (void) */ if (nIntSlots > state->GetAifsn ()) { - NS_LOG_DEBUG ("dcf " << k << " dec backoff slots=" << nIntSlots - state->GetAifsn ()); - state->UpdateBackoffSlotsNow (nIntSlots - state->GetAifsn ()); + MY_DEBUG ("dcf " << k << " dec backoff slots=" << nIntSlots); + state->UpdateBackoffSlotsNow (nIntSlots); } } } @@ -321,25 +343,19 @@ DcfManager::DoRestartAccessTimeoutIfNeeded (void) * if there is one, how many slots for AIFS+backoff does it require ? */ bool accessTimeoutNeeded = false; - uint32_t minNSlots = 0xffffffff; - Time backoffStart; + Time expectedBackoffEnd = MaxSeconds (); for (States::const_iterator i = m_states.begin (); i != m_states.end (); i++) { DcfState *state = *i; if (state->NeedsAccess ()) { accessTimeoutNeeded = true; - minNSlots = std::min (state->GetAifsn () + state->GetBackoffSlots (), minNSlots); + expectedBackoffEnd = std::min (expectedBackoffEnd, GetBackoffEndFor (state)); } } if (accessTimeoutNeeded) { - /** - * If one of the DcfState needs access to the medium, calculate when its - * backoff is expected to end. - */ - Time expectedBackoffEnd = GetAccessGrantStart () + Scalar (minNSlots) * m_slotTime; - NS_LOG_DEBUG ("min n slots=" << minNSlots << ", expected backoff end="<