A Discrete-Event Network Simulator
API
dsss-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> (DsssSigHeader)
20  */
21 
22 #include "dsss-ppdu.h"
23 
24 #include "dsss-phy.h"
25 
26 #include "ns3/log.h"
27 #include "ns3/wifi-phy.h"
28 #include "ns3/wifi-psdu.h"
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("DsssPpdu");
34 
36  const WifiTxVector& txVector,
37  uint16_t txCenterFreq,
38  Time ppduDuration,
39  uint64_t uid)
40  : WifiPpdu(psdu, txVector, txCenterFreq, uid)
41 {
42  NS_LOG_FUNCTION(this << psdu << txVector << txCenterFreq << ppduDuration << uid);
43  SetPhyHeaders(txVector, ppduDuration);
44 }
45 
46 void
47 DsssPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration)
48 {
49  NS_LOG_FUNCTION(this << txVector);
50 
51 #ifdef NS3_BUILD_PROFILE_DEBUG
52  DsssSigHeader dsssSig;
53  SetDsssHeader(dsssSig, txVector, ppduDuration);
54  m_phyHeaders->AddHeader(dsssSig);
55 #else
56  SetDsssHeader(m_dsssSig, txVector, ppduDuration);
57 #endif
58 }
59 
60 void
62  const WifiTxVector& txVector,
63  Time ppduDuration) const
64 {
65  dsssSig.SetRate(txVector.GetMode().GetDataRate(22));
66  Time psduDuration = ppduDuration - WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector);
67  dsssSig.SetLength(psduDuration.GetMicroSeconds());
68 }
69 
72 {
73  WifiTxVector txVector;
74  txVector.SetPreambleType(m_preamble);
75  txVector.SetChannelWidth(22);
76 
77 #ifdef NS3_BUILD_PROFILE_DEBUG
78  DsssSigHeader dsssSig;
79  if (m_phyHeaders->PeekHeader(dsssSig) == 0)
80  {
81  NS_FATAL_ERROR("Missing DSSS SIG PHY header in DSSS PPDU");
82  }
83 
84  SetTxVectorFromDsssHeader(txVector, dsssSig);
85 #else
86  SetTxVectorFromDsssHeader(txVector, m_dsssSig);
87 #endif
88 
89  return txVector;
90 }
91 
92 void
94 {
95  txVector.SetMode(DsssPhy::GetDsssRate(dsssSig.GetRate()));
96 }
97 
98 Time
100 {
101  Time ppduDuration = Seconds(0);
102  const WifiTxVector& txVector = GetTxVector();
103  uint16_t length = 0;
104 #ifdef NS3_BUILD_PROFILE_DEBUG
105  DsssSigHeader dsssSig;
106  m_phyHeaders->PeekHeader(dsssSig);
107  length = dsssSig.GetLength();
108 #else
109  length = m_dsssSig.GetLength();
110 #endif
111  ppduDuration = MicroSeconds(length) + WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector);
112  return ppduDuration;
113 }
114 
117 {
118  return Ptr<WifiPpdu>(new DsssPpdu(*this), false);
119 }
120 
122  : m_rate(0b00001010),
123  m_length(0)
124 {
125 }
126 
127 TypeId
129 {
130  static TypeId tid = TypeId("ns3::DsssSigHeader")
131  .SetParent<Header>()
132  .SetGroupName("Wifi")
133  .AddConstructor<DsssSigHeader>();
134  return tid;
135 }
136 
137 TypeId
139 {
140  return GetTypeId();
141 }
142 
143 void
144 DsssPpdu::DsssSigHeader::Print(std::ostream& os) const
145 {
146  os << "SIGNAL=" << GetRate() << " LENGTH=" << m_length;
147 }
148 
149 uint32_t
151 {
152  return 6;
153 }
154 
155 void
157 {
158  /* Here is the binary representation for a given rate:
159  * 1 Mbit/s: 00001010
160  * 2 Mbit/s: 00010100
161  * 5.5 Mbit/s: 00110111
162  * 11 Mbit/s: 01101110
163  */
164  switch (rate)
165  {
166  case 1000000:
167  m_rate = 0b00001010;
168  break;
169  case 2000000:
170  m_rate = 0b00010100;
171  break;
172  case 5500000:
173  m_rate = 0b00110111;
174  break;
175  case 11000000:
176  m_rate = 0b01101110;
177  break;
178  default:
179  NS_ASSERT_MSG(false, "Invalid rate");
180  break;
181  }
182 }
183 
184 uint64_t
186 {
187  uint64_t rate = 0;
188  switch (m_rate)
189  {
190  case 0b00001010:
191  rate = 1000000;
192  break;
193  case 0b00010100:
194  rate = 2000000;
195  break;
196  case 0b00110111:
197  rate = 5500000;
198  break;
199  case 0b01101110:
200  rate = 11000000;
201  break;
202  default:
203  NS_ASSERT_MSG(false, "Invalid rate");
204  break;
205  }
206  return rate;
207 }
208 
209 void
211 {
212  m_length = length;
213 }
214 
215 uint16_t
217 {
218  return m_length;
219 }
220 
221 void
223 {
224  start.WriteU8(m_rate);
225  start.WriteU8(0); /* SERVICE */
226  start.WriteU16(m_length);
227  start.WriteU16(0); /* CRC */
228 }
229 
230 uint32_t
232 {
234  m_rate = i.ReadU8();
235  i.ReadU8(); /* SERVICE */
236  m_length = i.ReadU16();
237  i.ReadU16(); /* CRC */
238  return i.GetDistanceFrom(start);
239 }
240 
241 } // 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
static WifiMode GetDsssRate(uint64_t rate)
Return a WifiMode for HR/DSSS corresponding to the provided rate.
Definition: dsss-phy.cc:292
DSSS SIG PHY header.
Definition: dsss-ppdu.h:53
uint32_t GetSerializedSize() const override
Definition: dsss-ppdu.cc:150
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: dsss-ppdu.cc:138
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:210
void Print(std::ostream &os) const override
Definition: dsss-ppdu.cc:144
void Serialize(Buffer::Iterator start) const override
Definition: dsss-ppdu.cc:222
uint64_t GetRate() const
Return the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:185
static TypeId GetTypeId()
Get the type ID.
Definition: dsss-ppdu.cc:128
void SetRate(uint64_t rate)
Fill the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:156
uint16_t GetLength() const
Return the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:216
Time GetTxDuration() const override
Get the total transmission duration of the PPDU.
Definition: dsss-ppdu.cc:99
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
Definition: dsss-ppdu.cc:71
Ptr< WifiPpdu > Copy() const override
Copy this instance.
Definition: dsss-ppdu.cc:116
virtual void SetTxVectorFromDsssHeader(WifiTxVector &txVector, const DsssSigHeader &dsssSig) const
Fill in the TXVECTOR from DSSS header.
Definition: dsss-ppdu.cc:93
DsssPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint16_t txCenterFreq, Time ppduDuration, uint64_t uid)
Create a DSSS (HR/DSSS) PPDU.
Definition: dsss-ppdu.cc:35
void SetPhyHeaders(const WifiTxVector &txVector, Time ppduDuration)
Fill in the PHY headers.
Definition: dsss-ppdu.cc:47
void SetDsssHeader(DsssSigHeader &dsssSig, const WifiTxVector &txVector, Time ppduDuration) const
Fill in the DSSS header.
Definition: dsss-ppdu.cc:61
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:305
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:412
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 CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1473
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:56
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:201
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:82
Ptr< Packet > m_phyHeaders
the PHY headers contained in this PPDU
Definition: wifi-ppdu.h:211
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.
Declaration of ns3::DsssPhy class.
Declaration of ns3::DsssPpdu class.
#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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#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 MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.