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