A Discrete-Event Network Simulator
API
wifi-tx-timer.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #ifndef WIFI_TX_TIMER_H
22 #define WIFI_TX_TIMER_H
23 
24 #include "ns3/event-id.h"
25 #include "ns3/nstime.h"
26 #include "ns3/simulator.h"
27 #include "ns3/traced-callback.h"
28 #include <functional>
29 #include <unordered_map>
30 
31 namespace ns3 {
32 
33 class WifiMacQueueItem;
34 class WifiPsdu;
35 class WifiTxVector;
36 class Mac48Address;
37 
38 typedef std::unordered_map <uint16_t /* staId */, Ptr<WifiPsdu> /* PSDU */> WifiPsduMap;
39 
48 {
49 public:
54  enum Reason : uint8_t
55  {
65  };
66 
68  WifiTxTimer ();
69 
70  virtual ~WifiTxTimer ();
71 
86  template<typename MEM, typename OBJ, typename... Args>
87  void Set (Reason reason, const Time &delay, MEM mem_ptr, OBJ obj, Args... args);
88 
95  void Reschedule (const Time &delay);
96 
103  Reason GetReason (void) const;
104 
111  std::string GetReasonString (Reason reason) const;
112 
118  bool IsRunning (void) const;
119 
123  void Cancel (void);
124 
131  Time GetDelayLeft (void) const;
132 
137 
142 
147 
155 
163 
171 
172 private:
184  template<typename MEM, typename OBJ, typename... Args>
185  void Timeout (MEM mem_ptr, OBJ obj, Args... args);
186 
190  void Expire (void);
191 
199  void FeedTraceSource (Ptr<WifiMacQueueItem> item, WifiTxVector txVector);
200 
208  void FeedTraceSource (Ptr<WifiPsdu> psdu, WifiTxVector txVector);
209 
218  void FeedTraceSource (WifiPsduMap* psduMap, std::set<Mac48Address>* missingStations,
219  std::size_t nTotalStations);
220 
226 
233 };
234 
235 } // namespace ns3
236 
237 
238 /***************************************************************
239  * Implementation of the templates declared above.
240  ***************************************************************/
241 
242 namespace ns3 {
243 
244 template<typename MEM, typename OBJ, typename... Args>
245 void
246 WifiTxTimer::Set (Reason reason, const Time &delay, MEM mem_ptr, OBJ obj, Args... args)
247 {
248  typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
249 
251  m_reason = reason;
252  m_end = Simulator::Now () + delay;
253 
254  // create an event to invoke when the timer expires
255  m_impl = Ptr<EventImpl> (MakeEvent<TimeoutType> (&WifiTxTimer::Timeout, this, mem_ptr, obj,
256  std::forward<Args> (args)... ), false);
257 }
258 
259 template<typename MEM, typename OBJ, typename... Args>
260 void
261 WifiTxTimer::Timeout (MEM mem_ptr, OBJ obj, Args... args)
262 {
263  FeedTraceSource (std::forward<Args> (args)...);
264 
265  // Invoke the method set by the user
266  ((*obj).*mem_ptr)(std::forward<Args> (args)...);
267 }
268 
269 } //namespace ns3
270 
271 #endif /* WIFI_TX_TIMER_H */
272 
ns3::WifiTxTimer::GetReasonString
std::string GetReasonString(Reason reason) const
Get a string associated with the given reason.
Definition: wifi-tx-timer.cc:94
ns3::WifiPsduMap
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.
Definition: he-frame-exchange-manager.h:34
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::WifiTxTimer::PsduResponseTimeout
Callback< void, uint8_t, Ptr< const WifiPsdu >, const WifiTxVector & > PsduResponseTimeout
PSDU response timeout callback typedef.
Definition: wifi-tx-timer.h:141
ns3::WifiTxTimer::~WifiTxTimer
virtual ~WifiTxTimer()
Definition: wifi-tx-timer.cc:40
ns3::Callback
Callback template class.
Definition: callback.h:1279
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiTxTimer::GetDelayLeft
Time GetDelayLeft(void) const
Get the remaining time until the timer will expire.
Definition: wifi-tx-timer.cc:135
ns3::WifiTxTimer::m_psduResponseTimeoutCallback
PsduResponseTimeout m_psduResponseTimeoutCallback
the PSDU response timeout callback
Definition: wifi-tx-timer.h:230
ns3::WifiTxTimer::WAIT_TB_PPDU_AFTER_BASIC_TF
@ WAIT_TB_PPDU_AFTER_BASIC_TF
Definition: wifi-tx-timer.h:62
ns3::WifiTxTimer::SetPsduResponseTimeoutCallback
void SetPsduResponseTimeoutCallback(PsduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU expires.
Definition: wifi-tx-timer.cc:156
ns3::WifiTxTimer::IsRunning
bool IsRunning(void) const
Return true if the timer is running.
Definition: wifi-tx-timer.cc:121
ns3::WifiTxTimer::WAIT_QOS_NULL_AFTER_BSRP_TF
@ WAIT_QOS_NULL_AFTER_BSRP_TF
Definition: wifi-tx-timer.h:63
ns3::WifiTxTimer::MpduResponseTimeout
Callback< void, uint8_t, Ptr< const WifiMacQueueItem >, const WifiTxVector & > MpduResponseTimeout
MPDU response timeout callback typedef.
Definition: wifi-tx-timer.h:136
ns3::WifiTxTimer::FeedTraceSource
void FeedTraceSource(Ptr< WifiMacQueueItem > item, WifiTxVector txVector)
This method is called when the timer expires to feed the MPDU response timeout callback.
Definition: wifi-tx-timer.cc:147
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::WifiTxTimer::m_mpduResponseTimeoutCallback
MpduResponseTimeout m_mpduResponseTimeoutCallback
the MPDU response timeout callback
Definition: wifi-tx-timer.h:228
ns3::WifiTxTimer::SetPsduMapResponseTimeoutCallback
void SetPsduMapResponseTimeoutCallback(PsduMapResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU map expires.
Definition: wifi-tx-timer.cc:171
ns3::WifiTxTimer::SetMpduResponseTimeoutCallback
void SetMpduResponseTimeoutCallback(MpduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
Definition: wifi-tx-timer.cc:141
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::WifiTxTimer::WAIT_BLOCK_ACK_AFTER_TB_PPDU
@ WAIT_BLOCK_ACK_AFTER_TB_PPDU
Definition: wifi-tx-timer.h:64
ns3::WifiTxTimer::PsduMapResponseTimeout
Callback< void, uint8_t, WifiPsduMap *, const std::set< Mac48Address > *, std::size_t > PsduMapResponseTimeout
PSDU map response timeout callback typedef.
Definition: wifi-tx-timer.h:146
ns3::Ptr< WifiMacQueueItem >
ns3::WifiTxTimer::Reschedule
void Reschedule(const Time &delay)
Reschedule the timer to time out the given amount of time from the moment this function is called.
Definition: wifi-tx-timer.cc:47
ns3::WifiTxTimer::WAIT_NORMAL_ACK_AFTER_DL_MU_PPDU
@ WAIT_NORMAL_ACK_AFTER_DL_MU_PPDU
Definition: wifi-tx-timer.h:60
ns3::WifiTxTimer::WAIT_NORMAL_ACK
@ WAIT_NORMAL_ACK
Definition: wifi-tx-timer.h:58
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiTxTimer::WAIT_BLOCK_ACK
@ WAIT_BLOCK_ACK
Definition: wifi-tx-timer.h:59
ns3::WifiTxTimer::Expire
void Expire(void)
Internal callback invoked when the timer expires.
Definition: wifi-tx-timer.cc:71
ns3::WifiTxTimer::Reason
Reason
The reason why the timer was started.
Definition: wifi-tx-timer.h:55
ns3::WifiTxTimer::m_timeoutEvent
EventId m_timeoutEvent
the timeout event after a missing response
Definition: wifi-tx-timer.h:221
ns3::WifiTxTimer::WifiTxTimer
WifiTxTimer()
Default constructor.
Definition: wifi-tx-timer.cc:32
ns3::WifiTxTimer::Timeout
void Timeout(MEM mem_ptr, OBJ obj, Args... args)
This method is called when the timer expires.
Definition: wifi-tx-timer.h:261
ns3::WifiTxTimer::WAIT_CTS
@ WAIT_CTS
Definition: wifi-tx-timer.h:57
ns3::WifiTxTimer::m_psduMapResponseTimeoutCallback
PsduMapResponseTimeout m_psduMapResponseTimeoutCallback
the PSDU map response timeout callback
Definition: wifi-tx-timer.h:232
ns3::WifiTxTimer::GetReason
Reason GetReason(void) const
Get the reason why the timer was started.
Definition: wifi-tx-timer.cc:87
ns3::WifiTxTimer::WAIT_BLOCK_ACKS_IN_TB_PPDU
@ WAIT_BLOCK_ACKS_IN_TB_PPDU
Definition: wifi-tx-timer.h:61
ns3::WifiTxTimer::m_reason
Reason m_reason
the reason why the timer was started
Definition: wifi-tx-timer.h:222
ns3::WifiTxTimer::NOT_RUNNING
@ NOT_RUNNING
Definition: wifi-tx-timer.h:56
ns3::WifiTxTimer::m_end
Time m_end
the absolute time when the timer will expire
Definition: wifi-tx-timer.h:225
ns3::WifiTxTimer::Set
void Set(Reason reason, const Time &delay, MEM mem_ptr, OBJ obj, Args... args)
This method is called when a frame soliciting a response is transmitted.
Definition: wifi-tx-timer.h:246
ns3::WifiTxTimer::Cancel
void Cancel(void)
Cancel the timer.
Definition: wifi-tx-timer.cc:127
ns3::WifiTxTimer
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
Definition: wifi-tx-timer.h:48
ns3::WifiTxTimer::m_impl
Ptr< EventImpl > m_impl
the timer implementation, which contains the bound callback function and arguments
Definition: wifi-tx-timer.h:223