A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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-operating-channel.h"
28#include "ns3/wifi-phy.h"
29#include "ns3/wifi-psdu.h"
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("OfdmPpdu");
35
37 const WifiTxVector& txVector,
38 const WifiPhyOperatingChannel& channel,
39 uint64_t uid,
40 bool instantiateLSig /* = true */)
41 : WifiPpdu(psdu, txVector, channel, uid),
42 m_channelWidth(txVector.IsNonHtDuplicate() ? 20 : txVector.GetChannelWidth())
43{
44 NS_LOG_FUNCTION(this << psdu << txVector << channel << uid);
45 if (instantiateLSig)
46 {
47 SetPhyHeaders(txVector, psdu->GetSize());
48 }
49}
50
51void
52OfdmPpdu::SetPhyHeaders(const WifiTxVector& txVector, std::size_t psduSize)
53{
54 NS_LOG_FUNCTION(this << txVector << psduSize);
55 SetLSigHeader(m_lSig, txVector, psduSize);
56}
57
58void
59OfdmPpdu::SetLSigHeader(LSigHeader& lSig, const WifiTxVector& txVector, std::size_t psduSize) const
60{
61 lSig.SetRate(txVector.GetMode().GetDataRate(txVector), m_channelWidth);
62 lSig.SetLength(psduSize);
63}
64
67{
68 WifiTxVector txVector;
71 return txVector;
72}
73
74void
76{
78 // OFDM uses 20 MHz, unless PHY channel width is 5 MHz or 10 MHz
81}
82
83Time
85{
86 const auto& txVector = GetTxVector();
87 const auto length = m_lSig.GetLength();
90}
91
94{
95 return Ptr<WifiPpdu>(new OfdmPpdu(*this), false);
96}
97
99 : m_rate(0b1101),
100 m_length(0)
101{
102}
103
104void
105OfdmPpdu::LSigHeader::SetRate(uint64_t rate, uint16_t channelWidth)
106{
107 if (channelWidth == 5)
108 {
109 rate *= 4; // corresponding 20 MHz rate if 5 MHz is used
110 }
111 else if (channelWidth == 10)
112 {
113 rate *= 2; // corresponding 20 MHz rate if 10 MHz is used
114 }
115 /* Here is the binary representation for a given rate:
116 * 6 Mbit/s: 1101
117 * 9 Mbit/s: 1111
118 * 12 Mbit/s: 0101
119 * 18 Mbit/s: 0111
120 * 24 Mbit/s: 1001
121 * 36 Mbit/s: 1011
122 * 48 Mbit/s: 0001
123 * 54 Mbit/s: 0011
124 */
125 switch (rate)
126 {
127 case 6000000:
128 m_rate = 0b1101;
129 break;
130 case 9000000:
131 m_rate = 0b1111;
132 break;
133 case 12000000:
134 m_rate = 0b0101;
135 break;
136 case 18000000:
137 m_rate = 0b0111;
138 break;
139 case 24000000:
140 m_rate = 0b1001;
141 break;
142 case 36000000:
143 m_rate = 0b1011;
144 break;
145 case 48000000:
146 m_rate = 0b0001;
147 break;
148 case 54000000:
149 m_rate = 0b0011;
150 break;
151 default:
152 NS_ASSERT_MSG(false, "Invalid rate");
153 break;
154 }
155}
156
157uint64_t
158OfdmPpdu::LSigHeader::GetRate(uint16_t channelWidth) const
159{
160 uint64_t rate = 0;
161 switch (m_rate)
162 {
163 case 0b1101:
164 rate = 6000000;
165 break;
166 case 0b1111:
167 rate = 9000000;
168 break;
169 case 0b0101:
170 rate = 12000000;
171 break;
172 case 0b0111:
173 rate = 18000000;
174 break;
175 case 0b1001:
176 rate = 24000000;
177 break;
178 case 0b1011:
179 rate = 36000000;
180 break;
181 case 0b0001:
182 rate = 48000000;
183 break;
184 case 0b0011:
185 rate = 54000000;
186 break;
187 default:
188 NS_ASSERT_MSG(false, "Invalid rate");
189 break;
190 }
191 if (channelWidth == 5)
192 {
193 rate /= 4; // compute corresponding 5 MHz rate
194 }
195 else if (channelWidth == 10)
196 {
197 rate /= 2; // compute corresponding 10 MHz rate
198 }
199 return rate;
200}
201
202void
204{
205 NS_ASSERT_MSG(length < 4096, "Invalid length");
206 m_length = length;
207}
208
209uint16_t
211{
212 return m_length;
213}
214
215} // namespace ns3
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:414
OFDM and ERP OFDM L-SIG PHY header.
Definition: ofdm-ppdu.h:54
void SetRate(uint64_t rate, uint16_t channelWidth=20)
Fill the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:105
uint64_t GetRate(uint16_t channelWidth=20) const
Return the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:158
uint16_t GetLength() const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:210
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
void SetLSigHeader(LSigHeader &lSig, const WifiTxVector &txVector, std::size_t psduSize) const
Fill in the L-SIG header.
Definition: ofdm-ppdu.cc:59
void SetPhyHeaders(const WifiTxVector &txVector, std::size_t psduSize)
Fill in the PHY headers.
Definition: ofdm-ppdu.cc:52
OfdmPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, const WifiPhyOperatingChannel &channel, uint64_t uid, bool instantiateLSig=true)
Create an OFDM PPDU.
Definition: ofdm-ppdu.cc:36
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:110
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: ofdm-ppdu.cc:84
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz (needed to distinguish 5 MHz, 10 MHz or 20 MHz PP...
Definition: ofdm-ppdu.h:140
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: ofdm-ppdu.cc:93
virtual void SetTxVectorFromLSigHeader(WifiTxVector &txVector, const LSigHeader &lSig) const
Fill in the TXVECTOR from L-SIG header.
Definition: ofdm-ppdu.cc:75
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: ofdm-ppdu.cc:66
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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:1528
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.
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:57
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
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(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of ns3::OfdmPhy class and ns3::OfdmPhyVariant enum.
Declaration of ns3::OfdmPpdu class.