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