A Discrete-Event Network Simulator
API
wifi-ppdu.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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  */
19 
20 #include "wifi-ppdu.h"
21 
23 #include "wifi-psdu.h"
24 
25 #include "ns3/log.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("WifiPpdu");
31 
33  const WifiTxVector& txVector,
35  uint64_t uid /* = UINT64_MAX */)
36  : m_preamble(txVector.GetPreambleType()),
37  m_modulation(txVector.IsValid() ? txVector.GetModulationClass() : WIFI_MOD_CLASS_UNKNOWN),
38  m_txCenterFreq(channel.IsSet()
39  ? channel.GetPrimaryChannelCenterFrequency(txVector.GetChannelWidth())
40  : 0),
41  m_uid(uid),
42  m_txVector(txVector),
43  m_operatingChannel(channel),
44  m_truncatedTx(false),
45  m_txPowerLevel(txVector.GetTxPowerLevel()),
46  m_txAntennas(txVector.GetNTx()),
47  m_txChannelWidth(txVector.GetChannelWidth())
48 {
49  NS_LOG_FUNCTION(this << *psdu << txVector << channel << uid);
50  m_psdus.insert(std::make_pair(SU_STA_ID, psdu));
51 }
52 
54  const WifiTxVector& txVector,
56  uint64_t uid)
57  : m_preamble(txVector.GetPreambleType()),
58  m_modulation(txVector.IsValid() ? txVector.GetMode(psdus.begin()->first).GetModulationClass()
60  m_txCenterFreq(channel.IsSet()
61  ? channel.GetPrimaryChannelCenterFrequency(txVector.GetChannelWidth())
62  : 0),
63  m_uid(uid),
64  m_txVector(txVector),
65  m_operatingChannel(channel),
66  m_truncatedTx(false),
67  m_txPowerLevel(txVector.GetTxPowerLevel()),
68  m_txAntennas(txVector.GetNTx()),
69  m_txChannelWidth(txVector.GetChannelWidth())
70 {
71  NS_LOG_FUNCTION(this << psdus << txVector << channel << uid);
72  m_psdus = psdus;
73 }
74 
76 {
77  for (auto& psdu : m_psdus)
78  {
79  psdu.second = nullptr;
80  }
81  m_psdus.clear();
82 }
83 
84 const WifiTxVector&
86 {
87  if (!m_txVector.has_value())
88  {
90  m_txVector->SetTxPowerLevel(m_txPowerLevel);
91  m_txVector->SetNTx(m_txAntennas);
92  m_txVector->SetChannelWidth(m_txChannelWidth);
93  }
94  return m_txVector.value();
95 }
96 
99 {
100  NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
101  "overloaded version in the amendment-specific PPDU subclasses instead!");
102  return WifiTxVector(); // should be overloaded
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION(this);
109  m_txVector.reset();
110 }
111 
112 void
113 WifiPpdu::UpdateTxVector(const WifiTxVector& updatedTxVector) const
114 {
115  NS_LOG_FUNCTION(this << updatedTxVector);
116  ResetTxVector();
117  m_txVector = updatedTxVector;
118 }
119 
122 {
123  return m_psdus.begin()->second;
124 }
125 
126 bool
128 {
129  return m_truncatedTx;
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION(this);
136  m_truncatedTx = true;
137 }
138 
141 {
142  return m_modulation;
143 }
144 
145 uint16_t
147 {
148  return m_txChannelWidth;
149 }
150 
151 uint16_t
153 {
154  return m_txCenterFreq;
155 }
156 
157 bool
158 WifiPpdu::DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
159 {
160  NS_LOG_FUNCTION(this << m_txCenterFreq << minFreq << maxFreq);
161  uint16_t minTxFreq = m_txCenterFreq - m_txChannelWidth / 2;
162  uint16_t maxTxFreq = m_txCenterFreq + m_txChannelWidth / 2;
192  return minTxFreq < maxFreq && maxTxFreq > minFreq;
193 }
194 
195 uint64_t
197 {
198  return m_uid;
199 }
200 
203 {
204  return m_preamble;
205 }
206 
209 {
210  return WIFI_PPDU_TYPE_SU;
211 }
212 
213 uint16_t
215 {
216  return SU_STA_ID;
217 }
218 
219 Time
221 {
222  NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
223  "overloaded version in the amendment-specific PPDU subclasses instead!");
224  return MicroSeconds(0); // should be overloaded
225 }
226 
227 void
228 WifiPpdu::Print(std::ostream& os) const
229 {
230  os << "[ preamble=" << m_preamble << ", modulation=" << m_modulation
231  << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N") << ", UID=" << m_uid << ", "
232  << PrintPayload() << "]";
233 }
234 
235 std::string
237 {
238  std::ostringstream ss;
239  ss << "PSDU=" << GetPsdu() << " ";
240  return ss.str();
241 }
242 
245 {
246  NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
247  "overloaded version in the amendment-specific PPDU subclasses instead!");
248  return Ptr<WifiPpdu>(new WifiPpdu(*this), false);
249 }
250 
251 std::ostream&
252 operator<<(std::ostream& os, const Ptr<const WifiPpdu>& ppdu)
253 {
254  ppdu->Print(os);
255  return os;
256 }
257 
258 std::ostream&
259 operator<<(std::ostream& os, const WifiConstPsduMap& psdus)
260 {
261  for (const auto& psdu : psdus)
262  {
263  os << "PSDU for STA_ID=" << psdu.first << " (" << *psdu.second << ") ";
264  }
265  return os;
266 }
267 
268 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Class that keeps track of all information about the current PHY operating channel.
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:228
virtual Time GetTxDuration() const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:220
bool IsTruncatedTx() const
Definition: wifi-ppdu.cc:127
WifiPreamble GetPreamble() const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:202
uint16_t GetTxCenterFreq() const
Definition: wifi-ppdu.cc:152
void ResetTxVector() const
Reset the TXVECTOR.
Definition: wifi-ppdu.cc:106
virtual uint16_t GetStaId() const
Get the ID of the STA that transmitted the PPDU for UL MU, SU_STA_ID otherwise.
Definition: wifi-ppdu.cc:214
uint16_t m_txChannelWidth
The channel width (MHz) used for the transmission of this PPDU.
Definition: wifi-ppdu.h:226
WifiPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, const WifiPhyOperatingChannel &channel, uint64_t uid=UINT64_MAX)
Create a PPDU storing a PSDU.
Definition: wifi-ppdu.cc:32
uint16_t m_txCenterFreq
the center frequency (MHz) used for the transmission of this PPDU
Definition: wifi-ppdu.h:205
void UpdateTxVector(const WifiTxVector &updatedTxVector) const
Update the TXVECTOR based on some information known at the receiver.
Definition: wifi-ppdu.cc:113
virtual WifiPpduType GetType() const
Return the PPDU type (.
Definition: wifi-ppdu.cc:208
std::optional< WifiTxVector > m_txVector
the TXVECTOR at TX PHY or the reconstructed TXVECTOR at RX PHY (or std::nullopt if TXVECTOR has not b...
Definition: wifi-ppdu.h:208
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:203
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:202
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:75
Ptr< const WifiPsdu > GetPsdu() const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:121
virtual WifiTxVector DoGetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:98
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:206
void SetTruncatedTx()
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:133
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:85
uint64_t GetUid() const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:196
WifiModulationClass GetModulation() const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:140
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:204
virtual std::string PrintPayload() const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:236
virtual uint16_t GetTxChannelWidth() const
Get the channel width over which the PPDU will effectively be transmitted.
Definition: wifi-ppdu.cc:146
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:224
bool DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
Check whether the given PPDU overlaps a given channel.
Definition: wifi-ppdu.cc:158
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector)
Definition: wifi-ppdu.h:222
virtual Ptr< WifiPpdu > Copy() const
Copy this instance.
Definition: wifi-ppdu.cc:244
bool m_truncatedTx
flag indicating whether the frame's transmission was aborted due to transmitter switch off
Definition: wifi-ppdu.h:220
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#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:1350
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
@ WIFI_PPDU_TYPE_SU
@ WIFI_MOD_CLASS_UNKNOWN
Modulation class unknown or unspecified.
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition: wifi-mode.h:35
channel
Definition: third.py:88
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.