A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-mac-queue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005, 2009 INRIA
3 * Copyright (c) 2009 MIRKO BANCHI
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 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Mirko Banchi <mk.banchi@gmail.com>
20 * Stefano Avallone <stavallo@unina.it>
21 */
22
23#ifndef WIFI_MAC_QUEUE_H
24#define WIFI_MAC_QUEUE_H
25
26#include "qos-utils.h"
28#include "wifi-mpdu.h"
29
30#include "ns3/queue.h"
31
32#include <functional>
33#include <optional>
34#include <unordered_map>
35
36namespace ns3
37{
38
39class WifiMacQueueScheduler;
40
41// The following explicit template instantiation declaration prevents modules
42// including this header file from implicitly instantiating Queue<WifiMpdu>.
43// This would cause python examples using wifi to crash at runtime with the
44// following error message: "Trying to allocate twice the same UID:
45// ns3::Queue<WifiMpdu>"
46extern template class Queue<WifiMpdu, ns3::WifiMacQueueContainer>;
47
48/**
49 * \ingroup wifi
50 *
51 * This queue implements the timeout procedure described in
52 * (Section 9.19.2.6 "Retransmit procedures" paragraph 6; IEEE 802.11-2012).
53 *
54 * When a packet is received by the MAC, to be sent to the PHY,
55 * it is queued in the internal queue after being tagged by the
56 * current time.
57 *
58 * When a packet is dequeued, the queue checks its timestamp
59 * to verify whether or not it should be dropped. If
60 * dot11EDCATableMSDULifetime has elapsed, it is dropped.
61 * Otherwise, it is returned to the caller.
62 *
63 * Compiling python bindings fails if the namespace (ns3) is not
64 * specified for WifiMacQueueContainerT.
65 */
67{
68 public:
69 /**
70 * \brief Get the type ID.
71 * \return the object TypeId
72 */
73 static TypeId GetTypeId();
74
75 /**
76 * Constructor
77 *
78 * \param ac the Access Category of the packets stored in this queue
79 */
81
82 ~WifiMacQueue() override;
83
84 /// allow the usage of iterators and const iterators
85 using Queue<WifiMpdu, WifiMacQueueContainer>::ConstIterator;
86 using Queue<WifiMpdu, WifiMacQueueContainer>::Iterator;
87 using Queue<WifiMpdu, WifiMacQueueContainer>::IsEmpty;
88 using Queue<WifiMpdu, WifiMacQueueContainer>::GetNPackets;
89 using Queue<WifiMpdu, WifiMacQueueContainer>::GetNBytes;
90
91 /**
92 * Get the Access Category of the packets stored in this queue
93 *
94 * \return the Access Category of the packets stored in this queue
95 */
96 AcIndex GetAc() const;
97
98 /**
99 * Set the wifi MAC queue scheduler
100 *
101 * \param scheduler the wifi MAC queue scheduler
102 */
103 void SetScheduler(Ptr<WifiMacQueueScheduler> scheduler);
104
105 /**
106 * Set the maximum delay before the packet is discarded.
107 *
108 * \param delay the maximum delay
109 */
110 void SetMaxDelay(Time delay);
111 /**
112 * Return the maximum delay before the packet is discarded.
113 *
114 * \return the maximum delay
115 */
116 Time GetMaxDelay() const;
117
118 /**
119 * Enqueue the given Wifi MAC queue item at the <i>end</i> of the queue.
120 *
121 * \param item the Wifi MAC queue item to be enqueued at the end
122 * \return true if success, false if the packet has been dropped
123 */
124 bool Enqueue(Ptr<WifiMpdu> item) override;
125 /**
126 * Dequeue the packet in the front of the queue.
127 *
128 * \return the packet
129 */
130 Ptr<WifiMpdu> Dequeue() override;
131 /**
132 * Dequeue the given MPDUs if they are stored in this queue.
133 *
134 * \param mpdus the given MPDUs
135 */
136 void DequeueIfQueued(const std::list<Ptr<const WifiMpdu>>& mpdus);
137 /**
138 * Peek the packet in the front of the queue. The packet is not removed.
139 *
140 * \return the packet
141 */
142 Ptr<const WifiMpdu> Peek() const override;
143 /**
144 * Peek the packet in the front of the queue for transmission on the given
145 * link (if any). The packet is not removed.
146 *
147 * \param linkId the ID of the link onto which we can transmit a packet
148 * \return the packet
149 */
150 Ptr<WifiMpdu> Peek(std::optional<uint8_t> linkId) const;
151 /**
152 * Search and return, if present in the queue, the first packet having the
153 * receiver address equal to <i>dest</i>, and TID equal to <i>tid</i>.
154 * If <i>item</i> is not a null pointer, the search starts from the packet
155 * following <i>item</i> in the queue; otherwise, the search starts from the
156 * head of the queue. This method does not remove the packet from the queue.
157 * It is typically used by ns3::QosTxop in order to perform correct MSDU aggregation
158 * (A-MSDU).
159 *
160 * \param tid the given TID
161 * \param dest the given destination
162 * \param item the item after which the search starts from
163 *
164 * \return the peeked packet or nullptr if no packet was found
165 */
166 Ptr<WifiMpdu> PeekByTidAndAddress(uint8_t tid,
167 Mac48Address dest,
168 Ptr<const WifiMpdu> item = nullptr) const;
169 /**
170 * Search and return the first packet present in the container queue identified
171 * by the given queue ID. If <i>item</i> is a null pointer, the search starts from
172 * the head of the container queue; MPDUs with expired lifetime at the head of the
173 * container queue are ignored (and moved to the container queue storing MPDUs with
174 * expired lifetime). If <i>item</i> is not a null pointer, the search starts from
175 * the packet following <i>item</i> in the container queue (and we do not check for
176 * expired lifetime because we assume that a previous call was made with a null
177 * pointer as argument, which removed the MPDUs with expired lifetime).
178 *
179 * \param queueId the given queue ID
180 * \param item the item after which the search starts from
181 * \return the peeked packet or nullptr if no packet was found
182 */
183 Ptr<WifiMpdu> PeekByQueueId(const WifiContainerQueueId& queueId,
184 Ptr<const WifiMpdu> item = nullptr) const;
185
186 /**
187 * Return first available packet for transmission on the given link. If <i>item</i>
188 * is not a null pointer, the search starts from the packet following <i>item</i>
189 * in the queue; otherwise, the search starts from the head of the queue.
190 * The packet is not removed from queue.
191 *
192 * \param linkId the ID of the given link
193 * \param item the item after which the search starts from
194 *
195 * \return the peeked packet or nullptr if no packet was found
196 */
197 Ptr<WifiMpdu> PeekFirstAvailable(uint8_t linkId, Ptr<const WifiMpdu> item = nullptr) const;
198 /**
199 * Remove the packet in the front of the queue.
200 *
201 * \return the packet
202 */
203 Ptr<WifiMpdu> Remove() override;
204 /**
205 * Remove the given item from the queue and return the item following the
206 * removed one, if any, or a null pointer otherwise. If <i>removeExpired</i> is
207 * true, all the items in the queue from the head to the given position are
208 * removed if their lifetime expired.
209 *
210 * \param item the item to be removed
211 * \return the removed item
212 */
214
215 /**
216 * Flush the queue.
217 */
218 void Flush();
219
220 /**
221 * Replace the given current item with the given new item. Actually, the current
222 * item is dequeued and the new item is enqueued in its place. In this way,
223 * statistics about queue size (in terms of bytes) are correctly updated.
224 *
225 * \param currentItem the given current item
226 * \param newItem the given new item
227 */
228 void Replace(Ptr<const WifiMpdu> currentItem, Ptr<WifiMpdu> newItem);
229
230 /**
231 * Get the number of MPDUs currently stored in the container queue identified
232 * by the given queue ID.
233 *
234 * \param queueId the given queue ID
235 * \return the number of MPDUs currently stored in the container queue
236 */
237 uint32_t GetNPackets(const WifiContainerQueueId& queueId) const;
238
239 /**
240 * Get the amount of bytes currently stored in the container queue identified
241 * by the given queue ID.
242 *
243 * \param queueId the given queue ID
244 * \return the amount of bytes currently stored in the container queue
245 */
246 uint32_t GetNBytes(const WifiContainerQueueId& queueId) const;
247
248 /**
249 * Remove the given item if it has been in the queue for too long. Return true
250 * if the item is removed, false otherwise.
251 *
252 * \param item the item whose lifetime is checked
253 * \param now a copy of Simulator::Now()
254 * \return true if the item is removed, false otherwise
255 */
256 bool TtlExceeded(Ptr<const WifiMpdu> item, const Time& now);
257
258 /**
259 * Move MPDUs with expired lifetime from the container queue identified by the
260 * given queue ID to the container queue storing MPDUs with expired lifetime.
261 * Each MPDU that is found to have an expired lifetime feeds the "Expired"
262 * trace source and is notified to the scheduler.
263 * \note that such MPDUs are not removed from the WifiMacQueue (and hence are
264 * still accounted for in the overall statistics kept by the Queue base class)
265 * in order to make this method const.
266 *
267 * \param queueId the given queue ID
268 */
269 void ExtractExpiredMpdus(const WifiContainerQueueId& queueId) const;
270 /**
271 * Move MPDUs with expired lifetime from all the container queues to the
272 * container queue storing MPDUs with expired lifetime. Each MPDU that is found
273 * to have an expired lifetime feeds the "Expired" trace source and is notified
274 * to the scheduler.
275 * \note that such MPDUs are not removed from the WifiMacQueue (and hence are
276 * still accounted for in the overall statistics kept by the Queue base class)
277 * in order to make this method const.
278 */
279 void ExtractAllExpiredMpdus() const;
280 /**
281 * Remove all MPDUs with expired lifetime from this WifiMacQueue object.
282 */
283 void WipeAllExpiredMpdus();
284
285 /**
286 * Unlike the GetOriginal() method of WifiMpdu, this method returns a non-const
287 * pointer to the original copy of the given MPDU.
288 *
289 * \param mpdu the given MPDU
290 * \return the original copy of the given MPDU
291 */
292 Ptr<WifiMpdu> GetOriginal(Ptr<WifiMpdu> mpdu);
293
294 /**
295 * \param mpdu the given MPDU
296 * \param linkId the ID of the given link
297 * \return the alias of the given MPDU that is inflight on the given link, if any, or
298 * a null pointer, otherwise
299 */
300 Ptr<WifiMpdu> GetAlias(Ptr<const WifiMpdu> mpdu, uint8_t linkId);
301
302 protected:
303 using Queue<WifiMpdu, WifiMacQueueContainer>::GetContainer;
304
305 void DoDispose() override;
306
307 private:
308 /**
309 * \param mpdu the given MPDU
310 * \return the queue iterator stored by the given MPDU
311 */
312 Iterator GetIt(Ptr<const WifiMpdu> mpdu) const;
313
314 /**
315 * Enqueue the given Wifi MAC queue item before the given position.
316 *
317 * \param pos the position before which the item is to be inserted
318 * \param item the Wifi MAC queue item to be enqueued
319 * \return true if success, false if the packet has been dropped
320 */
321 bool Insert(ConstIterator pos, Ptr<WifiMpdu> item);
322 /**
323 * Wrapper for the DoEnqueue method provided by the base class that additionally
324 * sets the iterator field of the item and updates internal statistics, if
325 * insertion succeeded.
326 *
327 * \param pos the position before where the item will be inserted
328 * \param item the item to enqueue
329 * \return true if success, false if the packet has been dropped.
330 */
331 bool DoEnqueue(ConstIterator pos, Ptr<WifiMpdu> item);
332 /**
333 * Wrapper for the DoDequeue method provided by the base class that additionally
334 * resets the iterator field of the dequeued items and notifies the scheduler, if
335 * any item was dequeued.
336 *
337 * \param iterators the list of iterators pointing to the items to dequeue
338 */
339 void DoDequeue(const std::list<ConstIterator>& iterators);
340 /**
341 * Wrapper for the DoRemove method provided by the base class that additionally
342 * resets the iterator field of the item and notifies the scheduleer, if an
343 * item was dropped.
344 *
345 * \param pos the position of the item to drop
346 * \return the dropped item.
347 */
348 Ptr<WifiMpdu> DoRemove(ConstIterator pos);
349
350 Time m_maxDelay; //!< Time to live for packets in the queue
351 AcIndex m_ac; //!< the access category
352 Ptr<WifiMacQueueScheduler> m_scheduler; //!< the MAC queue scheduler
353
354 /// Traced callback: fired when a packet is dropped due to lifetime expiration
356
357 NS_LOG_TEMPLATE_DECLARE; //!< redefinition of the log component
358};
359
360} // namespace ns3
361
362#endif /* WIFI_MAC_QUEUE_H */
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Template class for packet Queues.
Definition: queue.h:268
Container::iterator Iterator
Iterator.
Definition: queue.h:321
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Class for the container used by WifiMacQueue.
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
Time m_maxDelay
Time to live for packets in the queue.
Ptr< WifiMacQueueScheduler > m_scheduler
the MAC queue scheduler
NS_LOG_TEMPLATE_DECLARE
redefinition of the log component
TracedCallback< Ptr< const WifiMpdu > > m_traceExpired
Traced callback: fired when a packet is dropped due to lifetime expiration.
AcIndex m_ac
the access category
WifiMpdu stores a (const) packet along with a MAC header.
Definition: wifi-mpdu.h:62
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:87
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.