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 
29 namespace ns3 {
30 
31 NS_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 
64 Time
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 
74 OfdmPpdu::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 
89 TypeId
91 {
92  static TypeId tid = TypeId ("ns3::LSigHeader")
93  .SetParent<Header> ()
94  .SetGroupName ("Wifi")
95  .AddConstructor<LSigHeader> ()
96  ;
97  return tid;
98 }
99 
100 TypeId
102 {
103  return GetTypeId ();
104 }
105 
106 void
107 OfdmPpdu::LSigHeader::Print (std::ostream &os) const
108 {
109  os << "SIGNAL=" << GetRate ()
110  << " LENGTH=" << m_length;
111 }
112 
113 uint32_t
115 {
116  return 3;
117 }
118 
119 void
120 OfdmPpdu::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 
172 uint64_t
173 OfdmPpdu::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 
217 void
219 {
220  NS_ASSERT_MSG (length < 4096, "Invalid length");
221  m_length = length;
222 }
223 
224 uint16_t
226 {
227  return m_length;
228 }
229 
230 void
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 
244 uint32_t
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
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::OfdmPpdu::LSigHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: ofdm-ppdu.cc:90
ns3::OfdmPpdu::DoGetTxVector
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: ofdm-ppdu.cc:53
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::OfdmPpdu::LSigHeader::Print
void Print(std::ostream &os) const override
Definition: ofdm-ppdu.cc:107
ns3::WifiPhy::CalculateTxDuration
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1610
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
ns3::WifiPpdu::GetTxVector
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition: buffer.h:1021
ns3::OfdmPpdu::OfdmPpdu
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
ns3::OfdmPpdu::LSigHeader::LSigHeader
LSigHeader()
Definition: ofdm-ppdu.cc:79
ns3::OfdmPpdu::LSigHeader::SetRate
void SetRate(uint64_t rate, uint16_t channelWidth=20)
Fill the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:120
ns3::OfdmPpdu::m_channelWidth
uint16_t m_channelWidth
the channel width used to transmit that PPDU in MHz
Definition: ofdm-ppdu.h:127
ns3::WifiPpdu
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:52
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition: wifi-tx-vector.cc:226
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::OfdmPpdu::LSigHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const override
Definition: ofdm-ppdu.cc:114
ns3::Ptr< const WifiPsdu >
ns3::OfdmPpdu::~OfdmPpdu
virtual ~OfdmPpdu()
Destructor for OfdmPpdu.
Definition: ofdm-ppdu.cc:48
visualizer.core.start
def start()
Definition: core.py:1855
ns3::OfdmPpdu::LSigHeader::GetLength
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:225
ns3::OfdmPpdu::LSigHeader::GetInstanceTypeId
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: ofdm-ppdu.cc:101
ns3::OfdmPpdu::m_lSig
LSigHeader m_lSig
the L-SIG PHY header
Definition: ofdm-ppdu.h:128
ns3::WifiPsdu::GetSize
uint32_t GetSize(void) const
Return the size of the PSDU in bytes.
Definition: wifi-psdu.cc:260
ns3::OfdmPpdu::GetTxDuration
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: ofdm-ppdu.cc:65
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Header
Protocol header serialization and deserialization.
Definition: header.h:43
ns3::WifiTxVector::SetChannelWidth
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Definition: wifi-tx-vector.cc:254
NS_ASSERT_MSG
#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
ofdm-phy.h
Declaration of ns3::OfdmPhy class and ns3::OfdmPhyVariant enum.
ns3::OfdmPpdu::LSigHeader
OFDM and ERP OFDM L-SIG PHY header.
Definition: ofdm-ppdu.h:56
ns3::OfdmPpdu::LSigHeader::SetLength
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: ofdm-ppdu.cc:218
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16(void)
Definition: buffer.h:1029
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition: buffer.h:99
ns3::OfdmPpdu::m_band
WifiPhyBand m_band
the WifiPhyBand used to transmit that PPDU
Definition: ofdm-ppdu.h:126
ns3::OfdmPpdu::LSigHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition: ofdm-ppdu.cc:231
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ofdm-ppdu.h
Declaration of ns3::OfdmPpdu class.
ns3::OfdmPhy::GetOfdmRate
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
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WifiPhyBand
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
ns3::WifiPpdu::m_uid
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:182
ns3::WifiMode::GetDataRate
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
ns3::OfdmPpdu::LSigHeader::~LSigHeader
virtual ~LSigHeader()
Definition: ofdm-ppdu.cc:85
ns3::OfdmPpdu::Copy
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: ofdm-ppdu.cc:74
ns3::OfdmPpdu::LSigHeader::GetRate
uint64_t GetRate(uint16_t channelWidth=20) const
Return the RATE field of L-SIG (in bit/s).
Definition: ofdm-ppdu.cc:173
ns3::WifiPpdu::GetPsdu
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
ns3::WifiPpdu::m_preamble
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:179
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition: wifi-tx-vector.cc:248
ns3::WifiTxVector::GetMode
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.
Definition: wifi-tx-vector.cc:112