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  {
62  };
63 
65  WifiTxTimer ();
66 
67  virtual ~WifiTxTimer ();
68 
83  template<typename MEM, typename OBJ, typename... Args>
84  void Set (Reason reason, const Time &delay, MEM mem_ptr, OBJ obj, Args... args);
85 
93  void Reschedule (const Time &delay);
94 
101  Reason GetReason (void) const;
102 
109  std::string GetReasonString (Reason reason) const;
110 
116  bool IsRunning (void) const;
117 
121  void Cancel (void);
122 
129  Time GetDelayLeft (void) const;
130 
135 
140 
145 
153 
161 
169 
170 private:
182  template<typename MEM, typename OBJ, typename... Args>
183  void Timeout (MEM mem_ptr, OBJ obj, Args... args);
184 
193  template<typename... Args>
194  void FeedTraceSource (Args... args);
195 
200 
207 };
208 
209 } // namespace ns3
210 
211 
212 /***************************************************************
213  * Declaration of member function template specialization.
214  ***************************************************************/
215 
216 namespace ns3 {
217 
225 template<>
226 void WifiTxTimer::FeedTraceSource<Ptr<WifiMacQueueItem>, WifiTxVector> (Ptr<WifiMacQueueItem> item,
227  WifiTxVector txVector);
228 
236 template<>
237 void WifiTxTimer::FeedTraceSource<Ptr<WifiPsdu>, WifiTxVector> (Ptr<WifiPsdu> psdu,
238  WifiTxVector txVector);
239 
248 template<>
249 void WifiTxTimer::FeedTraceSource<WifiPsduMap*, std::set<Mac48Address>*, std::size_t> (WifiPsduMap* psduMap,
250  std::set<Mac48Address>* missingStations,
251  std::size_t nTotalStations);
252 
253 } // namespace ns3
254 
255 
256 /***************************************************************
257  * Implementation of the templates declared above.
258  ***************************************************************/
259 
260 namespace ns3 {
261 
262 template<typename MEM, typename OBJ, typename... Args>
263 void
264 WifiTxTimer::Set (Reason reason, const Time &delay, MEM mem_ptr, OBJ obj, Args... args)
265 {
266  typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
267 
268  m_timeoutEvent = Simulator::Schedule<TimeoutType> (delay, &WifiTxTimer::Timeout, this, mem_ptr, obj, args...);
269  m_reason = reason;
270  m_rescheduled = false;
271 
272  // create an event to schedule if the PHY notifies the reception of a response
273  m_endRxEvent = Ptr<EventImpl> (MakeEvent<TimeoutType> (&WifiTxTimer::Timeout, this, mem_ptr, obj,
274  std::forward<Args> (args)... ), false);
275 }
276 
277 template<typename MEM, typename OBJ, typename... Args>
278 void
279 WifiTxTimer::Timeout (MEM mem_ptr, OBJ obj, Args... args)
280 {
281  FeedTraceSource (std::forward<Args> (args)...);
282 
283  // Invoke the method set by the user
284  ((*obj).*mem_ptr)(std::forward<Args> (args)...);
285 }
286 
287 template<typename... Args>
288 void
290 {
291 }
292 
293 } //namespace ns3
294 
295 #endif /* WIFI_TX_TIMER_H */
296 
std::string GetReasonString(Reason reason) const
Get a string associated with the given reason.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1278
Callback< void, uint8_t, Ptr< const WifiMacQueueItem >, const WifiTxVector & > MpduResponseTimeout
MPDU response timeout callback typedef.
Callback< void, uint8_t, Ptr< const WifiPsdu >, const WifiTxVector & > PsduResponseTimeout
PSDU response timeout callback typedef.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
virtual ~WifiTxTimer()
Reason
The reason why the timer was started.
Definition: wifi-tx-timer.h:54
void SetMpduResponseTimeoutCallback(MpduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of an MPDU expires...
PsduMapResponseTimeout m_psduMapResponseTimeoutCallback
EventId m_timeoutEvent
the timeout event after a missing response
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.
Reason GetReason(void) const
Get the reason why the timer was started.
bool m_rescheduled
whether the timer has been already rescheduled
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Timeout(MEM mem_ptr, OBJ obj, Args... args)
This method is called when the timer expires.
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
Definition: wifi-tx-timer.h:47
WifiTxTimer()
Default constructor.
void Cancel(void)
Cancel the timer.
bool IsRunning(void) const
Return true if the timer is running.
MpduResponseTimeout m_mpduResponseTimeoutCallback
the PSDU response timeout callback
void SetPsduResponseTimeoutCallback(PsduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU expires...
void Reschedule(const Time &delay)
Reschedule the timer to time out the given amount of time from the moment this function is called...
An identifier for simulation events.
Definition: event-id.h:53
Callback< void, uint8_t, WifiPsduMap *, const std::set< Mac48Address > *, std::size_t > PsduMapResponseTimeout
PSDU map response timeout callback typedef.
void FeedTraceSource(Args... args)
This method is called when the timer expires to feed the trace sources reporting timeout events...
void SetPsduMapResponseTimeoutCallback(PsduMapResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU map expires...
Ptr< EventImpl > m_endRxEvent
event to schedule upon RXSTART.indication
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
PsduResponseTimeout m_psduResponseTimeoutCallback
the PSDU map response timeout callback
Reason m_reason
the reason why the timer was started
Time GetDelayLeft(void) const
Get the remaining time until the timer will expire.