14#include "ns3/mac48-address.h"
15#include "ns3/simulator.h"
36 "pos iterator does not point to the correct container queue");
37 NS_ABORT_MSG_IF(!item->IsOriginal(),
"Only the original copy of an MPDU can be inserted");
40 it->second += item->GetSize();
42 return m_queues[queueId].emplace(pos, item);
56 NS_ASSERT(it->second >= pos->mpdu->GetSize());
57 it->second -= pos->mpdu->GetSize();
73 const auto& hdr = mpdu->GetOriginal()->GetHeader();
76 std::optional<Mac48Address> addr1;
77 std::optional<Mac48Address> addr2;
79 if (hdr.GetAddr1().IsBroadcast())
82 addr2 = hdr.GetAddr2();
84 else if (hdr.GetAddr1().IsGroup())
87 addr1 = hdr.IsQosAmsdu() ? mpdu->begin()->second.GetDestinationAddr() : hdr.GetAddr1();
88 addr2 = hdr.GetAddr2();
93 addr1 = hdr.GetAddr1();
120 if (
auto it =
m_queues.find(queueId); it ==
m_queues.end() || it->second.empty())
127std::pair<WifiMacQueueContainer::iterator, WifiMacQueueContainer::iterator>
133std::pair<WifiMacQueueContainer::iterator, WifiMacQueueContainer::iterator>
136 std::optional<std::pair<WifiMacQueueContainer::iterator, WifiMacQueueContainer::iterator>> ret;
137 auto firstExpiredIt = queue.begin();
138 auto lastExpiredIt = firstExpiredIt;
144 for (firstExpiredIt = lastExpiredIt;
145 firstExpiredIt != queue.end() && !firstExpiredIt->inflights.empty();
146 ++firstExpiredIt, ++lastExpiredIt)
153 ret = std::make_pair(firstExpiredIt, lastExpiredIt);
157 while (lastExpiredIt != queue.end() && lastExpiredIt->expiryTime <= now &&
158 lastExpiredIt->inflights.empty())
160 lastExpiredIt->expired =
true;
163 lastExpiredIt->deleter(lastExpiredIt->mpdu);
168 NS_ASSERT(it->second >= lastExpiredIt->mpdu->GetSize());
169 it->second -= lastExpiredIt->mpdu->GetSize();
174 if (lastExpiredIt == firstExpiredIt)
188std::pair<WifiMacQueueContainer::iterator, WifiMacQueueContainer::iterator>
191 std::optional<WifiMacQueueContainer::iterator> firstExpiredIt;
197 if (firstIt != lastIt && !firstExpiredIt)
200 firstExpiredIt = firstIt;
203 return std::make_pair(firstExpiredIt ? *firstExpiredIt :
m_expiredQueue.end(),
207std::pair<WifiMacQueueContainer::iterator, WifiMacQueueContainer::iterator>
219 return os <<
"CTL_QUEUE";
221 return os <<
"MGT_QUEUE";
223 return os <<
"QOSDATA_QUEUE";
225 return os <<
"DATA_QUEUE";
227 return os <<
"UNKNOWN(" <<
static_cast<uint16_t
>(queueType) <<
")";
236 return os <<
"UNICAST";
238 return os <<
"BROADCAST";
240 return os <<
"GROUPCAST";
242 return os <<
"COUNT";
244 return os <<
"UNKNOWN(" <<
static_cast<uint16_t
>(rcvAddrType) <<
")";
251 if (
const auto& addr1 = queueId.
addr1)
253 os <<
", addr1=" << addr1.value();
255 if (
const auto& addr2 = queueId.
addr2)
257 os <<
", addr2=" << addr2.value();
259 if (
const auto& tid = queueId.
tid)
261 os <<
", tid=" << +tid.value();
275 std::vector<uint8_t> buffer;
276 buffer.reserve(1 + 1 + 6 + 6 + 1);
277 buffer.emplace_back(queueId.
type);
278 buffer.emplace_back(
static_cast<uint8_t
>(queueId.
addrType));
279 if (queueId.
addr1.has_value())
281 const auto size = buffer.size();
282 buffer.resize(size + 6);
283 queueId.
addr1.value().CopyTo(&buffer[size]);
285 if (queueId.
addr2.has_value())
287 const auto size = buffer.size();
288 buffer.resize(size + 6);
289 queueId.
addr2.value().CopyTo(&buffer[size]);
291 if (queueId.
tid.has_value())
293 buffer.emplace_back(*queueId.
tid);
296 std::string s(buffer.begin(), buffer.end());
297 return std::hash<std::string>{}(s);
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
const ContainerQueue & GetQueue(const WifiContainerQueueId &queueId) const
Get a const reference to the container queue identified by the given QueueId.
void clear()
Erase all elements from the container.
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.
ContainerQueue::iterator iterator
iterator over elements in a container queue
std::unordered_map< WifiContainerQueueId, uint32_t > m_nBytesPerQueue
size in bytes of the container queues
uint32_t GetNBytes(const WifiContainerQueueId &queueId) const
Get the total size of the MPDUs stored in the queue identified by the given QueueId.
Ptr< WifiMpdu > GetItem(const const_iterator it) const
Return the WifiMpdu included in the element pointed to by the given iterator.
std::pair< iterator, iterator > ExtractAllExpiredMpdus() const
Transfer non-inflight MPDUs with expired lifetime in all the container queues to the container queue ...
iterator insert(const_iterator pos, Ptr< WifiMpdu > item)
Insert the given item at the specified location in the container.
std::unordered_map< WifiContainerQueueId, ContainerQueue > m_queues
the container queues
std::list< WifiMacQueueElem > ContainerQueue
Type of a queue held by the container.
iterator erase(const_iterator pos)
Erase the specified elements from the container.
std::pair< iterator, iterator > GetAllExpiredMpdus() const
Get the range [first, last) of iterators pointing to all the MPDUs queued in the container queue stor...
ContainerQueue::const_iterator const_iterator
const iterator over elements in a container queue
ContainerQueue m_expiredQueue
queue storing MPDUs with expired lifetime
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...
std::pair< iterator, iterator > DoExtractExpiredMpdus(ContainerQueue &queue) const
Transfer non-inflight MPDUs with expired lifetime in the given container queue to the container queue...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
@ AC_UNDEF
Total number of ACs.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
WifiRcvAddr
enumeration of frame types based on receiver address
WifiContainerQueueType
enumeration of container queue types
Structure identifying a container queue.
std::optional< Mac48Address > addr1
the receiver address for unicast and groupcast queues, or nullopt otherwise
std::optional< Mac48Address > addr2
the transmitter address for broadcast and groupcast queues, or nullopt otherwise
std::optional< tid_t > tid
the TID for QoS data queues, or nullopt otherwise
WifiContainerQueueType type
the container queue type
WifiRcvAddr addrType
the type of receiver address
std::size_t operator()(ns3::WifiContainerQueueId queueId) const
The functor.