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 
32 namespace ns3 {
33 
34 class QosBlockedDestinations;
35 
36 // The following explicit template instantiation declaration prevents modules
37 // including this header file from implicitly instantiating Queue<WifiMacQueueItem>.
38 // This would cause python examples using wifi to crash at runtime with the
39 // following error message: "Trying to allocate twice the same UID:
40 // ns3::Queue<WifiMacQueueItem>"
41 extern template class Queue<WifiMacQueueItem>;
42 
43 
60 {
61 public:
66  static TypeId GetTypeId (void);
67 
74 
75  ~WifiMacQueue ();
76 
79  {
81  DROP_OLDEST
82  };
83 
89 
95  void SetMaxDelay (Time delay);
101  Time GetMaxDelay (void) const;
102 
109  bool Enqueue (Ptr<WifiMacQueueItem> item) override;
116  bool PushFront (Ptr<WifiMacQueueItem> item);
124  bool Insert (ConstIterator pos, Ptr<WifiMacQueueItem> item);
130  Ptr<WifiMacQueueItem> Dequeue (void) override;
136  void DequeueIfQueued (Ptr<const WifiMacQueueItem> mpdu);
142  Ptr<const WifiMacQueueItem> Peek (void) const override;
155  ConstIterator PeekByAddress (Mac48Address dest, ConstIterator pos = EMPTY) const;
167  ConstIterator PeekByTid (uint8_t tid, ConstIterator pos = EMPTY) const;
182  ConstIterator PeekByTidAndAddress (uint8_t tid, Mac48Address dest, ConstIterator pos = EMPTY) const;
191  ConstIterator PeekFirstAvailable (const Ptr<QosBlockedDestinations> blockedPackets = nullptr,
192  ConstIterator pos = EMPTY) const;
198  Ptr<WifiMacQueueItem> Remove (void) override;
208  bool Remove (Ptr<const Packet> packet);
219  ConstIterator Remove (ConstIterator pos, bool removeExpired = false);
228  uint32_t GetNPacketsByAddress (Mac48Address dest);
239  uint32_t GetNPacketsByTidAndAddress (uint8_t tid, Mac48Address dest);
240 
252  uint32_t GetNPackets (uint8_t tid, Mac48Address dest) const;
264  uint32_t GetNBytes (uint8_t tid, Mac48Address dest) const;
265 
271  bool IsEmpty (void);
272 
278  uint32_t GetNPackets (void);
279 
285  uint32_t GetNBytes (void);
286 
296  inline bool TtlExceeded (ConstIterator &it, const Time& now);
297 
298  static const ConstIterator EMPTY;
299 
300 
301 private:
311  bool DoEnqueue (ConstIterator pos, Ptr<WifiMacQueueItem> item);
320  Ptr<WifiMacQueueItem> DoDequeue (ConstIterator pos);
329  Ptr<WifiMacQueueItem> DoRemove (ConstIterator pos);
330 
334 
336  std::unordered_map<WifiAddressTidPair, uint32_t, WifiAddressTidHash> m_nQueuedPackets;
338  std::unordered_map<WifiAddressTidPair, uint32_t, WifiAddressTidHash> m_nQueuedBytes;
339 
342 
344 };
345 
346 
351 bool
352 WifiMacQueue::TtlExceeded (ConstIterator &it, const Time& now)
353 {
354  if (now > (*it)->GetTimeStamp () + m_maxDelay)
355  {
356  NS_LOG_DEBUG ("Removing packet that stayed in the queue for too long (" <<
357  now - (*it)->GetTimeStamp () << ")");
358  auto curr = it++;
359  m_traceExpired (DoRemove (curr));
360  return true;
361  }
362  return false;
363 }
364 
365 } //namespace ns3
366 
367 #endif /* WIFI_MAC_QUEUE_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::WifiMacQueue
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
Definition: wifi-mac-queue.h:60
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:336
ns3::WifiMacQueue::DoRemove
Ptr< WifiMacQueueItem > DoRemove(ConstIterator pos)
Wrapper for the DoRemove method provided by the base class that additionally resets the iterator fiel...
Definition: wifi-mac-queue.cc:560
ns3::WifiMacQueue::NS_LOG_TEMPLATE_DECLARE
NS_LOG_TEMPLATE_DECLARE
redefinition of the log component
Definition: wifi-mac-queue.h:343
ns3::Ptr< WifiMacQueueItem >
ns3::WifiMacQueue::m_maxDelay
Time m_maxDelay
Time to live for packets in the queue.
Definition: wifi-mac-queue.h:331
ns3::WifiMacQueue::DropPolicy
DropPolicy
drop policy
Definition: wifi-mac-queue.h:79
ns3::WifiMacQueue::m_ac
AcIndex m_ac
the access category
Definition: wifi-mac-queue.h:333
ns3::WifiMacQueue::DROP_NEWEST
@ DROP_NEWEST
Definition: wifi-mac-queue.h:80
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:338
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
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::WifiMacQueue::m_dropPolicy
DropPolicy m_dropPolicy
Drop behavior of queue.
Definition: wifi-mac-queue.h:332
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::EMPTY
static const ConstIterator EMPTY
Invalid iterator to signal an empty queue.
Definition: wifi-mac-queue.h:298
ns3::WifiMacQueue::TtlExceeded
bool TtlExceeded(ConstIterator &it, const Time &now)
Remove the item pointed to by the iterator it if it has been in the queue for too long.
Definition: wifi-mac-queue.h:352
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:341