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
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
void Serialize(Buffer::Iterator start) const
Definition: vht-ppdu.cc:251
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
uint32_t ReadU32(void)
Definition: buffer.cc:972
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static WifiMode GetVhtMcs(uint8_t index)
Return the VHT MCS corresponding to the provided index.
Definition: vht-phy.cc:328
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetShortGuardIntervalDisambiguation(bool disambiguation)
Fill the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:226
VHT PHY header (VHT-SIG-A1/A2/B).
Definition: vht-ppdu.h:52
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
uint8_t GetSuMcs(void) const
Return the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:245
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:225
def start()
Definition: core.py:1855
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:130
#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
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:160
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
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.
uint32_t Deserialize(Buffer::Iterator start)
Definition: vht-ppdu.cc:277
static TypeId GetTypeId(void)
Get the type ID.
Definition: vht-ppdu.cc:113
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:128
iterator in a Buffer instance
Definition: buffer.h:98
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: vht-ppdu.cc:87
VhtSigHeader m_vhtSig
the VHT-SIG PHY header
Definition: vht-ppdu.h:179
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...
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
void SetMuFlag(bool mu)
Set the Multi-User (MU) flag.
Definition: vht-ppdu.cc:153
bool GetShortGuardIntervalDisambiguation(void) const
Return the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:232
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: vht-ppdu.cc:124
void Print(std::ostream &os) const
Definition: vht-ppdu.cc:130
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1313
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:157
VhtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create a VHT PPDU.
Definition: vht-ppdu.cc:33
void SetNss(uint8_t nss)
Sets the number of Nss.
OFDM PPDU (11a)OfdmPpdu stores a preamble, PHY headers and a PSDU of a PPDU with non-HT header...
Definition: ofdm-ppdu.h:47
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of VHT-SIG-A1 (in MHz).
Definition: vht-ppdu.cc:159
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of VHT-SIG-A2.
Definition: vht-ppdu.cc:214
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of ns3::VhtPhy class.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
void SetAggregation(bool aggregation)
Sets if PSDU contains A-MPDU.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: vht-ppdu.cc:70
WifiPpduType GetType(void) const override
Return the PPDU type (.
Definition: vht-ppdu.cc:93
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetSuMcs(uint8_t mcs)
Fill the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:238
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:32
virtual ~VhtPpdu()
Destructor for VhtPpdu.
Definition: vht-ppdu.cc:52
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1604
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint8_t GetNStreams(void) const
Return the number of streams.
Definition: vht-ppdu.cc:208
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: vht-ppdu.cc:57
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:218
void SetNStreams(uint8_t nStreams)
Fill the number of streams field of VHT-SIG-A1.
Definition: vht-ppdu.cc:201
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:137
Declaration of ns3::VhtPpdu class.
a unique identifier for an interface.
Definition: type-id.h:58
uint16_t GetChannelWidth(void) const
Return the channel width (in MHz).
Definition: vht-ppdu.cc:180
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint32_t GetSerializedSize(void) const
Definition: vht-ppdu.cc:140
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:129
bool GetShortGuardInterval(void) const
Return the short GI field of VHT-SIG-A2.
Definition: vht-ppdu.cc:220