A Discrete-Event Network Simulator
API
vht-ppdu.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 Orange Labs
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: Rediet <getachew.redieteab@orange.com>
19  * Muhammad Iqbal Rochman <muhiqbalcr@uchicago.edu>
20  * S├ębastien Deronne <sebastien.deronne@gmail.com> (VhtSigHeader)
21  */
22 
23 #include "ns3/wifi-phy.h"
24 #include "ns3/wifi-psdu.h"
25 #include "vht-phy.h"
26 #include "vht-ppdu.h"
27 #include "ns3/log.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("VhtPpdu");
32 
33 VhtPpdu::VhtPpdu (Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector, Time ppduDuration,
34  WifiPhyBand band, uint64_t uid)
35  : OfdmPpdu (psdu, txVector, band, uid, false) //don't instantiate LSigHeader of OfdmPpdu
36 {
37  NS_LOG_FUNCTION (this << psdu << txVector << ppduDuration << band << uid);
38  uint16_t length = ((ceil ((static_cast<double> (ppduDuration.GetNanoSeconds () - (20 * 1000)) / 1000) / 4.0) * 3) - 3);
39  m_lSig.SetLength (length);
42  m_vhtSig.SetShortGuardInterval (txVector.GetGuardInterval () == 400);
43  uint32_t nSymbols = (static_cast<double> ((ppduDuration - WifiPhy::CalculatePhyPreambleAndHeaderDuration (txVector)).GetNanoSeconds ()) / (3200 + txVector.GetGuardInterval ()));
44  if (txVector.GetGuardInterval () == 400)
45  {
46  m_vhtSig.SetShortGuardIntervalDisambiguation ((nSymbols % 10) == 9);
47  }
48  m_vhtSig.SetSuMcs (txVector.GetMode ().GetMcsValue ());
49  m_vhtSig.SetNStreams (txVector.GetNss ());
50 }
51 
53 {
54 }
55 
58 {
59  WifiTxVector txVector;
60  txVector.SetPreambleType (m_preamble);
63  txVector.SetNss (m_vhtSig.GetNStreams ());
64  txVector.SetGuardInterval (m_vhtSig.GetShortGuardInterval () ? 400 : 800);
65  txVector.SetAggregation (GetPsdu ()->IsAggregate ());
66  return txVector;
67 }
68 
69 Time
71 {
72  Time ppduDuration = Seconds (0);
73  const WifiTxVector& txVector = GetTxVector ();
74  Time tSymbol = NanoSeconds (3200 + txVector.GetGuardInterval ());
75  Time preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration (txVector);
76  Time calculatedDuration = MicroSeconds (((ceil (static_cast<double> (m_lSig.GetLength () + 3) / 3)) * 4) + 20);
77  uint32_t nSymbols = floor (static_cast<double> ((calculatedDuration - preambleDuration).GetNanoSeconds ()) / tSymbol.GetNanoSeconds ());
79  {
80  nSymbols--;
81  }
82  ppduDuration = preambleDuration + (nSymbols * tSymbol);
83  return ppduDuration;
84 }
85 
87 VhtPpdu::Copy (void) const
88 {
89  return Create<VhtPpdu> (GetPsdu (), GetTxVector (), GetTxDuration (), m_band, m_uid);
90 }
91 
93 VhtPpdu::GetType (void) const
94 {
96 }
97 
99  : m_bw (0),
100  m_nsts (0),
101  m_sgi (0),
102  m_sgi_disambiguation (0),
103  m_suMcs (0),
104  m_mu (false)
105 {
106 }
107 
109 {
110 }
111 
112 TypeId
114 {
115  static TypeId tid = TypeId ("ns3::VhtSigHeader")
116  .SetParent<Header> ()
117  .SetGroupName ("Wifi")
118  .AddConstructor<VhtSigHeader> ()
119  ;
120  return tid;
121 }
122 
123 TypeId
125 {
126  return GetTypeId ();
127 }
128 
129 void
130 VhtPpdu::VhtSigHeader::Print (std::ostream &os) const
131 {
132  os << "SU_MCS=" << +m_suMcs
133  << " CHANNEL_WIDTH=" << GetChannelWidth ()
134  << " SGI=" << +m_sgi
135  << " NSTS=" << +m_nsts
136  << " MU=" << +m_mu;
137 }
138 
139 uint32_t
141 {
142  uint32_t size = 0;
143  size += 3; //VHT-SIG-A1
144  size += 3; //VHT-SIG-A2
145  if (m_mu)
146  {
147  size += 4; //VHT-SIG-B
148  }
149  return size;
150 }
151 
152 void
154 {
155  m_mu = mu;
156 }
157 
158 void
160 {
161  if (channelWidth == 160)
162  {
163  m_bw = 3;
164  }
165  else if (channelWidth == 80)
166  {
167  m_bw = 2;
168  }
169  else if (channelWidth == 40)
170  {
171  m_bw = 1;
172  }
173  else
174  {
175  m_bw = 0;
176  }
177 }
178 
179 uint16_t
181 {
182  if (m_bw == 3)
183  {
184  return 160;
185  }
186  else if (m_bw == 2)
187  {
188  return 80;
189  }
190  else if (m_bw == 1)
191  {
192  return 40;
193  }
194  else
195  {
196  return 20;
197  }
198 }
199 
200 void
202 {
203  NS_ASSERT (nStreams <= 8);
204  m_nsts = (nStreams - 1);
205 }
206 
207 uint8_t
209 {
210  return (m_nsts + 1);
211 }
212 
213 void
215 {
216  m_sgi = sgi ? 1 : 0;
217 }
218 
219 bool
221 {
222  return m_sgi ? true : false;
223 }
224 
225 void
227 {
228  m_sgi_disambiguation = disambiguation ? 1 : 0;
229 }
230 
231 bool
233 {
234  return m_sgi_disambiguation ? true : false;
235 }
236 
237 void
239 {
240  NS_ASSERT (mcs <= 9);
241  m_suMcs = mcs;
242 }
243 
244 uint8_t
246 {
247  return m_suMcs;
248 }
249 
250 void
252 {
253  //VHT-SIG-A1
254  uint8_t byte = m_bw;
255  byte |= (0x01 << 2); //Set Reserved bit #2 to 1
256  start.WriteU8 (byte);
257  uint16_t bytes = (m_nsts & 0x07) << 2;
258  bytes |= (0x01 << (23 - 8)); //Set Reserved bit #23 to 1
259  start.WriteU16 (bytes);
260 
261  //VHT-SIG-A2
262  byte = m_sgi & 0x01;
263  byte |= ((m_sgi_disambiguation & 0x01) << 1);
264  byte |= ((m_suMcs & 0x0f) << 4);
265  start.WriteU8 (byte);
266  bytes = (0x01 << (9 - 8)); //Set Reserved bit #9 to 1
267  start.WriteU16 (bytes);
268 
269  if (m_mu)
270  {
271  //VHT-SIG-B
272  start.WriteU32 (0);
273  }
274 }
275 
276 uint32_t
278 {
280 
281  //VHT-SIG-A1
282  uint8_t byte = i.ReadU8 ();
283  m_bw = byte & 0x03;
284  uint16_t bytes = i.ReadU16 ();
285  m_nsts = ((bytes >> 2) & 0x07);
286 
287  //VHT-SIG-A2
288  byte = i.ReadU8 ();
289  m_sgi = byte & 0x01;
290  m_sgi_disambiguation = ((byte >> 1) & 0x01);
291  m_suMcs = ((byte >> 4) & 0x0f);
292  i.ReadU16 ();
293 
294  if (m_mu)
295  {
296  //VHT-SIG-B
297  i.ReadU32 ();
298  }
299 
300  return i.GetDistanceFrom (start);
301 }
302 
303 } //namespace ns3
ns3::OfdmPpdu
OFDM PPDU (11a)
Definition: ofdm-ppdu.h:48
ns3::VhtPpdu::VhtSigHeader::SetShortGuardIntervalDisambiguation
void SetShortGuardIntervalDisambiguation(bool disambiguation)
Fill the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:226
ns3::VhtPpdu::VhtSigHeader::SetMuFlag
void SetMuFlag(bool mu)
Set the Multi-User (MU) flag.
Definition: vht-ppdu.cc:153
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_ASSERT
#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
vht-phy.h
Declaration of ns3::VhtPhy class.
ns3::VhtPpdu::VhtSigHeader::GetNStreams
uint8_t GetNStreams(void) const
Return the number of streams.
Definition: vht-ppdu.cc:208
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
ns3::VhtPpdu::GetType
WifiPpduType GetType(void) const override
Return the PPDU type (.
Definition: vht-ppdu.cc:93
ns3::WifiPpdu::GetTxVector
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition: buffer.h:1021
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ns3::VhtPpdu::VhtSigHeader::VhtSigHeader
VhtSigHeader()
Definition: vht-ppdu.cc:98
ns3::WifiTxVector::SetGuardInterval
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
Definition: wifi-tx-vector.cc:260
ns3::VhtPpdu::VhtSigHeader::SetSuMcs
void SetSuMcs(uint8_t mcs)
Fill the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:238
ns3::WifiPhy::CalculatePhyPreambleAndHeaderDuration
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1604
ns3::WifiTxVector::SetNss
void SetNss(uint8_t nss)
Sets the number of Nss.
Definition: wifi-tx-vector.cc:272
ns3::WifiTxVector::SetAggregation
void SetAggregation(bool aggregation)
Sets if PSDU contains A-MPDU.
Definition: wifi-tx-vector.cc:292
ns3::OfdmPpdu::m_channelWidth
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:127
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition: wifi-tx-vector.cc:226
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::VhtPpdu::VhtSigHeader::GetChannelWidth
uint16_t GetChannelWidth(void) const
Return the channel width (in MHz).
Definition: vht-ppdu.cc:180
ns3::VhtPpdu::VhtSigHeader::GetSuMcs
uint8_t GetSuMcs(void) const
Return the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:245
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
vht-ppdu.h
Declaration of ns3::VhtPpdu class.
ns3::Ptr< const WifiPsdu >
visualizer.core.start
def start()
Definition: core.py:1855
ns3::VhtPpdu::VhtSigHeader::SetChannelWidth
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of VHT-SIG-A1 (in MHz).
Definition: vht-ppdu.cc:159
ns3::VhtPpdu::VhtSigHeader::GetShortGuardInterval
bool GetShortGuardInterval(void) const
Return the short GI field of VHT-SIG-A2.
Definition: vht-ppdu.cc:220
ns3::OfdmPpdu::LSigHeader::GetLength
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:225
ns3::NanoSeconds
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1313
ns3::OfdmPpdu::m_lSig
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:128
ns3::VhtPpdu::VhtSigHeader::GetShortGuardIntervalDisambiguation
bool GetShortGuardIntervalDisambiguation(void) const
Return the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:232
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Header
Protocol header serialization and deserialization.
Definition: header.h:43
ns3::WifiTxVector::SetChannelWidth
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Definition: wifi-tx-vector.cc:254
ns3::Time::GetNanoSeconds
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
ns3::WIFI_PREAMBLE_VHT_MU
@ WIFI_PREAMBLE_VHT_MU
Definition: wifi-phy-common.h:73
ns3::VhtPpdu::Copy
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: vht-ppdu.cc:87
ns3::OfdmPpdu::LSigHeader::SetLength
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:218
ns3::VhtPpdu::VhtSigHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const override
Definition: vht-ppdu.cc:140
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16(void)
Definition: buffer.h:1029
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Buffer::Iterator::ReadU32
uint32_t ReadU32(void)
Definition: buffer.cc:973
ns3::VhtPpdu::DoGetTxVector
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: vht-ppdu.cc:57
ns3::VhtPpdu::VhtSigHeader
VHT PHY header (VHT-SIG-A1/A2/B).
Definition: vht-ppdu.h:53
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition: buffer.h:99
ns3::VhtPpdu::VhtSigHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition: vht-ppdu.cc:251
ns3::VhtPhy::GetVhtMcs
static WifiMode GetVhtMcs(uint8_t index)
Return the VHT MCS corresponding to the provided index.
Definition: vht-phy.cc:328
ns3::WifiTxVector::GetGuardInterval
uint16_t GetGuardInterval(void) const
Definition: wifi-tx-vector.cc:160
ns3::OfdmPpdu::m_band
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:126
ns3::VhtPpdu::VhtSigHeader::~VhtSigHeader
virtual ~VhtSigHeader()
Definition: vht-ppdu.cc:108
ns3::WifiTxVector::GetNss
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.
Definition: wifi-tx-vector.cc:172
ns3::VhtPpdu::VhtPpdu
VhtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create a VHT PPDU.
Definition: vht-ppdu.cc:33
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::WifiPpduType
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
Definition: wifi-phy-common.h:229
ns3::VhtPpdu::VhtSigHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: vht-ppdu.cc:113
ns3::WIFI_PPDU_TYPE_DL_MU
@ WIFI_PPDU_TYPE_DL_MU
Definition: wifi-phy-common.h:231
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::VhtPpdu::~VhtPpdu
virtual ~VhtPpdu()
Destructor for VhtPpdu.
Definition: vht-ppdu.cc:52
ns3::WifiPhyBand
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
ns3::WifiPpdu::m_uid
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:182
ns3::VhtPpdu::VhtSigHeader::SetNStreams
void SetNStreams(uint8_t nStreams)
Fill the number of streams field of VHT-SIG-A1.
Definition: vht-ppdu.cc:201
ns3::VhtPpdu::VhtSigHeader::Print
void Print(std::ostream &os) const override
Definition: vht-ppdu.cc:130
ns3::WifiPpdu::GetPsdu
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
ns3::WifiPpdu::m_preamble
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:179
ns3::VhtPpdu::VhtSigHeader::SetShortGuardInterval
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of VHT-SIG-A2.
Definition: vht-ppdu.cc:214
ns3::VhtPpdu::GetTxDuration
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: vht-ppdu.cc:70
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition: wifi-tx-vector.cc:248
ns3::WIFI_PPDU_TYPE_SU
@ WIFI_PPDU_TYPE_SU
Definition: wifi-phy-common.h:230
ns3::VhtPpdu::m_vhtSig
VhtSigHeader m_vhtSig
the VHT-SIG PHY header
Definition: vht-ppdu.h:176
ns3::WifiTxVector::GetMode
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.
Definition: wifi-tx-vector.cc:112
ns3::VhtPpdu::VhtSigHeader::GetInstanceTypeId
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: vht-ppdu.cc:124
ns3::WifiMode::GetMcsValue
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:137