16#include "ns3/simulator.h"
33 TypeId(
"ns3::WifiMacQueue")
37 .AddAttribute(
"MaxSize",
42 .AddAttribute(
"MaxDelay",
43 "If a packet stays longer than this delay in the queue, it is dropped.",
47 .AddTraceSource(
"Expired",
48 "MPDU dropped because its lifetime expired.",
50 "ns3::WifiMpdu::TracedCallback");
89 return GetIt(mpdu)->mpdu;
95 if (!mpdu->IsQueued())
99 if (
auto aliasIt =
GetIt(mpdu)->inflights.find(linkId);
100 aliasIt !=
GetIt(mpdu)->inflights.cend())
102 return aliasIt->second;
112 std::list<Ptr<WifiMpdu>> mpdus;
115 for (
auto it =
first; it != last; it++)
117 mpdus.push_back(it->mpdu);
119 for (
const auto& mpdu : mpdus)
122 auto fire = [
this, mpdu]() ->
void { this->
m_traceExpired(mpdu); };
137 std::list<Ptr<WifiMpdu>> mpdus;
140 for (
auto it =
first; it != last; it++)
142 mpdus.push_back(it->mpdu);
144 for (
const auto& mpdu : mpdus)
147 auto fire = [
this, mpdu]() ->
void { this->
m_traceExpired(mpdu); };
166 for (
auto it =
first; it != last;)
180 auto it =
GetIt(item);
181 if (now > it->expiryTime)
183 NS_LOG_DEBUG(
"Removing packet that stayed in the queue for too long (queuing time="
192 if (item->IsQueued())
235 "WifiMacQueues must be in packet mode");
249 "pos must point to an element in the same container queue as item");
277 std::list<ConstIterator> iterators;
279 for (
const auto& mpdu : mpdus)
281 if (mpdu->IsQueued())
283 auto it =
GetIt(mpdu);
285 NS_ASSERT(it->mpdu == mpdu->GetOriginal());
286 iterators.emplace_back(it);
296 return Peek(std::nullopt);
306 if (!queueId.has_value())
364 std::optional<WifiContainerQueueId> queueId;
375 if (!queueId.has_value())
395 auto it =
GetIt(mpdu);
397 NS_ASSERT(it->mpdu == mpdu->GetOriginal());
418 auto currentIt =
GetIt(currentItem);
420 NS_ASSERT(currentIt->mpdu == currentItem->GetOriginal());
423 Time expiryTime = currentIt->expiryTime;
424 auto pos = std::next(currentIt);
426 bool ret =
Insert(pos, newItem);
427 GetIt(newItem)->expiryTime = expiryTime;
453 if (item->GetHeader().IsCtl())
467 if (pos !=
GetContainer().GetQueue(queueId).cend() && mpdu && pos->mpdu == mpdu->GetOriginal())
470 pos = std::next(pos);
481 item->SetQueueIt(ret, {});
485 ret->deleter = [tag](
auto mpdu) { mpdu->SetQueueIt(std::nullopt, tag); };
499 std::list<Ptr<WifiMpdu>> items;
502 for (
auto& it : iterators)
506 items.push_back(item);
507 if (item->GetHeader().IsCtl())
530 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
ns3::WifiMacQueueContainer::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 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.
void DequeueIfQueued(const std::list< Ptr< const WifiMpdu > > &mpdus)
Dequeue the given MPDUs if they are stored in this queue.
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 > MakeQueueSizeAccessor(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 AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeQueueSizeChecker()
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.