A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-tx-timer.cc
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#include "wifi-tx-timer.h"
21
22#include "wifi-mpdu.h"
23#include "wifi-psdu.h"
24#include "wifi-tx-vector.h"
25
26#include "ns3/log.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("WifiTxTimer");
32
34 : m_timeoutEvent(),
35 m_reason(NOT_RUNNING),
36 m_impl(nullptr),
37 m_end(Seconds(0))
38{
39}
40
42{
44 m_impl = nullptr;
45}
46
47void
49{
50 NS_LOG_FUNCTION(this << delay);
51
53 {
54 NS_LOG_DEBUG("Rescheduling " << GetReasonString(m_reason) << " timeout in "
55 << delay.As(Time::US));
56 Time end = Simulator::Now() + delay;
57 // If timer expiration is postponed, we have to do nothing but updating
58 // the timer expiration, because Expire() will reschedule itself to be
59 // executed at the correct time. If timer expiration is moved up, we
60 // have to reschedule Expire() (which would be executed too late otherwise)
61 if (end < m_end)
62 {
63 // timer expiration is moved up
66 }
67 m_end = end;
68 }
69}
70
71void
73{
74 NS_LOG_FUNCTION(this);
75 Time now = Simulator::Now();
76
77 if (m_end == now)
78 {
79 m_impl->Invoke();
80 }
81 else
82 {
84 }
85}
86
89{
91 return m_reason;
92}
93
94std::string
96{
97#define CASE_REASON(x) \
98 case WAIT_##x: \
99 return #x;
100
101 switch (reason)
102 {
103 case NOT_RUNNING:
104 return "NOT_RUNNING";
105 CASE_REASON(CTS);
106 CASE_REASON(NORMAL_ACK);
107 CASE_REASON(BLOCK_ACK);
108 CASE_REASON(CTS_AFTER_MU_RTS);
109 CASE_REASON(NORMAL_ACK_AFTER_DL_MU_PPDU);
110 CASE_REASON(BLOCK_ACKS_IN_TB_PPDU);
111 CASE_REASON(TB_PPDU_AFTER_BASIC_TF);
112 CASE_REASON(QOS_NULL_AFTER_BSRP_TF);
113 CASE_REASON(BLOCK_ACK_AFTER_TB_PPDU);
114 default:
115 NS_ABORT_MSG("Unknown reason");
116 }
117#undef CASE_REASON
118}
119
120bool
122{
123 return m_timeoutEvent.IsRunning();
124}
125
126void
128{
131 m_impl = nullptr;
133}
134
135void
137{
138 m_staExpectResponseFrom.erase(from);
139}
140
141const std::set<Mac48Address>&
143{
145}
146
147Time
149{
150 return m_end - Simulator::Now();
151}
152
153void
155{
157}
158
159void
161{
163 {
165 }
166}
167
168void
170{
172}
173
174void
176{
178 {
180 }
181}
182
183void
185{
187}
188
189void
190WifiTxTimer::FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations)
191{
193 {
195 psduMap,
197 nTotalStations);
198 }
199}
200
201} // namespace ns3
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
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
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
@ US
microsecond
Definition: nstime.h:118
bool IsRunning() const
Return true if the timer is running.
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
MpduResponseTimeout m_mpduResponseTimeoutCallback
the MPDU response timeout callback
const std::set< Mac48Address > & GetStasExpectedToRespond() const
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
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
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
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
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.
#define CASE_REASON(x)