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_reason (NOT_RUNNING),
34  m_rescheduled (false)
35 {
36 }
37 
39 {
41  m_endRxEvent = 0;
42 }
43 
44 void
46 {
47  NS_LOG_FUNCTION (this << delay);
48 
50  {
51  NS_LOG_DEBUG ("Rescheduling " << GetReasonString (m_reason) << " timeout in "
52  << delay.As (Time::US));
55  m_rescheduled = true;
56  }
57 }
58 
61 {
62  NS_ASSERT (IsRunning ());
63  return m_reason;
64 }
65 
66 std::string
68 {
69 #define FOO(x) \
70 case WAIT_ ## x: \
71  return # x; \
72  break;
73 
74  switch (reason)
75  {
76  case NOT_RUNNING:
77  return "NOT_RUNNING";
78  break;
79  FOO (CTS);
80  FOO (NORMAL_ACK);
81  FOO (BLOCK_ACK);
82  default:
83  NS_ABORT_MSG ("Unknown reason");
84  }
85 #undef FOO
86 }
87 
88 bool
90 {
91  return m_timeoutEvent.IsRunning ();
92 }
93 
94 void
96 {
99  m_endRxEvent = 0;
100 }
101 
102 Time
104 {
106 }
107 
108 void
110 {
112 }
113 
114 template<>
115 void
116 WifiTxTimer::FeedTraceSource<Ptr<WifiMacQueueItem>, WifiTxVector> (Ptr<WifiMacQueueItem> item,
117  WifiTxVector txVector)
118 {
119  if (!m_mpduResponseTimeoutCallback.IsNull ())
120  {
121  m_mpduResponseTimeoutCallback (m_reason, item, txVector);
122  }
123 }
124 
125 void
127 {
129 }
130 
131 template<>
132 void
133 WifiTxTimer::FeedTraceSource<Ptr<WifiPsdu>, WifiTxVector> (Ptr<WifiPsdu> psdu,
134  WifiTxVector txVector)
135 {
136  if (!m_psduResponseTimeoutCallback.IsNull ())
137  {
138  m_psduResponseTimeoutCallback (m_reason, psdu, txVector);
139  }
140 }
141 
142 } //namespace ns3
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:204
std::string GetReasonString(Reason reason) const
Get a string associated with the given reason.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
microsecond
Definition: nstime.h:117
Callback template class.
Definition: callback.h:1278
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
virtual ~WifiTxTimer()
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Reason
The reason why the timer was started.
Definition: wifi-tx-timer.h:50
void SetMpduResponseTimeoutCallback(MpduResponseTimeout callback) const
Set the callback to invoke when the TX timer following the transmission of an MPDU expires...
EventId m_timeoutEvent
the timeout event after a missing response
Reason GetReason(void) const
Get the reason why the timer was started.
bool m_rescheduled
whether the timer has been already rescheduled
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiTxTimer()
Default constructor.
void Cancel(void)
Cancel the timer.
bool IsRunning(void) const
Return true if the timer is running.
MpduResponseTimeout m_mpduResponseTimeoutCallback
the PSDU response timeout callback
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...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
Ptr< EventImpl > m_endRxEvent
event to schedule upon RXSTART.indication
#define FOO(x)
PsduResponseTimeout m_psduResponseTimeoutCallback
Reason m_reason
the reason why the timer was started
Time GetDelayLeft(void) const
Get the remaining time until the timer will expire.