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
22#include "wifi-psdu.h"
23
24#include "ns3/log.h"
25#include "ns3/packet.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("WifiPpdu");
31
33 const WifiTxVector& txVector,
34 uint16_t txCenterFreq,
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(txCenterFreq),
39 m_uid(uid),
40 m_txVector(txVector),
41#ifdef NS3_BUILD_PROFILE_DEBUG
42 m_phyHeaders(Create<Packet>()),
43#endif
44 m_truncatedTx(false),
45 m_txPowerLevel(txVector.GetTxPowerLevel())
46{
47 NS_LOG_FUNCTION(this << *psdu << txVector << txCenterFreq << uid);
48 m_psdus.insert(std::make_pair(SU_STA_ID, psdu));
49}
50
52 const WifiTxVector& txVector,
53 uint16_t txCenterFreq,
54 uint64_t uid)
55 : m_preamble(txVector.GetPreambleType()),
56 m_modulation(txVector.IsValid() ? txVector.GetMode(psdus.begin()->first).GetModulationClass()
58 m_txCenterFreq(txCenterFreq),
59 m_uid(uid),
60 m_txVector(txVector),
61#ifdef NS3_BUILD_PROFILE_DEBUG
62 m_phyHeaders(Create<Packet>()),
63#endif
64 m_truncatedTx(false),
65 m_txPowerLevel(txVector.GetTxPowerLevel()),
66 m_txAntennas(txVector.GetNTx())
67{
68 NS_LOG_FUNCTION(this << psdus << txVector << txCenterFreq << uid);
69 m_psdus = psdus;
70}
71
73{
74 for (auto& psdu : m_psdus)
75 {
76 psdu.second = nullptr;
77 }
78 m_psdus.clear();
79}
80
81const WifiTxVector&
83{
84 if (!m_txVector.has_value())
85 {
87 m_txVector->SetTxPowerLevel(m_txPowerLevel);
88 m_txVector->SetNTx(m_txAntennas);
89 }
90 return m_txVector.value();
91}
92
95{
96 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
97 "overloaded version in the amendment-specific PPDU subclasses instead!");
98 return WifiTxVector(); // should be overloaded
99}
100
101void
103{
104 NS_LOG_FUNCTION(this);
105 m_txVector.reset();
106}
107
108void
109WifiPpdu::UpdateTxVector(const WifiTxVector& updatedTxVector) const
110{
111 NS_LOG_FUNCTION(this << updatedTxVector);
113 m_txVector = updatedTxVector;
114}
115
118{
119 return m_psdus.begin()->second;
120}
121
122bool
124{
125 return m_truncatedTx;
126}
127
128void
130{
131 NS_LOG_FUNCTION(this);
132 m_truncatedTx = true;
133}
134
137{
138 return m_modulation;
139}
140
141uint16_t
143{
144 return GetTxVector().GetChannelWidth();
145}
146
147uint16_t
149{
150 return m_txCenterFreq;
151}
152
153bool
154WifiPpdu::DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
155{
156 NS_LOG_FUNCTION(this << m_txCenterFreq << minFreq << maxFreq);
157 uint16_t txChannelWidth = GetTxVector().GetChannelWidth();
158 uint16_t minTxFreq = m_txCenterFreq - txChannelWidth / 2;
159 uint16_t maxTxFreq = m_txCenterFreq + txChannelWidth / 2;
189 if (minTxFreq >= maxFreq || maxTxFreq <= minFreq)
190 {
191 return false;
192 }
193 return true;
194}
195
196uint64_t
198{
199 return m_uid;
200}
201
204{
205 return m_preamble;
206}
207
210{
211 return WIFI_PPDU_TYPE_SU;
212}
213
214uint16_t
216{
217 return SU_STA_ID;
218}
219
220Time
222{
223 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
224 "overloaded version in the amendment-specific PPDU subclasses instead!");
225 return MicroSeconds(0); // should be overloaded
226}
227
228void
229WifiPpdu::Print(std::ostream& os) const
230{
231 os << "[ preamble=" << m_preamble << ", modulation=" << m_modulation
232 << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N") << ", UID=" << m_uid << ", "
233 << PrintPayload() << "]";
234}
235
236std::string
238{
239 std::ostringstream ss;
240 ss << "PSDU=" << GetPsdu() << " ";
241 return ss.str();
242}
243
246{
247 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
248 "overloaded version in the amendment-specific PPDU subclasses instead!");
249 return Ptr<WifiPpdu>(new WifiPpdu(*this), false);
250}
251
252std::ostream&
253operator<<(std::ostream& os, const Ptr<const WifiPpdu>& ppdu)
254{
255 ppdu->Print(os);
256 return os;
257}
258
259std::ostream&
260operator<<(std::ostream& os, const WifiConstPsduMap& psdus)
261{
262 for (const auto& psdu : psdus)
263 {
264 os << "PSDU for STA_ID=" << psdu.first << " (" << *psdu.second << ") ";
265 }
266 return os;
267}
268
269} // namespace ns3
network packets
Definition: packet.h:240
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:229
virtual Time GetTxDuration() const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:221
bool IsTruncatedTx() const
Definition: wifi-ppdu.cc:123
WifiPreamble GetPreamble() const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:203
uint16_t GetTxCenterFreq() const
Definition: wifi-ppdu.cc:148
void ResetTxVector() const
Reset the TXVECTOR.
Definition: wifi-ppdu.cc:102
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:215
uint16_t m_txCenterFreq
the center frequency (MHz) used for the transmission of this PPDU
Definition: wifi-ppdu.h:204
void UpdateTxVector(const WifiTxVector &updatedTxVector) const
Update the TXVECTOR based on some information known at the receiver.
Definition: wifi-ppdu.cc:109
virtual WifiPpduType GetType() const
Return the PPDU type (.
Definition: wifi-ppdu.cc:209
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:207
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:202
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:201
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:72
Ptr< const WifiPsdu > GetPsdu() const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:117
virtual WifiTxVector DoGetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:94
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:205
void SetTruncatedTx()
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:129
WifiPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint16_t txCenterFreq, uint64_t uid=UINT64_MAX)
Create a PPDU storing a PSDU.
Definition: wifi-ppdu.cc:32
const WifiTxVector & GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:82
uint64_t GetUid() const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:197
WifiModulationClass GetModulation() const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:136
virtual uint16_t GetTransmissionChannelWidth() const
Get the channel width over which the PPDU will effectively be transmitted.
Definition: wifi-ppdu.cc:142
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:203
virtual std::string PrintPayload() const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:237
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:226
bool DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
Check whether the given PPDU overlaps a given channel.
Definition: wifi-ppdu.cc:154
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector)
Definition: wifi-ppdu.h:224
virtual Ptr< WifiPpdu > Copy() const
Copy this instance.
Definition: wifi-ppdu.cc:245
bool m_truncatedTx
flag indicating whether the frame's transmission was aborted due to transmitter switch off
Definition: wifi-ppdu.h:222
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetChannelWidth() const
#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 ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition: ptr.h:481
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
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:129
#define SU_STA_ID
Definition: wifi-mode.h:34
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.