A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-mode.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006,2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 * Sébastien Deronne <sebastien.deronne@gmail.com>
19 */
20
21#ifndef WIFI_MODE_H
22#define WIFI_MODE_H
23
24#include "wifi-phy-common.h"
25
26#include "ns3/attribute-helper.h"
27#include "ns3/callback.h"
28
29#include <vector>
30
31namespace ns3
32{
33
34/// STA_ID to identify a single user (SU)
35static constexpr uint16_t SU_STA_ID = 65535;
36
37class WifiTxVector;
38
39/**
40 * \brief represent a single transmission mode
41 * \ingroup wifi
42 *
43 * A WifiMode is implemented by a single integer which is used
44 * to lookup in a global array the characteristics of the
45 * associated transmission mode. It is thus extremely cheap to
46 * keep a WifiMode variable around.
47 *
48 * \see attribute_WifiMode
49 */
51{
52 public:
53 /**
54 * \returns true if this <MCS, channel width, NSS> combination is allowed, false otherwise.
55 *
56 * \param channelWidth the considered channel width in MHz
57 * \param nss the considered number of streams
58 */
59 bool IsAllowed(uint16_t channelWidth, uint8_t nss) const;
60 /**
61 * \returns true if this TXVECTOR combination is allowed, false otherwise.
62 *
63 * \param txVector the const WifiTxVector& of the signal
64 */
65 bool IsAllowed(const WifiTxVector& txVector) const;
66 /**
67 *
68 * \param channelWidth the considered channel width in MHz
69 * \param guardInterval the considered guard interval duration in nanoseconds
70 * \param nss the considered number of streams
71 *
72 * \returns the physical bit rate of this signal in bps.
73 *
74 * If a transmission mode uses 1/2 FEC, and if its
75 * data rate is 3.25Mbps, the PHY rate is 6.5Mbps
76 */
77 uint64_t GetPhyRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const;
78 /**
79 * \param txVector the const WifiTxVector& of the signal
80 * \param staId the station ID for MU (unused if SU)
81 *
82 * \returns the physical bit rate of this signal in bps.
83 *
84 * If a transmission mode uses 1/2 FEC, and if its
85 * data rate is 3.25Mbps, the PHY rate is 6.5Mbps
86 */
87 uint64_t GetPhyRate(const WifiTxVector& txVector, uint16_t staId = SU_STA_ID) const;
88 /**
89 * \param channelWidth the considered channel width in MHz
90 *
91 * \returns the physical bit rate of this non-HT signal.
92 */
93 uint64_t GetPhyRate(uint16_t channelWidth) const;
94 /**
95 *
96 * \param channelWidth the considered channel width in MHz
97 * \param guardInterval the considered guard interval duration in nanoseconds
98 * \param nss the considered number of streams
99 *
100 * \returns the data bit rate of this signal in bps.
101 */
102 uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const;
103 /**
104 * \param txVector the const WifiTxVector& of the signal
105 * \param staId the station ID for MU (unused if SU)
106 *
107 * \returns the data bit rate of this signal.
108 */
109 uint64_t GetDataRate(const WifiTxVector& txVector, uint16_t staId = SU_STA_ID) const;
110 /**
111 * \param channelWidth the considered channel width in MHz
112 *
113 * \returns the data bit rate of this non-HT.
114 */
115 uint64_t GetDataRate(uint16_t channelWidth) const;
116
117 /**
118 * \returns the coding rate of this transmission mode
119 */
121 /**
122 * \returns the size of the modulation constellation.
123 */
124 uint16_t GetConstellationSize() const;
125 /**
126 * \returns the MCS value.
127 */
128 uint8_t GetMcsValue() const;
129 /**
130 * \returns a human-readable representation of this WifiMode
131 * instance.
132 */
133 std::string GetUniqueName() const;
134 /**
135 * \returns true if this mode is a mandatory mode, false
136 * otherwise.
137 */
138 bool IsMandatory() const;
139 /**
140 * \returns the UID associated to this wireless mode.
141 *
142 * Each specific wireless mode should have a different UID.
143 * For example, the 802.11b 1Mbps and the 802.11b 2Mbps modes
144 * should have different UIDs.
145 */
146 uint32_t GetUid() const;
147 /**
148 *
149 * \returns the Modulation Class (Section 9.7.8 "Modulation classes"; IEEE 802.11-2012)
150 * to which this WifiMode belongs.
151 */
153 /**
154 * \returns the rate (in bps) of the non-HT Reference Rate
155 * which corresponds to the HT MCS of this WifiMode.
156 *
157 * To convert an HT MCS to is corresponding non-HT Reference Rate
158 * use the modulation and coding rate of the HT MCS
159 * and lookup in Table 9-5 of IEEE 802.11-2012.
160 */
161 uint64_t GetNonHtReferenceRate() const;
162 /**
163 * \param mode the WifiMode
164 * \returns true if this WifiMode has a
165 * a code rate strictly higher than mode.
166 */
167 bool IsHigherCodeRate(WifiMode mode) const;
168 /**
169 * \param mode the WifiMode
170 * \returns true if this WifiMode has a
171 * a rate strictly higher than mode.
172 */
173 bool IsHigherDataRate(WifiMode mode) const;
174
175 /**
176 * Create an invalid WifiMode. Calling any method on the
177 * instance created will trigger an assert. This is useful
178 * to separate the declaration of a WifiMode variable from
179 * its initialization.
180 */
181 WifiMode();
182 /**
183 * Create a WifiMode if the given string represents a valid
184 * WifiMode name.
185 *
186 * \param name std::string of a valid WifiMode name
187 */
188 WifiMode(std::string name);
189
190 private:
191 /// allow WifiModeFactory class access
192 friend class WifiModeFactory;
193 /**
194 * Create a WifiMode from a given unique ID.
195 *
196 * \param uid unique ID
197 */
198 WifiMode(uint32_t uid);
199 uint32_t m_uid; ///< UID
200};
201
202/**
203 * Check if the two WifiModes are identical.
204 *
205 * \param a WifiMode
206 * \param b WifiMode
207 *
208 * \return true if the two WifiModes are identical,
209 * false otherwise
210 */
211bool operator==(const WifiMode& a, const WifiMode& b);
212
213/**
214 * Check if the two WifiModes are different.
215 *
216 * \param a WifiMode
217 * \param b WifiMode
218 *
219 * \return true if the two WifiModes are different,
220 * false otherwise
221 */
222bool operator!=(const WifiMode& a, const WifiMode& b);
223
224/**
225 * Compare two WifiModes
226 *
227 * \param a WifiMode
228 * \param b WifiMode
229 *
230 * \return true if a is less than b,
231 * false otherwise
232 */
233bool operator<(const WifiMode& a, const WifiMode& b);
234
235/**
236 * Serialize WifiMode to ostream (human-readable).
237 *
238 * \param os the output stream
239 * \param mode the WifiMode
240 *
241 * \return std::ostream
242 */
243std::ostream& operator<<(std::ostream& os, const WifiMode& mode);
244/**
245 * Serialize WifiMode from istream (human-readable).
246 *
247 * \param is the input stream
248 * \param mode the WifiMode
249 *
250 * \return std::istream
251 */
252std::istream& operator>>(std::istream& is, WifiMode& mode);
253
255
256/**
257 * In various parts of the code, folk are interested in maintaining a
258 * list of transmission modes. The vector class provides a good basis
259 * for this, but we here add some syntactic sugar by defining a
260 * WifiModeList type, and a corresponding iterator.
261 */
262typedef std::vector<WifiMode> WifiModeList;
263/**
264 * An iterator for WifiModeList vector.
265 */
266typedef WifiModeList::const_iterator WifiModeListIterator;
267
268/**
269 * \brief create WifiMode class instances and keep track of them.
270 *
271 * This factory ensures that each WifiMode created has a unique name
272 * and assigns to each of them a unique integer.
273 */
275{
276 public:
277 // Typedefs for callbacks used by WifiModeItem
278 /**
279 * Typedef for callback used to retrieve code rate of a WifiMode
280 * \return the code rate of the WifiMode.
281 */
283 /**
284 * Typedef for callback used to retrieve constellation size of a WifiMode
285 * \return the size of modulation constellation of the WifiMode.
286 */
288 /**
289 * Typedef for callback used to calculate PHY rate of a WifiMode
290 * from a TXVECTOR.
291 *
292 * \param txVector the TXVECTOR used for the transmission
293 * \param staId the station ID
294 * \return the physical bit rate of the signal in bps.
295 */
296 typedef Callback<uint64_t, const WifiTxVector& /* txVector */, uint16_t /* staId */>
298 /**
299 * Typedef for callback used to calculate data rate of a WifiMode
300 * from a TXVECTOR.
301 *
302 * \param txVector the TXVECTOR used for the transmission
303 * \param staId the station ID
304 * \return the data rate of the signal in bps.
305 */
306 typedef Callback<uint64_t, const WifiTxVector& /* txVector */, uint16_t /* staId */>
308 /**
309 * Typedef for callback used to calculate Non-HT Reference Rate of
310 * an MCS defined in HT or later amendment. For Non-HT modes (DSSS, OFDM,
311 * etc) this should be defined as null.
312 *
313 * \return the rate (in bps) of the non-HT Reference Rate.
314 */
316 /**
317 * Typedef for callback used to check whether a given combination is allowed
318 *
319 * \param txVector the TXVECTOR containing the combination to check
320 * \return true if combination of current WifiMode and TXVECTOR is allowed.
321 */
322 typedef Callback<bool, const WifiTxVector& /* txVector */> AllowedCallback;
323
324 /**
325 * \param uniqueName the name of the associated WifiMode. This name
326 * must be unique across _all_ instances.
327 * \param modClass the class of modulation
328 * \param isMandatory true if this WifiMode is mandatory, false otherwise.
329 * \param codeRateCallback a callback function to retrieve coding rate of
330 * this WifiMode. If convolutional coding is used for this rate
331 * then the callback returns the convolutional coding rate used. If
332 * there is no explicit convolutional coding step (e.g., for DSSS
333 * rates) then the callback should returns WIFI_CODE_RATE_UNDEFINED.
334 * \param constellationSizeCallback a callback function that returns the
335 * order of the constellation used.
336 * \param phyRateCallback a callback function to calculate the PHY rate (in
337 * bps) of this WifiMode.
338 * \param dataRateCallback a callback function to calculate the data rate
339 * (in bps) of this WifiMode.
340 * \param isAllowedCallback a callback function to check whether a
341 * specific combination of this WifiMode is allowed.
342 *
343 * \return WifiMode
344 *
345 * Create a non-HT WifiMode.
346 */
347 static WifiMode CreateWifiMode(std::string uniqueName,
348 WifiModulationClass modClass,
349 bool isMandatory,
350 CodeRateCallback codeRateCallback,
351 ConstellationSizeCallback constellationSizeCallback,
352 PhyRateCallback phyRateCallback,
353 DataRateCallback dataRateCallback,
354 AllowedCallback isAllowedCallback);
355
356 /**
357 * \param uniqueName the name of the associated WifiMode. This name
358 * must be unique across _all_ instances.
359 * \param mcsValue the MCS value
360 * \param modClass the class of modulation
361 * \param isMandatory true if this WifiMode is mandatory, false otherwise.
362 * \param codeRateCallback a callback function that returns the coding rate
363 * of this WifiMode.
364 * \param constellationSizeCallback a callback function that returns the size
365 * of modulation constellation of this WifiMode.
366 * \param phyRateCallback a callback function to calculate the PHY rate (in
367 * bps) of this WifiMode.
368 * \param dataRateCallback a callback function to calculate the data rate (in
369 * bps) of this WifiMode.
370 * \param nonHtReferenceRateCallback a callback function to calculate the rate
371 * (in bps) of the non-HT Reference Rate of this WifiMode.
372 * \param isAllowedCallback a callback function to calculate whether a given
373 * combination of is allowed for this WifiMode.
374 *
375 * \return WifiMode
376 *
377 * Create a HT or later WifiMode.
378 */
379 static WifiMode CreateWifiMcs(std::string uniqueName,
380 uint8_t mcsValue,
381 WifiModulationClass modClass,
382 bool isMandatory,
383 CodeRateCallback codeRateCallback,
384 ConstellationSizeCallback constellationSizeCallback,
385 PhyRateCallback phyRateCallback,
386 DataRateCallback dataRateCallback,
387 NonHtReferenceRateCallback nonHtReferenceRateCallback,
388 AllowedCallback isAllowedCallback);
389
390 private:
391 /// allow WifiMode class access
392 friend class WifiMode;
393 friend std::istream& operator>>(std::istream& is, WifiMode& mode);
394
395 /**
396 * Return a WifiModeFactory
397 *
398 * \return a WifiModeFactory
399 */
400 static WifiModeFactory* GetFactory();
402
403 /**
404 * This is the data associated to a unique WifiMode.
405 * The integer stored in a WifiMode is in fact an index
406 * in an array of WifiModeItem objects.
407 */
409 {
410 std::string uniqueUid; ///< unique UID
411 WifiModulationClass modClass; ///< modulation class
412 bool isMandatory; ///< flag to indicate whether this mode is mandatory
413 uint8_t mcsValue; ///< MCS value
415 GetCodeRateCallback; ///< Callback to retrieve code rate of this WifiModeItem
417 GetConstellationSizeCallback; ///< Callback to retrieve constellation size of this
418 ///< WifiModeItem
420 GetPhyRateCallback; ///< Callback to calculate PHY rate in bps of this WifiModeItem
422 GetDataRateCallback; ///< Callback to calculate data rate in bps of this WifiModeItem
424 GetNonHtReferenceRateCallback; ///< Callback to calculate non-HT reference rate of this
425 ///< WifiModeItem
427 IsAllowedCallback; ///< Callback to check whether a given combination of is allowed
428 };
429
430 /**
431 * Search and return WifiMode from a given name.
432 *
433 * \param name human-readable WifiMode
434 *
435 * \return the WifiMode
436 */
437 WifiMode Search(std::string name) const;
438 /**
439 * Allocate a WifiModeItem from a given uniqueUid.
440 *
441 * \param uniqueUid the unique UID
442 *
443 * \return the allocated UID index
444 */
445 uint32_t AllocateUid(std::string uniqueUid);
446 /**
447 * Return a WifiModeItem at the given UID index.
448 *
449 * \param uid the UID index
450 *
451 * \return WifiModeItem at the given UID
452 */
454
455 /**
456 * typedef for a vector of WifiModeItem.
457 */
458 typedef std::vector<WifiModeItem> WifiModeItemList;
460};
461
462} // namespace ns3
463
464#endif /* WIFI_MODE_H */
Callback template class.
Definition: callback.h:438
create WifiMode class instances and keep track of them.
Definition: wifi-mode.h:275
Callback< uint64_t, const WifiTxVector &, uint16_t > PhyRateCallback
Typedef for callback used to calculate PHY rate of a WifiMode from a TXVECTOR.
Definition: wifi-mode.h:297
WifiModeItem * Get(uint32_t uid)
Return a WifiModeItem at the given UID index.
Definition: wifi-mode.cc:400
Callback< WifiCodeRate > CodeRateCallback
Typedef for callback used to retrieve code rate of a WifiMode.
Definition: wifi-mode.h:282
static WifiMode CreateWifiMcs(std::string uniqueName, uint8_t mcsValue, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, NonHtReferenceRateCallback nonHtReferenceRateCallback, AllowedCallback isAllowedCallback)
Definition: wifi-mode.cc:318
std::vector< WifiModeItem > WifiModeItemList
typedef for a vector of WifiModeItem.
Definition: wifi-mode.h:458
uint32_t AllocateUid(std::string uniqueUid)
Allocate a WifiModeItem from a given uniqueUid.
Definition: wifi-mode.cc:383
static WifiModeFactory * GetFactory()
Return a WifiModeFactory.
Definition: wifi-mode.cc:407
WifiModeItemList m_itemList
item list
Definition: wifi-mode.h:459
Callback< uint64_t, const WifiTxVector &, uint16_t > DataRateCallback
Typedef for callback used to calculate data rate of a WifiMode from a TXVECTOR.
Definition: wifi-mode.h:307
WifiMode Search(std::string name) const
Search and return WifiMode from a given name.
Definition: wifi-mode.cc:350
Callback< uint16_t > ConstellationSizeCallback
Typedef for callback used to retrieve constellation size of a WifiMode.
Definition: wifi-mode.h:287
friend std::istream & operator>>(std::istream &is, WifiMode &mode)
Serialize WifiMode from istream (human-readable).
Definition: wifi-mode.cc:59
Callback< bool, const WifiTxVector & > AllowedCallback
Typedef for callback used to check whether a given combination is allowed.
Definition: wifi-mode.h:322
Callback< uint64_t > NonHtReferenceRateCallback
Typedef for callback used to calculate Non-HT Reference Rate of an MCS defined in HT or later amendme...
Definition: wifi-mode.h:315
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, AllowedCallback isAllowedCallback)
Definition: wifi-mode.cc:270
represent a single transmission mode
Definition: wifi-mode.h:51
WifiMode()
Create an invalid WifiMode.
Definition: wifi-mode.cc:248
uint32_t GetUid() const
Definition: wifi-mode.cc:179
std::string GetUniqueName() const
Definition: wifi-mode.cc:148
bool IsHigherDataRate(WifiMode mode) const
Definition: wifi-mode.cc:208
uint16_t GetConstellationSize() const
Definition: wifi-mode.cc:141
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetPhyRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:91
bool IsMandatory() const
Definition: wifi-mode.cc:156
uint64_t GetNonHtReferenceRate() const
Definition: wifi-mode.cc:192
WifiCodeRate GetCodeRate() const
Definition: wifi-mode.cc:134
uint32_t m_uid
UID.
Definition: wifi-mode.h:199
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
bool IsHigherCodeRate(WifiMode mode) const
Definition: wifi-mode.cc:201
bool IsAllowed(uint16_t channelWidth, uint8_t nss) const
Definition: wifi-mode.cc:68
uint8_t GetMcsValue() const
Definition: wifi-mode.cc:163
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:678
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
WifiModeList::const_iterator WifiModeListIterator
An iterator for WifiModeList vector.
Definition: wifi-mode.h:266
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes.
Definition: wifi-mode.h:262
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition: wifi-mode.h:35
WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
This is the data associated to a unique WifiMode.
Definition: wifi-mode.h:409
WifiModulationClass modClass
modulation class
Definition: wifi-mode.h:411
AllowedCallback IsAllowedCallback
Callback to check whether a given combination of is allowed.
Definition: wifi-mode.h:427
std::string uniqueUid
unique UID
Definition: wifi-mode.h:410
bool isMandatory
flag to indicate whether this mode is mandatory
Definition: wifi-mode.h:412
PhyRateCallback GetPhyRateCallback
Callback to calculate PHY rate in bps of this WifiModeItem.
Definition: wifi-mode.h:420
DataRateCallback GetDataRateCallback
Callback to calculate data rate in bps of this WifiModeItem.
Definition: wifi-mode.h:422
NonHtReferenceRateCallback GetNonHtReferenceRateCallback
Callback to calculate non-HT reference rate of this WifiModeItem.
Definition: wifi-mode.h:424
ConstellationSizeCallback GetConstellationSizeCallback
Callback to retrieve constellation size of this WifiModeItem.
Definition: wifi-mode.h:417
CodeRateCallback GetCodeRateCallback
Callback to retrieve code rate of this WifiModeItem.
Definition: wifi-mode.h:415
Declaration of the following enums: