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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#include "wifi-tx-timer.h"
10
11#include "wifi-mpdu.h"
12#include "wifi-psdu.h"
13#include "wifi-tx-vector.h"
14
15#include "ns3/log.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("WifiTxTimer");
21
23 : m_timeoutEvent(),
24 m_reason(NOT_RUNNING),
25 m_impl(nullptr),
26 m_end()
27{
28}
29
35
36void
38{
39 NS_LOG_FUNCTION(this << delay);
40
42 {
43 NS_LOG_DEBUG("Rescheduling " << GetReasonString(m_reason) << " timeout in "
44 << delay.As(Time::US));
45 Time end = Simulator::Now() + delay;
46 // If timer expiration is postponed, we have to do nothing but updating
47 // the timer expiration, because Expire() will reschedule itself to be
48 // executed at the correct time. If timer expiration is moved up, we
49 // have to reschedule Expire() (which would be executed too late otherwise)
50 if (end < m_end)
51 {
52 // timer expiration is moved up
55 }
56 m_end = end;
57 }
58}
59
60void
62{
63 NS_LOG_FUNCTION(this);
64 Time now = Simulator::Now();
65
66 if (m_end == now)
67 {
68 m_impl->Invoke();
69 }
70 else
71 {
73 }
74}
75
78{
80 return m_reason;
81}
82
83std::string
85{
86#define CASE_REASON(x) \
87 case WAIT_##x: \
88 return #x;
89
90 switch (reason)
91 {
92 case NOT_RUNNING:
93 return "NOT_RUNNING";
94 CASE_REASON(CTS);
95 CASE_REASON(NORMAL_ACK);
96 CASE_REASON(BLOCK_ACK);
97 CASE_REASON(CTS_AFTER_MU_RTS);
98 CASE_REASON(NORMAL_ACK_AFTER_DL_MU_PPDU);
99 CASE_REASON(BLOCK_ACKS_IN_TB_PPDU);
100 CASE_REASON(TB_PPDU_AFTER_BASIC_TF);
101 CASE_REASON(QOS_NULL_AFTER_BSRP_TF);
102 CASE_REASON(BLOCK_ACK_AFTER_TB_PPDU);
103 default:
104 NS_ABORT_MSG("Unknown reason");
105 }
106#undef CASE_REASON
107}
108
109bool
111{
112 return m_timeoutEvent.IsPending();
113}
114
115void
123
124void
129
130const std::set<Mac48Address>&
135
136Time
138{
139 return m_end - Simulator::Now();
140}
141
142void
147
148void
156
157void
162
163void
171
172void
177
178void
179WifiTxTimer::FeedTraceSource(WifiPsduMap* psduMap, std::size_t nTotalStations)
180{
182 {
184 psduMap,
186 nTotalStations);
187 }
188}
189
190} // namespace ns3
bool IsNull() const
Check for null implementation.
Definition callback.h:555
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
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
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ US
microsecond
Definition nstime.h:107
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.
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:55
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
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)