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
89 template <typename MEM, typename OBJ, typename... Args>
90 void Set(Reason reason,
91 const Time& delay,
92 const std::set<Mac48Address>& from,
93 MEM mem_ptr,
94 OBJ obj,
95 Args... args);
96
103 void Reschedule(const Time& delay);
104
111 Reason GetReason() const;
112
119 std::string GetReasonString(Reason reason) const;
120
126 bool IsRunning() const;
127
131 void Cancel();
132
138 void GotResponseFrom(const Mac48Address& from);
139
143 const std::set<Mac48Address>& GetStasExpectedToRespond() const;
144
151 Time GetDelayLeft() const;
152
157
162
168
176
184
193
194 private:
206 template <typename MEM, typename OBJ, typename... Args>
207 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
208
212 void Expire();
213
221 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
222
230 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
231
239 void FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations);
240
246 std::set<Mac48Address>
248
255};
256
257} // namespace ns3
258
259/***************************************************************
260 * Implementation of the templates declared above.
261 ***************************************************************/
262
263namespace ns3
264{
265
266template <typename MEM, typename OBJ, typename... Args>
267void
269 const Time& delay,
270 const std::set<Mac48Address>& from,
271 MEM mem_ptr,
272 OBJ obj,
273 Args... args)
274{
275 typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
276
278 m_reason = reason;
279 m_end = Simulator::Now() + delay;
281
282 // create an event to invoke when the timer expires
283 m_impl = Ptr<EventImpl>(MakeEvent<TimeoutType>(&WifiTxTimer::Timeout,
284 this,
285 mem_ptr,
286 obj,
287 std::forward<Args>(args)...),
288 false);
289}
290
291template <typename MEM, typename OBJ, typename... Args>
292void
293WifiTxTimer::Timeout(MEM mem_ptr, OBJ obj, Args... args)
294{
295 FeedTraceSource(std::forward<Args>(args)...);
296
297 // Invoke the method set by the user
298 ((*obj).*mem_ptr)(std::forward<Args>(args)...);
299}
300
301} // namespace ns3
302
303#endif /* WIFI_TX_TIMER_H */
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
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 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
const std::set< Mac48Address > & GetStasExpectedToRespond() const
void Set(Reason reason, const Time &delay, const std::set< Mac48Address > &from, MEM mem_ptr, OBJ obj, Args... args)
This method is called when a frame soliciting a response is transmitted.
Reason GetReason() const
Get the reason why the timer was started.
std::set< Mac48Address > m_staExpectResponseFrom
the set of stations we expect to receive a response from
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.
void GotResponseFrom(const Mac48Address &from)
Notify that a response was got from the given station.
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.