A Discrete-Event Network Simulator
API
ofdm-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> (LSigHeader)
20 */
21
22#include "ofdm-ppdu.h"
23
24#include "ofdm-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
33NS_LOG_COMPONENT_DEFINE("OfdmPpdu");
34
36 const WifiTxVector& txVector,
37 uint16_t txCenterFreq,
38 WifiPhyBand band,
39 uint64_t uid,
40 bool instantiateLSig /* = true */)
41 : WifiPpdu(psdu, txVector, txCenterFreq, uid),
42 m_band(band),
43 m_channelWidth(txVector.GetChannelWidth())
44{
45 NS_LOG_FUNCTION(this << psdu << txVector << txCenterFreq << band << uid);
46 if (instantiateLSig)
47 {
48 m_lSig.SetRate(txVector.GetMode().GetDataRate(txVector), m_channelWidth);
49 m_lSig.SetLength(psdu->GetSize());
50 }
51}
52
54{
55}
56
59{
60 WifiTxVector txVector;
62 // OFDM uses 20 MHz, unless PHY channel width is 5 MHz or 10 MHz
63 uint16_t channelWidth = m_channelWidth < 20 ? m_channelWidth : 20;
65 txVector.SetChannelWidth(channelWidth);
66 return txVector;
67}
68
69Time
71{
72 Time ppduDuration = Seconds(0);
73 const WifiTxVector& txVector = GetTxVector();
74 ppduDuration = WifiPhy::CalculateTxDuration(m_lSig.GetLength(), txVector, m_band);
75 return ppduDuration;
76}
77
80{
81 return Ptr<WifiPpdu>(new OfdmPpdu(*this), false);
82}
83
85 : m_rate(0b1101),
86 m_length(0)
87{
88}
89
91{
92}
93
96{
97 static TypeId tid = TypeId("ns3::LSigHeader")
99 .SetGroupName("Wifi")
100 .AddConstructor<LSigHeader>();
101 return tid;
102}
103
104TypeId
106{
107 return GetTypeId();
108}
109
110void
111OfdmPpdu::LSigHeader::Print(std::ostream& os) const
112{
113 os << "SIGNAL=" << GetRate() << " LENGTH=" << m_length;
114}
115
118{
119 return 3;
120}
121
122void
123OfdmPpdu::LSigHeader::SetRate(uint64_t rate, uint16_t channelWidth)
124{
125 if (channelWidth == 5)
126 {
127 rate *= 4; // corresponding 20 MHz rate if 5 MHz is used
128 }
129 else if (channelWidth == 10)
130 {
131 rate *= 2; // corresponding 20 MHz rate if 10 MHz is used
132 }
133 /* Here is the binary representation for a given rate:
134 * 6 Mbit/s: 1101
135 * 9 Mbit/s: 1111
136 * 12 Mbit/s: 0101
137 * 18 Mbit/s: 0111
138 * 24 Mbit/s: 1001
139 * 36 Mbit/s: 1011
140 * 48 Mbit/s: 0001
141 * 54 Mbit/s: 0011
142 */
143 switch (rate)
144 {
145 case 6000000:
146 m_rate = 0b1101;
147 break;
148 case 9000000:
149 m_rate = 0b1111;
150 break;
151 case 12000000:
152 m_rate = 0b0101;
153 break;
154 case 18000000:
155 m_rate = 0b0111;
156 break;
157 case 24000000:
158 m_rate = 0b1001;
159 break;
160 case 36000000:
161 m_rate = 0b1011;
162 break;
163 case 48000000:
164 m_rate = 0b0001;
165 break;
166 case 54000000:
167 m_rate = 0b0011;
168 break;
169 default:
170 NS_ASSERT_MSG(false, "Invalid rate");
171 break;
172 }
173}
174
175uint64_t
176OfdmPpdu::LSigHeader::GetRate(uint16_t channelWidth) const
177{
178 uint64_t rate = 0;
179 switch (m_rate)
180 {
181 case 0b1101:
182 rate = 6000000;
183 break;
184 case 0b1111:
185 rate = 9000000;
186 break;
187 case 0b0101:
188 rate = 12000000;
189 break;
190 case 0b0111:
191 rate = 18000000;
192 break;
193 case 0b1001:
194 rate = 24000000;
195 break;
196 case 0b1011:
197 rate = 36000000;
198 break;
199 case 0b0001:
200 rate = 48000000;
201 break;
202 case 0b0011:
203 rate = 54000000;
204 break;
205 default:
206 NS_ASSERT_MSG(false, "Invalid rate");
207 break;
208 }
209 if (channelWidth == 5)
210 {
211 rate /= 4; // compute corresponding 5 MHz rate
212 }
213 else if (channelWidth == 10)
214 {
215 rate /= 2; // compute corresponding 10 MHz rate
216 }
217 return rate;
218}
219
220void
222{
223 NS_ASSERT_MSG(length < 4096, "Invalid length");
224 m_length = length;
225}
226
227uint16_t
229{
230 return m_length;
231}
232
233void
235{
236 uint8_t byte = 0;
237 uint16_t bytes = 0;
238
239 byte |= m_rate;
240 byte |= (m_length & 0x07) << 5;
241 start.WriteU8(byte);
242
243 bytes |= (m_length & 0x0ff8) >> 3;
244 start.WriteU16(bytes);
245}
246
249{
251
252 uint8_t byte = i.ReadU8();
253 m_rate = byte & 0x0f;
254 m_length = (byte >> 5) & 0x07;
255
256 uint16_t bytes = i.ReadU16();
257 m_length |= (bytes << 3) & 0x0ff8;
258
259 return i.GetDistanceFrom(start);
260}
261
262} // 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 GetOfdmRate(uint64_t rate, uint16_t bw=20)
Return a WifiMode for OFDM corresponding to the provided rate and the channel bandwidth (20,...
Definition: ofdm-phy.cc:396
OFDM and ERP OFDM L-SIG PHY header.
Definition: ofdm-ppdu.h:55
void SetRate(uint64_t rate, uint16_t channelWidth=20)
Fill the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:123
uint64_t GetRate(uint16_t channelWidth=20) const
Return the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:176
uint16_t GetLength() const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:228
void Print(std::ostream &os) const override
Definition: ofdm-ppdu.cc:111
uint32_t Deserialize(Buffer::Iterator start) override
Definition: ofdm-ppdu.cc:248
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: ofdm-ppdu.cc:105
uint32_t GetSerializedSize() const override
Definition: ofdm-ppdu.cc:117
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:221
static TypeId GetTypeId()
Get the type ID.
Definition: ofdm-ppdu.cc:95
void Serialize(Buffer::Iterator start) const override
Definition: ofdm-ppdu.cc:234
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:130
OfdmPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint16_t txCenterFreq, WifiPhyBand band, uint64_t uid, bool instantiateLSig=true)
Create an OFDM PPDU.
Definition: ofdm-ppdu.cc:35
~OfdmPpdu() override
Destructor for OfdmPpdu.
Definition: ofdm-ppdu.cc:53
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:132
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: ofdm-ppdu.cc:70
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:131
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: ofdm-ppdu.cc:79
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: ofdm-ppdu.cc:58
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1458
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:55
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:197
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:76
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...
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
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 SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#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:1336
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1864
Declaration of ns3::OfdmPhy class and ns3::OfdmPhyVariant enum.
Declaration of ns3::OfdmPpdu class.