wifi: reuse NiChangesPerBand iterators

This commit is contained in:
Gabriel Ferreira
2021-07-21 20:55:42 -03:00
parent cd400c6e17
commit a17b86cdd5
2 changed files with 55 additions and 57 deletions

View File

@@ -225,9 +225,10 @@ InterferenceHelper::AddBand (WifiSpectrumBand band)
NS_LOG_FUNCTION (this << band.first << band.second);
NS_ASSERT (m_niChangesPerBand.find (band) == m_niChangesPerBand.end ());
NiChanges niChanges;
m_niChangesPerBand.insert ({band, niChanges});
auto result = m_niChangesPerBand.insert ({band, niChanges});
NS_ASSERT (result.second);
// Always have a zero power noise event in the list
AddNiChangeEvent (Time (0), NiChange (0.0, 0), band);
AddNiChangeEvent (Time (0), NiChange (0.0, 0), result.first);
m_firstPowerPerBand.insert ({band, 0.0});
}
@@ -259,11 +260,11 @@ Time
InterferenceHelper::GetEnergyDuration (double energyW, WifiSpectrumBand band)
{
Time now = Simulator::Now ();
auto i = GetPreviousPosition (now, band);
auto niIt = m_niChangesPerBand.find (band);
NS_ASSERT (niIt != m_niChangesPerBand.end ());
auto i = GetPreviousPosition (now, niIt);
Time end = i->first;
auto ni_it = m_niChangesPerBand.find (band);
NS_ASSERT (ni_it != m_niChangesPerBand.end ());
for (; i != ni_it->second.end (); ++i)
for (; i != niIt->second.end (); ++i)
{
double noiseInterferenceW = i->second.GetPower ();
end = i->first;
@@ -282,17 +283,18 @@ InterferenceHelper::AppendEvent (Ptr<Event> event, bool isStartOfdmaRxing)
for (auto const& it : event->GetRxPowerWPerBand ())
{
WifiSpectrumBand band = it.first;
auto ni_it = m_niChangesPerBand.find (band);
NS_ASSERT (ni_it != m_niChangesPerBand.end ());
auto niIt = m_niChangesPerBand.find (band);
NS_ASSERT (niIt != m_niChangesPerBand.end ());
double previousPowerStart = 0;
double previousPowerEnd = 0;
previousPowerStart = GetPreviousPosition (event->GetStartTime (), band)->second.GetPower ();
previousPowerEnd = GetPreviousPosition (event->GetEndTime (), band)->second.GetPower ();
auto previousPowerPosition = GetPreviousPosition (event->GetStartTime (), niIt);
previousPowerStart = previousPowerPosition->second.GetPower ();
previousPowerEnd = GetPreviousPosition (event->GetEndTime (), niIt)->second.GetPower ();
if (!m_rxing)
{
m_firstPowerPerBand.find (band)->second = previousPowerStart;
// Always leave the first zero power noise event in the list
ni_it->second.erase (++(ni_it->second.begin ()), GetNextPosition (event->GetStartTime (), band));
niIt->second.erase (++(niIt->second.begin ()), ++previousPowerPosition);
}
else if (isStartOfdmaRxing)
{
@@ -301,8 +303,8 @@ InterferenceHelper::AppendEvent (Ptr<Event> event, bool isStartOfdmaRxing)
//UL MU transmission and the start of UL-OFDMA payload.
m_firstPowerPerBand.find (band)->second = previousPowerStart;
}
auto first = AddNiChangeEvent (event->GetStartTime (), NiChange (previousPowerStart, event), band);
auto last = AddNiChangeEvent (event->GetEndTime (), NiChange (previousPowerEnd, event), band);
auto first = AddNiChangeEvent (event->GetStartTime (), NiChange (previousPowerStart, event), niIt);
auto last = AddNiChangeEvent (event->GetEndTime (), NiChange (previousPowerEnd, event), niIt);
for (auto i = first; i != last; ++i)
{
i->second.AddPower (it.second);
@@ -318,10 +320,10 @@ InterferenceHelper::UpdateEvent (Ptr<Event> event, const RxPowerWattPerChannelBa
for (auto const& it : rxPower)
{
WifiSpectrumBand band = it.first;
auto ni_it = m_niChangesPerBand.find (band);
NS_ASSERT (ni_it != m_niChangesPerBand.end ());
auto first = GetPreviousPosition (event->GetStartTime (), band);
auto last = GetPreviousPosition (event->GetEndTime (), band);
auto niIt = m_niChangesPerBand.find (band);
NS_ASSERT (niIt != m_niChangesPerBand.end ());
auto first = GetPreviousPosition (event->GetStartTime (), niIt);
auto last = GetPreviousPosition (event->GetEndTime (), niIt);
for (auto i = first; i != last; ++i)
{
i->second.AddPower (it.second);
@@ -363,19 +365,19 @@ InterferenceHelper::CalculateNoiseInterferenceW (Ptr<Event> event, NiChangesPerB
auto firstPower_it = m_firstPowerPerBand.find (band);
NS_ASSERT (firstPower_it != m_firstPowerPerBand.end ());
double noiseInterferenceW = firstPower_it->second;
auto ni_it = m_niChangesPerBand.find (band);
NS_ASSERT (ni_it != m_niChangesPerBand.end ());
auto it = ni_it->second.find (event->GetStartTime ());
for (; it != ni_it->second.end () && it->first < Simulator::Now (); ++it)
auto niIt = m_niChangesPerBand.find (band);
NS_ASSERT (niIt != m_niChangesPerBand.end ());
auto it = niIt->second.find (event->GetStartTime ());
for (; it != niIt->second.end () && it->first < Simulator::Now (); ++it)
{
noiseInterferenceW = it->second.GetPower () - event->GetRxPowerW (band);
}
it = ni_it->second.find (event->GetStartTime ());
NS_ASSERT (it != ni_it->second.end ());
for (; it != ni_it->second.end () && it->second.GetEvent () != event; ++it);
it = niIt->second.find (event->GetStartTime ());
NS_ASSERT (it != niIt->second.end ());
for (; it != niIt->second.end () && it->second.GetEvent () != event; ++it);
NiChanges ni;
ni.emplace (event->GetStartTime (), NiChange (0, event));
while (++it != ni_it->second.end () && it->second.GetEvent () != event)
while (++it != niIt->second.end () && it->second.GetEvent () != event)
{
ni.insert (*it);
}
@@ -420,8 +422,8 @@ InterferenceHelper::CalculatePayloadPer (Ptr<const Event> event, uint16_t channe
{
NS_LOG_FUNCTION (this << channelWidth << band.first << band.second << staId << window.first << window.second);
double psr = 1.0; /* Packet Success Rate */
auto ni_it = nis->find (band)->second;
auto j = ni_it.begin ();
auto niIt = nis->find (band)->second;
auto j = niIt.begin ();
Time previous = j->first;
WifiMode payloadMode = event->GetTxVector ().GetMode (staId);
Time phyPayloadStart = j->first;
@@ -433,7 +435,7 @@ InterferenceHelper::CalculatePayloadPer (Ptr<const Event> event, uint16_t channe
Time windowEnd = phyPayloadStart + window.second;
double noiseInterferenceW = m_firstPowerPerBand.find (band)->second;
double powerW = event->GetRxPowerW (band);
while (++j != ni_it.end ())
while (++j != niIt.end ())
{
Time current = j->first;
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
@@ -470,8 +472,8 @@ InterferenceHelper::CalculatePhyHeaderSectionPsr (Ptr<const Event> event, NiChan
{
NS_LOG_FUNCTION (this << band.first << band.second);
double psr = 1.0; /* Packet Success Rate */
auto ni_it = nis->find (band)->second;
auto j = ni_it.begin ();
auto niIt = nis->find (band)->second;
auto j = niIt.begin ();
NS_ASSERT (!phyHeaderSections.empty ());
Time stopLastSection = Seconds (0);
@@ -483,7 +485,7 @@ InterferenceHelper::CalculatePhyHeaderSectionPsr (Ptr<const Event> event, NiChan
Time previous = j->first;
double noiseInterferenceW = m_firstPowerPerBand.find (band)->second;
double powerW = event->GetRxPowerW (band);
while (++j != ni_it.end ())
while (++j != niIt.end ())
{
Time current = j->first;
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
@@ -522,11 +524,11 @@ InterferenceHelper::CalculatePhyHeaderPer (Ptr<const Event> event, NiChangesPerB
WifiPpduField header) const
{
NS_LOG_FUNCTION (this << band.first << band.second << header);
auto ni_it = nis->find (band)->second;
auto niIt = nis->find (band)->second;
auto phyEntity = WifiPhy::GetStaticPhyEntity (event->GetTxVector ().GetModulationClass ());
PhyEntity::PhyHeaderSections sections;
for (const auto & section : phyEntity->GetPhyHeaderSections (event->GetTxVector (), ni_it.begin ()->first))
for (const auto & section : phyEntity->GetPhyHeaderSections (event->GetTxVector (), niIt.begin ()->first))
{
if (section.first == header)
{
@@ -597,28 +599,26 @@ InterferenceHelper::CalculatePhyHeaderSnrPer (Ptr<Event> event, uint16_t channel
void
InterferenceHelper::EraseEvents (void)
{
for (auto it : m_niChangesPerBand)
for (auto niIt = m_niChangesPerBand.begin(); niIt != m_niChangesPerBand.end(); ++niIt)
{
it.second.clear ();
niIt->second.clear ();
// Always have a zero power noise event in the list
AddNiChangeEvent (Time (0), NiChange (0.0, 0), it.first);
m_firstPowerPerBand.at (it.first) = 0.0;
AddNiChangeEvent (Time (0), NiChange (0.0, 0), niIt);
m_firstPowerPerBand.at (niIt->first) = 0.0;
}
m_rxing = false;
}
InterferenceHelper::NiChanges::iterator
InterferenceHelper::GetNextPosition (Time moment, WifiSpectrumBand band)
InterferenceHelper::GetNextPosition (Time moment, NiChangesPerBand::iterator niIt)
{
auto it = m_niChangesPerBand.find (band);
NS_ASSERT (it != m_niChangesPerBand.end ());
return it->second.upper_bound (moment);
return niIt->second.upper_bound (moment);
}
InterferenceHelper::NiChanges::iterator
InterferenceHelper::GetPreviousPosition (Time moment, WifiSpectrumBand band)
InterferenceHelper::GetPreviousPosition (Time moment, NiChangesPerBand::iterator niIt)
{
auto it = GetNextPosition (moment, band);
auto it = GetNextPosition (moment, niIt);
// This is safe since there is always an NiChange at time 0,
// before moment.
--it;
@@ -626,11 +626,9 @@ InterferenceHelper::GetPreviousPosition (Time moment, WifiSpectrumBand band)
}
InterferenceHelper::NiChanges::iterator
InterferenceHelper::AddNiChangeEvent (Time moment, NiChange change, WifiSpectrumBand band)
InterferenceHelper::AddNiChangeEvent (Time moment, NiChange change, NiChangesPerBand::iterator niIt)
{
auto it = m_niChangesPerBand.find (band);
NS_ASSERT (it != m_niChangesPerBand.end ());
return it->second.insert (GetNextPosition (moment, band), std::make_pair (moment, change));
return niIt->second.insert (GetNextPosition (moment, niIt), std::make_pair (moment, change));
}
void
@@ -646,12 +644,12 @@ InterferenceHelper::NotifyRxEnd (Time endTime)
NS_LOG_FUNCTION (this << endTime);
m_rxing = false;
//Update m_firstPowerPerBand for frame capture
for (auto ni : m_niChangesPerBand)
for (auto niIt = m_niChangesPerBand.begin(); niIt != m_niChangesPerBand.end(); ++niIt)
{
NS_ASSERT (ni.second.size () > 1);
auto it = GetPreviousPosition (endTime, ni.first);
NS_ASSERT (niIt->second.size () > 1);
auto it = GetPreviousPosition (endTime, niIt);
it--;
m_firstPowerPerBand.find (ni.first)->second = it->second.GetPower ();
m_firstPowerPerBand.find (niIt->first)->second = it->second.GetPower ();
}
}

View File

@@ -432,18 +432,18 @@ private:
* Returns an iterator to the first NiChange that is later than moment
*
* \param moment time to check from
* \param band identify the band to check
* \param niIt iterator of the band to check
* \returns an iterator to the list of NiChanges
*/
NiChanges::iterator GetNextPosition (Time moment, WifiSpectrumBand band);
NiChanges::iterator GetNextPosition (Time moment, NiChangesPerBand::iterator niIt);
/**
* Returns an iterator to the last NiChange that is before than moment
*
* \param moment time to check from
* \param band identify the band to check
* \param niIt iterator of the band to check
* \returns an iterator to the list of NiChanges
*/
NiChanges::iterator GetPreviousPosition (Time moment, WifiSpectrumBand band);
NiChanges::iterator GetPreviousPosition (Time moment, NiChangesPerBand::iterator niIt);
/**
* Add NiChange to the list at the appropriate position and
@@ -451,10 +451,10 @@ private:
*
* \param moment time to check from
* \param change the NiChange to add
* \param band identify the band to check
* \param niIt iterator of the band to check
* \returns the iterator of the new event
*/
NiChanges::iterator AddNiChangeEvent (Time moment, NiChange change, WifiSpectrumBand band);
NiChanges::iterator AddNiChangeEvent (Time moment, NiChange change, NiChangesPerBand::iterator niIt);
};
} //namespace ns3