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 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("WifiPpdu");
29 
30 WifiPpdu::WifiPpdu (Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector, uint64_t uid /* = UINT64_MAX */)
31  : m_preamble (txVector.GetPreambleType ()),
32  m_modulation (txVector.IsValid () ? txVector.GetModulationClass () : WIFI_MOD_CLASS_UNKNOWN),
33  m_uid (uid),
34  m_truncatedTx (false),
35  m_txPowerLevel (txVector.GetTxPowerLevel ())
36 {
37  NS_LOG_FUNCTION (this << *psdu << txVector << uid);
38  m_psdus.insert (std::make_pair (SU_STA_ID, psdu));
39 }
40 
41 WifiPpdu::WifiPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, uint64_t uid)
42  : m_preamble (txVector.GetPreambleType ()),
43  m_modulation (txVector.IsValid () ? txVector.GetMode (psdus.begin()->first).GetModulationClass () : WIFI_MOD_CLASS_UNKNOWN),
44  m_uid (uid),
45  m_truncatedTx (false),
46  m_txPowerLevel (txVector.GetTxPowerLevel ()),
47  m_txAntennas (txVector.GetNTx ())
48 {
49  NS_LOG_FUNCTION (this << psdus << txVector << uid);
50  m_psdus = psdus;
51 }
52 
54 {
55  for (auto & psdu : m_psdus)
56  {
57  psdu.second = 0;
58  }
59  m_psdus.clear ();
60 }
61 
64 {
65  WifiTxVector txVector = DoGetTxVector ();
67  txVector.SetNTx (m_txAntennas);
68  return txVector;
69 }
70 
73 {
74  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!");
75  return WifiTxVector (); //should be overloaded
76 }
77 
79 WifiPpdu::GetPsdu (void) const
80 {
81  return m_psdus.begin ()->second;
82 }
83 
84 bool
86 {
87  return m_truncatedTx;
88 }
89 
90 void
92 {
93  NS_LOG_FUNCTION (this);
94  m_truncatedTx = true;
95 }
96 
99 {
100  return m_modulation;
101 }
102 
103 uint16_t
105 {
106  return GetTxVector ().GetChannelWidth ();
107 }
108 
109 bool
110 WifiPpdu::CanBeReceived (uint16_t txCenterFreq, uint16_t p20MinFreq,
111  uint16_t p20MaxFreq) const
112 {
113  NS_LOG_FUNCTION (this << txCenterFreq << p20MinFreq << p20MaxFreq);
114 
115  uint16_t txChannelWidth = GetTxVector ().GetChannelWidth ();
116  uint16_t minTxFreq = txCenterFreq - txChannelWidth / 2;
117  uint16_t maxTxFreq = txCenterFreq + txChannelWidth / 2;
118 
119  if (minTxFreq > p20MinFreq || maxTxFreq < p20MaxFreq)
120  {
121  NS_LOG_INFO ("Received PPDU does not overlap with the primary20 channel");
122  return false;
123  }
124  return true;
125 }
126 
127 
128 uint64_t
129 WifiPpdu::GetUid (void) const
130 {
131  return m_uid;
132 }
133 
136 {
137  return m_preamble;
138 }
139 
141 WifiPpdu::GetType (void) const
142 {
143  return WIFI_PPDU_TYPE_SU;
144 }
145 
146 uint16_t
147 WifiPpdu::GetStaId (void) const
148 {
149  return SU_STA_ID;
150 }
151 
152 Time
154 {
155  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!");
156  return MicroSeconds (0); //should be overloaded
157 }
158 
159 void
160 WifiPpdu::Print (std::ostream& os) const
161 {
162  os << "[ preamble=" << m_preamble
163  << ", modulation=" << m_modulation
164  << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N")
165  << ", UID=" << m_uid
166  << ", " << PrintPayload ()
167  << "]";
168 }
169 
170 std::string
172 {
173  std::ostringstream ss;
174  ss << "PSDU=" << GetPsdu () << " ";
175  return ss.str ();
176 }
177 
179 WifiPpdu::Copy (void) const
180 {
181  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!");
182  return Create<WifiPpdu> (GetPsdu (), GetTxVector ());
183 }
184 
185 std::ostream & operator << (std::ostream &os, const Ptr<const WifiPpdu> &ppdu)
186 {
187  ppdu->Print (os);
188  return os;
189 }
190 
191 std::ostream & operator << (std::ostream &os, const WifiConstPsduMap &psdus)
192 {
193  for (auto const& psdu : psdus)
194  {
195  os << "PSDU for STA_ID=" << psdu.first
196  << " (" << *psdu.second << ") ";
197  }
198  return os;
199 }
200 
201 } //namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::WifiTxVector::SetTxPowerLevel
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
Definition: wifi-tx-vector.cc:241
first
Definition: first.py:1
ns3::WifiPpdu::SetTruncatedTx
void SetTruncatedTx(void)
Indicate that the PPDU's transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:91
ns3::WifiPpdu::GetTxDuration
virtual Time GetTxDuration(void) const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:153
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiPpdu::GetTxVector
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
ns3::WifiPpdu::CanBeReceived
virtual bool CanBeReceived(uint16_t txCenterFreq, uint16_t p20MinFreq, uint16_t p20MaxFreq) const
Check whether the given PPDU can be received on the specified primary channel.
Definition: wifi-ppdu.cc:110
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ns3::WifiPpdu::m_modulation
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:180
ns3::WifiPpdu::GetUid
uint64_t GetUid(void) const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:129
ns3::WifiPpdu::DoGetTxVector
virtual WifiTxVector DoGetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:72
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::WifiPpdu::IsTruncatedTx
bool IsTruncatedTx(void) const
Definition: wifi-ppdu.cc:85
ns3::WifiConstPsduMap
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition: he-frame-exchange-manager.h:43
ns3::WIFI_MOD_CLASS_UNKNOWN
@ WIFI_MOD_CLASS_UNKNOWN
Modulation class unknown or unspecified.
Definition: wifi-phy-common.h:120
ns3::WifiPpdu::GetModulation
WifiModulationClass GetModulation(void) const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:98
wifi-psdu.h
ns3::Ptr< const WifiPsdu >
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::WifiPpdu::m_txPowerLevel
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector)
Definition: wifi-ppdu.h:193
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
wifi-ppdu.h
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.
SU_STA_ID
#define SU_STA_ID
Definition: wifi-mode.h:32
ns3::WifiPpdu::WifiPpdu
WifiPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint64_t uid=UINT64_MAX)
Create a PPDU storing a PSDU.
Definition: wifi-ppdu.cc:30
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiTxVector::GetChannelWidth
uint16_t GetChannelWidth(void) const
Definition: wifi-tx-vector.cc:153
ns3::WifiPpdu::Copy
virtual Ptr< WifiPpdu > Copy(void) const
Copy this instance.
Definition: wifi-ppdu.cc:179
ns3::WifiPpdu::Print
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:160
ns3::WifiPreamble
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-phy-common.h:63
ns3::WifiPpdu::~WifiPpdu
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:53
ns3::WifiPpduType
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
Definition: wifi-phy-common.h:224
ns3::WifiPpdu::m_txAntennas
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:194
ns3::WifiPpdu::m_truncatedTx
bool m_truncatedTx
flag indicating whether the frame's transmission was aborted due to transmitter switch off
Definition: wifi-ppdu.h:192
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WifiTxVector::SetNTx
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
Definition: wifi-tx-vector.cc:265
ns3::WifiPpdu::PrintPayload
virtual std::string PrintPayload(void) const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:171
ns3::WifiPpdu::GetPreamble
WifiPreamble GetPreamble(void) const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:135
ns3::WifiPpdu::m_uid
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:182
ns3::WifiPpdu::GetTransmissionChannelWidth
virtual uint16_t GetTransmissionChannelWidth(void) const
Get the channel width over which the PPDU will effectively be transmitted.
Definition: wifi-ppdu.cc:104
ns3::WifiPpdu::GetStaId
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:147
ns3::WifiPpdu::GetType
virtual WifiPpduType GetType(void) const
Return the PPDU type (.
Definition: wifi-ppdu.cc:141
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::WifiPpdu::GetPsdu
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
ns3::WifiPpdu::m_preamble
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:179
ns3::WifiPpdu::m_psdus
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:181
ns3::WIFI_PPDU_TYPE_SU
@ WIFI_PPDU_TYPE_SU
Definition: wifi-phy-common.h:225
ns3::WifiModulationClass
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
Definition: wifi-phy-common.h:117