14#include "ns3/assert.h"
288 : m_channelIts(channelIts),
293 "Operating channel does not support more than 2 segments");
311 std::stringstream ss;
312 for (
const auto& segment : segments)
318 NS_ASSERT_MSG(!segments.empty(),
"At least one frequency segment has to be provided");
321 for (
const auto& segment : segments)
323 if (
const auto channelIt =
324 FindFirst(segment.number, segment.frequency, segment.width, standard, segment.band);
334 channelIts.insert(channelIt);
338 if (channelIts.size() != segments.size())
341 throw std::runtime_error(
342 "WifiPhyOperatingChannel: No unique channel found given the specified criteria");
345 auto it = channelIts.begin();
346 for (std::size_t segment = 0; segment < (channelIts.size() - 1); ++segment)
348 const auto freq = (*it)->frequency;
349 const auto width = (*it)->width;
350 const auto band = (*it)->band;
351 const auto maxFreq = freq + (width / 2);
353 const auto nextFreq = (*it)->frequency;
354 const auto nextWidth = (*it)->width;
355 const auto nextBand = (*it)->band;
356 const auto nextMinFreq = nextFreq - (nextWidth / 2);
357 if (maxFreq >= nextMinFreq)
359 throw std::runtime_error(
360 "WifiPhyOperatingChannel is invalid: segments cannot be adjacent nor overlap");
362 if (band != nextBand)
364 throw std::runtime_error(
"WifiPhyOperatingChannel is invalid: all segments shall "
365 "belong to the same band");
369 if ((channelIts.size() > 2) ||
370 ((channelIts.size() == 2) &&
371 !std::all_of(channelIts.cbegin(), channelIts.cend(), [](
const auto& channel) {
372 return channel->width == 80;
375 throw std::runtime_error(
"WifiPhyOperatingChannel is invalid: only 80+80MHz is "
376 "expected as non-contiguous channel");
395 std::optional<uint8_t> previousChannelNumber )
399 if (previousChannelNumber)
401 prevSegmentChannelIt =
FindFirst(*previousChannelNumber, 0, width, standard, band, start);
404 start = std::next(prevSegmentChannelIt);
407 auto channelIt =
FindFirst(0, 0, width, standard, band, start);
410 const auto prevFreq = prevSegmentChannelIt->frequency;
411 const auto prevWidth = prevSegmentChannelIt->width;
412 const auto prevMaxFreq = prevFreq + (prevWidth / 2);
413 const auto nextFreq = channelIt->frequency;
414 const auto nextWidth = channelIt->width;
415 const auto nextMinFreq = nextFreq - (nextWidth / 2);
416 if (prevMaxFreq <= nextMinFreq)
420 channelIt =
FindFirst(0, 0, width, standard, band, std::next(channelIt));
426 return channelIt->number;
430 throw std::runtime_error(
"WifiPhyOperatingChannel: No default channel found of the given width "
431 "and for the given PHY standard and band");
444 if (number != 0 && channel.number != number)
448 if (frequency != 0 && channel.frequency != frequency)
452 if (width != 0 && channel.width != width)
473 (std::find(standardIt->second.cbegin(), standardIt->second.cend(), band) ==
474 standardIt->second.cend() ||
487 return (*std::next(
m_channelIts.begin(), segment))->number;
494 return (*std::next(
m_channelIts.begin(), segment))->frequency;
538 std::vector<uint8_t> channelNumbers{};
541 std::back_inserter(channelNumbers),
542 [](
const auto& channel) { return channel->number; });
543 return channelNumbers;
550 std::vector<MHz_u> centerFrequencies{};
553 std::back_inserter(centerFrequencies),
554 [](
const auto& channel) { return channel->frequency; });
555 return centerFrequencies;
562 std::vector<MHz_u> channelWidths{};
565 std::back_inserter(channelWidths),
566 [](
const auto& channel) { return channel->width; });
567 return channelWidths;
577 [](
MHz_u sum,
const auto& channel) { return sum + channel->width; });
612 if (
static_cast<uint16_t
>(primaryChannelWidth) % 20 != 0)
614 NS_LOG_DEBUG(
"The operating channel width is not a multiple of 20 MHz; return 0");
625 while (width < primaryChannelWidth)
637 const uint8_t secondaryIndex =
638 (primaryIndex % 2 == 0) ? (primaryIndex + 1) : (primaryIndex - 1);
639 return secondaryIndex;
659 const auto numIndices =
GetTotalWidth() / primaryChannelWidth;
661 return (primaryIndex >= (numIndices / 2)) ? 1 : 0;
668 "Primary channel width cannot be larger than the width of a frequency segment");
674 const auto numIndices =
GetTotalWidth() / primaryChannelWidth;
676 return (secondaryIndex >= (numIndices / 2)) ? 1 : 0;
684 const auto segmentWidth =
GetWidth(segmentIndex);
686 const uint8_t segmentOffset = (segmentIndex * (segmentWidth / primaryChannelWidth));
697 const auto segmentWidth =
GetWidth(segmentIndex);
699 const uint8_t segmentOffset = (segmentIndex * (segmentWidth / secondaryChannelWidth));
702 secondaryChannelWidth;
710 "Primary channel width cannot be larger than the width of a frequency segment");
715 return primaryChanIt->number;
723 "Requested primary channel width ("
724 << primaryChannelWidth <<
" MHz) exceeds total width (" <<
GetTotalWidth()
740 (primaryChannelWidth / 20));
743 return primaryChannel;
755 MHz_u currWidth = 20;
756 std::set<uint8_t> indices;
759 while (currWidth < width)
776 const std::set<uint8_t>& primaryIndices)
const
784 MHz_u primaryWidth = 20;
787 while (size != primaryIndices.size())
800 std::set<uint8_t> secondaryIndices;
801 for (
const auto& index : primaryIndices)
803 secondaryIndices.insert(index ^ size);
806 return secondaryIndices;
815 "No RU of type " << ruType <<
" is contained in a " << width <<
" MHz channel");
817 "The given width (" << width <<
" MHz) exceeds the operational width ("
823 return {0, 1, 2, 3, 4, 5, 6, 7};
830 "26-tone RU with index 19 is only present in channels of at least 80 MHz");
835 indices.erase(indices.begin());
836 indices.erase(std::prev(indices.end()));
861 ruIndex += nRusIn80MHz;
865 uint8_t n20MHzChannels;
885 auto nRusInCoveringChannel =
HeRu::GetNRus(n20MHzChannels * 20, ruType);
887 std::size_t indexOfCoveringChannelInGivenWidth = (ruIndex - 1) / nRusInCoveringChannel;
891 NS_ASSERT(indexOfCoveringChannelInGivenWidth < 8);
892 std::set<uint8_t> indices({
static_cast<uint8_t
>(indexOfCoveringChannelInGivenWidth)});
894 while (n20MHzChannels > 1)
896 std::set<uint8_t> updatedIndices;
897 for (
const auto& idx : indices)
899 updatedIndices.insert(idx * 2);
900 updatedIndices.insert(idx * 2 + 1);
902 indices.swap(updatedIndices);
911 std::set<uint8_t> updatedIndices;
912 for (
const auto& idx : indices)
914 updatedIndices.insert(idx + offset);
916 indices.swap(updatedIndices);
937 return !(*
this == other);
945 const auto numSegments = channel.GetNSegments();
946 for (std::size_t segmentId = 0; segmentId < numSegments; ++segmentId)
950 os <<
"segment " << segmentId <<
" ";
952 os <<
"channel " << +channel.GetNumber() <<
" frequency " << channel.GetFrequency()
953 <<
" width " << channel.GetWidth() <<
" band " << channel.GetPhyBand();
954 if ((segmentId == 0) && (
static_cast<uint16_t
>(channel.GetTotalWidth()) % 20 == 0))
956 os <<
" primary20 " << +channel.GetPrimaryChannelIndex(20);
958 if (segmentId < numSegments - 1)
966 os <<
"channel not set";
std::size_t GetIndex() const
Get the RU index.
RuType GetRuType() const
Get the RU type.
bool GetPrimary80MHz() const
Get the primary 80 MHz flag.
static MHz_u GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
static std::size_t GetNRus(MHz_u bw, RuType ruType)
Get the number of distinct RUs of the given type (number of tones) available in a HE PPDU of the give...
Class that keeps track of all information about the current PHY operating channel.
MHz_u GetTotalWidth() const
Return the width of the whole operating channel.
bool IsSet() const
Return true if a valid channel has been set, false otherwise.
std::set< ConstIterator, Compare > ConstIteratorSet
Typedef for a set of const iterator pointing to the segments of a channel.
uint8_t GetNumber(std::size_t segment=0) const
Return the channel number for a given frequency segment.
bool operator==(const WifiPhyOperatingChannel &other) const
Check if the given WifiPhyOperatingChannel is equivalent.
WifiPhyOperatingChannel()
Create an uninitialized PHY operating channel.
WifiChannelWidthType GetWidthType() const
Return the width type of the operating channel.
std::set< uint8_t > Get20MHzIndicesCoveringRu(HeRu::RuSpec ru, MHz_u width) const
Get the channel indices of the minimum subset of 20 MHz channels containing the given RU.
MHz_u GetSecondaryChannelCenterFrequency(MHz_u secondaryChannelWidth) const
Get the center frequency of the secondary channel of the given width.
static const std::set< FrequencyChannelInfo > m_frequencyChannels
Available frequency channels.
std::set< FrequencyChannelInfo >::const_iterator ConstIterator
Typedef for a const iterator pointing to a channel in the set of available channels.
bool operator!=(const WifiPhyOperatingChannel &other) const
Check if the given WifiPhyOperatingChannel is different.
std::set< uint8_t > GetAll20MHzChannelIndicesInSecondary(MHz_u width) const
Get the channel indices of all the 20 MHz channels included in the secondary channel of the given wid...
bool IsDsss() const
Return whether the operating channel is a DSSS channel.
void SetPrimary20Index(uint8_t index)
Set the index of the primary 20 MHz channel (0 indicates the 20 MHz subchannel with the lowest center...
static uint8_t GetDefaultChannelNumber(MHz_u width, WifiStandard standard, WifiPhyBand band, std::optional< uint8_t > previousChannelNumber=std::nullopt)
Get the default channel number for a given segment of the given width and for the given standard and ...
uint8_t GetSecondarySegmentIndex(MHz_u secondaryChannelWidth) const
Get the index of the segment that contains a given secondary channel.
std::set< uint8_t > GetAll20MHzChannelIndicesInPrimary(MHz_u width) const
Get the channel indices of all the 20 MHz channels included in the primary channel of the given width...
uint8_t GetSecondaryChannelIndex(MHz_u secondaryChannelWidth) const
If the operating channel width is made of a multiple of 20 MHz, return the index of the secondary cha...
std::size_t GetNSegments() const
Get the number of frequency segments in the operating channel.
void Set(const std::vector< FrequencyChannelInfo > &segments, WifiStandard standard)
Set the channel according to the specified parameters if a unique frequency channel matches the speci...
void SetDefault(MHz_u width, WifiStandard standard, WifiPhyBand band)
Set the default channel of the given width and for the given standard and band.
ConstIteratorSet m_channelIts
const iterators pointing to the configured frequency channel
MHz_u GetWidth(std::size_t segment=0) const
Return the channel width for a given frequency segment.
uint8_t GetPrimaryChannelIndex(MHz_u primaryChannelWidth) const
If the operating channel width is a multiple of 20 MHz, return the index of the primary channel of th...
bool Is80211p() const
Return whether the operating channel is an 802.11p channel.
MHz_u GetPrimaryChannelCenterFrequency(MHz_u primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
std::vector< uint8_t > GetNumbers() const
Return the channel number per segment.
std::vector< MHz_u > GetFrequencies() const
Return the center frequency per segment.
bool IsOfdm() const
Return whether the operating channel is an OFDM channel.
MHz_u GetFrequency(std::size_t segment=0) const
Return the center frequency for a given frequency segment.
static ConstIterator FindFirst(uint8_t number, MHz_u frequency, MHz_u width, WifiStandard standard, WifiPhyBand band, ConstIterator start=m_frequencyChannels.begin())
Find the first frequency segment matching the specified parameters.
uint8_t m_primary20Index
index of the primary20 channel (0 indicates the 20 MHz subchannel with the lowest center frequency)
std::vector< MHz_u > GetWidths() const
Return the channel width per segment.
uint8_t GetPrimarySegmentIndex(MHz_u primaryChannelWidth) const
Get the index of the segment that contains a given primary channel.
WifiPhyBand GetPhyBand() const
Return the PHY band of the operating channel.
WifiPhyOperatingChannel GetPrimaryChannel(MHz_u primaryChannelWidth) const
Get a WifiPhyOperatingChannel object corresponding to the primary channel of the given width.
virtual ~WifiPhyOperatingChannel()
uint8_t GetPrimaryChannelNumber(MHz_u primaryChannelWidth, WifiStandard standard) const
Get channel number of the primary channel.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyBand
Identifies the PHY band.
WifiChannelWidthType
Enumeration of the possible channel widths.
@ WIFI_STANDARD_UNSPECIFIED
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
@ WIFI_PHY_BAND_UNSPECIFIED
Unspecified.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
double MHz_u
MHz weak type.
MHz_u GetMaximumChannelWidth(WifiModulationClass modulation)
Get the maximum channel width allowed for the given modulation class.
WifiModulationClass GetModulationClassForStandard(WifiStandard standard)
Return the modulation class corresponding to a given standard.
const std::map< WifiStandard, std::list< WifiPhyBand > > wifiStandards
map a given standard configured by the user to the allowed PHY bands
FrequencyChannelType GetFrequencyChannelType(WifiStandard standard)
Get the type of the frequency channel for the given standard.
A structure containing the information about a frequency channel.
WifiPhyBand band
the PHY band
uint8_t number
the channel number
MHz_u width
the channel width
MHz_u frequency
the center frequency
bool operator()(const ConstIterator &a, const ConstIterator &b) const
Functional operator for sorting the frequency segments.
Declaration of the following enums: