A Discrete-Event Network Simulator
API
vht-ppdu.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Orange Labs
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Rediet <getachew.redieteab@orange.com>
18 * Muhammad Iqbal Rochman <muhiqbalcr@uchicago.edu>
19 * Sébastien Deronne <sebastien.deronne@gmail.com> (VhtSigHeader)
20 */
21
22#include "vht-ppdu.h"
23
24#include "vht-phy.h"
25
26#include "ns3/log.h"
27#include "ns3/wifi-phy.h"
28#include "ns3/wifi-psdu.h"
29
30namespace ns3
31{
32
34
36 const WifiTxVector& txVector,
37 uint16_t txCenterFreq,
38 Time ppduDuration,
39 WifiPhyBand band,
40 uint64_t uid)
41 : OfdmPpdu(psdu,
42 txVector,
43 txCenterFreq,
44 band,
45 uid,
46 false) // don't instantiate LSigHeader of OfdmPpdu
47{
48 NS_LOG_FUNCTION(this << psdu << txVector << txCenterFreq << ppduDuration << band << uid);
49 uint16_t length =
50 ((ceil((static_cast<double>(ppduDuration.GetNanoSeconds() - (20 * 1000)) / 1000) / 4.0) *
51 3) -
52 3);
53 m_lSig.SetLength(length);
57 uint32_t nSymbols =
58 (static_cast<double>(
59 (ppduDuration - WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector))
60 .GetNanoSeconds()) /
61 (3200 + txVector.GetGuardInterval()));
62 if (txVector.GetGuardInterval() == 400)
63 {
65 }
67 m_vhtSig.SetNStreams(txVector.GetNss());
68}
69
71{
72}
73
76{
77 WifiTxVector txVector;
81 txVector.SetNss(m_vhtSig.GetNStreams());
82 txVector.SetGuardInterval(m_vhtSig.GetShortGuardInterval() ? 400 : 800);
83 txVector.SetAggregation(GetPsdu()->IsAggregate());
84 return txVector;
85}
86
87Time
89{
90 Time ppduDuration = Seconds(0);
91 const WifiTxVector& txVector = GetTxVector();
92 Time tSymbol = NanoSeconds(3200 + txVector.GetGuardInterval());
93 Time preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector);
94 Time calculatedDuration =
95 MicroSeconds(((ceil(static_cast<double>(m_lSig.GetLength() + 3) / 3)) * 4) + 20);
96 uint32_t nSymbols =
97 floor(static_cast<double>((calculatedDuration - preambleDuration).GetNanoSeconds()) /
98 tSymbol.GetNanoSeconds());
100 {
101 nSymbols--;
102 }
103 ppduDuration = preambleDuration + (nSymbols * tSymbol);
104 return ppduDuration;
105}
106
109{
110 return Create<VhtPpdu>(GetPsdu(),
111 GetTxVector(),
114 m_band,
115 m_uid);
116}
117
120{
122}
123
125 : m_bw(0),
126 m_nsts(0),
127 m_sgi(0),
128 m_sgi_disambiguation(0),
129 m_suMcs(0),
130 m_mu(false)
131{
132}
133
135{
136}
137
138TypeId
140{
141 static TypeId tid = TypeId("ns3::VhtSigHeader")
142 .SetParent<Header>()
143 .SetGroupName("Wifi")
144 .AddConstructor<VhtSigHeader>();
145 return tid;
146}
147
148TypeId
150{
151 return GetTypeId();
152}
153
154void
155VhtPpdu::VhtSigHeader::Print(std::ostream& os) const
156{
157 os << "SU_MCS=" << +m_suMcs << " CHANNEL_WIDTH=" << GetChannelWidth() << " SGI=" << +m_sgi
158 << " NSTS=" << +m_nsts << " MU=" << +m_mu;
159}
160
163{
164 uint32_t size = 0;
165 size += 3; // VHT-SIG-A1
166 size += 3; // VHT-SIG-A2
167 if (m_mu)
168 {
169 size += 4; // VHT-SIG-B
170 }
171 return size;
172}
173
174void
176{
177 m_mu = mu;
178}
179
180void
182{
183 if (channelWidth == 160)
184 {
185 m_bw = 3;
186 }
187 else if (channelWidth == 80)
188 {
189 m_bw = 2;
190 }
191 else if (channelWidth == 40)
192 {
193 m_bw = 1;
194 }
195 else
196 {
197 m_bw = 0;
198 }
199}
200
201uint16_t
203{
204 if (m_bw == 3)
205 {
206 return 160;
207 }
208 else if (m_bw == 2)
209 {
210 return 80;
211 }
212 else if (m_bw == 1)
213 {
214 return 40;
215 }
216 else
217 {
218 return 20;
219 }
220}
221
222void
224{
225 NS_ASSERT(nStreams <= 8);
226 m_nsts = (nStreams - 1);
227}
228
229uint8_t
231{
232 return (m_nsts + 1);
233}
234
235void
237{
238 m_sgi = sgi ? 1 : 0;
239}
240
241bool
243{
244 return m_sgi;
245}
246
247void
249{
250 m_sgi_disambiguation = disambiguation ? 1 : 0;
251}
252
253bool
255{
256 return m_sgi_disambiguation;
257}
258
259void
261{
262 NS_ASSERT(mcs <= 9);
263 m_suMcs = mcs;
264}
265
266uint8_t
268{
269 return m_suMcs;
270}
271
272void
274{
275 // VHT-SIG-A1
276 uint8_t byte = m_bw;
277 byte |= (0x01 << 2); // Set Reserved bit #2 to 1
278 start.WriteU8(byte);
279 uint16_t bytes = (m_nsts & 0x07) << 2;
280 bytes |= (0x01 << (23 - 8)); // Set Reserved bit #23 to 1
281 start.WriteU16(bytes);
282
283 // VHT-SIG-A2
284 byte = m_sgi & 0x01;
285 byte |= ((m_sgi_disambiguation & 0x01) << 1);
286 byte |= ((m_suMcs & 0x0f) << 4);
287 start.WriteU8(byte);
288 bytes = (0x01 << (9 - 8)); // Set Reserved bit #9 to 1
289 start.WriteU16(bytes);
290
291 if (m_mu)
292 {
293 // VHT-SIG-B
294 start.WriteU32(0);
295 }
296}
297
300{
302
303 // VHT-SIG-A1
304 uint8_t byte = i.ReadU8();
305 m_bw = byte & 0x03;
306 uint16_t bytes = i.ReadU16();
307 m_nsts = ((bytes >> 2) & 0x07);
308
309 // VHT-SIG-A2
310 byte = i.ReadU8();
311 m_sgi = byte & 0x01;
312 m_sgi_disambiguation = ((byte >> 1) & 0x01);
313 m_suMcs = ((byte >> 4) & 0x0f);
314 i.ReadU16();
315
316 if (m_mu)
317 {
318 // VHT-SIG-B
319 i.ReadU32();
320 }
321
322 return i.GetDistanceFrom(start);
323}
324
325} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
uint32_t ReadU32()
Definition: buffer.cc:969
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:783
uint16_t ReadU16()
Definition: buffer.h:1035
Protocol header serialization and deserialization.
Definition: header.h:44
uint16_t GetLength() const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:228
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:221
OFDM PPDU (11a)
Definition: ofdm-ppdu.h:48
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:130
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:132
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:131
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
static WifiMode GetVhtMcs(uint8_t index)
Return the VHT MCS corresponding to the provided index.
Definition: vht-phy.cc:344
VHT PHY header (VHT-SIG-A1/A2/B).
Definition: vht-ppdu.h:52
static TypeId GetTypeId()
Get the type ID.
Definition: vht-ppdu.cc:139
void SetNStreams(uint8_t nStreams)
Fill the number of streams field of VHT-SIG-A1.
Definition: vht-ppdu.cc:223
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of VHT-SIG-A1 (in MHz).
Definition: vht-ppdu.cc:181
uint16_t GetChannelWidth() const
Return the channel width (in MHz).
Definition: vht-ppdu.cc:202
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: vht-ppdu.cc:149
uint32_t Deserialize(Buffer::Iterator start) override
Definition: vht-ppdu.cc:299
uint8_t GetSuMcs() const
Return the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:267
uint8_t GetNStreams() const
Return the number of streams.
Definition: vht-ppdu.cc:230
bool GetShortGuardInterval() const
Return the short GI field of VHT-SIG-A2.
Definition: vht-ppdu.cc:242
void Serialize(Buffer::Iterator start) const override
Definition: vht-ppdu.cc:273
void SetMuFlag(bool mu)
Set the Multi-User (MU) flag.
Definition: vht-ppdu.cc:175
void SetSuMcs(uint8_t mcs)
Fill the SU VHT MCS field of VHT-SIG-A2.
Definition: vht-ppdu.cc:260
void SetShortGuardIntervalDisambiguation(bool disambiguation)
Fill the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:248
bool GetShortGuardIntervalDisambiguation() const
Return the short GI NSYM disambiguation field of VHT-SIG-A2.
Definition: vht-ppdu.cc:254
uint32_t GetSerializedSize() const override
Definition: vht-ppdu.cc:162
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of VHT-SIG-A2.
Definition: vht-ppdu.cc:236
void Print(std::ostream &os) const override
Definition: vht-ppdu.cc:155
VhtSigHeader m_vhtSig
the VHT-SIG PHY header
Definition: vht-ppdu.h:180
VhtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint16_t txCenterFreq, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create a VHT PPDU.
Definition: vht-ppdu.cc:35
WifiPpduType GetType() const override
Return the PPDU type (.
Definition: vht-ppdu.cc:119
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: vht-ppdu.cc:75
~VhtPpdu() override
Destructor for VhtPpdu.
Definition: vht-ppdu.cc:70
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: vht-ppdu.cc:88
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: vht-ppdu.cc:108
uint8_t GetMcsValue() const
Definition: wifi-mode.cc:163
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1415
uint16_t m_txCenterFreq
the center frequency (MHz) used for the transmission of this PPDU
Definition: wifi-ppdu.h:196
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:193
Ptr< const WifiPsdu > GetPsdu() const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:91
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:197
WifiTxVector GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:74
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetGuardInterval() const
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.
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:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:1362
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1374
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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:1861
Declaration of ns3::VhtPhy class.
Declaration of ns3::VhtPpdu class.