A Discrete-Event Network Simulator
API
wifi-mac-queue.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2005, 2009 INRIA
4 * Copyright (c) 2009 MIRKO BANCHI
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 * Mirko Banchi <mk.banchi@gmail.com>
21 * Stefano Avallone <stavallo@unina.it>
22 */
23
24#ifndef WIFI_MAC_QUEUE_H
25#define WIFI_MAC_QUEUE_H
26
27#include "wifi-mac-queue-item.h"
28#include "ns3/queue.h"
29#include <unordered_map>
30#include "qos-utils.h"
31#include <functional>
32
33namespace ns3 {
34
35class QosBlockedDestinations;
36
37// The following explicit template instantiation declaration prevents modules
38// including this header file from implicitly instantiating Queue<WifiMacQueueItem>.
39// This would cause python examples using wifi to crash at runtime with the
40// following error message: "Trying to allocate twice the same UID:
41// ns3::Queue<WifiMacQueueItem>"
42extern template class Queue<WifiMacQueueItem>;
43
44
61{
62public:
67 static TypeId GetTypeId (void);
68
75
77
80 {
82 DROP_OLDEST
83 };
84
90
96 void SetMaxDelay (Time delay);
102 Time GetMaxDelay (void) const;
103
110 bool Enqueue (Ptr<WifiMacQueueItem> item) override;
117 bool PushFront (Ptr<WifiMacQueueItem> item);
123 Ptr<WifiMacQueueItem> Dequeue (void) override;
129 void DequeueIfQueued (Ptr<const WifiMacQueueItem> mpdu);
135 Ptr<const WifiMacQueueItem> Peek (void) const override;
148 Ptr<const WifiMacQueueItem> PeekByAddress (Mac48Address dest,
149 Ptr<const WifiMacQueueItem> item = nullptr) const;
162 Ptr<const WifiMacQueueItem> PeekByTid (uint8_t tid,
163 Ptr<const WifiMacQueueItem> item = nullptr) const;
179 Ptr<const WifiMacQueueItem> PeekByTidAndAddress (uint8_t tid, Mac48Address dest,
180 Ptr<const WifiMacQueueItem> item = nullptr) const;
192 Ptr<const WifiMacQueueItem> PeekFirstAvailable (const Ptr<QosBlockedDestinations> blockedPackets = nullptr,
193 Ptr<const WifiMacQueueItem> item = nullptr) const;
199 Ptr<WifiMacQueueItem> Remove (void) override;
210 Ptr<const WifiMacQueueItem> Remove (Ptr<const WifiMacQueueItem> item, bool removeExpired = false);
211
220 void Replace (Ptr<const WifiMacQueueItem> currentItem, Ptr<WifiMacQueueItem> newItem);
245 template <class CALLABLE>
246 void Transform (Ptr<const WifiMacQueueItem> item, CALLABLE func);
247
256 uint32_t GetNPacketsByAddress (Mac48Address dest);
267 uint32_t GetNPacketsByTidAndAddress (uint8_t tid, Mac48Address dest);
268
280 uint32_t GetNPackets (uint8_t tid, Mac48Address dest) const;
292 uint32_t GetNBytes (uint8_t tid, Mac48Address dest) const;
293
299 bool IsEmpty (void);
300
306 uint32_t GetNPackets (void);
307
313 uint32_t GetNBytes (void);
314
323 bool TtlExceeded (Ptr<const WifiMacQueueItem> item, const Time& now);
324
325private:
335 inline bool TtlExceeded (ConstIterator &it, const Time& now);
336
344 bool Insert (ConstIterator pos, Ptr<WifiMacQueueItem> item);
354 bool DoEnqueue (ConstIterator pos, Ptr<WifiMacQueueItem> item);
363 Ptr<WifiMacQueueItem> DoDequeue (ConstIterator pos);
372 Ptr<WifiMacQueueItem> DoRemove (ConstIterator pos);
373
377
379 std::unordered_map<WifiAddressTidPair, uint32_t, WifiAddressTidHash> m_nQueuedPackets;
381 std::unordered_map<WifiAddressTidPair, uint32_t, WifiAddressTidHash> m_nQueuedBytes;
382
385
387};
388
389} // namespace ns3
390
391
392/***************************************************************
393 * Implementation of the templates declared above.
394 ***************************************************************/
395
396namespace ns3 {
397
398template <class CALLABLE>
399void
401{
402 NS_ASSERT (item->IsQueued ());
403 NS_ASSERT (item->m_queueAc == m_ac);
404 NS_ASSERT (*item->m_queueIt == item);
405
406 auto pos = std::next (item->m_queueIt);
407 Ptr<WifiMacQueueItem> mpdu = DoDequeue (item->m_queueIt);
408 NS_ASSERT (mpdu != nullptr);
409 func (mpdu); // python bindings scanning does not like std::invoke (func, mpdu);
410 bool ret = Insert (pos, mpdu);
411 // The size of a WifiMacQueue is measured as number of packets. We dequeued
412 // one packet, so there is certainly room for inserting one packet
413 NS_ABORT_IF (!ret);
414}
415
416} //namespace ns3
417
418#endif /* WIFI_MAC_QUEUE_H */
an EUI-48 address
Definition: mac48-address.h:44
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Introspection did not find any typical Config paths.
Template class for packet Queues.
Definition: queue.h:262
std::list< Ptr< Item > >::iterator Iterator
Iterator.
Definition: queue.h:316
std::list< Ptr< Item > >::const_iterator ConstIterator
Const iterator.
Definition: queue.h:314
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
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.
std::unordered_map< WifiAddressTidPair, uint32_t, WifiAddressTidHash > m_nQueuedBytes
Per (MAC address, TID) pair queued bytes.
Ptr< WifiMacQueueItem > DoDequeue(ConstIterator pos)
Wrapper for the DoDequeue method provided by the base class that additionally resets the iterator fie...
NS_LOG_TEMPLATE_DECLARE
redefinition of the log component
void Transform(Ptr< const WifiMacQueueItem > item, CALLABLE func)
Transform the given item by invoking the given function with the given item as parameter.
std::unordered_map< WifiAddressTidPair, uint32_t, WifiAddressTidHash > m_nQueuedPackets
Per (MAC address, TID) pair queued packets.
DropPolicy
drop policy
bool Insert(ConstIterator pos, Ptr< WifiMacQueueItem > item)
Enqueue the given Wifi MAC queue item before the given position.
TracedCallback< Ptr< const WifiMacQueueItem > > m_traceExpired
Traced callback: fired when a packet is dropped due to lifetime expiration.
AcIndex m_ac
the access category
DropPolicy m_dropPolicy
Drop behavior of queue.
#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_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:71
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:85
Every class exported by the ns3 library is enclosed in the ns3 namespace.