A Discrete-Event Network Simulator
API
ht-ppdu.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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> (HtSigHeader)
20 */
21
22#include "ht-ppdu.h"
23
24#include "ht-phy.h"
25
26#include "ns3/log.h"
27#include "ns3/wifi-phy.h"
28#include "ns3/wifi-psdu.h"
29#include "ns3/wifi-utils.h"
30
31namespace ns3
32{
33
35
37 const WifiTxVector& txVector,
38 uint16_t txCenterFreq,
39 Time ppduDuration,
40 WifiPhyBand band,
41 uint64_t uid)
42 : OfdmPpdu(psdu,
43 txVector,
44 txCenterFreq,
45 band,
46 uid,
47 false) // don't instantiate LSigHeader of OfdmPpdu
48{
49 NS_LOG_FUNCTION(this << psdu << txVector << txCenterFreq << ppduDuration << band << uid);
50 uint8_t sigExtension = 0;
52 {
53 sigExtension = 6;
54 }
55 uint16_t length = ((ceil((static_cast<double>(ppduDuration.GetNanoSeconds() - (20 * 1000) -
56 (sigExtension * 1000)) /
57 1000) /
58 4.0) *
59 3) -
60 3);
61 m_lSig.SetLength(length);
62 m_htSig.SetMcs(txVector.GetMode().GetMcsValue());
67}
68
70{
71}
72
75{
76 WifiTxVector txVector;
80 txVector.SetNss(1 + (m_htSig.GetMcs() / 8));
81 txVector.SetGuardInterval(m_htSig.GetShortGuardInterval() ? 400 : 800);
83 return txVector;
84}
85
86Time
88{
89 Time ppduDuration = Seconds(0);
90 const WifiTxVector& txVector = GetTxVector();
91 ppduDuration = WifiPhy::CalculateTxDuration(m_htSig.GetHtLength(), txVector, m_band);
92 return ppduDuration;
93}
94
97{
98 return Create<HtPpdu>(GetPsdu(), GetTxVector(), m_txCenterFreq, GetTxDuration(), m_band, m_uid);
99}
100
102 : m_mcs(0),
103 m_cbw20_40(0),
104 m_htLength(0),
105 m_aggregation(0),
106 m_sgi(0)
107{
108}
109
111{
112}
113
114TypeId
116{
117 static TypeId tid = TypeId("ns3::HtSigHeader")
118 .SetParent<Header>()
119 .SetGroupName("Wifi")
120 .AddConstructor<HtSigHeader>();
121 return tid;
122}
123
124TypeId
126{
127 return GetTypeId();
128}
129
130void
131HtPpdu::HtSigHeader::Print(std::ostream& os) const
132{
133 os << "MCS=" << +m_mcs << " HT_LENGTH=" << m_htLength << " CHANNEL_WIDTH=" << GetChannelWidth()
134 << " SGI=" << +m_sgi << " AGGREGATION=" << +m_aggregation;
135}
136
139{
140 return 6;
141}
142
143void
145{
146 NS_ASSERT(mcs <= 31);
147 m_mcs = mcs;
148}
149
150uint8_t
152{
153 return m_mcs;
154}
155
156void
158{
159 m_cbw20_40 = (channelWidth > 20) ? 1 : 0;
160}
161
162uint16_t
164{
165 return m_cbw20_40 ? 40 : 20;
166}
167
168void
170{
171 m_htLength = length;
172}
173
174uint16_t
176{
177 return m_htLength;
178}
179
180void
182{
183 m_aggregation = aggregation ? 1 : 0;
184}
185
186bool
188{
189 return m_aggregation;
190}
191
192void
194{
195 m_sgi = sgi ? 1 : 0;
196}
197
198bool
200{
201 return m_sgi;
202}
203
204void
206{
207 uint8_t byte = m_mcs;
208 byte |= ((m_cbw20_40 & 0x01) << 7);
209 start.WriteU8(byte);
210 start.WriteU16(m_htLength);
211 byte = (0x01 << 2); // Set Reserved bit #2 to 1
212 byte |= ((m_aggregation & 0x01) << 3);
213 byte |= ((m_sgi & 0x01) << 7);
214 start.WriteU8(byte);
215 start.WriteU16(0);
216}
217
220{
222 uint8_t byte = i.ReadU8();
223 m_mcs = byte & 0x7f;
224 m_cbw20_40 = ((byte >> 7) & 0x01);
225 m_htLength = i.ReadU16();
226 byte = i.ReadU8();
227 m_aggregation = ((byte >> 3) & 0x01);
228 m_sgi = ((byte >> 7) & 0x01);
229 i.ReadU16();
230 return i.GetDistanceFrom(start);
231}
232
233} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
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
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition: ht-phy.cc:491
HT PHY header (HT-SIG1/2).
Definition: ht-ppdu.h:52
void Print(std::ostream &os) const override
Definition: ht-ppdu.cc:131
uint16_t GetHtLength() const
Return the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:175
uint8_t GetMcs() const
Return the MCS field of HT-SIG.
Definition: ht-ppdu.cc:151
void SetHtLength(uint16_t length)
Fill the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:169
bool GetAggregation() const
Return the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:187
void SetMcs(uint8_t mcs)
Fill the MCS field of HT-SIG.
Definition: ht-ppdu.cc:144
bool GetShortGuardInterval() const
Return the short guard interval field of HT-SIG.
Definition: ht-ppdu.cc:199
uint32_t Deserialize(Buffer::Iterator start) override
Definition: ht-ppdu.cc:219
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: ht-ppdu.cc:125
uint16_t GetChannelWidth() const
Return the channel width (in MHz).
Definition: ht-ppdu.cc:163
void SetAggregation(bool aggregation)
Fill the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:181
uint32_t GetSerializedSize() const override
Definition: ht-ppdu.cc:138
~HtSigHeader() override
Definition: ht-ppdu.cc:110
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of HT-SIG (in MHz).
Definition: ht-ppdu.cc:157
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of HT-SIG.
Definition: ht-ppdu.cc:193
static TypeId GetTypeId()
Get the type ID.
Definition: ht-ppdu.cc:115
void Serialize(Buffer::Iterator start) const override
Definition: ht-ppdu.cc:205
HtSigHeader m_htSig
the HT-SIG PHY header
Definition: ht-ppdu.h:165
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: ht-ppdu.cc:74
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: ht-ppdu.cc:96
~HtPpdu() override
Destructor for HtPpdu.
Definition: ht-ppdu.cc:69
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: ht-ppdu.cc:87
HtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint16_t txCenterFreq, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create an HT PPDU.
Definition: ht-ppdu.cc:36
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
uint8_t GetMcsValue() const
Definition: wifi-mode.cc:163
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1422
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
uint32_t GetSize() const
Return the size of the PSDU in bytes.
Definition: wifi-psdu.cc:263
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.
bool IsAggregation() const
Checks whether the PSDU contains A-MPDU.
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 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
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
Declaration of ns3::HtPhy class.
Declaration of ns3::HtPpdu class.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1861