diff -r 0c7e5ae39dcf src/wifi/model/interference-helper.cc --- a/src/wifi/model/interference-helper.cc Sat Jan 13 12:16:29 2018 +0100 +++ b/src/wifi/model/interference-helper.cc Fri Jan 19 22:16:36 2018 +0100 @@ -88,9 +88,9 @@ * short period of time. ****************************************************************/ -InterferenceHelper::NiChange::NiChange (Time time, double delta, Ptr event) +InterferenceHelper::NiChange::NiChange (Time time, double power, Ptr event) : m_time (time), - m_delta (delta), + m_power (power), m_event (event) { } @@ -102,9 +102,15 @@ } double -InterferenceHelper::NiChange::GetDelta (void) const +InterferenceHelper::NiChange::GetPower (void) const { - return m_delta; + return m_power; +} + +void +InterferenceHelper::NiChange::AddPower (double power) +{ + m_power += power; } Ptr @@ -191,12 +197,11 @@ InterferenceHelper::GetEnergyDuration (double energyW) const { Time now = Simulator::Now (); - double noiseInterferenceW = 0; + double noiseInterferenceW = m_firstPower; Time end = now; - noiseInterferenceW = m_firstPower; for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) { - noiseInterferenceW += i->GetDelta (); + noiseInterferenceW = i->GetPower (); end = i->GetTime (); if (end < now) { @@ -213,18 +218,32 @@ void InterferenceHelper::AppendEvent (Ptr event) { - Time now = Simulator::Now (); + double previousPowerStart = 0; + NiChanges::iterator itPreviousEvent = GetPreviousPosition (event->GetStartTime ()); + if ((std::distance (m_niChanges.begin (), itPreviousEvent) > 0) || (itPreviousEvent == m_niChanges.begin ())) + { + previousPowerStart = itPreviousEvent->GetPower (); + } + double previousPowerEnd = 0; + NiChanges::iterator itNextEvent = GetPreviousPosition (event->GetEndTime ()); + if ((std::distance (m_niChanges.begin (), itNextEvent) > 0) || (itNextEvent == m_niChanges.begin ())) + { + previousPowerEnd = itNextEvent->GetPower (); + } if (!m_rxing) { - NiChanges::const_iterator nowIterator = GetPosition (now); - for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++) + m_firstPower = previousPowerStart; + m_niChanges.erase (m_niChanges.begin (), GetNextPosition (event->GetStartTime ())); + } + AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart + event->GetRxPowerW (), event)); + AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event)); + for (NiChanges::iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) + { + if (i->GetTime () > event->GetStartTime () && i->GetTime () <= event->GetEndTime () && i->GetEvent () != event) { - m_firstPower += i->GetDelta (); + i->AddPower (event->GetRxPowerW ()); } - m_niChanges.erase (m_niChanges.begin (), nowIterator); } - AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); - AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event)); } double @@ -262,7 +281,7 @@ // as the interference. This considers the case that the receiving event // arrives while another receiving event is going on. The SINR of // the newly arrived event is calculated for checking the possibility of frame capture - noiseInterference += eventIterator->GetDelta (); + noiseInterference = eventIterator->GetPower (); } else { @@ -270,7 +289,7 @@ } ++eventIterator; } - + ni->push_back (NiChange (event->GetStartTime (), 0, event)); for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) { if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) @@ -279,7 +298,6 @@ } ni->push_back (*i); } - ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); ni->push_back (NiChange (event->GetEndTime (), 0, event)); return noiseInterference; } @@ -311,19 +329,19 @@ const WifiTxVector txVector = event->GetTxVector (); double psr = 1.0; /* Packet Success Rate */ NiChanges::const_iterator j = ni->begin (); - Time previous = (*j).GetTime (); + Time previous = j->GetTime (); WifiMode payloadMode = event->GetPayloadMode (); WifiPreamble preamble = txVector.GetPreambleType (); - Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble + Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B - double noiseInterferenceW = (*j).GetDelta (); + double noiseInterferenceW = m_firstPower; double powerW = event->GetRxPowerW (); j++; while (ni->end () != j) { - Time current = (*j).GetTime (); + Time current = j->GetTime (); NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); NS_ASSERT (current >= previous); //Case 1: Both previous and current point to the payload @@ -346,8 +364,8 @@ payloadMode, txVector); NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); } - noiseInterferenceW += (*j).GetDelta (); - previous = (*j).GetTime (); + noiseInterferenceW = j->GetPower () - powerW; + previous = j->GetTime (); j++; } double per = 1 - psr; @@ -361,7 +379,7 @@ const WifiTxVector txVector = event->GetTxVector (); double psr = 1.0; /* Packet Success Rate */ NiChanges::const_iterator j = ni->begin (); - Time previous = (*j).GetTime (); + Time previous = j->GetTime (); WifiPreamble preamble = txVector.GetPreambleType (); WifiMode mcsHeaderMode; if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) @@ -380,16 +398,16 @@ mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); } WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); - Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble + Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B - double noiseInterferenceW = (*j).GetDelta (); + double noiseInterferenceW = m_firstPower; double powerW = event->GetRxPowerW (); j++; while (ni->end () != j) { - Time current = (*j).GetTime (); + Time current = j->GetTime (); NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); NS_ASSERT (current >= previous); //Case 1: previous and current after playload start: nothing to do @@ -762,8 +780,8 @@ } } - noiseInterferenceW += (*j).GetDelta (); - previous = (*j).GetTime (); + noiseInterferenceW = j->GetPower () - powerW; + previous = j->GetTime (); j++; } @@ -819,16 +837,24 @@ m_firstPower = 0; } -InterferenceHelper::NiChanges::const_iterator -InterferenceHelper::GetPosition (Time moment) +InterferenceHelper::NiChanges::iterator +InterferenceHelper::GetNextPosition (Time moment) { return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); } +InterferenceHelper::NiChanges::iterator +InterferenceHelper::GetPreviousPosition (Time moment) +{ + InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment); + --it; + return it; +} + void InterferenceHelper::AddNiChangeEvent (NiChange change) { - m_niChanges.insert (GetPosition (change.GetTime ()), change); + m_niChanges.insert (GetNextPosition (change.GetTime ()), change); } void @@ -843,6 +869,16 @@ { NS_LOG_FUNCTION (this); m_rxing = false; + Time now = Simulator::Now (); + //Update m_firstPower for frame capture + for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) + { + if (i->GetTime () >= now) + { + break; + } + m_firstPower = i->GetPower (); + } } } //namespace ns3 diff -r 0c7e5ae39dcf src/wifi/model/interference-helper.h --- a/src/wifi/model/interference-helper.h Sat Jan 13 12:16:29 2018 +0100 +++ b/src/wifi/model/interference-helper.h Fri Jan 19 22:16:36 2018 +0100 @@ -213,10 +213,10 @@ * Create a NiChange at the given time and the amount of NI change. * * \param time time of the event - * \param delta the power + * \param power the power * \param event causes this NI change */ - NiChange (Time time, double delta, Ptr event); + NiChange (Time time, double power, Ptr event); /** * Return the event time. * @@ -228,7 +228,13 @@ * * \return the power */ - double GetDelta (void) const; + double GetPower (void) const; + /** + * Add a given amount of power. + * + * \param power the power to be added to the existing value + */ + void AddPower (double power); /** * Return the event causes the corresponding NI change * @@ -246,7 +252,7 @@ private: Time m_time; ///< time - double m_delta; ///< delta + double m_power; ///< power Ptr m_event; ///< event }; /** @@ -322,12 +328,20 @@ bool m_rxing; ///< flag whether it is in receiving state /** - * Returns a const iterator to the first nichange, which is later than moment + * Returns an iterator to the first nichange that is later than moment * * \param moment time to check from * \returns an iterator to the list of NiChanges */ - NiChanges::const_iterator GetPosition (Time moment); + NiChanges::iterator GetNextPosition (Time moment); + /** + * Returns an iterator to the last nichange that is before than moment + * + * \param moment time to check from + * \returns an iterator to the list of NiChanges + */ + NiChanges::iterator GetPreviousPosition (Time moment); + /** * Add NiChange to the list at the appropriate position. *