wifi: Calculate start and stop frequencies for a given band
This commit is contained in:
committed by
Sébastien Deronne
parent
1f4b434b12
commit
eef793c6c3
@@ -586,27 +586,50 @@ SpectrumWifiPhy::GetBandForInterface(uint16_t bandWidth,
|
||||
FrequencyRange freqRange,
|
||||
uint16_t channelWidth)
|
||||
{
|
||||
uint32_t subcarrierSpacing = GetSubcarrierSpacing();
|
||||
size_t numBandsInChannel = static_cast<size_t>(channelWidth * 1e6 / subcarrierSpacing);
|
||||
size_t numBandsInBand = static_cast<size_t>(bandWidth * 1e6 / subcarrierSpacing);
|
||||
auto subcarrierSpacing = GetSubcarrierSpacing();
|
||||
auto numBandsInChannel = static_cast<size_t>(channelWidth * 1e6 / subcarrierSpacing);
|
||||
auto numBandsInBand = static_cast<size_t>(bandWidth * 1e6 / subcarrierSpacing);
|
||||
if (numBandsInBand % 2 == 0)
|
||||
{
|
||||
numBandsInChannel += 1; // symmetry around center frequency
|
||||
}
|
||||
size_t totalNumBands =
|
||||
m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel()->GetNumBands();
|
||||
auto rxSpectrumModel = m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel();
|
||||
size_t totalNumBands = rxSpectrumModel->GetNumBands();
|
||||
NS_ASSERT_MSG((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
|
||||
"Should have odd number of bands");
|
||||
NS_ASSERT_MSG((bandIndex * bandWidth) < channelWidth, "Band index is out of bound");
|
||||
NS_ASSERT(totalNumBands >= numBandsInChannel);
|
||||
auto startIndex = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
|
||||
auto stopIndex = startIndex + numBandsInBand - 1;
|
||||
auto frequencies = ConvertIndicesForInterface({startIndex, stopIndex}, freqRange);
|
||||
NS_ASSERT(frequencies.first >= (freqRange.minFrequency * 1e6));
|
||||
NS_ASSERT(frequencies.second <= (freqRange.maxFrequency * 1e6));
|
||||
NS_ASSERT((frequencies.second - frequencies.first) == (bandWidth * 1e6));
|
||||
if (startIndex >= totalNumBands / 2)
|
||||
{
|
||||
// step past DC
|
||||
startIndex += 1;
|
||||
}
|
||||
return {{startIndex, stopIndex}, {0, 0}};
|
||||
return {{startIndex, stopIndex}, frequencies};
|
||||
}
|
||||
|
||||
WifiSpectrumBandFrequencies
|
||||
SpectrumWifiPhy::ConvertIndicesToFrequencies(const WifiSpectrumBandIndices& indices) const
|
||||
{
|
||||
return ConvertIndicesForInterface(indices, GetCurrentFrequencyRange());
|
||||
}
|
||||
|
||||
WifiSpectrumBandFrequencies
|
||||
SpectrumWifiPhy::ConvertIndicesForInterface(const WifiSpectrumBandIndices& indices,
|
||||
const FrequencyRange& freqRange) const
|
||||
{
|
||||
auto rxSpectrumModel = m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel();
|
||||
auto startGuardBand = rxSpectrumModel->Begin();
|
||||
auto startChannel = std::next(startGuardBand, indices.first);
|
||||
auto endChannel = std::next(startGuardBand, indices.second + 1);
|
||||
auto lowFreq = static_cast<uint64_t>(startChannel->fc);
|
||||
auto highFreq = static_cast<uint64_t>(endChannel->fc);
|
||||
return {lowFreq, highFreq};
|
||||
}
|
||||
|
||||
std::tuple<double, double, double>
|
||||
|
||||
@@ -77,6 +77,8 @@ class SpectrumWifiPhy : public WifiPhy
|
||||
std::tuple<double, double, double> GetTxMaskRejectionParams() const override;
|
||||
WifiSpectrumBandInfo GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override;
|
||||
FrequencyRange GetCurrentFrequencyRange() const override;
|
||||
WifiSpectrumBandFrequencies ConvertIndicesToFrequencies(
|
||||
const WifiSpectrumBandIndices& indices) const override;
|
||||
|
||||
/**
|
||||
* Attach a SpectrumChannel to use for a given frequency range.
|
||||
@@ -183,6 +185,9 @@ class SpectrumWifiPhy : public WifiPhy
|
||||
//!< reasons)
|
||||
|
||||
private:
|
||||
WifiSpectrumBandFrequencies ConvertIndicesForInterface(const WifiSpectrumBandIndices& indices,
|
||||
const FrequencyRange& freqRange) const;
|
||||
|
||||
/**
|
||||
* Perform run-time spectrum model change
|
||||
*/
|
||||
|
||||
@@ -1053,6 +1053,15 @@ class WifiPhy : public Object
|
||||
*/
|
||||
void NotifyChannelAccessRequested();
|
||||
|
||||
/**
|
||||
* This is a helper function to convert start and stop indices to start and stop frequencies.
|
||||
*
|
||||
* \param indices the start/stop indices to convert
|
||||
* \return the converted frequencies
|
||||
*/
|
||||
virtual WifiSpectrumBandFrequencies ConvertIndicesToFrequencies(
|
||||
const WifiSpectrumBandIndices& indices) const = 0;
|
||||
|
||||
/**
|
||||
* Add the PHY entity to the map of __implemented__ PHY entities for the
|
||||
* given modulation class.
|
||||
|
||||
@@ -118,4 +118,10 @@ YansWifiPhy::GetCurrentFrequencyRange() const
|
||||
return WHOLE_WIFI_SPECTRUM;
|
||||
}
|
||||
|
||||
WifiSpectrumBandFrequencies
|
||||
YansWifiPhy::ConvertIndicesToFrequencies(const WifiSpectrumBandIndices& /*indices*/) const
|
||||
{
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -63,6 +63,8 @@ class YansWifiPhy : public WifiPhy
|
||||
std::tuple<double, double, double> GetTxMaskRejectionParams() const override;
|
||||
WifiSpectrumBandInfo GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override;
|
||||
FrequencyRange GetCurrentFrequencyRange() const override;
|
||||
WifiSpectrumBandFrequencies ConvertIndicesToFrequencies(
|
||||
const WifiSpectrumBandIndices& indices) const override;
|
||||
|
||||
/**
|
||||
* Set the YansWifiChannel this YansWifiPhy is to be connected to.
|
||||
|
||||
Reference in New Issue
Block a user