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 */
57
58 /** Default constructor */
60
61 virtual ~WifiTxTimer();
62
63 /**
64 * This method is called when a frame soliciting a response is transmitted.
65 * This method starts a timer of the given duration and schedules a call to
66 * the given method in case the timer expires.
67 *
68 * @tparam MEM \deduced Class method function signature type
69 * @tparam OBJ \deduced Class type of the object
70 * @tparam Args \deduced Type template parameter pack
71 * @param reason the reason why the timer was started
72 * @param delay the time to the expiration of the timer
73 * @param from the set of stations we expect to receive a response from
74 * @param mem_ptr Member method pointer to invoke
75 * @param obj The object on which to invoke the member method
76 * @param args The arguments to pass to the invoked method
77 */
78 template <typename MEM, typename OBJ, typename... Args>
79 void Set(Reason reason,
80 const Time& delay,
81 const std::set<Mac48Address>& from,
82 MEM mem_ptr,
83 OBJ obj,
84 Args... args);
85
86 /**
87 * Reschedule the timer to time out the given amount of time from the moment
88 * this function is called. Note that nothing is done if the timer is not running.
89 *
90 * @param delay the time to the expiration of the timer
91 */
92 void Reschedule(const Time& delay);
93
94 /**
95 * Get the reason why the timer was started. Call
96 * this method only if the timer is running
97 *
98 * @return the reason why the timer was started
99 */
100 Reason GetReason() const;
101
102 /**
103 * Get a string associated with the given reason
104 *
105 * @param reason the given reason
106 * @return a string associated with the given reason
107 */
108 std::string GetReasonString(Reason reason) const;
109
110 /**
111 * Return true if the timer is running
112 *
113 * @return true if the timer is running
114 */
115 bool IsRunning() const;
116
117 /**
118 * Cancel the timer.
119 */
120 void Cancel();
121
122 /**
123 * Notify that a response was got from the given station.
124 *
125 * @param from the MAC address of the given station
126 */
127 void GotResponseFrom(const Mac48Address& from);
128
129 /**
130 * @return the set of stations that are still expected to respond
131 */
132 const std::set<Mac48Address>& GetStasExpectedToRespond() const;
133
134 /**
135 * Get the remaining time until the timer will expire.
136 *
137 * @return the remaining time until the timer will expire.
138 * If the timer is not running, this method returns zero.
139 */
140 Time GetDelayLeft() const;
141
142 /**
143 * MPDU response timeout callback typedef
144 */
146
147 /**
148 * PSDU response timeout callback typedef
149 */
151
152 /**
153 * PSDU map response timeout callback typedef
154 */
157
158 /**
159 * Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
160 *
161 * @param callback the callback to invoke when the TX timer following the transmission
162 * of an MPDU expires
163 */
165
166 /**
167 * Set the callback to invoke when the TX timer following the transmission of a PSDU expires.
168 *
169 * @param callback the callback to invoke when the TX timer following the transmission
170 * of a PSDU expires
171 */
173
174 /**
175 * Set the callback to invoke when the TX timer following the transmission of a PSDU map
176 * expires.
177 *
178 * @param callback the callback to invoke when the TX timer following the transmission
179 * of a PSDU map expires
180 */
182
183 private:
184 /**
185 * This method is called when the timer expires. It invokes the callbacks
186 * and the method set by the user.
187 *
188 * @tparam MEM \deduced Class method function signature type
189 * @tparam OBJ \deduced Class type of the object
190 * @tparam Args \deduced Type template parameter pack
191 * @param mem_ptr Member method pointer to invoke
192 * @param obj The object on which to invoke the member method
193 * @param args The arguments to pass to the invoked method
194 */
195 template <typename MEM, typename OBJ, typename... Args>
196 void Timeout(MEM mem_ptr, OBJ obj, Args... args);
197
198 /**
199 * Internal callback invoked when the timer expires.
200 */
201 void Expire();
202
203 /**
204 * This method is called when the timer expires to feed the MPDU response
205 * timeout callback.
206 *
207 * @param item the MPDU followed by no response
208 * @param txVector the TXVECTOR used to transmit the MPDU
209 */
210 void FeedTraceSource(Ptr<WifiMpdu> item, WifiTxVector txVector);
211
212 /**
213 * This method is called when the timer expires to feed the PSDU response
214 * timeout callback.
215 *
216 * @param psdu the PSDU followed by no response
217 * @param txVector the TXVECTOR used to transmit the PSDU
218 */
219 void FeedTraceSource(Ptr<WifiPsdu> psdu, WifiTxVector txVector);
220
221 /**
222 * This method is called when the timer expires to feed the PSDU map response
223 * timeout callback.
224 *
225 * @param psduMap the PSDU map for which not all responses were received
226 * @param nTotalStations the total number of expected responses
227 */
228 void FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations);
229
230 EventId m_timeoutEvent; //!< the timeout event after a missing response
231 Reason m_reason; //!< the reason why the timer was started
232 Ptr<EventImpl> m_impl; /**< the timer implementation, which contains the bound
233 callback function and arguments */
234 Time m_end; //!< the absolute time when the timer will expire
235 std::set<Mac48Address>
236 m_staExpectResponseFrom; //!< the set of stations we expect to receive a response from
237
238 /// the MPDU response timeout callback
240 /// the PSDU response timeout callback
242 /// the PSDU map response timeout callback
244};
245
246} // namespace ns3
247
248/***************************************************************
249 * Implementation of the templates declared above.
250 ***************************************************************/
251
252namespace ns3
253{
254
255template <typename MEM, typename OBJ, typename... Args>
256void
258 const Time& delay,
259 const std::set<Mac48Address>& from,
260 MEM mem_ptr,
261 OBJ obj,
262 Args... args)
263{
264 typedef void (WifiTxTimer::*TimeoutType)(MEM, OBJ, Args...);
265
267 m_reason = reason;
268 m_end = Simulator::Now() + delay;
270
271 // create an event to invoke when the timer expires
273 this,
274 mem_ptr,
275 obj,
276 std::forward<Args>(args)...),
277 false);
278}
279
280template <typename MEM, typename OBJ, typename... Args>
281void
282WifiTxTimer::Timeout(MEM mem_ptr, OBJ obj, Args... args)
283{
284 FeedTraceSource(std::forward<Args>(args)...);
285
286 // Invoke the method set by the user
287 ((*obj).*mem_ptr)(std::forward<Args>(args)...);
288}
289
290} // namespace ns3
291
292#endif /* WIFI_TX_TIMER_H */
Callback template class.
Definition callback.h:422
An identifier for simulation events.
Definition event-id.h:45
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
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.