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
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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)
virtual ~DsssPpdu()
Destructor for DsssPpdu.
Definition: dsss-ppdu.cc:42
void SetRate(uint64_t rate)
Fill the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:112
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
Declaration of ns3::DsssPpdu class.
def start()
Definition: core.py:1855
DsssSigHeader m_dsssSig
the DSSS SIG PHY header
Definition: dsss-ppdu.h:121
static TypeId GetTypeId(void)
Get the type ID.
Definition: dsss-ppdu.cc:82
Time GetTxDuration(void) const override
Get the total transmission duration of the PPDU.
Definition: dsss-ppdu.cc:57
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:182
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint64_t GetRate(void) const
Return the RATE field of L-SIG (in bit/s).
Definition: dsss-ppdu.cc:141
DsssPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, Time ppduDuration, uint64_t uid)
Create a DSSS (HR/DSSS) PPDU.
Definition: dsss-ppdu.cc:33
DSSS SIG PHY header.
Definition: dsss-ppdu.h:53
iterator in a Buffer instance
Definition: buffer.h:98
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...
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:179
uint32_t GetSerializedSize(void) const override
Definition: dsss-ppdu.cc:106
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:51
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:388
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
uint32_t Deserialize(Buffer::Iterator start) override
Definition: dsss-ppdu.cc:187
static WifiMode GetDsssRate(uint64_t rate)
Return a WifiMode for HR/DSSS corresponding to the provided rate.
Definition: dsss-phy.cc:261
void SetLength(uint16_t length)
Fill the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:166
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void Print(std::ostream &os) const override
Definition: dsss-ppdu.cc:99
#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
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Definition: dsss-ppdu.cc:93
uint16_t GetLength(void) const
Return the LENGTH field of L-SIG (in bytes).
Definition: dsss-ppdu.cc:172
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1604
WifiTxVector DoGetTxVector(void) const override
Get the TXVECTOR used to send the PPDU.
Definition: dsss-ppdu.cc:47
uint8_t ReadU8(void)
Definition: buffer.h:1021
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
Ptr< WifiPpdu > Copy(void) const override
Copy this instance.
Definition: dsss-ppdu.cc:66
Declaration of ns3::DsssPhy class.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
void Serialize(Buffer::Iterator start) const override
Definition: dsss-ppdu.cc:178