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 
33 namespace ns3 {
34 
35 class 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>"
42 extern template class Queue<WifiMacQueueItem>;
43 
44 
61 {
62 public:
67  static TypeId GetTypeId (void);
68 
75 
76  ~WifiMacQueue ();
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 
325 private:
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 
396 namespace ns3 {
397 
398 template <class CALLABLE>
399 void
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 */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::WifiMacQueue::Transform
void Transform(Ptr< const WifiMacQueueItem > item, CALLABLE func)
Transform the given item by invoking the given function with the given item as parameter.
Definition: wifi-mac-queue.h:400
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::WifiMacQueue
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
Definition: wifi-mac-queue.h:61
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
qos-utils.h
ns3::Queue::ConstIterator
std::list< Ptr< Item > >::const_iterator ConstIterator
Const iterator.
Definition: queue.h:306
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
wifi-mac-queue-item.h
ns3::WifiMacQueue::m_nQueuedPackets
std::unordered_map< WifiAddressTidPair, uint32_t, WifiAddressTidHash > m_nQueuedPackets
Per (MAC address, TID) pair queued packets.
Definition: wifi-mac-queue.h:379
ns3::WifiMacQueue::Insert
bool Insert(ConstIterator pos, Ptr< WifiMacQueueItem > item)
Enqueue the given Wifi MAC queue item before the given position.
Definition: wifi-mac-queue.cc:130
ns3::WifiMacQueue::NS_LOG_TEMPLATE_DECLARE
NS_LOG_TEMPLATE_DECLARE
redefinition of the log component
Definition: wifi-mac-queue.h:386
ns3::Ptr< WifiMacQueueItem >
ns3::WifiMacQueue::m_maxDelay
Time m_maxDelay
Time to live for packets in the queue.
Definition: wifi-mac-queue.h:374
ns3::WifiMacQueue::DropPolicy
DropPolicy
drop policy
Definition: wifi-mac-queue.h:80
ns3::WifiMacQueue::m_ac
AcIndex m_ac
the access category
Definition: wifi-mac-queue.h:376
ns3::WifiMacQueue::DROP_NEWEST
@ DROP_NEWEST
Definition: wifi-mac-queue.h:81
ns3::WifiMacQueue::m_nQueuedBytes
std::unordered_map< WifiAddressTidPair, uint32_t, WifiAddressTidHash > m_nQueuedBytes
Per (MAC address, TID) pair queued bytes.
Definition: wifi-mac-queue.h:381
Queue< WifiMacQueueItem >
Introspection did not find any typical Config paths.
ns3::AC_UNDEF
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:85
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiMacQueue::DoDequeue
Ptr< WifiMacQueueItem > DoDequeue(ConstIterator pos)
Wrapper for the DoDequeue method provided by the base class that additionally resets the iterator fie...
Definition: wifi-mac-queue.cc:549
NS_ABORT_IF
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
ns3::WifiMacQueue::m_dropPolicy
DropPolicy m_dropPolicy
Drop behavior of queue.
Definition: wifi-mac-queue.h:375
ns3::Queue::Iterator
std::list< Ptr< Item > >::iterator Iterator
Iterator.
Definition: queue.h:308
ns3::AcIndex
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:71
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition: traced-callback.h:53
ns3::Queue
Template class for packet Queues.
Definition: queue.h:254
ns3::WifiMacQueue::m_traceExpired
TracedCallback< Ptr< const WifiMacQueueItem > > m_traceExpired
Traced callback: fired when a packet is dropped due to lifetime expiration.
Definition: wifi-mac-queue.h:384