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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Rediet <getachew.redieteab@orange.com>
7 * Muhammad Iqbal Rochman <muhiqbalcr@uchicago.edu>
8 * Sébastien Deronne <sebastien.deronne@gmail.com> (LSigHeader)
9 */
10
11#include "ofdm-ppdu.h"
12
13#include "ofdm-phy.h"
14
15#include "ns3/log.h"
16#include "ns3/wifi-phy-operating-channel.h"
17#include "ns3/wifi-phy.h"
18#include "ns3/wifi-psdu.h"
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("OfdmPpdu");
24
26 const WifiTxVector& txVector,
27 const WifiPhyOperatingChannel& channel,
28 uint64_t uid,
29 bool instantiateLSig /* = true */)
30 : WifiPpdu(psdu, txVector, channel, uid),
31 m_channelWidth(txVector.IsNonHtDuplicate() ? 20 : txVector.GetChannelWidth())
32{
33 NS_LOG_FUNCTION(this << psdu << txVector << channel << uid);
34 if (instantiateLSig)
35 {
36 SetPhyHeaders(txVector, psdu->GetSize());
37 }
38}
39
40void
41OfdmPpdu::SetPhyHeaders(const WifiTxVector& txVector, std::size_t psduSize)
42{
43 NS_LOG_FUNCTION(this << txVector << psduSize);
44 SetLSigHeader(m_lSig, txVector, psduSize);
45}
46
47void
48OfdmPpdu::SetLSigHeader(LSigHeader& lSig, const WifiTxVector& txVector, std::size_t psduSize) const
49{
50 lSig.SetRate(txVector.GetMode().GetDataRate(txVector), m_channelWidth);
51 lSig.SetLength(psduSize);
52}
53
56{
57 WifiTxVector txVector;
60 return txVector;
61}
62
63void
65{
67 // OFDM uses 20 MHz, unless PHY channel width is 5 MHz or 10 MHz
70}
71
72Time
74{
75 const auto& txVector = GetTxVector();
76 const auto length = m_lSig.GetLength();
79}
80
83{
84 return Ptr<WifiPpdu>(new OfdmPpdu(*this), false);
85}
86
88 : m_rate(0b1101),
89 m_length(0)
90{
91}
92
93void
94OfdmPpdu::LSigHeader::SetRate(uint64_t rate, MHz_u channelWidth)
95{
96 if (channelWidth == 5)
97 {
98 rate *= 4; // corresponding 20 MHz rate if 5 MHz is used
99 }
100 else if (channelWidth == 10)
101 {
102 rate *= 2; // corresponding 20 MHz rate if 10 MHz is used
103 }
104 /* Here is the binary representation for a given rate:
105 * 6 Mbit/s: 1101
106 * 9 Mbit/s: 1111
107 * 12 Mbit/s: 0101
108 * 18 Mbit/s: 0111
109 * 24 Mbit/s: 1001
110 * 36 Mbit/s: 1011
111 * 48 Mbit/s: 0001
112 * 54 Mbit/s: 0011
113 */
114 switch (rate)
115 {
116 case 6000000:
117 m_rate = 0b1101;
118 break;
119 case 9000000:
120 m_rate = 0b1111;
121 break;
122 case 12000000:
123 m_rate = 0b0101;
124 break;
125 case 18000000:
126 m_rate = 0b0111;
127 break;
128 case 24000000:
129 m_rate = 0b1001;
130 break;
131 case 36000000:
132 m_rate = 0b1011;
133 break;
134 case 48000000:
135 m_rate = 0b0001;
136 break;
137 case 54000000:
138 m_rate = 0b0011;
139 break;
140 default:
141 NS_ASSERT_MSG(false, "Invalid rate");
142 break;
143 }
144}
145
146uint64_t
148{
149 uint64_t rate = 0;
150 switch (m_rate)
151 {
152 case 0b1101:
153 rate = 6000000;
154 break;
155 case 0b1111:
156 rate = 9000000;
157 break;
158 case 0b0101:
159 rate = 12000000;
160 break;
161 case 0b0111:
162 rate = 18000000;
163 break;
164 case 0b1001:
165 rate = 24000000;
166 break;
167 case 0b1011:
168 rate = 36000000;
169 break;
170 case 0b0001:
171 rate = 48000000;
172 break;
173 case 0b0011:
174 rate = 54000000;
175 break;
176 default:
177 NS_ASSERT_MSG(false, "Invalid rate");
178 break;
179 }
180 if (channelWidth == 5)
181 {
182 rate /= 4; // compute corresponding 5 MHz rate
183 }
184 else if (channelWidth == 10)
185 {
186 rate /= 2; // compute corresponding 10 MHz rate
187 }
188 return rate;
189}
190
191void
193{
194 NS_ASSERT_MSG(length < 4096, "Invalid length");
195 m_length = length;
196}
197
198uint16_t
200{
201 return m_length;
202}
203
204} // namespace ns3
static WifiMode GetOfdmRate(uint64_t rate, MHz_u bw=20)
Return a WifiMode for OFDM corresponding to the provided rate and the channel bandwidth (20,...
Definition ofdm-phy.cc:404
OFDM and ERP OFDM L-SIG PHY header.
Definition ofdm-ppdu.h:43
uint16_t GetLength() const
Return the LENGTH field of L-SIG (in bytes).
Definition ofdm-ppdu.cc:199
void SetRate(uint64_t rate, MHz_u channelWidth=20)
Fill the RATE field of L-SIG (in bit/s).
Definition ofdm-ppdu.cc:94
uint64_t GetRate(MHz_u channelWidth=20) const
Return the RATE field of L-SIG (in bit/s).
Definition ofdm-ppdu.cc:147
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition ofdm-ppdu.cc:192
void SetLSigHeader(LSigHeader &lSig, const WifiTxVector &txVector, std::size_t psduSize) const
Fill in the L-SIG header.
Definition ofdm-ppdu.cc:48
void SetPhyHeaders(const WifiTxVector &txVector, std::size_t psduSize)
Fill in the PHY headers.
Definition ofdm-ppdu.cc:41
MHz_u m_channelWidth
the channel width used to transmit that PPDU (needed to distinguish 5 MHz, 10 MHz or 20 MHz PPDUs)
Definition ofdm-ppdu.h:129
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:25
LSigHeader m_lSig
the L-SIG PHY header
Definition ofdm-ppdu.h:99
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition ofdm-ppdu.cc:73
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition ofdm-ppdu.cc:82
virtual void SetTxVectorFromLSigHeader(WifiTxVector &txVector, const LSigHeader &lSig) const
Fill in the TXVECTOR from L-SIG header.
Definition ofdm-ppdu.cc:64
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition ofdm-ppdu.cc:55
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:111
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition wifi-phy.cc:1572
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:47
const WifiPhyOperatingChannel & m_operatingChannel
the operating channel of the PHY
Definition wifi-ppdu.h:201
WifiPreamble m_preamble
the PHY preamble
Definition wifi-ppdu.h:192
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition wifi-ppdu.cc:113
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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 SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
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:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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.