A Discrete-Event Network Simulator
API
ht-operations.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Sébastien Deronne
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  * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ht-operations.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("HtOperations");
28 
30  : m_primaryChannel (0),
31  m_secondaryChannelOffset (0),
32  m_staChannelWidth (0),
33  m_rifsMode (0),
34  m_reservedInformationSubset1 (0),
35  m_htProtection (0),
36  m_nonGfHtStasPresent (0),
37  m_reservedInformationSubset2_1 (0),
38  m_obssNonHtStasPresent (0),
39  m_reservedInformationSubset2_2 (0),
40  m_reservedInformationSubset3_1 (0),
41  m_dualBeacon (0),
42  m_dualCtsProtection (0),
43  m_stbcBeacon (0),
44  m_lSigTxopProtectionFullSupport (0),
45  m_pcoActive (0),
46  m_pcoPhase (0),
47  m_reservedInformationSubset3_2 (0),
48  m_reservedMcsSet1 (0),
49  m_rxHighestSupportedDataRate (0),
50  m_reservedMcsSet2 (0),
51  m_txMcsSetDefined (0),
52  m_txRxMcsSetUnequal (0),
53  m_txMaxNSpatialStreams (0),
54  m_txUnequalModulation (0),
55  m_reservedMcsSet3 (0),
56  m_htSupported (0)
57 {
58  for (uint32_t k = 0; k < MAX_SUPPORTED_MCS; k++)
59  {
60  m_rxMcsBitmask[k] = 0;
61  }
62 }
63 
66 {
67  return IE_HT_OPERATIONS;
68 }
69 
70 void
71 HtOperations::SetHtSupported (uint8_t htsupported)
72 {
73  m_htSupported = htsupported;
74 }
75 
76 uint8_t
78 {
79  //we should not be here if ht is not supported
81  return 22;
82 }
83 
84 void
86 {
87  m_primaryChannel = ctrl;
88 }
89 
90 void
91 HtOperations::SetSecondaryChannelOffset (uint8_t secondarychanneloffset)
92 {
93  m_secondaryChannelOffset = secondarychanneloffset;
94 }
95 
96 void
97 HtOperations::SetStaChannelWidth (uint8_t stachannelwidth)
98 {
99  m_staChannelWidth = stachannelwidth;
100 }
101 
102 void
103 HtOperations::SetRifsMode (uint8_t rifsmode)
104 {
105  m_rifsMode = rifsmode;
106 }
107 
108 void
109 HtOperations::SetHtProtection (uint8_t htprotection)
110 {
111  m_htProtection = htprotection;
112 }
113 
114 void
115 HtOperations::SetNonGfHtStasPresent (uint8_t nongfhtstaspresent)
116 {
117  m_nonGfHtStasPresent = nongfhtstaspresent;
118 }
119 
120 void
121 HtOperations::SetObssNonHtStasPresent (uint8_t obssnonhtstaspresent)
122 {
123  m_obssNonHtStasPresent = obssnonhtstaspresent;
124 }
125 
126 void
127 HtOperations::SetDualBeacon (uint8_t dualbeacon)
128 {
129  m_dualBeacon = dualbeacon;
130 }
131 
132 void
133 HtOperations::SetDualCtsProtection (uint8_t dualctsprotection)
134 {
135  m_dualCtsProtection = dualctsprotection;
136 }
137 
138 void
139 HtOperations::SetStbcBeacon (uint8_t stbcbeacon)
140 {
141  m_stbcBeacon = stbcbeacon;
142 }
143 
144 void
145 HtOperations::SetLSigTxopProtectionFullSupport (uint8_t lsigtxopprotectionfullsupport)
146 {
147  m_lSigTxopProtectionFullSupport = lsigtxopprotectionfullsupport;
148 }
149 
150 void
151 HtOperations::SetPcoActive (uint8_t pcoactive)
152 {
153  m_pcoActive = pcoactive;
154 }
155 
156 void
157 HtOperations::SetPhase (uint8_t pcophase)
158 {
159  m_pcoPhase = pcophase;
160 }
161 
162 void
164 {
165  m_rxMcsBitmask[index] = 1;
166 }
167 
168 void
170 {
171  m_rxHighestSupportedDataRate = maxsupportedrate;
172 }
173 
174 void
175 HtOperations::SetTxMcsSetDefined (uint8_t txmcssetdefined)
176 {
177  m_txMcsSetDefined = txmcssetdefined;
178 }
179 
180 void
181 HtOperations::SetTxRxMcsSetUnequal (uint8_t txrxmcssetunequal)
182 {
183  m_txRxMcsSetUnequal = txrxmcssetunequal;
184 }
185 
186 void
187 HtOperations::SetTxMaxNSpatialStreams (uint8_t maxtxspatialstreams)
188 {
189  m_txMaxNSpatialStreams = maxtxspatialstreams;
190 }
191 
192 void
193 HtOperations::SetTxUnequalModulation (uint8_t txunequalmodulation)
194 {
195  m_txUnequalModulation = txunequalmodulation;
196 }
197 
198 uint8_t
200 {
201  return m_primaryChannel;
202 }
203 
204 uint8_t
206 {
208 }
209 
210 uint8_t
212 {
213  return m_staChannelWidth;
214 }
215 
216 uint8_t
218 {
219  return m_rifsMode;
220 }
221 
222 uint8_t
224 {
225  return m_htProtection;
226 }
227 
228 uint8_t
230 {
231  return m_nonGfHtStasPresent;
232 }
233 
234 uint8_t
236 {
237  return m_obssNonHtStasPresent;
238 }
239 
240 uint8_t
242 {
243  return m_dualBeacon;
244 }
245 
246 uint8_t
248 {
249  return m_dualCtsProtection;
250 }
251 
252 uint8_t
254 {
255  return m_stbcBeacon;
256 }
257 
258 uint8_t
260 {
262 }
263 
264 uint8_t
266 {
267  return m_pcoActive;
268 }
269 
270 uint8_t
272 {
273  return m_pcoPhase;
274 }
275 
276 bool
278 {
279  if (m_rxMcsBitmask[mcs] == 1)
280  {
281  return true;
282  }
283  return false;
284 }
285 
286 uint16_t
288 {
290 }
291 
292 uint8_t
294 {
295  return m_txMcsSetDefined;
296 }
297 
298 uint8_t
300 {
301  return m_txRxMcsSetUnequal;
302 }
303 
304 uint8_t
306 {
307  return m_txMaxNSpatialStreams;
308 }
309 
310 uint8_t
312 {
313  return m_txUnequalModulation;
314 }
315 
318 {
319  if (m_htSupported < 1)
320  {
321  return i;
322  }
324 }
325 
326 uint16_t
328 {
329  if (m_htSupported < 1)
330  {
331  return 0;
332  }
334 }
335 
336 uint8_t
338 {
339  uint16_t val = 0;
340  val |= m_secondaryChannelOffset & 0x03;
341  val |= (m_staChannelWidth & 0x01) << 2;
342  val |= (m_rifsMode & 0x01) << 3;
343  val |= (m_reservedInformationSubset1 & 0x0f) << 4;
344  return val;
345 }
346 
347 void
349 {
350  m_secondaryChannelOffset = ctrl & 0x03;
351  m_staChannelWidth = (ctrl >> 2) & 0x01;
352  m_rifsMode = (ctrl >> 3) & 0x01;
353  m_reservedInformationSubset1 = (ctrl >> 4) & 0x0f;
354 }
355 
356 uint16_t
358 {
359  uint16_t val = 0;
360  val |= m_htProtection & 0x03;
361  val |= (m_nonGfHtStasPresent & 0x01) << 2;
362  val |= (m_reservedInformationSubset2_1 & 0x01) << 3;
363  val |= (m_obssNonHtStasPresent & 0x01) << 4;
364  val |= (m_reservedInformationSubset2_1 & 0x07ff) << 5;
365  return val;
366 }
367 
368 void
370 {
371  m_htProtection = ctrl & 0x03;
372  m_nonGfHtStasPresent = (ctrl >> 2) & 0x01;
373  m_reservedInformationSubset2_1 = (ctrl >> 3) & 0x01;
374  m_obssNonHtStasPresent = (ctrl >> 4) & 0x01;
375  m_reservedInformationSubset2_1 = (ctrl >> 5) & 0x07ff;
376 }
377 
378 uint16_t
380 {
381  uint16_t val = 0;
382  val |= m_reservedInformationSubset3_1 & 0x3f;
383  val |= (m_dualBeacon & 0x01) << 6;
384  val |= (m_dualCtsProtection & 0x01) << 7;
385  val |= (m_stbcBeacon & 0x01) << 8;
386  val |= (m_lSigTxopProtectionFullSupport & 0x01) << 9;
387  val |= (m_pcoActive & 0x01) << 10;
388  val |= (m_pcoPhase & 0x01) << 11;
389  val |= (m_reservedInformationSubset3_2 & 0x0f) << 12;
390  return val;
391 }
392 
393 void
395 {
396  m_reservedInformationSubset3_1 = ctrl & 0x3f;
397  m_dualBeacon = (ctrl >> 6) & 0x01;
398  m_dualCtsProtection = (ctrl >> 7) & 0x01;
399  m_stbcBeacon = (ctrl >> 8) & 0x01;
400  m_lSigTxopProtectionFullSupport = (ctrl >> 9) & 0x01;
401  m_pcoActive = (ctrl >> 10) & 0x01;
402  m_pcoPhase = (ctrl >> 11) & 0x01;
403  m_reservedInformationSubset3_2 = (ctrl >> 12) & 0x0f;
404 }
405 
406 void
407 HtOperations::SetBasicMcsSet (uint64_t ctrl1, uint64_t ctrl2)
408 {
409  for (uint64_t i = 0; i < 77; i++)
410  {
411  if (i < 64)
412  {
413  m_rxMcsBitmask[i] = (ctrl1 >> i) & 0x01;
414  }
415  else
416  {
417  m_rxMcsBitmask[i] = (ctrl2 >> (i - 64)) & 0x01;
418  }
419  }
420  m_reservedMcsSet1 = (ctrl2 >> 13) & 0x07;
421  m_rxHighestSupportedDataRate = (ctrl2 >> 16) & 0x03ff;
422  m_reservedMcsSet2 = (ctrl2 >> 26) & 0x3f;
423  m_txMcsSetDefined = (ctrl2 >> 32) & 0x01;
424  m_txRxMcsSetUnequal = (ctrl2 >> 33) & 0x01;
425  m_txMaxNSpatialStreams = (ctrl2 >> 34) & 0x03;
426  m_txUnequalModulation = (ctrl2 >> 36) & 0x01;
427  m_reservedMcsSet3 = (ctrl2 >> 37) & 0x07ffffff;
428 }
429 
430 uint64_t
432 {
433  uint64_t val = 0;
434  for (uint64_t i = 63; i > 0; i--)
435  {
436  val = (val << 1) | (m_rxMcsBitmask[i] & 0x01);
437  }
438  val = (val << 1) | (m_rxMcsBitmask[0] & 0x01);
439  return val;
440 }
441 
442 uint64_t
444 {
445  uint64_t val = 0;
446  val = val | (m_reservedMcsSet3 & 0x07ffffff);
447  val = (val << 1) | (m_txUnequalModulation & 0x01);
448  val = (val << 2) | (m_txMaxNSpatialStreams & 0x03);
449  val = (val << 1) | (m_txRxMcsSetUnequal & 0x01);
450  val = (val << 1) | (m_txMcsSetDefined & 0x01);
451  val = (val << 6) | (m_reservedMcsSet2 & 0x3f);
452  val = (val << 10) | (m_rxHighestSupportedDataRate & 0x3ff);
453  val = (val << 3) | (m_reservedMcsSet1 & 0x07);
454 
455  for (uint64_t i = 13; i > 0; i--)
456  {
457  val = (val << 1) | ( m_rxMcsBitmask[i + 63] & 0x01);
458  }
459  return val;
460 }
461 
462 void
464 {
465  if (m_htSupported == 1)
466  {
467  //write the corresponding value for each bit
468  start.WriteU8 (GetPrimaryChannel ());
469  start.WriteU8 (GetInformationSubset1 ());
470  start.WriteU16 (GetInformationSubset2 ());
471  start.WriteU16 (GetInformationSubset3 ());
472  start.WriteHtolsbU64 (GetBasicMcsSet1 ());
473  start.WriteHtolsbU64 (GetBasicMcsSet2 ());
474  }
475 }
476 
477 uint8_t
479  uint8_t length)
480 {
482  uint8_t primarychannel = i.ReadU8 ();
483  uint8_t informationsubset1 = i.ReadU8 ();
484  uint8_t informationsubset2 = i.ReadU16 ();
485  uint8_t informationsubset3 = i.ReadU16 ();
486  uint64_t mcsset1 = i.ReadLsbtohU64 ();
487  uint64_t mcsset2 = i.ReadLsbtohU64 ();
488  SetPrimaryChannel (primarychannel);
489  SetInformationSubset1 (informationsubset1);
490  SetInformationSubset2 (informationsubset2);
491  SetInformationSubset3 (informationsubset3);
492  SetBasicMcsSet (mcsset1, mcsset2);
493  return length;
494 }
495 
497 
498 std::ostream &
499 operator << (std::ostream &os, const HtOperations &htoperations)
500 {
501  os << bool (htoperations.GetStaChannelWidth ())
502  << "|" << bool (htoperations.GetRifsMode ())
503  << "|" << bool (htoperations.GetDualCtsProtection());
504 
505  return os;
506 }
507 
508 std::istream &operator >> (std::istream &is, HtOperations &htoperations)
509 {
510  bool c1, c2, c3;
511  is >> c1 >> c2 >> c3;
512  htoperations.SetStaChannelWidth (c1);
513  htoperations.SetRifsMode (c2);
514  htoperations.SetDualCtsProtection (c3);
515 
516  return is;
517 }
518 
519 } //namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:1028
Buffer::Iterator Serialize(Buffer::Iterator start) const
This information element is a bit special in that it is only included if the STA is an HT STA...
The HT Operations Information ElementThis class knows how to serialise and deserialise the HT Operati...
Definition: ht-operations.h:54
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
uint8_t m_txRxMcsSetUnequal
uint64_t GetBasicMcsSet1(void) const
uint8_t m_primaryChannel
uint8_t GetStaChannelWidth(void) const
#define MAX_SUPPORTED_MCS
This defines the maximum number of supported MCSs that a STA is allowed to have.
uint8_t m_reservedInformationSubset2_1
uint8_t GetNonGfHtStasPresent(void) const
void SetTxRxMcsSetUnequal(uint8_t txrxmcssetunequal)
uint8_t m_nonGfHtStasPresent
uint8_t m_reservedMcsSet2
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
def start()
Definition: core.py:1482
void SetStbcBeacon(uint8_t stbcbeacon)
void SetTxMcsSetDefined(uint8_t txmcssetdefined)
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SerializeInformationField(Buffer::Iterator start) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
uint8_t m_lSigTxopProtectionFullSupport
uint8_t GetTxRxMcsSetUnequal(void) const
void SetStaChannelWidth(uint8_t stachannelwidth)
void SetHtProtection(uint8_t htprotection)
uint8_t GetLSigTxopProtectionFullSupport(void) const
uint8_t GetPcoActive(void) const
void SetLSigTxopProtectionFullSupport(uint8_t lsigtxopprotectionfullsupport)
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
iterator in a Buffer instance
Definition: buffer.h:98
uint16_t GetSerializedSize() const
Return the serialized size of this HT Operations IE.
bool IsSupportedMcs(uint8_t mcs)
void SetInformationSubset3(uint16_t ctrl)
Set the Information Subset 3 field in the HT Operations information element.
void SetSecondaryChannelOffset(uint8_t secondarychanneloffset)
#define IE_HT_OPERATIONS
void SetRxHighestSupportedDataRate(uint16_t maxsupportedrate)
uint8_t GetTxUnequalModulation(void) const
uint8_t m_txMaxNSpatialStreams
void SetTxMaxNSpatialStreams(uint8_t maxtxspatialstreams)
void WriteU16(uint16_t data)
Definition: buffer.cc:870
uint8_t GetInformationSubset1(void) const
uint8_t GetDualCtsProtection(void) const
void SetPcoActive(uint8_t pcoactive)
void SetNonGfHtStasPresent(uint8_t nongfhtstaspresent)
uint8_t m_secondaryChannelOffset
uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
WifiInformationElementId ElementId() const
Own unique Element ID.
uint8_t m_reservedInformationSubset1
uint16_t GetInformationSubset3(void) const
void SetRxMcsBitmask(uint8_t index)
uint8_t m_dualCtsProtection
void SetTxUnequalModulation(uint8_t txunequalmodulation)
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
uint8_t m_staChannelWidth
uint8_t m_obssNonHtStasPresent
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetHtSupported(uint8_t htsupported)
uint8_t GetTxMaxNSpatialStreams(void) const
uint8_t m_txMcsSetDefined
void SetDualCtsProtection(uint8_t dualctsprotection)
uint8_t GetPhase(void) const
void SetDualBeacon(uint8_t dualbeacon)
uint8_t m_rxMcsBitmask[MAX_SUPPORTED_MCS]
uint8_t GetPrimaryChannel(void) const
uint8_t m_txUnequalModulation
void WriteU8(uint8_t data)
Definition: buffer.h:868
void SetInformationSubset1(uint8_t ctrl)
Set the Information Subset 1 field in the HT Operations information element.
uint8_t GetStbcBeacon(void) const
uint8_t GetHtProtection(void) const
void WriteHtolsbU64(uint64_t data)
Definition: buffer.cc:926
uint8_t m_reservedInformationSubset3_1
uint8_t m_reservedInformationSubset3_2
void SetRifsMode(uint8_t rifsmode)
uint8_t GetRifsMode(void) const
uint32_t m_reservedMcsSet3
uint8_t ReadU8(void)
Definition: buffer.h:1020
void SetPrimaryChannel(uint8_t ctrl)
Set the Primary Channel field in the HT Operations information element.
void SetInformationSubset2(uint16_t ctrl)
Set the Information Subset 2 field in the HT Operations information element.
uint16_t GetRxHighestSupportedDataRate(void) const
void SetBasicMcsSet(uint64_t ctrl1, uint64_t ctrl2)
Set the Basic MCS Set field in the HT Operations information element.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint16_t GetInformationSubset2(void) const
uint64_t ReadLsbtohU64(void)
Definition: buffer.cc:1093
uint8_t GetSecondaryChannelOffset(void) const
void SetPhase(uint8_t pcophase)
void SetObssNonHtStasPresent(uint8_t obssnonhtstaspresent)
uint8_t GetObssNonHtStasPresent(void) const
uint8_t GetDualBeacon(void) const
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
uint8_t m_reservedMcsSet1
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
uint16_t m_rxHighestSupportedDataRate
uint64_t GetBasicMcsSet2(void) const
uint8_t GetTxMcsSetDefined(void) const