A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 {
67 };
68
71
72 virtual ~WifiTxTimer();
73
88 template <typename MEM, typename OBJ, typename... Args>
89 void Set(Reason reason, const Time& delay, MEM mem_ptr, OBJ obj, Args... args);
90
97 void Reschedule(const Time& delay);
98
105 Reason GetReason() const;
106
113 std::string GetReasonString(Reason reason) const;
114
120 bool IsRunning() const;
121
125 void Cancel();
126
133 Time GetDelayLeft() const;
134
139
144
150
158
166
175
176 private:
188 template <typename MEM, typename OBJ, typename... Args>
189 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
190
194 void Expire();
195
203 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
204
212 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
213
222 void FeedTraceSource(WifiPsduMap* psduMap,
223 std::set<Mac48Address>* missingStations,
224 std::size_t nTotalStations);
225
231
238};
239
240} // namespace ns3
241
242/***************************************************************
243 * Implementation of the templates declared above.
244 ***************************************************************/
245
246namespace ns3
247{
248
249template <typename MEM, typename OBJ, typename... Args>
250void
251WifiTxTimer::Set(Reason reason, const Time& delay, MEM mem_ptr, OBJ obj, Args... args)
252{
253 typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
254
256 m_reason = reason;
257 m_end = Simulator::Now() + delay;
258
259 // create an event to invoke when the timer expires
260 m_impl = Ptr<EventImpl>(MakeEvent<TimeoutType>(&WifiTxTimer::Timeout,
261 this,
262 mem_ptr,
263 obj,
264 std::forward<Args>(args)...),
265 false);
266}
267
268template <typename MEM, typename OBJ, typename... Args>
269void
270WifiTxTimer::Timeout(MEM mem_ptr, OBJ obj, Args... args)
271{
272 FeedTraceSource(std::forward<Args>(args)...);
273
274 // Invoke the method set by the user
275 ((*obj).*mem_ptr)(std::forward<Args>(args)...);
276}
277
278} // namespace ns3
279
280#endif /* WIFI_TX_TIMER_H */
Callback template class.
Definition: callback.h:438
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:62
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.