A Discrete-Event Network Simulator
API
wifi-ppdu.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2019 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 */
20
21#include "wifi-ppdu.h"
22#include "wifi-psdu.h"
23#include "ns3/log.h"
24#include "ns3/packet.h"
25
26namespace ns3 {
27
28NS_LOG_COMPONENT_DEFINE ("WifiPpdu");
29
30WifiPpdu::WifiPpdu (Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector, uint16_t txCenterFreq, uint64_t uid /* = UINT64_MAX */)
31 : m_preamble (txVector.GetPreambleType ()),
32 m_modulation (txVector.IsValid () ? txVector.GetModulationClass () : WIFI_MOD_CLASS_UNKNOWN),
33 m_txCenterFreq (txCenterFreq),
34 m_uid (uid),
35 m_truncatedTx (false),
36 m_txPowerLevel (txVector.GetTxPowerLevel ())
37{
38 NS_LOG_FUNCTION (this << *psdu << txVector << txCenterFreq << uid);
39 m_psdus.insert (std::make_pair (SU_STA_ID, psdu));
40}
41
42WifiPpdu::WifiPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, uint16_t txCenterFreq, uint64_t uid)
43 : m_preamble (txVector.GetPreambleType ()),
44 m_modulation (txVector.IsValid () ? txVector.GetMode (psdus.begin()->first).GetModulationClass () : WIFI_MOD_CLASS_UNKNOWN),
45 m_txCenterFreq (txCenterFreq),
46 m_uid (uid),
47 m_truncatedTx (false),
48 m_txPowerLevel (txVector.GetTxPowerLevel ()),
49 m_txAntennas (txVector.GetNTx ())
50{
51 NS_LOG_FUNCTION (this << psdus << txVector << txCenterFreq << uid);
52 m_psdus = psdus;
53}
54
56{
57 for (auto & psdu : m_psdus)
58 {
59 psdu.second = 0;
60 }
61 m_psdus.clear ();
62}
63
66{
67 WifiTxVector txVector = DoGetTxVector ();
69 txVector.SetNTx (m_txAntennas);
70 return txVector;
71}
72
75{
76 NS_FATAL_ERROR ("This method should not be called for the base WifiPpdu class. Use the overloaded version in the amendment-specific PPDU subclasses instead!");
77 return WifiTxVector (); //should be overloaded
78}
79
82{
83 return m_psdus.begin ()->second;
84}
85
86bool
88{
89 return m_truncatedTx;
90}
91
92void
94{
95 NS_LOG_FUNCTION (this);
96 m_truncatedTx = true;
97}
98
101{
102 return m_modulation;
103}
104
105uint16_t
107{
108 return GetTxVector ().GetChannelWidth ();
109}
110
111bool
112WifiPpdu::DoesOverlapChannel (uint16_t minFreq, uint16_t maxFreq) const
113{
114 NS_LOG_FUNCTION (this << m_txCenterFreq << minFreq << maxFreq);
115 uint16_t txChannelWidth = GetTxVector ().GetChannelWidth ();
116 uint16_t minTxFreq = m_txCenterFreq - txChannelWidth / 2;
117 uint16_t maxTxFreq = m_txCenterFreq + txChannelWidth / 2;
147 if (minTxFreq >= maxFreq || maxTxFreq <= minFreq)
148 {
149 return false;
150 }
151 return true;
152}
153
154bool
155WifiPpdu::CanBeReceived (uint16_t p20MinFreq, uint16_t p20MaxFreq) const
156{
157 NS_LOG_FUNCTION (this << p20MinFreq << p20MaxFreq);
158 const bool overlap = DoesOverlapChannel (p20MinFreq, p20MaxFreq);
159 if (!overlap)
160 {
161 NS_LOG_INFO ("Received PPDU does not overlap with the primary20 channel");
162 return false;
163 }
164 return true;
165}
166
167uint64_t
169{
170 return m_uid;
171}
172
175{
176 return m_preamble;
177}
178
181{
182 return WIFI_PPDU_TYPE_SU;
183}
184
185uint16_t
187{
188 return SU_STA_ID;
189}
190
191Time
193{
194 NS_FATAL_ERROR ("This method should not be called for the base WifiPpdu class. Use the overloaded version in the amendment-specific PPDU subclasses instead!");
195 return MicroSeconds (0); //should be overloaded
196}
197
198void
199WifiPpdu::Print (std::ostream& os) const
200{
201 os << "[ preamble=" << m_preamble
202 << ", modulation=" << m_modulation
203 << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N")
204 << ", UID=" << m_uid
205 << ", " << PrintPayload ()
206 << "]";
207}
208
209std::string
211{
212 std::ostringstream ss;
213 ss << "PSDU=" << GetPsdu () << " ";
214 return ss.str ();
215}
216
218WifiPpdu::Copy (void) const
219{
220 NS_FATAL_ERROR ("This method should not be called for the base WifiPpdu class. Use the overloaded version in the amendment-specific PPDU subclasses instead!");
221 return Create<WifiPpdu> (GetPsdu (), GetTxVector (), m_txCenterFreq);
222}
223
224std::ostream & operator << (std::ostream &os, const Ptr<const WifiPpdu> &ppdu)
225{
226 ppdu->Print (os);
227 return os;
228}
229
230std::ostream & operator << (std::ostream &os, const WifiConstPsduMap &psdus)
231{
232 for (auto const& psdu : psdus)
233 {
234 os << "PSDU for STA_ID=" << psdu.first
235 << " (" << *psdu.second << ") ";
236 }
237 return os;
238}
239
240} //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:199
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:155
WifiModulationClass GetModulation(void) const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:100
virtual WifiPpduType GetType(void) const
Return the PPDU type (.
Definition: wifi-ppdu.cc:180
uint16_t m_txCenterFreq
the center frequency (MHz) used for the transmission of this PPDU
Definition: wifi-ppdu.h:188
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:65
virtual WifiTxVector DoGetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:74
WifiPreamble GetPreamble(void) const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:174
virtual Ptr< WifiPpdu > Copy(void) const
Copy this instance.
Definition: wifi-ppdu.cc:218
virtual Time GetTxDuration(void) const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:192
virtual std::string PrintPayload(void) const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:210
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:186
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:185
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:55
virtual uint16_t GetStaId(void) const
Get the ID of the STA that transmitted the PPDU for UL MU, SU_STA_ID otherwise.
Definition: wifi-ppdu.cc:186
uint64_t GetUid(void) const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:168
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:189
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:30
bool IsTruncatedTx(void) const
Definition: wifi-ppdu.cc:87
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:187
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:201
bool DoesOverlapChannel(uint16_t minFreq, uint16_t maxFreq) const
Check whether the given PPDU overlaps a given channel.
Definition: wifi-ppdu.cc:112
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector)
Definition: wifi-ppdu.h:200
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:81
bool m_truncatedTx
flag indicating whether the frame's transmission was aborted due to transmitter switch off
Definition: wifi-ppdu.h:199
virtual uint16_t GetTransmissionChannelWidth(void) const
Get the channel width over which the PPDU will effectively be transmitted.
Definition: wifi-ppdu.cc:106
void SetTruncatedTx(void)
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:93
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(void) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#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:282
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1261
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:139
#define SU_STA_ID
Definition: wifi-mode.h:32
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.