A Discrete-Event Network Simulator
API
dsss-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> (DsssSigHeader)
21  */
22 
23 #include "ns3/wifi-phy.h"
24 #include "ns3/wifi-psdu.h"
25 #include "dsss-phy.h"
26 #include "dsss-ppdu.h"
27 #include "ns3/log.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("DsssPpdu");
32 
33 DsssPpdu::DsssPpdu (Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector, Time ppduDuration, uint64_t uid)
34  : WifiPpdu (psdu, txVector, uid)
35 {
36  NS_LOG_FUNCTION (this << psdu << txVector << ppduDuration << uid);
37  m_dsssSig.SetRate (txVector.GetMode ().GetDataRate (22));
38  Time psduDuration = ppduDuration - WifiPhy::CalculatePhyPreambleAndHeaderDuration (txVector);
39  m_dsssSig.SetLength (psduDuration.GetMicroSeconds ());
40 }
41 
43 {
44 }
45 
48 {
49  WifiTxVector txVector;
50  txVector.SetPreambleType (m_preamble);
52  txVector.SetChannelWidth (22);
53  return txVector;
54 }
55 
56 Time
58 {
59  Time ppduDuration = Seconds (0);
60  const WifiTxVector& txVector = GetTxVector ();
62  return ppduDuration;
63 }
64 
66 DsssPpdu::Copy (void) const
67 {
68  return Create<DsssPpdu> (GetPsdu (), GetTxVector (), GetTxDuration (), m_uid);
69 }
70 
72  : m_rate (0b00001010),
73  m_length (0)
74 {
75 }
76 
78 {
79 }
80 
81 TypeId
83 {
84  static TypeId tid = TypeId ("ns3::DsssSigHeader")
85  .SetParent<Header> ()
86  .SetGroupName ("Wifi")
87  .AddConstructor<DsssSigHeader> ()
88  ;
89  return tid;
90 }
91 
92 TypeId
94 {
95  return GetTypeId ();
96 }
97 
98 void
99 DsssPpdu::DsssSigHeader::Print (std::ostream &os) const
100 {
101  os << "SIGNAL=" << GetRate ()
102  << " LENGTH=" << m_length;
103 }
104 
105 uint32_t
107 {
108  return 6;
109 }
110 
111 void
113 {
114  /* Here is the binary representation for a given rate:
115  * 1 Mbit/s: 00001010
116  * 2 Mbit/s: 00010100
117  * 5.5 Mbit/s: 00110111
118  * 11 Mbit/s: 01101110
119  */
120  switch (rate)
121  {
122  case 1000000:
123  m_rate = 0b00001010;
124  break;
125  case 2000000:
126  m_rate = 0b00010100;
127  break;
128  case 5500000:
129  m_rate = 0b00110111;
130  break;
131  case 11000000:
132  m_rate = 0b01101110;
133  break;
134  default:
135  NS_ASSERT_MSG (false, "Invalid rate");
136  break;
137  }
138 }
139 
140 uint64_t
142 {
143  uint64_t rate = 0;
144  switch (m_rate)
145  {
146  case 0b00001010:
147  rate = 1000000;
148  break;
149  case 0b00010100:
150  rate = 2000000;
151  break;
152  case 0b00110111:
153  rate = 5500000;
154  break;
155  case 0b01101110:
156  rate = 11000000;
157  break;
158  default:
159  NS_ASSERT_MSG (false, "Invalid rate");
160  break;
161  }
162  return rate;
163 }
164 
165 void
167 {
168  m_length = length;
169 }
170 
171 uint16_t
173 {
174  return m_length;
175 }
176 
177 void
179 {
180  start.WriteU8 (m_rate);
181  start.WriteU8 (0); /* SERVICE */
182  start.WriteU16 (m_length);
183  start.WriteU16 (0); /* CRC */
184 }
185 
186 uint32_t
188 {
190  m_rate = i.ReadU8 ();
191  i.ReadU8 (); /* SERVICE */
192  m_length = i.ReadU16 ();
193  i.ReadU16 (); /* CRC */
194  return i.GetDistanceFrom (start);
195 }
196 
197 } //namespace ns3
ns3::DsssPpdu::GetTxDuration
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: dsss-ppdu.cc:57
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::DsssPpdu::DsssSigHeader::DsssSigHeader
DsssSigHeader()
Definition: dsss-ppdu.cc:71
dsss-phy.h
Declaration of ns3::DsssPhy class.
ns3::DsssPpdu::DsssSigHeader::SetLength
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:166
ns3::DsssPhy::GetDsssRate
static WifiMode GetDsssRate(uint64_t rate)
Return a WifiMode for HR/DSSS corresponding to the provided rate.
Definition: dsss-phy.cc:261
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ns3::WifiPhy::CalculatePhyPreambleAndHeaderDuration
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1604
ns3::DsssPpdu::DsssSigHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: dsss-ppdu.cc:82
ns3::DsssPpdu::DsssSigHeader::~DsssSigHeader
virtual ~DsssSigHeader()
Definition: dsss-ppdu.cc:77
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::DsssPpdu::DsssSigHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition: dsss-ppdu.cc:178
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DsssPpdu::DoGetTxVector
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: dsss-ppdu.cc:47
ns3::Ptr< const WifiPsdu >
visualizer.core.start
def start()
Definition: core.py:1855
ns3::DsssPpdu::Copy
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: dsss-ppdu.cc:66
ns3::Time::GetMicroSeconds
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:388
ns3::DsssPpdu::DsssPpdu
DsssPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, uint64_t uid)
Create a DSSS (HR/DSSS) PPDU.
Definition: dsss-ppdu.cc:33
ns3::DsssPpdu::DsssSigHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const override
Definition: dsss-ppdu.cc:106
ns3::DsssPpdu::DsssSigHeader
DSSS SIG PHY header.
Definition: dsss-ppdu.h:54
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
ns3::DsssPpdu::DsssSigHeader::Print
void Print(std::ostream &os) const override
Definition: dsss-ppdu.cc:99
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
ns3::DsssPpdu::m_dsssSig
DsssSigHeader m_dsssSig
the DSSS SIG PHY header
Definition: dsss-ppdu.h:121
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::DsssPpdu::DsssSigHeader::GetRate
uint64_t GetRate(void) const
Return the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:141
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::DsssPpdu::DsssSigHeader::SetRate
void SetRate(uint64_t rate)
Fill the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:112
ns3::DsssPpdu::~DsssPpdu
virtual ~DsssPpdu()
Destructor for DsssPpdu.
Definition: dsss-ppdu.cc:42
ns3::DsssPpdu::DsssSigHeader::GetInstanceTypeId
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: dsss-ppdu.cc:93
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::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::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
ns3::DsssPpdu::DsssSigHeader::GetLength
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:172
dsss-ppdu.h
Declaration of ns3::DsssPpdu class.