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-operating-channel.h"
28 #include "ns3/wifi-phy.h"
29 #include "ns3/wifi-psdu.h"
30 #include "ns3/wifi-utils.h"
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("HtPpdu");
36 
38  const WifiTxVector& txVector,
40  Time ppduDuration,
41  uint64_t uid)
42  : OfdmPpdu(psdu,
43  txVector,
44  channel,
45  uid,
46  false) // don't instantiate LSigHeader of OfdmPpdu
47 {
48  NS_LOG_FUNCTION(this << psdu << txVector << channel << ppduDuration << uid);
49  SetPhyHeaders(txVector, ppduDuration, psdu->GetSize());
50 }
51 
52 void
53 HtPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration, std::size_t psduSize)
54 {
55  NS_LOG_FUNCTION(this << txVector << ppduDuration << psduSize);
56  SetLSigHeader(m_lSig, ppduDuration);
57  SetHtSigHeader(m_htSig, txVector, psduSize);
58 }
59 
60 void
61 HtPpdu::SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const
62 {
63  uint8_t sigExtension = 0;
66  {
67  sigExtension = 6;
68  }
69  uint16_t length = ((ceil((static_cast<double>(ppduDuration.GetNanoSeconds() - (20 * 1000) -
70  (sigExtension * 1000)) /
71  1000) /
72  4.0) *
73  3) -
74  3);
75  lSig.SetLength(length);
76 }
77 
78 void
79 HtPpdu::SetHtSigHeader(HtSigHeader& htSig, const WifiTxVector& txVector, std::size_t psduSize) const
80 {
81  htSig.SetMcs(txVector.GetMode().GetMcsValue());
82  htSig.SetChannelWidth(txVector.GetChannelWidth());
83  htSig.SetHtLength(psduSize);
84  htSig.SetAggregation(txVector.IsAggregation());
85  htSig.SetShortGuardInterval(txVector.GetGuardInterval() == 400);
86 }
87 
90 {
91  WifiTxVector txVector;
92  txVector.SetPreambleType(m_preamble);
94  return txVector;
95 }
96 
97 void
99  const LSigHeader& lSig,
100  const HtSigHeader& htSig) const
101 {
102  txVector.SetMode(HtPhy::GetHtMcs(htSig.GetMcs()));
103  txVector.SetChannelWidth(htSig.GetChannelWidth());
104  txVector.SetNss(1 + (htSig.GetMcs() / 8));
105  txVector.SetGuardInterval(htSig.GetShortGuardInterval() ? 400 : 800);
106  txVector.SetAggregation(htSig.GetAggregation());
107 }
108 
109 Time
111 {
112  const auto& txVector = GetTxVector();
113  const auto htLength = m_htSig.GetHtLength();
115  return WifiPhy::CalculateTxDuration(htLength, txVector, m_operatingChannel.GetPhyBand());
116 }
117 
120 {
121  return Ptr<WifiPpdu>(new HtPpdu(*this), false);
122 }
123 
125  : m_mcs(0),
126  m_cbw20_40(0),
127  m_htLength(0),
128  m_aggregation(0),
129  m_sgi(0)
130 {
131 }
132 
133 void
135 {
136  NS_ASSERT(mcs <= 31);
137  m_mcs = mcs;
138 }
139 
140 uint8_t
142 {
143  return m_mcs;
144 }
145 
146 void
148 {
149  m_cbw20_40 = (channelWidth > 20) ? 1 : 0;
150 }
151 
152 uint16_t
154 {
155  return m_cbw20_40 ? 40 : 20;
156 }
157 
158 void
160 {
161  m_htLength = length;
162 }
163 
164 uint16_t
166 {
167  return m_htLength;
168 }
169 
170 void
172 {
173  m_aggregation = aggregation ? 1 : 0;
174 }
175 
176 bool
178 {
179  return m_aggregation;
180 }
181 
182 void
184 {
185  m_sgi = sgi ? 1 : 0;
186 }
187 
188 bool
190 {
191  return m_sgi;
192 }
193 
194 } // namespace ns3
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition: ht-phy.cc:488
HT PHY header (HT-SIG1/2).
Definition: ht-ppdu.h:52
uint16_t GetHtLength() const
Return the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:165
uint8_t GetMcs() const
Return the MCS field of HT-SIG.
Definition: ht-ppdu.cc:141
void SetHtLength(uint16_t length)
Fill the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:159
bool GetAggregation() const
Return the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:177
void SetMcs(uint8_t mcs)
Fill the MCS field of HT-SIG.
Definition: ht-ppdu.cc:134
bool GetShortGuardInterval() const
Return the short guard interval field of HT-SIG.
Definition: ht-ppdu.cc:189
uint16_t GetChannelWidth() const
Return the channel width (in MHz).
Definition: ht-ppdu.cc:153
void SetAggregation(bool aggregation)
Fill the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:171
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of HT-SIG (in MHz).
Definition: ht-ppdu.cc:147
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of HT-SIG.
Definition: ht-ppdu.cc:183
HtSigHeader m_htSig
the HT-SIG PHY header
Definition: ht-ppdu.h:185
HtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, const WifiPhyOperatingChannel &channel, Time ppduDuration, uint64_t uid)
Create an HT PPDU.
Definition: ht-ppdu.cc:37
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: ht-ppdu.cc:89
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: ht-ppdu.cc:119
void SetHtSigHeader(HtSigHeader &htSig, const WifiTxVector &txVector, std::size_t psduSize) const
Fill in the HT-SIG header.
Definition: ht-ppdu.cc:79
virtual void SetLSigHeader(LSigHeader &lSig, Time ppduDuration) const
Fill in the L-SIG header.
Definition: ht-ppdu.cc:61
void SetPhyHeaders(const WifiTxVector &txVector, Time ppduDuration, std::size_t psduSize)
Fill in the PHY headers.
Definition: ht-ppdu.cc:53
void SetTxVectorFromPhyHeaders(WifiTxVector &txVector, const LSigHeader &lSig, const HtSigHeader &htSig) const
Fill in the TXVECTOR from PHY headers.
Definition: ht-ppdu.cc:98
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: ht-ppdu.cc:110
OFDM and ERP OFDM L-SIG PHY header.
Definition: ofdm-ppdu.h:54
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:203
OFDM PPDU (11a)
Definition: ofdm-ppdu.h:47
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:110
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:418
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:1507
Class that keeps track of all information about the current PHY operating channel.
bool IsSet() const
Return true if a valid channel has been set, false otherwise.
WifiPhyBand GetPhyBand() const
Return the PHY band of the operating channel.
const WifiPhyOperatingChannel & m_operatingChannel
the operating channel of the PHY
Definition: wifi-ppdu.h:210
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:202
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:85
uint32_t GetSize() const
Return the size of the PSDU in bytes.
Definition: wifi-psdu.cc:273
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.
uint16_t GetChannelWidth() 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: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 ",...
@ 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.
channel
Definition: third.py:88