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
29namespace ns3 {
30
31NS_LOG_COMPONENT_DEFINE ("VhtPpdu");
32
33VhtPpdu::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);
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
69Time
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
87VhtPpdu::Copy (void) const
88{
89 return Create<VhtPpdu> (GetPsdu (), GetTxVector (), GetTxDuration (), m_band, m_uid);
90}
91
93VhtPpdu::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
112TypeId
114{
115 static TypeId tid = TypeId ("ns3::VhtSigHeader")
116 .SetParent<Header> ()
117 .SetGroupName ("Wifi")
118 .AddConstructor<VhtSigHeader> ()
119 ;
120 return tid;
121}
122
123TypeId
125{
126 return GetTypeId ();
127}
128
129void
130VhtPpdu::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
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
152void
154{
155 m_mu = mu;
156}
157
158void
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
179uint16_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
200void
202{
203 NS_ASSERT (nStreams <= 8);
204 m_nsts = (nStreams - 1);
205}
206
207uint8_t
209{
210 return (m_nsts + 1);
211}
212
213void
215{
216 m_sgi = sgi ? 1 : 0;
217}
218
219bool
221{
222 return m_sgi;
223}
224
225void
227{
228 m_sgi_disambiguation = disambiguation ? 1 : 0;
229}
230
231bool
233{
234 return m_sgi_disambiguation;
235}
236
237void
239{
240 NS_ASSERT (mcs <= 9);
241 m_suMcs = mcs;
242}
243
244uint8_t
246{
247 return m_suMcs;
248}
249
250void
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
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
iterator in a Buffer instance
Definition: buffer.h:99
uint16_t ReadU16(void)
Definition: buffer.h:1029
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
uint32_t ReadU32(void)
Definition: buffer.cc:973
Protocol header serialization and deserialization.
Definition: header.h:43
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:218
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:225
OFDM PPDU (11a)
Definition: ofdm-ppdu.h:48
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:126
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:128
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:127
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
static WifiMode GetVhtMcs(uint8_t index)
Return the VHT MCS corresponding to the provided index.
Definition: vht-phy.cc:328
VHT PHY header (VHT-SIG-A1/A2/B).
Definition: vht-ppdu.h:53
uint8_t GetNStreams(void) const
Return the number of streams.
Definition: vht-ppdu.cc:208
uint8_t GetSuMcs(void) const
Return the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:245
uint16_t GetChannelWidth(void) const
Return the channel width (in MHz).
Definition: vht-ppdu.cc:180
void SetNStreams(uint8_t nStreams)
Fill the number of streams field of VHT-SIG-A1.
Definition: vht-ppdu.cc:201
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of VHT-SIG-A1 (in MHz).
Definition: vht-ppdu.cc:159
static TypeId GetTypeId(void)
Get the type ID.
Definition: vht-ppdu.cc:113
bool GetShortGuardIntervalDisambiguation(void) const
Return the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:232
uint32_t Deserialize(Buffer::Iterator start) override
Definition: vht-ppdu.cc:277
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: vht-ppdu.cc:124
void Serialize(Buffer::Iterator start) const override
Definition: vht-ppdu.cc:251
void SetMuFlag(bool mu)
Set the Multi-User (MU) flag.
Definition: vht-ppdu.cc:153
uint32_t GetSerializedSize(void) const override
Definition: vht-ppdu.cc:140
void SetSuMcs(uint8_t mcs)
Fill the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:238
void SetShortGuardIntervalDisambiguation(bool disambiguation)
Fill the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:226
bool GetShortGuardInterval(void) const
Return the short GI field of VHT-SIG-A2.
Definition: vht-ppdu.cc:220
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of VHT-SIG-A2.
Definition: vht-ppdu.cc:214
void Print(std::ostream &os) const override
Definition: vht-ppdu.cc:130
VhtSigHeader m_vhtSig
the VHT-SIG PHY header
Definition: vht-ppdu.h:176
virtual ~VhtPpdu()
Destructor for VhtPpdu.
Definition: vht-ppdu.cc:52
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: vht-ppdu.cc:70
VhtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create a VHT PPDU.
Definition: vht-ppdu.cc:33
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: vht-ppdu.cc:57
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: vht-ppdu.cc:87
WifiPpduType GetType(void) const override
Return the PPDU type (.
Definition: vht-ppdu.cc:93
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:155
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1300
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:177
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:180
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
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)
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
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.
void SetAggregation(bool aggregation)
Sets if PSDU contains A-MPDU.
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.
uint16_t GetGuardInterval(void) const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetNss(uint8_t nss)
Sets the number of Nss.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#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:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1268
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
@ WIFI_PREAMBLE_VHT_MU
@ WIFI_PPDU_TYPE_DL_MU
@ WIFI_PPDU_TYPE_SU
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1853
Declaration of ns3::VhtPhy class.
Declaration of ns3::VhtPpdu class.