15#include "ns3/assert.h"
302 "Operating channel does not support more than 2 segments");
320 std::stringstream ss;
321 for (
const auto& segment : segments)
327 NS_ASSERT_MSG(!segments.empty(),
"At least one frequency segment has to be provided");
330 for (
const auto& segment : segments)
332 if (
const auto channelIt =
333 FindFirst(segment.number, segment.frequency, segment.width, standard, segment.band);
343 channelIts.insert(channelIt);
347 if (channelIts.size() != segments.size())
350 throw std::runtime_error(
351 "WifiPhyOperatingChannel: No unique channel found given the specified criteria");
354 auto it = channelIts.begin();
355 for (std::size_t segment = 0; segment < (channelIts.size() - 1); ++segment)
357 const auto freq = (*it)->frequency;
358 const auto width = (*it)->width;
359 const auto band = (*it)->band;
360 const auto maxFreq = freq + (width / 2);
362 const auto nextFreq = (*it)->frequency;
363 const auto nextWidth = (*it)->width;
364 const auto nextBand = (*it)->band;
365 const auto nextMinFreq = nextFreq - (nextWidth / 2);
366 if (maxFreq >= nextMinFreq)
368 throw std::runtime_error(
369 "WifiPhyOperatingChannel is invalid: segments cannot be adjacent nor overlap");
371 if (band != nextBand)
373 throw std::runtime_error(
"WifiPhyOperatingChannel is invalid: all segments shall "
374 "belong to the same band");
378 if ((channelIts.size() > 2) ||
379 ((channelIts.size() == 2) &&
380 !std::all_of(channelIts.cbegin(), channelIts.cend(), [](
const auto& channel) {
381 return channel->width == MHz_u{80};
384 throw std::runtime_error(
"WifiPhyOperatingChannel is invalid: only 80+80MHz is "
385 "expected as non-contiguous channel");
388 m_channelIts = channelIts;
389 m_primary20Index = 0;
404 std::optional<uint8_t> previousChannelNumber )
408 if (previousChannelNumber)
410 prevSegmentChannelIt =
411 FindFirst(*previousChannelNumber,
MHz_u{0}, width, standard, band, start);
414 start = std::next(prevSegmentChannelIt);
417 auto channelIt =
FindFirst(0,
MHz_u{0}, width, standard, band, start);
420 const auto prevFreq = prevSegmentChannelIt->frequency;
421 const auto prevWidth = prevSegmentChannelIt->width;
422 const auto prevMaxFreq = prevFreq + (prevWidth / 2);
423 const auto nextFreq = channelIt->frequency;
424 const auto nextWidth = channelIt->width;
425 const auto nextMinFreq = nextFreq - (nextWidth / 2);
426 if (prevMaxFreq <= nextMinFreq)
430 channelIt =
FindFirst(0,
MHz_u{0}, width, standard, band, std::next(channelIt));
436 return channelIt->number;
440 throw std::runtime_error(
"WifiPhyOperatingChannel: No default channel found of the given width "
441 "and for the given PHY standard and band");
454 if (number != 0 && channel.number != number)
458 if (frequency !=
MHz_u{0} && channel.frequency != frequency)
462 if (width !=
MHz_u{0} && channel.width != width)
483 (std::find(standardIt->second.cbegin(), standardIt->second.cend(), band) ==
484 standardIt->second.cend() ||
497 return (*std::next(
m_channelIts.begin(), segment))->number;
504 return (*std::next(
m_channelIts.begin(), segment))->frequency;
548 std::vector<uint8_t> channelNumbers{};
551 std::back_inserter(channelNumbers),
552 [](
const auto& channel) { return channel->number; });
553 return channelNumbers;
560 std::vector<MHz_u> centerFrequencies{};
563 std::back_inserter(centerFrequencies),
564 [](
const auto& channel) { return channel->frequency; });
565 return centerFrequencies;
572 std::vector<MHz_u> channelWidths{};
575 std::back_inserter(channelWidths),
576 [](
const auto& channel) { return channel->width; });
577 return channelWidths;
587 [](
MHz_u sum,
const auto& channel) { return sum + channel->width; });
624 if (
static_cast<uint16_t
>(primaryChannelWidth) % 20 != 0)
626 NS_LOG_DEBUG(
"The operating channel width is not a multiple of 20 MHz; return 0");
637 while (width < primaryChannelWidth)
649 const uint8_t secondaryIndex =
650 (primaryIndex % 2 == 0) ? (primaryIndex + 1) : (primaryIndex - 1);
651 return secondaryIndex;
660 "Primary20 index out of range");
672 const auto numIndices =
GetTotalWidth() / primaryChannelWidth;
674 return (primaryIndex >= (numIndices / 2)) ? 1 : 0;
681 "Primary channel width cannot be larger than the width of a frequency segment");
687 const auto numIndices =
GetTotalWidth() / primaryChannelWidth;
689 return (secondaryIndex >= (numIndices / 2)) ? 1 : 0;
697 const auto segmentWidth =
GetWidth(segmentIndex);
699 const uint8_t segmentOffset = (segmentIndex * (segmentWidth / primaryChannelWidth));
710 const auto segmentWidth =
GetWidth(segmentIndex);
712 const uint8_t segmentOffset = (segmentIndex * (segmentWidth / secondaryChannelWidth));
715 secondaryChannelWidth;
723 "Primary channel width cannot be larger than the width of a frequency segment");
728 return primaryChanIt->number;
736 "Requested primary channel width ("
737 << primaryChannelWidth <<
" MHz) exceeds total width (" <<
GetTotalWidth()
756 return primaryChannel;
769 std::set<uint8_t> indices;
772 while (currWidth < width)
789 const std::set<uint8_t>& primaryIndices)
const
797 MHz_u primaryWidth{20};
800 while (size != primaryIndices.size())
813 std::set<uint8_t> secondaryIndices;
814 for (
const auto& index : primaryIndices)
816 secondaryIndices.insert(index ^ size);
819 return secondaryIndices;
828 "No RU of type " << ruType <<
" is contained in a " << width <<
" MHz channel");
830 "The given width (" << width <<
" MHz) exceeds the operational width ("
838 "26-tone RU with index 19 is only present in channels of at least 80 MHz");
841 auto indices = std::get<HeRu::RuSpec>(ru).GetPrimary80MHz()
844 indices.erase(indices.begin());
845 indices.erase(std::prev(indices.end()));
856 ruPhyIndex -= (ruPhyIndex - 19) / 37;
860 uint8_t n20MHzChannels;
886 auto nRusInCoveringChannel =
891 std::size_t indexOfCoveringChannelInGivenWidth = (ruPhyIndex - 1) / nRusInCoveringChannel;
895 NS_ASSERT(indexOfCoveringChannelInGivenWidth < 16);
896 std::set<uint8_t> indices({
static_cast<uint8_t
>(indexOfCoveringChannelInGivenWidth)});
898 while (n20MHzChannels > 1)
900 std::set<uint8_t> updatedIndices;
901 for (
const auto& idx : indices)
903 updatedIndices.insert(idx * 2);
904 updatedIndices.insert(idx * 2 + 1);
906 indices.swap(updatedIndices);
915 std::set<uint8_t> updatedIndices;
916 for (
const auto& idx : indices)
918 updatedIndices.insert(idx + offset);
920 indices.swap(updatedIndices);
941 return !(*
this == other);
949 const auto numSegments = channel.GetNSegments();
950 for (std::size_t segmentId = 0; segmentId < numSegments; ++segmentId)
954 os <<
"segment " << segmentId <<
" ";
956 os <<
"channel " << +channel.GetNumber() <<
" frequency " << channel.GetFrequency()
957 <<
" width " << channel.GetWidth() <<
" band " << channel.GetPhyBand();
958 if ((segmentId == 0) && (
static_cast<uint16_t
>(channel.GetTotalWidth()) % 20 == 0))
960 os <<
" primary20 " << +channel.GetPrimaryChannelIndex(
MHz_u{20});
962 if (segmentId < numSegments - 1)
970 os <<
"channel not set";
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.
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.
std::set< uint8_t > Get20MHzIndicesCoveringRu(WifiRu::RuSpec ru, MHz_u width) const
Get the channel indices of the minimum subset of 20 MHz channels containing the given RU.
static std::size_t GetNRus(MHz_u bw, RuType ruType, WifiModulationClass mc)
Get the number of distinct RUs of the given type (number of tones) available in a PPDU of the given b...
std::variant< HeRu::RuSpec, EhtRu::RuSpec > RuSpec
variant of the RU specification
static bool IsHe(RuSpec ru)
Get whether a given RU variant is a HE RU.
static MHz_u GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
static RuType GetRuType(RuSpec ru)
Get the type of a given RU.
static std::size_t GetPhyIndex(RuSpec ru, MHz_u bw, uint8_t p20Index)
Get the RU PHY index.
static std::size_t GetIndex(RuSpec ru)
Get the index of a given RU.
#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.
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
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.
std::size_t Count20MHzSubchannels(MHz_u channelWidth)
Return the number of 20 MHz subchannels covering the channel width.
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.
std::ostream & operator<<(std::ostream &os, const PairObject &obj)
Stream insertion operator.
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: