A Discrete-Event Network Simulator
API
wifi-tx-timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
20#ifndef WIFI_TX_TIMER_H
21#define WIFI_TX_TIMER_H
22
23#include "ns3/event-id.h"
24#include "ns3/nstime.h"
25#include "ns3/simulator.h"
26#include "ns3/traced-callback.h"
27
28#include <functional>
29#include <unordered_map>
30
31namespace ns3
32{
33
34class WifiMpdu;
35class WifiPsdu;
36class WifiTxVector;
37class Mac48Address;
38
39typedef std::unordered_map<uint16_t /* staId */, Ptr<WifiPsdu> /* PSDU */> WifiPsduMap;
40
49{
50 public:
55 enum Reason : uint8_t
56 {
66 };
67
70
71 virtual ~WifiTxTimer();
72
87 template <typename MEM, typename OBJ, typename... Args>
88 void Set(Reason reason, const Time& delay, MEM mem_ptr, OBJ obj, Args... args);
89
96 void Reschedule(const Time& delay);
97
104 Reason GetReason() const;
105
112 std::string GetReasonString(Reason reason) const;
113
119 bool IsRunning() const;
120
124 void Cancel();
125
132 Time GetDelayLeft() const;
133
138
143
149
157
165
174
175 private:
187 template <typename MEM, typename OBJ, typename... Args>
188 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
189
193 void Expire();
194
202 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
203
211 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
212
221 void FeedTraceSource(WifiPsduMap* psduMap,
222 std::set<Mac48Address>* missingStations,
223 std::size_t nTotalStations);
224
230
237};
238
239} // namespace ns3
240
241/***************************************************************
242 * Implementation of the templates declared above.
243 ***************************************************************/
244
245namespace ns3
246{
247
248template <typename MEM, typename OBJ, typename... Args>
249void
250WifiTxTimer::Set(Reason reason, const Time& delay, MEM mem_ptr, OBJ obj, Args... args)
251{
252 typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
253
255 m_reason = reason;
256 m_end = Simulator::Now() + delay;
257
258 // create an event to invoke when the timer expires
259 m_impl = Ptr<EventImpl>(MakeEvent<TimeoutType>(&WifiTxTimer::Timeout,
260 this,
261 mem_ptr,
262 obj,
263 std::forward<Args>(args)...),
264 false);
265}
266
267template <typename MEM, typename OBJ, typename... Args>
268void
269WifiTxTimer::Timeout(MEM mem_ptr, OBJ obj, Args... args)
270{
271 FeedTraceSource(std::forward<Args>(args)...);
272
273 // Invoke the method set by the user
274 ((*obj).*mem_ptr)(std::forward<Args>(args)...);
275}
276
277} // namespace ns3
278
279#endif /* WIFI_TX_TIMER_H */
Callback template class.
Definition: callback.h:443
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
Definition: wifi-tx-timer.h:49
bool IsRunning() const
Return true if the timer is running.
void Timeout(MEM mem_ptr, OBJ obj, Args... args)
This method is called when the timer expires.
virtual ~WifiTxTimer()
void Cancel()
Cancel the timer.
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.
void FeedTraceSource(Ptr< WifiMpdu > item, WifiTxVector txVector)
This method is called when the timer expires to feed the MPDU response timeout callback.
Reason
The reason why the timer was started.
Definition: wifi-tx-timer.h:56
@ WAIT_NORMAL_ACK_AFTER_DL_MU_PPDU
Definition: wifi-tx-timer.h:61
MpduResponseTimeout m_mpduResponseTimeoutCallback
the MPDU response timeout callback
Reason GetReason() const
Get the reason why the timer was started.
PsduMapResponseTimeout m_psduMapResponseTimeoutCallback
the PSDU map response timeout callback
Callback< void, uint8_t, WifiPsduMap *, const std::set< Mac48Address > *, std::size_t > PsduMapResponseTimeout
PSDU map response timeout callback typedef.
Reason m_reason
the reason why the timer was started
Callback< void, uint8_t, Ptr< const WifiPsdu >, const WifiTxVector & > PsduResponseTimeout
PSDU response timeout callback typedef.
void Expire()
Internal callback invoked when the timer expires.
void SetPsduMapResponseTimeoutCallback(PsduMapResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU map expires.
Time GetDelayLeft() const
Get the remaining time until the timer will expire.
WifiTxTimer()
Default constructor.
PsduResponseTimeout m_psduResponseTimeoutCallback
the PSDU response timeout callback
std::string GetReasonString(Reason reason) const
Get a string associated with the given reason.
void SetMpduResponseTimeoutCallback(MpduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
Time m_end
the absolute time when the timer will expire
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.
Ptr< EventImpl > m_impl
the timer implementation, which contains the bound callback function and arguments
EventId m_timeoutEvent
the timeout event after a missing response
Callback< void, uint8_t, Ptr< const WifiMpdu >, const WifiTxVector & > MpduResponseTimeout
MPDU response timeout callback typedef.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.