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