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
41/**
42 * \ingroup wifi
43 *
44 * This class is used to handle the timer that a station starts when transmitting
45 * a frame that solicits a response. The timeout can be rescheduled (multiple times)
46 * when the RXSTART.indication is received from the PHY.
47 */
49{
50 public:
51 /**
52 * \enum Reason
53 * \brief The reason why the timer was started
54 */
55 enum Reason : uint8_t
56 {
67 };
68
69 /** Default constructor */
71
72 virtual ~WifiTxTimer();
73
74 /**
75 * This method is called when a frame soliciting a response is transmitted.
76 * This method starts a timer of the given duration and schedules a call to
77 * the given method in case the timer expires.
78 *
79 * \tparam MEM \deduced Class method function signature type
80 * \tparam OBJ \deduced Class type of the object
81 * \tparam Args \deduced Type template parameter pack
82 * \param reason the reason why the timer was started
83 * \param delay the time to the expiration of the timer
84 * \param from the set of stations we expect to receive a response from
85 * \param mem_ptr Member method pointer to invoke
86 * \param obj The object on which to invoke the member method
87 * \param args The arguments to pass to the invoked method
88 */
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
97 /**
98 * Reschedule the timer to time out the given amount of time from the moment
99 * this function is called. Note that nothing is done if the timer is not running.
100 *
101 * \param delay the time to the expiration of the timer
102 */
103 void Reschedule(const Time& delay);
104
105 /**
106 * Get the reason why the timer was started. Call
107 * this method only if the timer is running
108 *
109 * \return the reason why the timer was started
110 */
111 Reason GetReason() const;
112
113 /**
114 * Get a string associated with the given reason
115 *
116 * \param reason the given reason
117 * \return a string associated with the given reason
118 */
119 std::string GetReasonString(Reason reason) const;
120
121 /**
122 * Return true if the timer is running
123 *
124 * \return true if the timer is running
125 */
126 bool IsRunning() const;
127
128 /**
129 * Cancel the timer.
130 */
131 void Cancel();
132
133 /**
134 * Notify that a response was got from the given station.
135 *
136 * \param from the MAC address of the given station
137 */
138 void GotResponseFrom(const Mac48Address& from);
139
140 /**
141 * \return the set of stations that are still expected to respond
142 */
143 const std::set<Mac48Address>& GetStasExpectedToRespond() const;
144
145 /**
146 * Get the remaining time until the timer will expire.
147 *
148 * \return the remaining time until the timer will expire.
149 * If the timer is not running, this method returns zero.
150 */
151 Time GetDelayLeft() const;
152
153 /**
154 * MPDU response timeout callback typedef
155 */
157
158 /**
159 * PSDU response timeout callback typedef
160 */
162
163 /**
164 * PSDU map response timeout callback typedef
165 */
168
169 /**
170 * Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
171 *
172 * \param callback the callback to invoke when the TX timer following the transmission
173 * of an MPDU expires
174 */
176
177 /**
178 * Set the callback to invoke when the TX timer following the transmission of a PSDU expires.
179 *
180 * \param callback the callback to invoke when the TX timer following the transmission
181 * of a PSDU expires
182 */
184
185 /**
186 * Set the callback to invoke when the TX timer following the transmission of a PSDU map
187 * expires.
188 *
189 * \param callback the callback to invoke when the TX timer following the transmission
190 * of a PSDU map expires
191 */
193
194 private:
195 /**
196 * This method is called when the timer expires. It invokes the callbacks
197 * and the method set by the user.
198 *
199 * \tparam MEM \deduced Class method function signature type
200 * \tparam OBJ \deduced Class type of the object
201 * \tparam Args \deduced Type template parameter pack
202 * \param mem_ptr Member method pointer to invoke
203 * \param obj The object on which to invoke the member method
204 * \param args The arguments to pass to the invoked method
205 */
206 template <typename MEM, typename OBJ, typename... Args>
207 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
208
209 /**
210 * Internal callback invoked when the timer expires.
211 */
212 void Expire();
213
214 /**
215 * This method is called when the timer expires to feed the MPDU response
216 * timeout callback.
217 *
218 * \param item the MPDU followed by no response
219 * \param txVector the TXVECTOR used to transmit the MPDU
220 */
221 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
222
223 /**
224 * This method is called when the timer expires to feed the PSDU response
225 * timeout callback.
226 *
227 * \param psdu the PSDU followed by no response
228 * \param txVector the TXVECTOR used to transmit the PSDU
229 */
230 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
231
232 /**
233 * This method is called when the timer expires to feed the PSDU map response
234 * timeout callback.
235 *
236 * \param psduMap the PSDU map for which not all responses were received
237 * \param nTotalStations the total number of expected responses
238 */
239 void FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations);
240
241 EventId m_timeoutEvent; //!< the timeout event after a missing response
242 Reason m_reason; //!< the reason why the timer was started
243 Ptr<EventImpl> m_impl; /**< the timer implementation, which contains the bound
244 callback function and arguments */
245 Time m_end; //!< the absolute time when the timer will expire
246 std::set<Mac48Address>
247 m_staExpectResponseFrom; //!< the set of stations we expect to receive a response from
248
249 /// the MPDU response timeout callback
251 /// the PSDU response timeout callback
253 /// the PSDU map response timeout callback
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.