A Discrete-Event Network Simulator
API
dcf-state.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "dcf-state.h"
23 #include "dca-txop.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("DcfState");
28 
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::DcfState")
35  .SetParent<Object> ()
36  .SetGroupName ("Wifi")
37  ;
38  return tid;
39 }
40 
42  : m_backoffSlots (0),
43  m_backoffStart (Seconds (0.0)),
44  m_cwMin (0),
45  m_cwMax (0),
46  m_cw (0),
47  m_accessRequested (false),
48  m_txop (txop)
49 {
50  NS_LOG_FUNCTION (this);
51 }
52 
54 {
55  NS_LOG_FUNCTION (this);
56 }
57 
58 void
60 {
61  NS_LOG_FUNCTION (this);
62  m_txop->Dispose ();
63  m_txop = 0;
64 }
65 
66 void
67 DcfState::SetAifsn (uint32_t aifsn)
68 {
69  NS_LOG_FUNCTION (this << aifsn);
70  m_aifsn = aifsn;
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this << txopLimit);
77  NS_ASSERT_MSG ((txopLimit.GetMicroSeconds () % 32 == 0), "The TXOP limit must be expressed in multiple of 32 microseconds!");
78  m_txopLimit = txopLimit;
79 }
80 
81 void
82 DcfState::SetCwMin (uint32_t minCw)
83 {
84  NS_LOG_FUNCTION (this << minCw);
85  bool changed = (m_cwMin != minCw);
86  m_cwMin = minCw;
87  if (changed == true)
88  {
89  ResetCw ();
90  }
91 }
92 
93 void
94 DcfState::SetCwMax (uint32_t maxCw)
95 {
96  NS_LOG_FUNCTION (this << maxCw);
97  bool changed = (m_cwMax != maxCw);
98  m_cwMax = maxCw;
99  if (changed == true)
100  {
101  ResetCw ();
102  }
103 }
104 
105 uint32_t
106 DcfState::GetAifsn (void) const
107 {
108  return m_aifsn;
109 }
110 
111 Time
113 {
114  return m_txopLimit;
115 }
116 
117 uint32_t
118 DcfState::GetCwMin (void) const
119 {
120  return m_cwMin;
121 }
122 
123 uint32_t
124 DcfState::GetCwMax (void) const
125 {
126  return m_cwMax;
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION (this);
133  m_cw = m_cwMin;
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION (this);
140  //see 802.11-2012, section 9.19.2.5
141  m_cw = std::min ( 2 * (m_cw + 1) - 1, m_cwMax);
142 }
143 
144 void
145 DcfState::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
146 {
147  NS_LOG_FUNCTION (this << nSlots << backoffUpdateBound);
148  m_backoffSlots -= nSlots;
149  m_backoffStart = backoffUpdateBound;
150  NS_LOG_DEBUG ("update slots=" << nSlots << " slots, backoff=" << m_backoffSlots);
151 }
152 
153 void
154 DcfState::StartBackoffNow (uint32_t nSlots)
155 {
156  NS_LOG_FUNCTION (this << nSlots);
157  if (m_backoffSlots != 0)
158  {
159  NS_LOG_DEBUG ("reset backoff from " << m_backoffSlots << " to " << nSlots << " slots");
160  }
161  else
162  {
163  NS_LOG_DEBUG ("start backoff=" << nSlots << " slots");
164  }
165  m_backoffSlots = nSlots;
167 }
168 
169 uint32_t
170 DcfState::GetCw (void) const
171 {
172  return m_cw;
173 }
174 
175 uint32_t
177 {
178  return m_backoffSlots;
179 }
180 
181 Time
183 {
184  return m_backoffStart;
185 }
186 
187 bool
189 {
190  return m_accessRequested;
191 }
192 
193 void
195 {
196  NS_LOG_FUNCTION (this);
197  m_accessRequested = true;
198 }
199 
200 void
202 {
203  NS_LOG_FUNCTION (this);
205  m_accessRequested = false;
206  m_txop->NotifyAccessGranted ();
207 }
208 
209 void
211 {
212  NS_LOG_FUNCTION (this);
213  m_txop->NotifyCollision ();
214 }
215 
216 void
218 {
219  NS_LOG_FUNCTION (this);
220  m_txop->NotifyInternalCollision ();
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION (this);
227  m_txop->NotifyChannelSwitching ();
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION (this);
234  m_txop->NotifySleep ();
235 }
236 
237 void
239 {
240  NS_LOG_FUNCTION (this);
241  m_txop->NotifyWakeUp ();
242 }
243 
244 bool
245 DcfState::IsEdca (void) const
246 {
247  NS_LOG_FUNCTION (this);
248  return m_txop->IsEdca ();
249 }
250 
251 } //namespace ns3
uint32_t m_cwMin
the CW minimum
Definition: dcf-state.h:209
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: dcf-state.cc:74
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void NotifySleep(void)
Notify that the device has started to sleep.
Definition: dcf-state.cc:231
DcfState(Ptr< DcaTxop > txop)
Constructor.
Definition: dcf-state.cc:41
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void NotifyInternalCollision(void)
Notify that internal collision has occurred.
Definition: dcf-state.cc:217
uint32_t GetCwMin(void) const
Return the minimum congestion window size.
Definition: dcf-state.cc:118
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define min(a, b)
Definition: 80211b.c:44
void NotifyAccessGranted(void)
Notify that access has been granted.
Definition: dcf-state.cc:201
Time GetBackoffStart(void) const
Return the time when the backoff procedure started.
Definition: dcf-state.cc:182
#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:201
void NotifyWakeUp(void)
Notify that the device has started to wake up.
Definition: dcf-state.cc:238
Ptr< DcaTxop > m_txop
the DCA TXOP
Definition: dcf-state.h:214
bool m_accessRequested
flag whether channel access is already requested
Definition: dcf-state.h:213
void SetAifsn(uint32_t aifsn)
Definition: dcf-state.cc:67
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Definition: dcf-state.cc:130
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: dcf-state.cc:112
uint32_t m_backoffSlots
the backoff slots
Definition: dcf-state.h:202
Time m_txopLimit
the txop limit time
Definition: dcf-state.h:212
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:349
bool IsAccessRequested(void) const
Definition: dcf-state.cc:188
void DoDispose(void)
Destructor implementation.
Definition: dcf-state.cc:59
uint32_t GetBackoffSlots(void) const
Return the current number of backoff slots.
Definition: dcf-state.cc:176
virtual ~DcfState()
Definition: dcf-state.cc:53
uint32_t GetCwMax(void) const
Return the maximum congestion window size.
Definition: dcf-state.cc:124
void SetCwMin(uint32_t minCw)
Set the minimum congestion window size.
Definition: dcf-state.cc:82
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-state.cc:154
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_cwMax
the CW maximum
Definition: dcf-state.h:210
void NotifyAccessRequested(void)
Notify that access request has been received.
Definition: dcf-state.cc:194
uint32_t m_cw
the current CW
Definition: dcf-state.h:211
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
void SetCwMax(uint32_t maxCw)
Set the maximum congestion window size.
Definition: dcf-state.cc:94
void NotifyChannelSwitching(void)
Notify that the device is switching channel.
Definition: dcf-state.cc:224
uint32_t GetCw(void) const
Definition: dcf-state.cc:170
uint32_t GetAifsn(void) const
Return the number of slots that make up an AIFS.
Definition: dcf-state.cc:106
uint32_t m_aifsn
the AIFSN
Definition: dcf-state.h:201
void UpdateBackoffSlotsNow(uint32_t nSlots, Time backoffUpdateBound)
Update backoff slots that nSlots has passed.
Definition: dcf-state.cc:145
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
static TypeId GetTypeId(void)
Get the type ID.
Definition: dcf-state.cc:32
bool IsEdca(void) const
Definition: dcf-state.cc:245
void NotifyCollision(void)
Notify that collision has occurred.
Definition: dcf-state.cc:210
Time m_backoffStart
the backoffStart variable is used to keep track of the time at which a backoff was started or the tim...
Definition: dcf-state.h:208
A base class which provides memory management and object aggregation.
Definition: object.h:87
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Definition: dcf-state.cc:137
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914