A Discrete-Event Network Simulator
API
wifi-tx-vector.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Nicola Baldo <nbaldo@cttc.es>
19  * Ghada Badawy <gbadawy@gmail.com>
20  */
21 
22 #include "wifi-tx-vector.h"
23 #include "ns3/abort.h"
24 
25 namespace ns3 {
26 
28  : m_preamble (WIFI_PREAMBLE_LONG),
29  m_channelWidth (20),
30  m_guardInterval (800),
31  m_nTx (1),
32  m_nss (1),
33  m_ness (0),
34  m_aggregation (false),
35  m_stbc (false),
36  m_ldpc (false),
37  m_bssColor (0),
38  m_modeInitialized (false)
39 {
40 }
41 
43  uint8_t powerLevel,
44  WifiPreamble preamble,
45  uint16_t guardInterval,
46  uint8_t nTx,
47  uint8_t nss,
48  uint8_t ness,
49  uint16_t channelWidth,
50  bool aggregation,
51  bool stbc,
52  bool ldpc,
53  uint8_t bssColor)
54  : m_mode (mode),
55  m_txPowerLevel (powerLevel),
56  m_preamble (preamble),
57  m_channelWidth (channelWidth),
58  m_guardInterval (guardInterval),
59  m_nTx (nTx),
60  m_nss (nss),
61  m_ness (ness),
62  m_aggregation (aggregation),
63  m_stbc (stbc),
64  m_ldpc (ldpc),
65  m_bssColor (bssColor),
66  m_modeInitialized (true)
67 {
68 }
69 
71  : m_mode (txVector.m_mode),
72  m_txPowerLevel (txVector.m_txPowerLevel),
73  m_preamble (txVector.m_preamble),
74  m_channelWidth (txVector.m_channelWidth),
75  m_guardInterval (txVector.m_guardInterval),
76  m_nTx (txVector.m_nTx),
77  m_nss (txVector.m_nss),
78  m_ness (txVector.m_ness),
79  m_aggregation (txVector.m_aggregation),
80  m_stbc (txVector.m_stbc),
81  m_ldpc (txVector.m_ldpc),
82  m_bssColor (txVector.m_bssColor),
83  m_modeInitialized (txVector.m_modeInitialized)
84 {
85  m_muUserInfos.clear ();
86  if (!txVector.m_muUserInfos.empty ()) //avoids crashing for loop
87  {
88  for (auto & info : txVector.m_muUserInfos)
89  {
90  m_muUserInfos.insert (std::make_pair (info.first, info.second));
91  }
92  }
93 }
94 
96 {
97  m_muUserInfos.clear ();
98 }
99 
100 bool
102 {
103  return m_modeInitialized;
104 }
105 
106 WifiMode
107 WifiTxVector::GetMode (uint16_t staId) const
108 {
109  if (!m_modeInitialized)
110  {
111  NS_FATAL_ERROR ("WifiTxVector mode must be set before using");
112  }
114  {
115  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU (" << staId << ")");
116  NS_ASSERT (m_muUserInfos.find (staId) != m_muUserInfos.end ());
117  return m_muUserInfos.at (staId).mcs;
118  }
119  return m_mode;
120 }
121 
122 uint8_t
124 {
125  return m_txPowerLevel;
126 }
127 
130 {
131  return m_preamble;
132 }
133 
134 uint16_t
136 {
137  return m_channelWidth;
138 }
139 
140 uint16_t
142 {
143  return m_guardInterval;
144 }
145 
146 uint8_t
148 {
149  return m_nTx;
150 }
151 
152 uint8_t
153 WifiTxVector::GetNss (uint16_t staId) const
154 {
156  {
157  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU (" << staId << ")");
158  NS_ASSERT (m_muUserInfos.find (staId) != m_muUserInfos.end ());
159  return m_muUserInfos.at (staId).nss;
160  }
161  return m_nss;
162 }
163 
164 uint8_t
166 {
167  uint8_t nss = 0;
169  {
170  for (const auto & info : m_muUserInfos)
171  {
172  nss = (nss < info.second.nss) ? info.second.nss : nss;
173  }
174  }
175  else
176  {
177  nss = m_nss;
178  }
179  return nss;
180 }
181 
182 uint8_t
184 {
185  return m_ness;
186 }
187 
188 bool
190 {
191  return m_aggregation;
192 }
193 
194 bool
196 {
197  return m_stbc;
198 }
199 
200 bool
202 {
203  return m_ldpc;
204 }
205 
206 void
208 {
209  m_mode = mode;
210  m_modeInitialized = true;
211 }
212 
213 void
214 WifiTxVector::SetMode (WifiMode mode, uint16_t staId)
215 {
216  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "Not an HE MU transmission");
217  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU");
218  m_muUserInfos[staId].mcs = mode;
219  m_modeInitialized = true;
220 }
221 
222 void
223 WifiTxVector::SetTxPowerLevel (uint8_t powerlevel)
224 {
225  m_txPowerLevel = powerlevel;
226 }
227 
228 void
230 {
231  m_preamble = preamble;
232 }
233 
234 void
235 WifiTxVector::SetChannelWidth (uint16_t channelWidth)
236 {
237  m_channelWidth = channelWidth;
238 }
239 
240 void
241 WifiTxVector::SetGuardInterval (uint16_t guardInterval)
242 {
243  m_guardInterval = guardInterval;
244 }
245 
246 void
247 WifiTxVector::SetNTx (uint8_t nTx)
248 {
249  m_nTx = nTx;
250 }
251 
252 void
253 WifiTxVector::SetNss (uint8_t nss)
254 {
255  m_nss = nss;
256 }
257 
258 void
259 WifiTxVector::SetNss (uint8_t nss, uint16_t staId)
260 {
261  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "Not an HE MU transmission");
262  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU");
263  m_muUserInfos[staId].nss = nss;
264 }
265 
266 void
267 WifiTxVector::SetNess (uint8_t ness)
268 {
269  m_ness = ness;
270 }
271 
272 void
274 {
275  m_aggregation = aggregation;
276 }
277 
278 void
280 {
281  m_stbc = stbc;
282 }
283 
284 void
286 {
287  m_ldpc = ldpc;
288 }
289 
290 void
292 {
293  m_bssColor = color;
294 }
295 
296 uint8_t
298 {
299  return m_bssColor;
300 }
301 
302 bool
304 {
305  if (!GetModeInitialized ())
306  {
307  return false;
308  }
309  std::string modeName = m_mode.GetUniqueName ();
310  if (m_channelWidth == 20)
311  {
312  if (m_nss != 3 && m_nss != 6)
313  {
314  return (modeName != "VhtMcs9");
315  }
316  }
317  else if (m_channelWidth == 80)
318  {
319  if (m_nss == 3 || m_nss == 7)
320  {
321  return (modeName != "VhtMcs6");
322  }
323  else if (m_nss == 6)
324  {
325  return (modeName != "VhtMcs9");
326  }
327  }
328  else if (m_channelWidth == 160)
329  {
330  if (m_nss == 3)
331  {
332  return (modeName != "VhtMcs9");
333  }
334  }
335  return true;
336 }
337 
339 WifiTxVector::GetRu (uint16_t staId) const
340 {
341  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "RU only available for MU");
342  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU");
343  return m_muUserInfos.at (staId).ru;
344 }
345 
346 void
347 WifiTxVector::SetRu (HeRu::RuSpec ru, uint16_t staId)
348 {
349  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "RU only available for MU");
350  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU");
351  m_muUserInfos[staId].ru = ru;
352 }
353 
355 WifiTxVector::GetHeMuUserInfo (uint16_t staId) const
356 {
357  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "HE MU user info only available for MU");
358  return m_muUserInfos.at (staId);
359 }
360 
361 void
362 WifiTxVector::SetHeMuUserInfo (uint16_t staId, HeMuUserInfo userInfo)
363 {
364  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "HE MU user info only available for MU");
365  NS_ABORT_MSG_IF (staId > 2048, "STA-ID should be correctly set for HE MU");
366  NS_ABORT_MSG_IF (userInfo.mcs.GetModulationClass () != WIFI_MOD_CLASS_HE, "Only HE modes authorized for HE MU");
367  m_muUserInfos[staId] = userInfo;
368  m_modeInitialized = true;
369 }
370 
373 {
374  NS_ABORT_MSG_IF (m_preamble != WIFI_PREAMBLE_HE_MU, "HE MU user info map only available for MU");
375  return m_muUserInfos;
376 }
377 
378 std::ostream & operator << ( std::ostream &os, const WifiTxVector &v)
379 {
380  if (!v.IsValid ())
381  {
382  os << "TXVECTOR not valid";
383  return os;
384  }
385  os << "txpwrlvl: " << +v.GetTxPowerLevel ()
386  << " preamble: " << v.GetPreambleType ()
387  << " channel width: " << v.GetChannelWidth ()
388  << " GI: " << v.GetGuardInterval ()
389  << " NTx: " << +v.GetNTx ()
390  << " Ness: " << +v.GetNess ()
391  << " MPDU aggregation: " << v.IsAggregation ()
392  << " STBC: " << v.IsStbc ()
393  << " FEC coding: " << (v.IsLdpc () ? "LDPC" : "BCC");
395  {
397  os << " num User Infos: " << userInfoMap.size ();
398  for (auto & ui : userInfoMap)
399  {
400  os << ", {STA-ID: " << ui.first
401  << ", " << ui.second.ru
402  << ", MCS: " << ui.second.mcs
403  << ", Nss: " << +ui.second.nss << "}";
404  }
405  }
406  else
407  {
408  os << " mode: " << v.GetMode ()
409  << " Nss: " << +v.GetNss ();
410  }
411  return os;
412 }
413 
414 } //namespace ns3
uint16_t m_channelWidth
channel width in MHz
uint8_t GetNssMax(void) const
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
uint8_t m_nTx
number of TX antennas
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
bool m_ldpc
LDPC FEC coding if true, BCC otherwise.
void SetBssColor(uint8_t color)
Set the BSS color.
std::map< uint16_t, HeMuUserInfo > HeMuUserInfoMap
map of HE MU specific user info paramters indexed by STA-ID
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetStbc(bool stbc)
Sets if STBC is being used.
bool IsStbc(void) const
Check if STBC is used or not.
bool GetModeInitialized(void) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
uint8_t GetNess(void) const
uint16_t GetGuardInterval(void) const
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
void SetLdpc(bool ldpc)
Sets if LDPC FEC coding is being used.
HeMuUserInfo GetHeMuUserInfo(uint16_t staId) const
Get the HE MU user-specific transmission information for the given STA-ID.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
WifiMode mcs
MCS.
bool IsLdpc(void) const
Check if LDPC FEC coding is used or not.
uint8_t m_nss
number of spatial streams
HeRu::RuSpec GetRu(uint16_t staId) const
Get the RU specification for the STA-ID.
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode...
WifiPreamble GetPreambleType(void) const
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:32
uint8_t m_bssColor
BSS color.
bool IsValid(void) const
The standard disallows certain combinations of WifiMode, number of spatial streams, and channel widths.
RU Specification.
Definition: he-ru.h:64
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
uint16_t m_guardInterval
guard interval duration in nanoseconds
uint8_t GetNTx(void) const
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:480
std::string GetUniqueName(void) const
Definition: wifi-mode.cc:443
void SetHeMuUserInfo(uint16_t staId, HeMuUserInfo userInfo)
Set the HE MU user-specific transmission information for the given STA-ID.
void SetNss(uint8_t nss)
Sets the number of Nss.
bool m_modeInitialized
Internal initialization flag.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetAggregation(bool aggregation)
Sets if PSDU contains A-MPDU.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
bool m_aggregation
Flag whether the PSDU contains A-MPDU.
bool m_stbc
STBC used or not.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
uint8_t GetBssColor(void) const
Get the BSS color.
void SetNess(uint8_t ness)
Sets the Ness number.
HeMuUserInfoMap m_muUserInfos
HE MU specific per-user information indexed by station ID (STA-ID) corresponding to the 11 LSBs of th...
uint8_t GetTxPowerLevel(void) const
uint16_t GetChannelWidth(void) const
uint8_t m_ness
number of spatial streams in beamforming
const HeMuUserInfoMap & GetHeMuUserInfoMap(void) const
Get the map HE MU user-specific transmission information indexed by STA-ID.
void SetRu(HeRu::RuSpec ru, uint16_t staId)
Set the RU specification for the STA-ID.
HE MU specific user transmission parameters.
HE PHY (Clause 26)
Definition: wifi-mode.h:64
uint8_t m_txPowerLevel
The TXPWR_LEVEL parameter in Table 15-4.
WifiMode m_mode
The DATARATE parameter in Table 15-4.
WifiPreamble m_preamble
preamble