27 #include "ns3/simulator.h"
44 TypeId(
"ns3::WifiMacQueue")
48 .AddAttribute(
"MaxSize",
52 MakeQueueSizeChecker())
53 .AddAttribute(
"MaxDelay",
54 "If a packet stays longer than this delay in the queue, it is dropped.",
58 .AddTraceSource(
"Expired",
59 "MPDU dropped because its lifetime expired.",
61 "ns3::WifiMpdu::TracedCallback");
100 return GetIt(mpdu)->mpdu;
106 if (!mpdu->IsQueued())
110 if (
auto aliasIt =
GetIt(mpdu)->inflights.find(linkId);
111 aliasIt !=
GetIt(mpdu)->inflights.cend())
113 return aliasIt->second;
123 std::list<Ptr<WifiMpdu>> mpdus;
126 for (
auto it =
first; it != last; it++)
128 mpdus.push_back(it->mpdu);
130 for (
const auto& mpdu : mpdus)
147 std::list<Ptr<WifiMpdu>> mpdus;
150 for (
auto it =
first; it != last; it++)
152 mpdus.push_back(it->mpdu);
154 for (
const auto& mpdu : mpdus)
175 for (
auto it =
first; it != last;)
189 auto it =
GetIt(item);
190 if (now > it->expiryTime)
192 NS_LOG_DEBUG(
"Removing packet that stayed in the queue for too long (queuing time="
201 if (item->IsQueued())
244 "WifiMacQueues must be in packet mode");
258 "pos must point to an element in the same container queue as item");
286 std::list<ConstIterator> iterators;
288 for (
const auto& mpdu : mpdus)
290 if (mpdu->IsQueued())
292 auto it =
GetIt(mpdu);
294 NS_ASSERT(it->mpdu == mpdu->GetOriginal());
295 iterators.emplace_back(it);
305 return Peek(std::nullopt);
315 if (!queueId.has_value())
373 std::optional<WifiContainerQueueId> queueId;
384 if (!queueId.has_value())
404 auto it =
GetIt(mpdu);
406 NS_ASSERT(it->mpdu == mpdu->GetOriginal());
427 auto currentIt =
GetIt(currentItem);
429 NS_ASSERT(currentIt->mpdu == currentItem->GetOriginal());
432 Time expiryTime = currentIt->expiryTime;
433 auto pos = std::next(currentIt);
435 bool ret =
Insert(pos, newItem);
436 GetIt(newItem)->expiryTime = expiryTime;
462 if (item->GetHeader().IsCtl())
476 if (pos !=
GetContainer().GetQueue(queueId).cend() && mpdu && pos->mpdu == mpdu->GetOriginal())
479 pos = std::next(pos);
490 item->SetQueueIt(ret, {});
494 ret->deleter = [tag](
auto mpdu) { mpdu->SetQueueIt(std::nullopt, tag); };
508 std::list<Ptr<WifiMpdu>> items;
511 for (
auto& it : iterators)
515 items.push_back(item);
516 if (item->GetHeader().IsCtl())
539 if (item->GetHeader().IsCtl())
Smart pointer class similar to boost::intrusive_ptr.
QueueSize GetMaxSize() const
uint32_t GetNBytes() const
uint32_t GetNPackets() const
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Template class for packet Queues.
Ptr< Item > DoRemove(ConstIterator pos)
Pull the item to drop from the queue.
void Flush()
Flush the queue by calling Remove() on each item enqueued.
void DoDispose() override
Destructor implementation.
const ns3::WifiMacQueueContainer & GetContainer() const
Get a const reference to the container of queue items.
Container::iterator Iterator
Iterator.
Class for representing queue sizes.
static Time Now()
Return the current simulation virtual time.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Simulation virtual time values and global simulation resolution.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
const ContainerQueue & GetQueue(const WifiContainerQueueId &queueId) const
Get a const reference to the container queue identified by the given QueueId.
static WifiContainerQueueId GetQueueId(Ptr< const WifiMpdu > mpdu)
Return the QueueId identifying the container queue in which the given MPDU is (or is to be) enqueued.
uint32_t GetNBytes(const WifiContainerQueueId &queueId) const
Get the total size of the MPDUs stored in the queue identified by the given QueueId.
std::pair< iterator, iterator > ExtractAllExpiredMpdus() const
Transfer non-inflight MPDUs with expired lifetime in all the container queues to the container queue ...
std::pair< iterator, iterator > GetAllExpiredMpdus() const
Get the range [first, last) of iterators pointing to all the MPDUs queued in the container queue stor...
std::pair< iterator, iterator > ExtractExpiredMpdus(const WifiContainerQueueId &queueId) const
Transfer non-inflight MPDUs with expired lifetime in the container queue identified by the given Queu...
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.
void Replace(Ptr< const WifiMpdu > currentItem, Ptr< WifiMpdu > newItem)
Replace the given current item with the given new item.
Ptr< WifiMpdu > PeekByQueueId(const WifiContainerQueueId &queueId, Ptr< const WifiMpdu > item=nullptr) const
Search and return the first packet present in the container queue identified by the given queue ID.
Ptr< WifiMpdu > Remove() override
Remove the packet in the front of the queue.
Ptr< WifiMacQueueScheduler > m_scheduler
the MAC queue scheduler
AcIndex GetAc() const
Get the Access Category of the packets stored in this queue.
bool Insert(ConstIterator pos, Ptr< WifiMpdu > item)
Enqueue the given Wifi MAC queue item before the given position.
void ExtractExpiredMpdus(const WifiContainerQueueId &queueId) const
Move MPDUs with expired lifetime from the container queue identified by the given queue ID to the con...
bool Enqueue(Ptr< WifiMpdu > item) override
Enqueue the given Wifi MAC queue item at the end of the queue.
Ptr< const WifiMpdu > Peek() const override
Peek the packet in the front of the queue.
Iterator GetIt(Ptr< const WifiMpdu > mpdu) const
bool TtlExceeded(Ptr< const WifiMpdu > item, const Time &now)
Remove the given item if it has been in the queue for too long.
void WipeAllExpiredMpdus()
Remove all MPDUs with expired lifetime from this WifiMacQueue object.
Ptr< WifiMpdu > Dequeue() override
Dequeue the packet in the front of the queue.
void SetScheduler(Ptr< WifiMacQueueScheduler > scheduler)
Set the wifi MAC queue scheduler.
void SetMaxDelay(Time delay)
Set the maximum delay before the packet is discarded.
void DequeueIfQueued(const std::list< Ptr< const WifiMpdu >> &mpdus)
Dequeue the given MPDUs if they are stored in this queue.
void DoDispose() override
Destructor implementation.
Ptr< WifiMpdu > GetAlias(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Ptr< WifiMpdu > DoRemove(ConstIterator pos)
Wrapper for the DoRemove method provided by the base class that additionally resets the iterator fiel...
Ptr< WifiMpdu > GetOriginal(Ptr< WifiMpdu > mpdu)
Unlike the GetOriginal() method of WifiMpdu, this method returns a non-const pointer to the original ...
WifiMacQueue(AcIndex ac=AC_UNDEF)
Constructor.
Ptr< WifiMpdu > PeekFirstAvailable(uint8_t linkId, Ptr< const WifiMpdu > item=nullptr) const
Return first available packet for transmission on the given link.
TracedCallback< Ptr< const WifiMpdu > > m_traceExpired
Traced callback: fired when a packet is dropped due to lifetime expiration.
bool DoEnqueue(ConstIterator pos, Ptr< WifiMpdu > item)
Wrapper for the DoEnqueue method provided by the base class that additionally sets the iterator field...
AcIndex m_ac
the access category
Ptr< WifiMpdu > PeekByTidAndAddress(uint8_t tid, Mac48Address dest, Ptr< const WifiMpdu > item=nullptr) const
Search and return, if present in the queue, the first packet having the receiver address equal to des...
void Flush()
Flush the queue.
void DoDequeue(const std::list< ConstIterator > &iterators)
Wrapper for the DoDequeue method provided by the base class that additionally resets the iterator fie...
void ExtractAllExpiredMpdus() const
Move MPDUs with expired lifetime from all the container queues to the container queue storing MPDUs w...
static TypeId GetTypeId()
Get the type ID.
Time GetMaxDelay() const
Return the maximum delay before the packet is discarded.
Tag used to allow (only) WifiMacQueue to access the queue iterator stored by a WifiMpdu.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_TEMPLATE_CLASS_TWO_DEFINE(type, param1, param2)
Explicitly instantiate a template class with two template parameters and register the resulting insta...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
@ PACKETS
Use number of packets for queue size.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
std::tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.