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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef WIFI_TX_TIMER_H
10#define WIFI_TX_TIMER_H
11
12#include "ns3/event-id.h"
13#include "ns3/nstime.h"
14#include "ns3/simulator.h"
15#include "ns3/traced-callback.h"
16
17#include <functional>
18#include <unordered_map>
19
20namespace ns3
21{
22
23class WifiMpdu;
24class WifiPsdu;
25class WifiTxVector;
26class Mac48Address;
27
28typedef std::unordered_map<uint16_t /* staId */, Ptr<WifiPsdu> /* PSDU */> WifiPsduMap;
29
30/**
31 * @ingroup wifi
32 *
33 * This class is used to handle the timer that a station starts when transmitting
34 * a frame that solicits a response. The timeout can be rescheduled (multiple times)
35 * when the RXSTART.indication is received from the PHY.
36 */
38{
39 public:
40 /**
41 * @enum Reason
42 * @brief The reason why the timer was started
43 */
58
59 /** Default constructor */
61
62 virtual ~WifiTxTimer();
63
64 /**
65 * This method is called when a frame soliciting a response is transmitted.
66 * This method starts a timer of the given duration and schedules a call to
67 * the given method in case the timer expires.
68 *
69 * @tparam MEM \deduced Class method function signature type
70 * @tparam OBJ \deduced Class type of the object
71 * @tparam Args \deduced Type template parameter pack
72 * @param reason the reason why the timer was started
73 * @param delay the time to the expiration of the timer
74 * @param from the set of stations we expect to receive a response from
75 * @param mem_ptr Member method pointer to invoke
76 * @param obj The object on which to invoke the member method
77 * @param args The arguments to pass to the invoked method
78 */
79 template <typename MEM, typename OBJ, typename... Args>
80 void Set(Reason reason,
81 const Time& delay,
82 const std::set<Mac48Address>& from,
83 MEM mem_ptr,
84 OBJ obj,
85 Args... args);
86
87 /**
88 * Reschedule the timer to time out the given amount of time from the moment
89 * this function is called. Note that nothing is done if the timer is not running.
90 *
91 * @param delay the time to the expiration of the timer
92 */
93 void Reschedule(const Time& delay);
94
95 /**
96 * Get the reason why the timer was started. Call
97 * this method only if the timer is running
98 *
99 * @return the reason why the timer was started
100 */
101 Reason GetReason() const;
102
103 /**
104 * Get a string associated with the given reason
105 *
106 * @param reason the given reason
107 * @return a string associated with the given reason
108 */
109 std::string GetReasonString(Reason reason) const;
110
111 /**
112 * Return true if the timer is running
113 *
114 * @return true if the timer is running
115 */
116 bool IsRunning() const;
117
118 /**
119 * Cancel the timer.
120 */
121 void Cancel();
122
123 /**
124 * Notify that a response was got from the given station.
125 *
126 * @param from the MAC address of the given station
127 */
128 void GotResponseFrom(const Mac48Address& from);
129
130 /**
131 * @return the set of stations that are still expected to respond
132 */
133 const std::set<Mac48Address>& GetStasExpectedToRespond() const;
134
135 /**
136 * Get the remaining time until the timer will expire.
137 *
138 * @return the remaining time until the timer will expire.
139 * If the timer is not running, this method returns zero.
140 */
141 Time GetDelayLeft() const;
142
143 /**
144 * MPDU response timeout callback typedef
145 */
147
148 /**
149 * PSDU response timeout callback typedef
150 */
152
153 /**
154 * PSDU map response timeout callback typedef
155 */
158
159 /**
160 * Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
161 *
162 * @param callback the callback to invoke when the TX timer following the transmission
163 * of an MPDU expires
164 */
166
167 /**
168 * Set the callback to invoke when the TX timer following the transmission of a PSDU expires.
169 *
170 * @param callback the callback to invoke when the TX timer following the transmission
171 * of a PSDU expires
172 */
174
175 /**
176 * Set the callback to invoke when the TX timer following the transmission of a PSDU map
177 * expires.
178 *
179 * @param callback the callback to invoke when the TX timer following the transmission
180 * of a PSDU map expires
181 */
183
184 private:
185 /**
186 * This method is called when the timer expires. It invokes the callbacks
187 * and the method set by the user.
188 *
189 * @tparam MEM \deduced Class method function signature type
190 * @tparam OBJ \deduced Class type of the object
191 * @tparam Args \deduced Type template parameter pack
192 * @param mem_ptr Member method pointer to invoke
193 * @param obj The object on which to invoke the member method
194 * @param args The arguments to pass to the invoked method
195 */
196 template <typename MEM, typename OBJ, typename... Args>
197 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
198
199 /**
200 * Internal callback invoked when the timer expires.
201 */
202 void Expire();
203
204 /**
205 * This method is called when the timer expires to feed the MPDU response
206 * timeout callback.
207 *
208 * @param item the MPDU followed by no response
209 * @param txVector the TXVECTOR used to transmit the MPDU
210 */
211 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
212
213 /**
214 * This method is called when the timer expires to feed the PSDU response
215 * timeout callback.
216 *
217 * @param psdu the PSDU followed by no response
218 * @param txVector the TXVECTOR used to transmit the PSDU
219 */
220 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
221
222 /**
223 * This method is called when the timer expires to feed the PSDU map response
224 * timeout callback.
225 *
226 * @param psduMap the PSDU map for which not all responses were received
227 * @param nTotalStations the total number of expected responses
228 */
229 void FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations);
230
231 EventId m_timeoutEvent; //!< the timeout event after a missing response
232 Reason m_reason; //!< the reason why the timer was started
233 Ptr<EventImpl> m_impl; /**< the timer implementation, which contains the bound
234 callback function and arguments */
235 Time m_end; //!< the absolute time when the timer will expire
236 std::set<Mac48Address>
237 m_staExpectResponseFrom; //!< the set of stations we expect to receive a response from
238
239 /// the MPDU response timeout callback
241 /// the PSDU response timeout callback
243 /// the PSDU map response timeout callback
245};
246
247} // namespace ns3
248
249/***************************************************************
250 * Implementation of the templates declared above.
251 ***************************************************************/
252
253namespace ns3
254{
255
256template <typename MEM, typename OBJ, typename... Args>
257void
259 const Time& delay,
260 const std::set<Mac48Address>& from,
261 MEM mem_ptr,
262 OBJ obj,
263 Args... args)
264{
265 typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
266
268 m_reason = reason;
269 m_end = Simulator::Now() + delay;
271
272 // create an event to invoke when the timer expires
274 this,
275 mem_ptr,
276 obj,
277 std::forward<Args>(args)...),
278 false);
279}
280
281template <typename MEM, typename OBJ, typename... Args>
282void
283WifiTxTimer::Timeout(MEM mem_ptr, OBJ obj, Args... args)
284{
285 FeedTraceSource(std::forward<Args>(args)...);
286
287 // Invoke the method set by the user
288 ((*obj).*mem_ptr)(std::forward<Args>(args)...);
289}
290
291} // namespace ns3
292
293#endif /* WIFI_TX_TIMER_H */
Callback template class.
Definition callback.h:428
An identifier for simulation events.
Definition event-id.h:45
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
WifiMpdu stores a (const) packet along with a MAC header.
Definition wifi-mpdu.h:51
WifiPsdu stores an MPDU, S-MPDU or A-MPDU, by keeping header(s) and payload(s) separate for each cons...
Definition wifi-psdu.h:33
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.
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...
std::enable_if_t< std::is_member_pointer_v< MEM >, EventImpl * > MakeEvent(MEM mem_ptr, OBJ obj, Ts... args)
Make an EventImpl from class method members which take varying numbers of arguments.
Definition make-event.h:133
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.
Definition wifi-mac.h:78