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
30namespace ns3 {
31
33
34HtPpdu::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 ());
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
70Time
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
80HtPpdu::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
100{
101 static TypeId tid = TypeId ("ns3::HtSigHeader")
102 .SetParent<Header> ()
103 .SetGroupName ("Wifi")
104 .AddConstructor<HtSigHeader> ()
105 ;
106 return tid;
107}
108
109TypeId
111{
112 return GetTypeId ();
113}
114
115void
116HtPpdu::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
127{
128 return 6;
129}
130
131void
133{
134 NS_ASSERT (mcs <= 31);
135 m_mcs = mcs;
136}
137
138uint8_t
140{
141 return m_mcs;
142}
143
144void
146{
147 m_cbw20_40 = (channelWidth > 20) ? 1 : 0;
148}
149
150uint16_t
152{
153 return m_cbw20_40 ? 40 : 20;
154}
155
156void
158{
159 m_htLength = length;
160}
161
162uint16_t
164{
165 return m_htLength;
166}
167
168void
170{
171 m_aggregation = aggregation ? 1 : 0;
172}
173
174bool
176{
177 return m_aggregation;
178}
179
180void
182{
183 m_sgi = sgi ? 1 : 0;
184}
185
186bool
188{
189 return m_sgi;
190}
191
192void
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
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
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
Protocol header serialization and deserialization.
Definition: header.h:43
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition: ht-phy.cc:456
HT PHY header (HT-SIG1/2).
Definition: ht-ppdu.h:53
void Print(std::ostream &os) const override
Definition: ht-ppdu.cc:116
static TypeId GetTypeId(void)
Get the type ID.
Definition: ht-ppdu.cc:99
uint16_t GetHtLength(void) const
Return the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:163
void SetHtLength(uint16_t length)
Fill the HT length field of HT-SIG (in bytes).
Definition: ht-ppdu.cc:157
virtual ~HtSigHeader()
Definition: ht-ppdu.cc:94
bool GetShortGuardInterval(void) const
Return the short guard interval 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:132
uint32_t Deserialize(Buffer::Iterator start) override
Definition: ht-ppdu.cc:207
uint32_t GetSerializedSize(void) const override
Definition: ht-ppdu.cc:126
uint16_t GetChannelWidth(void) const
Return the channel width (in MHz).
Definition: ht-ppdu.cc:151
uint8_t GetMcs(void) const
Return the MCS field of HT-SIG.
Definition: ht-ppdu.cc:139
void SetAggregation(bool aggregation)
Fill the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:169
void SetChannelWidth(uint16_t channelWidth)
Fill the channel width field of HT-SIG (in MHz).
Definition: ht-ppdu.cc:145
void SetShortGuardInterval(bool sgi)
Fill the short guard interval field of HT-SIG.
Definition: ht-ppdu.cc:181
void Serialize(Buffer::Iterator start) const override
Definition: ht-ppdu.cc:193
bool GetAggregation(void) const
Return the aggregation field of HT-SIG.
Definition: ht-ppdu.cc:175
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: ht-ppdu.cc:110
HtSigHeader m_htSig
the HT-SIG PHY header
Definition: ht-ppdu.h:161
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: ht-ppdu.cc:58
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: ht-ppdu.cc:71
virtual ~HtPpdu()
Destructor for HtPpdu.
Definition: ht-ppdu.cc:53
HtPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, WifiPhyBand band, uint64_t uid)
Create an HT PPDU.
Definition: ht-ppdu.cc:34
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: ht-ppdu.cc:80
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:218
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
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:155
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1306
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
uint32_t GetSize(void) const
Return the size of the PSDU in bytes.
Definition: wifi-psdu.cc:260
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.
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
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 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
@ 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:1853