A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-phy-operating-channel.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Stefano Avallone <stavallo@unina.it>
7 * Sébastien Deronne <sebastien.deronne@gmail.com>
8 */
9
10#ifndef WIFI_PHY_OPERATING_CHANNEL_H
11#define WIFI_PHY_OPERATING_CHANNEL_H
12
13#include "wifi-phy-band.h"
14#include "wifi-phy-common.h"
15#include "wifi-ru.h"
16
17#include "ns3/wifi-export.h"
18
19#include <optional>
20#include <set>
21#include <tuple>
22#include <vector>
23
24namespace ns3
25{
26
27/**
28 * A structure containing the information about a frequency channel
29 */
30struct WIFI_EXPORT FrequencyChannelInfo
31{
32 /**
33 * @brief spaceship operator.
34 *
35 * @param info the frequency channel info
36 * @returns -1 if the provided channel info is located at a lower channel number, 0 if the
37 * provided channel info is identical or 1 if the provided channel info is located at a higher
38 * channel number
39 */
40 auto operator<=>(const FrequencyChannelInfo& info) const = default;
41 uint8_t number{0}; ///< the channel number
42 MHz_u frequency{0}; ///< the center frequency
43 MHz_u width{0}; ///< the channel width
45 FrequencyChannelType type{FrequencyChannelType::OFDM}; ///< the frequency channel type
46};
47
48/**
49 * @brief Stream insertion operator.
50 *
51 * @param os the stream
52 * @param info the frequency channel info
53 * @returns a reference to the stream
54 */
55std::ostream& operator<<(std::ostream& os, const FrequencyChannelInfo& info);
56
57/**
58 * @ingroup wifi
59 *
60 * Class that keeps track of all information about the current PHY operating channel.
61 */
62class WIFI_EXPORT WifiPhyOperatingChannel
63{
64 public:
65 /// Typedef for a const iterator pointing to a channel in the set of available channels
66 using ConstIterator = std::set<FrequencyChannelInfo>::const_iterator;
67
68 /// Comparison functor used to sort the segments by increasing frequencies
69 struct Compare
70 {
71 /**
72 * Functional operator for sorting the frequency segments.
73 *
74 * @param a const iterator pointing to the frequency channel for the first segment
75 * @param b const iterator pointing to the frequency channel for the second segment
76 * @return true if the center frequency of the first segment is lower than the center
77 * frequency of the second segment
78 */
79 bool operator()(const ConstIterator& a, const ConstIterator& b) const;
80 };
81
82 /// Typedef for a set of const iterator pointing to the segments of a channel
83 using ConstIteratorSet = std::set<ConstIterator, Compare>;
84
85 /**
86 * Create an uninitialized PHY operating channel.
87 */
89
90 /**
91 * Create a PHY operating channel from an iterator pointing to a channel in the set of available
92 * channels.
93 *
94 * @param it the iterator pointing to a channel in the set of available channels
95 */
97
98 /**
99 * Create a PHY operating channel from iterators pointing to multiple frequency segments in the
100 * set of available channels.
101 *
102 * @param its the iterators pointing to frequency segments in the set of available channels
103 */
105
106 virtual ~WifiPhyOperatingChannel();
107
108 /**
109 * Check if the given WifiPhyOperatingChannel is equivalent.
110 * Note that the primary20 channels are not compared.
111 *
112 * @param other another WifiPhyOperatingChannel
113 *
114 * @return true if the given WifiPhyOperatingChannel is equivalent,
115 * false otherwise
116 */
117 bool operator==(const WifiPhyOperatingChannel& other) const;
118
119 /**
120 * Check if the given WifiPhyOperatingChannel is different.
121 *
122 * @param other another WifiPhyOperatingChannel
123 *
124 * @return true if the given WifiPhyOperatingChannel is different,
125 * false otherwise
126 */
127 bool operator!=(const WifiPhyOperatingChannel& other) const;
128
129 static const std::set<FrequencyChannelInfo>
130 m_frequencyChannels; //!< Available frequency channels
131
132 /**
133 * Return a reference to the set of all available frequency channels
134 *
135 * @return reference to the set of frequency channels
136 */
137 static const std::set<FrequencyChannelInfo>& GetFrequencyChannels();
138
139 /**
140 * Return true if a valid channel has been set, false otherwise.
141 *
142 * @return true if a valid channel has been set, false otherwise
143 */
144 bool IsSet() const;
145 /**
146 * Set the channel according to the specified parameters if a unique
147 * frequency channel matches the specified criteria, or abort the
148 * simulation otherwise.
149 * If the channel width is a multiple of 20 MHz, the primary 20 MHz channel
150 * is set to the 20 MHz subchannel with the lowest center frequency.
151 *
152 * @param segments the frequency segments
153 * @param standard the standard
154 */
155 void Set(const std::vector<FrequencyChannelInfo>& segments, WifiStandard standard);
156 /**
157 * Set the default channel of the given width and for the given standard and band.
158 * If the channel width is a multiple of 20 MHz, the primary 20 MHz channel
159 * is set to the 20 MHz subchannel with the lowest center frequency.
160 *
161 * @param width the channel width
162 * @param standard the standard
163 * @param band the PHY band
164 */
165 void SetDefault(MHz_u width, WifiStandard standard, WifiPhyBand band);
166
167 /**
168 * Get the default channel number for a given segment of the given width and for the given
169 * standard and band.
170 *
171 * @param width the channel width
172 * @param standard the standard
173 * @param band the PHY band
174 * @param previousChannelNumber the channel number of the previous (in frequency) segment (if
175 * non-contiguous operating channel is used). If there is no place for another segment that is
176 * not contiguous to that previous one (at a higher frequency), an error is thrown
177 * @return the default channel number
178 */
179 static uint8_t GetDefaultChannelNumber(
180 MHz_u width,
181 WifiStandard standard,
182 WifiPhyBand band,
183 std::optional<uint8_t> previousChannelNumber = std::nullopt);
184
185 /**
186 * Return the channel number for a given frequency segment.
187 * Segments are ordered by increasing frequencies, hence by default
188 * it returns the channel number of the segment occuping the lowest
189 * frequencies when a non-contiguous operating channel is used.
190 *
191 * @param segment the index of the frequency segment (if operating channel is non-contiguous)
192 * @return the channel number for a given frequency segment
193 */
194 uint8_t GetNumber(std::size_t segment = 0) const;
195 /**
196 * Return the center frequency for a given frequency segment.
197 * Segments are ordered by increasing frequencies, hence by default
198 * it returns the center frequency of the segment occuping the lowest
199 * frequencies when a non-contiguous operating channel is used.
200 *
201 * @param segment the index of the frequency segment (if operating channel is non-contiguous)
202 * @return the center frequency for a given frequency segment
203 */
204 MHz_u GetFrequency(std::size_t segment = 0) const;
205 /**
206 * Return the channel width for a given frequency segment.
207 * Segments are ordered by increasing frequencies, hence by default
208 * it returns the channel width of the segment occuping the lowest
209 * frequencies when a non-contiguous operating channel is used.
210 *
211 * @param segment the index of the frequency segment (if operating channel is non-contiguous)
212 * @return the channel width for a given frequency segment
213 */
214 MHz_u GetWidth(std::size_t segment = 0) const;
215 /**
216 * Return the width of the whole operating channel.
217 *
218 * @return the width of the whole operating channel
219 */
220 MHz_u GetTotalWidth() const;
221 /**
222 * Return the channel number per segment.
223 * Segments are ordered by increasing frequencies.
224 *
225 * @return the channel number per segment
226 */
227 std::vector<uint8_t> GetNumbers() const;
228 /**
229 * Return the center frequency per segment.
230 * Segments are ordered by increasing frequencies.
231 *
232 * @return the center frequency per segment
233 */
234 std::vector<MHz_u> GetFrequencies() const;
235 /**
236 * Return the channel width per segment.
237 * Segments are ordered by increasing frequencies.
238 *
239 * @return the channel width per segment
240 */
241 std::vector<MHz_u> GetWidths() const;
242 /**
243 * Return the width type of the operating channel.
244 *
245 * @return the width type of the operating channel
246 */
248 /**
249 * Return the PHY band of the operating channel
250 *
251 * @return the PHY band of the operating channel
252 */
253 WifiPhyBand GetPhyBand() const;
254 /**
255 * Return whether the operating channel is an OFDM channel.
256 *
257 * @return whether the operating channel is an OFDM channel
258 */
259 bool IsOfdm() const;
260 /**
261 * Return whether the operating channel is a DSSS channel.
262 *
263 * @return whether the operating channel is a DSSS channel
264 */
265 bool IsDsss() const;
266 /**
267 * Return whether the operating channel is an 802.11p channel.
268 *
269 * @return whether the operating channel is an 802.11p channel
270 */
271 bool Is80211p() const;
272
273 /**
274 * If the operating channel width is a multiple of 20 MHz, return the index of the
275 * primary channel of the given width within the operating channel (0 indicates
276 * the 20 MHz subchannel with the lowest center frequency). Otherwise, return 0.
277 *
278 * @param primaryChannelWidth the width of the primary channel
279 * @return the index of the requested primary channel within the operating channel
280 */
281 uint8_t GetPrimaryChannelIndex(MHz_u primaryChannelWidth) const;
282
283 /**
284 * If the operating channel width is made of a multiple of 20 MHz, return the index of the
285 * secondary channel of the given width within the operating channel (0 indicates
286 * the 20 MHz subchannel with the lowest center frequency). Otherwise, return 0.
287 *
288 * @param secondaryChannelWidth the width of the secondary channel
289 * @return the index of the requested secondary channel within the operating channel
290 */
291 uint8_t GetSecondaryChannelIndex(MHz_u secondaryChannelWidth) const;
292
293 /**
294 * Set the index of the primary 20 MHz channel (0 indicates the 20 MHz subchannel
295 * with the lowest center frequency among all segments).
296 *
297 * @param index the index of the primary 20 MHz channel
298 */
299 void SetPrimary20Index(uint8_t index);
300
301 /**
302 * Get the center frequency of the primary channel of the given width.
303 *
304 * @param primaryChannelWidth the width of the primary channel
305 * @return the center frequency of the primary channel of the given width
306 */
307 MHz_u GetPrimaryChannelCenterFrequency(MHz_u primaryChannelWidth) const;
308
309 /**
310 * Get the center frequency of the secondary channel of the given width.
311 *
312 * @param secondaryChannelWidth the width of the secondary channel
313 * @return the center frequency of the secondary channel of the given width
314 */
315 MHz_u GetSecondaryChannelCenterFrequency(MHz_u secondaryChannelWidth) const;
316
317 /**
318 * Get the channel indices of all the 20 MHz channels included in the primary
319 * channel of the given width, if such primary channel exists, or an empty set,
320 * otherwise.
321 *
322 * @param width the width of the primary channel
323 * @return the channel indices of all the 20 MHz channels included in the primary
324 * channel of the given width, if such primary channel exists, or an empty set,
325 * otherwise
326 */
327 std::set<uint8_t> GetAll20MHzChannelIndicesInPrimary(MHz_u width) const;
328 /**
329 * Get the channel indices of all the 20 MHz channels included in the secondary
330 * channel of the given width, if such secondary channel exists, or an empty set,
331 * otherwise.
332 *
333 * @param width the width of the secondary channel
334 * @return the channel indices of all the 20 MHz channels included in the secondary
335 * channel of the given width, if such secondary channel exists, or an empty set,
336 * otherwise
337 */
338 std::set<uint8_t> GetAll20MHzChannelIndicesInSecondary(MHz_u width) const;
339 /**
340 * Get the channel indices of all the 20 MHz channels included in the secondary
341 * channel corresponding to the given primary channel, if such secondary channel
342 * exists, or an empty set, otherwise.
343 *
344 * @param primaryIndices the channel indices of all the 20 MHz channels included
345 * in the primary channel
346 * @return the channel indices of all the 20 MHz channels included in the secondary
347 * channel corresponding to the given primary channel, if such secondary channel
348 * exists, or an empty set, otherwise
349 */
350 std::set<uint8_t> GetAll20MHzChannelIndicesInSecondary(
351 const std::set<uint8_t>& primaryIndices) const;
352
353 /**
354 * Find the first frequency segment matching the specified parameters.
355 *
356 * @param number the channel number (use 0 to leave it unspecified)
357 * @param frequency the channel center frequency in MHz (use 0 to leave it unspecified)
358 * @param width the channel width (use 0 to leave it unspecified)
359 * @param standard the standard (use WIFI_STANDARD_UNSPECIFIED not to check whether a
360 * channel is suitable for a specific standard)
361 * @param band the PHY band
362 * @param start an iterator pointing to the channel to start the search with
363 * @return an iterator pointing to the found channel, if any, or to past-the-end
364 * of the set of available channels
365 */
366 static ConstIterator FindFirst(uint8_t number,
367 MHz_u frequency,
368 MHz_u width,
369 WifiStandard standard,
370 WifiPhyBand band,
371 ConstIterator start = GetFrequencyChannels().begin());
372
373 /**
374 * Get channel number of the primary channel
375 * @param primaryChannelWidth the width of the primary channel
376 * @param standard the standard
377 *
378 * @return channel number of the primary channel
379 */
380 uint8_t GetPrimaryChannelNumber(MHz_u primaryChannelWidth, WifiStandard standard) const;
381
382 /**
383 * Get a WifiPhyOperatingChannel object corresponding to the primary channel of the given width.
384 *
385 * @param primaryChannelWidth the width of the primary channel in MHz
386 * @return a WifiPhyOperatingChannel object corresponding to the primary channel of the given
387 * width
388 */
389 WifiPhyOperatingChannel GetPrimaryChannel(MHz_u primaryChannelWidth) const;
390
391 /**
392 * Get the channel indices of the minimum subset of 20 MHz channels containing the given RU.
393 *
394 * @param ru the given RU
395 * @param width the width of the channel to which the given RU refers to; normally,
396 * it is the width of the PPDU for which the RU is allocated
397 * @return the channel indices of the minimum subset of 20 MHz channels containing the given RU
398 */
399 std::set<uint8_t> Get20MHzIndicesCoveringRu(WifiRu::RuSpec ru, MHz_u width) const;
400
401 /**
402 * Get the index of the segment that contains a given primary channel.
403 *
404 * @param primaryChannelWidth the width of the primary channel
405 * @return the index of the segment that contains the primary channel
406 */
407 uint8_t GetPrimarySegmentIndex(MHz_u primaryChannelWidth) const;
408
409 /**
410 * Get the index of the segment that contains a given secondary channel.
411 *
412 * @param secondaryChannelWidth the width of the secondary channel
413 * @return the index of the segment that contains the secondary channel
414 */
415 uint8_t GetSecondarySegmentIndex(MHz_u secondaryChannelWidth) const;
416
417 /**
418 * Get the number of frequency segments in the operating channel.
419 * This is only more than one if a non-contiguous operating channel is used.
420 *
421 * @return the number of frequency segments
422 */
423 std::size_t GetNSegments() const;
424
425 private:
426 ConstIteratorSet m_channelIts; //!< const iterators pointing to the configured frequency channel
427 uint8_t m_primary20Index; /**< index of the primary20 channel (0 indicates the 20 MHz
428 subchannel with the lowest center frequency) */
429};
430
431/**
432 * @brief Stream insertion operator.
433 *
434 * @param os the stream
435 * @param channel the operating channel
436 * @returns a reference to the stream
437 */
438std::ostream& operator<<(std::ostream& os, const WifiPhyOperatingChannel& channel);
439
440} // namespace ns3
441
442#endif /* WIFI_PHY_OPERATING_CHANNEL_H */
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.
static const std::set< FrequencyChannelInfo > & GetFrequencyChannels()
Return a reference to the set of all available frequency 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=GetFrequencyChannels().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.
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.
std::variant< HeRu::RuSpec, EhtRu::RuSpec > RuSpec
variant of the RU specification
Definition wifi-ru.h:27
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
FrequencyChannelType
Enumeration of frequency channel types.
Definition wifi-types.h:89
WifiPhyBand
Identifies the PHY band.
WifiChannelWidthType
Enumeration of the possible channel widths.
Definition wifi-types.h:28
@ WIFI_PHY_BAND_UNSPECIFIED
Unspecified.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
double MHz_u
MHz weak type.
Definition wifi-units.h:31
A structure containing the information about a frequency channel.
uint8_t number
the channel number
auto operator<=>(const FrequencyChannelInfo &info) const =default
spaceship operator.
MHz_u frequency
the center frequency
FrequencyChannelType type
the frequency channel type
Comparison functor used to sort the segments by increasing frequencies.
bool operator()(const ConstIterator &a, const ConstIterator &b) const
Functional operator for sorting the frequency segments.
Declaration of the following enums: