A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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/wifi-phy-operating-channel.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("WifiPpdu");
31
33 const WifiTxVector& txVector,
34 const WifiPhyOperatingChannel& channel,
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{
47 NS_LOG_FUNCTION(this << *psdu << txVector << channel << uid);
48 m_psdus.insert(std::make_pair(SU_STA_ID, psdu));
49}
50
52 const WifiTxVector& txVector,
53 const WifiPhyOperatingChannel& channel,
54 uint64_t uid)
55 : m_preamble(txVector.GetPreambleType()),
56 m_modulation(txVector.IsValid() ? txVector.GetMode(psdus.begin()->first).GetModulationClass()
58 m_txCenterFreq(channel.IsSet()
59 ? channel.GetPrimaryChannelCenterFrequency(txVector.GetChannelWidth())
60 : 0),
61 m_uid(uid),
62 m_txVector(txVector),
63 m_operatingChannel(channel),
64 m_truncatedTx(false),
65 m_txPowerLevel(txVector.GetTxPowerLevel()),
66 m_txAntennas(txVector.GetNTx())
67{
68 NS_LOG_FUNCTION(this << psdus << txVector << channel << 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 return minTxFreq < maxFreq && maxTxFreq > minFreq;
190}
191
192uint64_t
194{
195 return m_uid;
196}
197
200{
201 return m_preamble;
202}
203
206{
207 return WIFI_PPDU_TYPE_SU;
208}
209
210uint16_t
212{
213 return SU_STA_ID;
214}
215
216Time
218{
219 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
220 "overloaded version in the amendment-specific PPDU subclasses instead!");
221 return MicroSeconds(0); // should be overloaded
222}
223
224void
225WifiPpdu::Print(std::ostream& os) const
226{
227 os << "[ preamble=" << m_preamble << ", modulation=" << m_modulation
228 << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N") << ", UID=" << m_uid << ", "
229 << PrintPayload() << "]";
230}
231
232std::string
234{
235 std::ostringstream ss;
236 ss << "PSDU=" << GetPsdu() << " ";
237 return ss.str();
238}
239
242{
243 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
244 "overloaded version in the amendment-specific PPDU subclasses instead!");
245 return Ptr<WifiPpdu>(new WifiPpdu(*this), false);
246}
247
248std::ostream&
249operator<<(std::ostream& os, const Ptr<const WifiPpdu>& ppdu)
250{
251 ppdu->Print(os);
252 return os;
253}
254
255std::ostream&
256operator<<(std::ostream& os, const WifiConstPsduMap& psdus)
257{
258 for (const auto& psdu : psdus)
259 {
260 os << "PSDU for STA_ID=" << psdu.first << " (" << *psdu.second << ") ";
261 }
262 return os;
263}
264
265} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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.
WifiPpdu stores a preamble, a modulation class, PHY headers and a PSDU.
Definition: wifi-ppdu.h:57
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:225
virtual Time GetTxDuration() const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:217
bool IsTruncatedTx() const
Definition: wifi-ppdu.cc:123
WifiPreamble GetPreamble() const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:199
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:211
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:109
virtual WifiPpduType GetType() const
Return the PPDU type (.
Definition: wifi-ppdu.cc:205
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: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:206
void SetTruncatedTx()
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:129
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:193
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:204
virtual std::string PrintPayload() const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:233
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:154
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:241
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...
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 ",...
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
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition: wifi-mode.h:35
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.