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_truncatedTx(false),
41 m_txPowerLevel(txVector.GetTxPowerLevel())
42{
43 NS_LOG_FUNCTION(this << *psdu << txVector << txCenterFreq << uid);
44 m_psdus.insert(std::make_pair(SU_STA_ID, psdu));
45}
46
48 const WifiTxVector& txVector,
49 uint16_t txCenterFreq,
50 uint64_t uid)
51 : m_preamble(txVector.GetPreambleType()),
52 m_modulation(txVector.IsValid() ? txVector.GetMode(psdus.begin()->first).GetModulationClass()
54 m_txCenterFreq(txCenterFreq),
55 m_uid(uid),
56 m_truncatedTx(false),
57 m_txPowerLevel(txVector.GetTxPowerLevel()),
58 m_txAntennas(txVector.GetNTx())
59{
60 NS_LOG_FUNCTION(this << psdus << txVector << txCenterFreq << uid);
61 m_psdus = psdus;
62}
63
65{
66 for (auto& psdu : m_psdus)
67 {
68 psdu.second = nullptr;
69 }
70 m_psdus.clear();
71}
72
75{
76 WifiTxVector txVector = DoGetTxVector();
78 txVector.SetNTx(m_txAntennas);
79 return txVector;
80}
81
84{
85 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
86 "overloaded version in the amendment-specific PPDU subclasses instead!");
87 return WifiTxVector(); // should be overloaded
88}
89
92{
93 return m_psdus.begin()->second;
94}
95
96bool
98{
99 return m_truncatedTx;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this);
106 m_truncatedTx = true;
107}
108
111{
112 return m_modulation;
113}
114
115uint16_t
117{
118 return GetTxVector().GetChannelWidth();
119}
120
121bool
122WifiPpdu::DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
123{
124 NS_LOG_FUNCTION(this << m_txCenterFreq << minFreq << maxFreq);
125 uint16_t txChannelWidth = GetTxVector().GetChannelWidth();
126 uint16_t minTxFreq = m_txCenterFreq - txChannelWidth / 2;
127 uint16_t maxTxFreq = m_txCenterFreq + txChannelWidth / 2;
157 if (minTxFreq >= maxFreq || maxTxFreq <= minFreq)
158 {
159 return false;
160 }
161 return true;
162}
163
164bool
165WifiPpdu::CanBeReceived(uint16_t p20MinFreq, uint16_t p20MaxFreq) const
166{
167 NS_LOG_FUNCTION(this << p20MinFreq << p20MaxFreq);
168 const bool overlap = DoesOverlapChannel(p20MinFreq, p20MaxFreq);
169 if (!overlap)
170 {
171 NS_LOG_INFO("Received PPDU does not overlap with the primary20 channel");
172 return false;
173 }
174 return true;
175}
176
177uint64_t
179{
180 return m_uid;
181}
182
185{
186 return m_preamble;
187}
188
191{
192 return WIFI_PPDU_TYPE_SU;
193}
194
195uint16_t
197{
198 return SU_STA_ID;
199}
200
201Time
203{
204 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
205 "overloaded version in the amendment-specific PPDU subclasses instead!");
206 return MicroSeconds(0); // should be overloaded
207}
208
209void
210WifiPpdu::Print(std::ostream& os) const
211{
212 os << "[ preamble=" << m_preamble << ", modulation=" << m_modulation
213 << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N") << ", UID=" << m_uid << ", "
214 << PrintPayload() << "]";
215}
216
217std::string
219{
220 std::ostringstream ss;
221 ss << "PSDU=" << GetPsdu() << " ";
222 return ss.str();
223}
224
227{
228 NS_FATAL_ERROR("This method should not be called for the base WifiPpdu class. Use the "
229 "overloaded version in the amendment-specific PPDU subclasses instead!");
230 return Create<WifiPpdu>(GetPsdu(), GetTxVector(), m_txCenterFreq);
231}
232
233std::ostream&
234operator<<(std::ostream& os, const Ptr<const WifiPpdu>& ppdu)
235{
236 ppdu->Print(os);
237 return os;
238}
239
240std::ostream&
241operator<<(std::ostream& os, const WifiConstPsduMap& psdus)
242{
243 for (const auto& psdu : psdus)
244 {
245 os << "PSDU for STA_ID=" << psdu.first << " (" << *psdu.second << ") ";
246 }
247 return os;
248}
249
250} // namespace ns3
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:210
virtual Time GetTxDuration() const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:202
bool IsTruncatedTx() const
Definition: wifi-ppdu.cc:97
WifiPreamble GetPreamble() const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:184
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:196
virtual bool CanBeReceived(uint16_t p20MinFreq, uint16_t p20MaxFreq) const
Check whether the given PPDU can be received on the specified primary channel.
Definition: wifi-ppdu.cc:165
uint16_t m_txCenterFreq
the center frequency (MHz) used for the transmission of this PPDU
Definition: wifi-ppdu.h:196
virtual WifiPpduType GetType() const
Return the PPDU type (.
Definition: wifi-ppdu.cc:190
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:194
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:193
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:64
Ptr< const WifiPsdu > GetPsdu() const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:91
virtual WifiTxVector DoGetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:83
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:197
void SetTruncatedTx()
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:103
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
uint64_t GetUid() const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:178
WifiModulationClass GetModulation() const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:110
virtual uint16_t GetTransmissionChannelWidth() const
Get the channel width over which the PPDU will effectively be transmitted.
Definition: wifi-ppdu.cc:116
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:195
WifiTxVector GetTxVector() const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:74
virtual std::string PrintPayload() const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:218
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:211
bool DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
Check whether the given PPDU overlaps a given channel.
Definition: wifi-ppdu.cc:122
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector)
Definition: wifi-ppdu.h:209
virtual Ptr< WifiPpdu > Copy() const
Copy this instance.
Definition: wifi-ppdu.cc:226
bool m_truncatedTx
flag indicating whether the frame's transmission was aborted due to transmitter switch off
Definition: wifi-ppdu.h:207
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
uint16_t GetChannelWidth() const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
#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 ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1362
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.