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 uint64_t
104 WifiPpdu::GetUid (void) const
105 {
106  return m_uid;
107 }
108 
111 {
112  return m_preamble;
113 }
114 
116 WifiPpdu::GetType (void) const
117 {
118  return WIFI_PPDU_TYPE_SU;
119 }
120 
121 uint16_t
122 WifiPpdu::GetStaId (void) const
123 {
124  return SU_STA_ID;
125 }
126 
127 Time
129 {
130  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!");
131  return MicroSeconds (0); //should be overloaded
132 }
133 
134 void
135 WifiPpdu::Print (std::ostream& os) const
136 {
137  os << "[ preamble=" << m_preamble
138  << ", modulation=" << m_modulation
139  << ", truncatedTx=" << (m_truncatedTx ? "Y" : "N")
140  << ", UID=" << m_uid
141  << ", " << PrintPayload ()
142  << "]";
143 }
144 
145 std::string
147 {
148  std::ostringstream ss;
149  ss << "PSDU=" << GetPsdu () << " ";
150  return ss.str ();
151 }
152 
154 WifiPpdu::Copy (void) const
155 {
156  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!");
157  return Create<WifiPpdu> (GetPsdu (), GetTxVector ());
158 }
159 
160 std::ostream & operator << (std::ostream &os, const Ptr<const WifiPpdu> &ppdu)
161 {
162  ppdu->Print (os);
163  return os;
164 }
165 
166 std::ostream & operator << (std::ostream &os, const WifiConstPsduMap &psdus)
167 {
168  for (auto const& psdu : psdus)
169  {
170  os << "PSDU for STA_ID=" << psdu.first
171  << " (" << *psdu.second << ") ";
172  }
173  return os;
174 }
175 
176 } //namespace ns3
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802...
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint64_t GetUid(void) const
Get the UID of the PPDU.
Definition: wifi-ppdu.cc:104
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:122
Ptr< const WifiPsdu > GetPsdu(void) const
Get the payload of the PPDU.
Definition: wifi-ppdu.cc:79
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition: wifi-ppdu.h:38
void SetTruncatedTx(void)
Indicate that the PPDU&#39;s transmission was aborted due to transmitter switch off.
Definition: wifi-ppdu.cc:91
WifiPpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, uint64_t uid=UINT64_MAX)
Create a PPDU storing a PSDU.
Definition: wifi-ppdu.cc:30
WifiTxVector GetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:63
uint64_t m_uid
the unique ID of this PPDU
Definition: wifi-ppdu.h:160
virtual WifiTxVector DoGetTxVector(void) const
Get the TXVECTOR used to send the PPDU.
Definition: wifi-ppdu.cc:72
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
WifiModulationClass GetModulation(void) const
Get the modulation used for the PPDU.
Definition: wifi-ppdu.cc:98
Modulation class unknown or unspecified.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
WifiPreamble GetPreamble(void) const
Get the preamble of the PPDU.
Definition: wifi-ppdu.cc:110
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
uint8_t m_txAntennas
the number of antennas used to transmit this PPDU
Definition: wifi-ppdu.h:174
virtual Time GetTxDuration(void) const
Get the total transmission duration of the PPDU.
Definition: wifi-ppdu.cc:128
void Print(std::ostream &os) const
Print the PPDU contents.
Definition: wifi-ppdu.cc:135
WifiPreamble m_preamble
the PHY preamble
Definition: wifi-ppdu.h:157
bool IsTruncatedTx(void) const
Definition: wifi-ppdu.cc:85
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~WifiPpdu()
Destructor for WifiPpdu.
Definition: wifi-ppdu.cc:53
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
uint8_t m_txPowerLevel
the transmission power level (used only for TX and initializing the returned WifiTxVector) ...
Definition: wifi-ppdu.h:173
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
bool m_truncatedTx
flag indicating whether the frame&#39;s transmission was aborted due to transmitter switch off ...
Definition: wifi-ppdu.h:172
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
Definition: wifi-ppdu.h:159
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
virtual Ptr< WifiPpdu > Copy(void) const
Copy this instance.
Definition: wifi-ppdu.cc:154
Definition: first.py:1
WifiModulationClass m_modulation
the modulation used for the transmission of this PPDU
Definition: wifi-ppdu.h:158
#define SU_STA_ID
Definition: wifi-mode.h:32
virtual WifiPpduType GetType(void) const
Return the PPDU type (.
Definition: wifi-ppdu.cc:116
virtual std::string PrintPayload(void) const
Print the payload of the PPDU.
Definition: wifi-ppdu.cc:146