A Discrete-Event Network Simulator
API
wifi-tx-timer.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "wifi-tx-timer.h"
23 #include "wifi-mac-queue-item.h"
24 #include "wifi-tx-vector.h"
25 #include "wifi-psdu.h"
26 
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("WifiTxTimer");
31 
33  : m_timeoutEvent (),
34  m_reason (NOT_RUNNING),
35  m_impl (nullptr),
36  m_end (Seconds (0))
37 {
38 }
39 
41 {
43  m_impl = 0;
44 }
45 
46 void
48 {
49  NS_LOG_FUNCTION (this << delay);
50 
52  {
53  NS_LOG_DEBUG ("Rescheduling " << GetReasonString (m_reason) << " timeout in "
54  << delay.As (Time::US));
55  Time end = Simulator::Now () + delay;
56  // If timer expiration is postponed, we have to do nothing but updating
57  // the timer expiration, because Expire() will reschedule itself to be
58  // executed at the correct time. If timer expiration is moved up, we
59  // have to reschedule Expire() (which would be executed too late otherwise)
60  if (end < m_end)
61  {
62  // timer expiration is moved up
65  }
66  m_end = end;
67  }
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this);
74  Time now = Simulator::Now ();
75 
76  if (m_end == now)
77  {
78  m_impl->Invoke ();
79  }
80  else
81  {
83  }
84 }
85 
88 {
89  NS_ASSERT (IsRunning ());
90  return m_reason;
91 }
92 
93 std::string
95 {
96 #define FOO(x) \
97 case WAIT_ ## x: \
98  return # x; \
99  break;
100 
101  switch (reason)
102  {
103  case NOT_RUNNING:
104  return "NOT_RUNNING";
105  break;
106  FOO (CTS);
107  FOO (NORMAL_ACK);
108  FOO (BLOCK_ACK);
109  FOO (NORMAL_ACK_AFTER_DL_MU_PPDU);
110  FOO (BLOCK_ACKS_IN_TB_PPDU);
111  FOO (TB_PPDU_AFTER_BASIC_TF);
112  FOO (QOS_NULL_AFTER_BSRP_TF);
113  FOO (BLOCK_ACK_AFTER_TB_PPDU);
114  default:
115  NS_ABORT_MSG ("Unknown reason");
116  }
117 #undef FOO
118 }
119 
120 bool
122 {
123  return m_timeoutEvent.IsRunning ();
124 }
125 
126 void
128 {
131  m_impl = 0;
132 }
133 
134 Time
136 {
138 }
139 
140 void
142 {
144 }
145 
146 void
148 {
150  {
151  m_mpduResponseTimeoutCallback (m_reason, item, txVector);
152  }
153 }
154 
155 void
157 {
159 }
160 
161 void
163 {
165  {
166  m_psduResponseTimeoutCallback (m_reason, psdu, txVector);
167  }
168 }
169 
170 void
172 {
174 }
175 
176 void
177 WifiTxTimer::FeedTraceSource (WifiPsduMap* psduMap, std::set<Mac48Address>* missingStations,
178  std::size_t nTotalStations)
179 {
181  {
182  m_psduMapResponseTimeoutCallback (m_reason, psduMap, missingStations, nTotalStations);
183  }
184 }
185 
186 } //namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::WifiTxTimer::GetReasonString
std::string GetReasonString(Reason reason) const
Get a string associated with the given reason.
Definition: wifi-tx-timer.cc:94
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::WifiPsduMap
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.
Definition: he-frame-exchange-manager.h:34
ns3::WifiTxTimer::~WifiTxTimer
virtual ~WifiTxTimer()
Definition: wifi-tx-timer.cc:40
ns3::Callback< void, uint8_t, Ptr< const WifiMacQueueItem >, const WifiTxVector & >
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiTxTimer::GetDelayLeft
Time GetDelayLeft(void) const
Get the remaining time until the timer will expire.
Definition: wifi-tx-timer.cc:135
ns3::WifiTxTimer::m_psduResponseTimeoutCallback
PsduResponseTimeout m_psduResponseTimeoutCallback
the PSDU response timeout callback
Definition: wifi-tx-timer.h:230
ns3::Callback::IsNull
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
ns3::WifiTxTimer::SetPsduResponseTimeoutCallback
void SetPsduResponseTimeoutCallback(PsduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU expires.
Definition: wifi-tx-timer.cc:156
ns3::Simulator::GetDelayLeft
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:204
ns3::WifiTxTimer::IsRunning
bool IsRunning(void) const
Return true if the timer is running.
Definition: wifi-tx-timer.cc:121
ns3::Time::US
@ US
microsecond
Definition: nstime.h:117
ns3::WifiTxTimer::FeedTraceSource
void FeedTraceSource(Ptr< WifiMacQueueItem > item, WifiTxVector txVector)
This method is called when the timer expires to feed the MPDU response timeout callback.
Definition: wifi-tx-timer.cc:147
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
wifi-mac-queue-item.h
ns3::WifiTxTimer::m_mpduResponseTimeoutCallback
MpduResponseTimeout m_mpduResponseTimeoutCallback
the MPDU response timeout callback
Definition: wifi-tx-timer.h:228
ns3::Time::As
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
ns3::WifiTxTimer::SetPsduMapResponseTimeoutCallback
void SetPsduMapResponseTimeoutCallback(PsduMapResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of a PSDU map expires.
Definition: wifi-tx-timer.cc:171
ns3::WifiTxTimer::SetMpduResponseTimeoutCallback
void SetMpduResponseTimeoutCallback(MpduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of an MPDU expires.
Definition: wifi-tx-timer.cc:141
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
wifi-psdu.h
ns3::Ptr< WifiMacQueueItem >
ns3::EventId::IsRunning
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
ns3::WifiTxTimer::Reschedule
void Reschedule(const Time &delay)
Reschedule the timer to time out the given amount of time from the moment this function is called.
Definition: wifi-tx-timer.cc:47
wifi-tx-vector.h
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
wifi-tx-timer.h
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiTxTimer::Expire
void Expire(void)
Internal callback invoked when the timer expires.
Definition: wifi-tx-timer.cc:71
ns3::WifiTxTimer::Reason
Reason
The reason why the timer was started.
Definition: wifi-tx-timer.h:55
ns3::WifiTxTimer::m_timeoutEvent
EventId m_timeoutEvent
the timeout event after a missing response
Definition: wifi-tx-timer.h:221
FOO
#define FOO(x)
ns3::WifiTxTimer::WifiTxTimer
WifiTxTimer()
Default constructor.
Definition: wifi-tx-timer.cc:32
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WifiTxTimer::m_psduMapResponseTimeoutCallback
PsduMapResponseTimeout m_psduMapResponseTimeoutCallback
the PSDU map response timeout callback
Definition: wifi-tx-timer.h:232
ns3::WifiTxTimer::GetReason
Reason GetReason(void) const
Get the reason why the timer was started.
Definition: wifi-tx-timer.cc:87
ns3::WifiTxTimer::m_reason
Reason m_reason
the reason why the timer was started
Definition: wifi-tx-timer.h:222
ns3::WifiTxTimer::NOT_RUNNING
@ NOT_RUNNING
Definition: wifi-tx-timer.h:56
ns3::WifiTxTimer::m_end
Time m_end
the absolute time when the timer will expire
Definition: wifi-tx-timer.h:225
ns3::WifiTxTimer::Cancel
void Cancel(void)
Cancel the timer.
Definition: wifi-tx-timer.cc:127
ns3::WifiTxTimer::m_impl
Ptr< EventImpl > m_impl
the timer implementation, which contains the bound callback function and arguments
Definition: wifi-tx-timer.h:223
NS_ABORT_MSG
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50