A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-mac-queue-container.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef WIFI_MAC_QUEUE_CONTAINER_H
10#define WIFI_MAC_QUEUE_CONTAINER_H
11
12#include "wifi-mac-queue-elem.h"
13
14#include "ns3/mac48-address.h"
15
16#include <list>
17#include <optional>
18#include <tuple>
19#include <unordered_map>
20
21namespace ns3
22{
23
24/// enumeration of container queue types
32
33/// enumeration of frame directions
39
40/**
41 * Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
42 *
43 * \note that Address has a different meaning depending on container queue type:
44 *
45 * - for container queue types holding unicast frames, Address is the Receiver Address (RA)
46 * of the frames stored in the queue. For 11be MLDs, it is expected that:
47 * + the RA of unicast management frames are link addresses (indicating the link on which
48 * they must be sent)
49 * + the RA of unicast QoS data frames are MLD addresses (indicating that they can be sent
50 * on any link)
51 * + if the RA of a unicast control frame is a link address, that control frame can only be
52 * sent on the corresponding link; if the RA is an MLD address, that control frame can be
53 * sent on any link
54 *
55 * - for container queue types holding broadcast frames, Address is the Transmitter Address (TA)
56 * of the frames stored in the queue. For 11be MLDs, it is expected that:
57 * + the TA of broadcast management frames are link addresses (indicating the link on which
58 * they must be sent)
59 * + the TA of broadcast QoS data frames are MLD addresses (indicating that they can be sent
60 * on any link)
61 * + if the TA of a broadcast control frame is a link address, that control frame can only be
62 * sent on the corresponding link; if the TA is an MLD address, that control frame can be
63 * sent on any link
64 *
65 * The TID is only specified for container queue types holding QoS data frames.
66 */
68 tuple<WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional<uint8_t>>;
69
70} // namespace ns3
71
72/****************************************************
73 * Global Functions (outside namespace ns3)
74 ***************************************************/
75
76/**
77 * \ingroup wifi
78 * Hashing functor taking a QueueId and returning a @c std::size_t.
79 * For use with `unordered_map` and `unordered_set`.
80 */
81template <>
82struct std::hash<ns3::WifiContainerQueueId>
83{
84 /**
85 * The functor.
86 * \param queueId The QueueId value to hash.
87 * \return the hash
88 */
89 std::size_t operator()(ns3::WifiContainerQueueId queueId) const;
90};
91
92namespace ns3
93{
94
95/**
96 * \ingroup wifi
97 * Class for the container used by WifiMacQueue
98 *
99 * This container holds multiple container queues organized in an hash table
100 * whose keys are WifiContainerQueueId tuples identifying the container queues.
101 */
103{
104 public:
105 /// Type of a queue held by the container
106 using ContainerQueue = std::list<WifiMacQueueElem>;
107 /// iterator over elements in a container queue
108 using iterator = ContainerQueue::iterator;
109 /// const iterator over elements in a container queue
110 using const_iterator = ContainerQueue::const_iterator;
111
112 /**
113 * Erase all elements from the container.
114 */
115 void clear();
116
117 /**
118 * Insert the given item at the specified location in the container.
119 *
120 * \param pos iterator before which the item will be inserted
121 * \param item the item to insert in the container
122 * \return iterator pointing to the inserted item
123 */
125
126 /**
127 * Erase the specified elements from the container.
128 *
129 * \param pos iterator to the element to remove
130 * \return iterator following the removed element
131 */
133
134 /**
135 * Return the WifiMpdu included in the element pointed to by the given iterator.
136 *
137 * \param it the given iterator
138 * \return the item included in the element pointed to by the given iterator
139 */
140 Ptr<WifiMpdu> GetItem(const const_iterator it) const;
141
142 /**
143 * Return the QueueId identifying the container queue in which the given MPDU is
144 * (or is to be) enqueued. Note that the given MPDU must not contain a control frame.
145 *
146 * \param mpdu the given MPDU
147 * \return the QueueId identifying the container queue in which the given MPDU
148 * is (or is to be) enqueued
149 */
151
152 /**
153 * Get a const reference to the container queue identified by the given QueueId.
154 * The container queue is created if it does not exist.
155 *
156 * \param queueId the given QueueId
157 * \return a const reference to the container queue identified by the given QueueId
158 */
159 const ContainerQueue& GetQueue(const WifiContainerQueueId& queueId) const;
160
161 /**
162 * Get the total size of the MPDUs stored in the queue identified by the given QueueId.
163 *
164 * \param queueId the given queue ID
165 * \return true if the given queue does not exist in the container or is empty,
166 * false otherwise
167 */
168 uint32_t GetNBytes(const WifiContainerQueueId& queueId) const;
169
170 /**
171 * Transfer non-inflight MPDUs with expired lifetime in the container queue identified by
172 * the given QueueId to the container queue storing MPDUs with expired lifetime.
173 *
174 * \param queueId the QueueId identifying the container queue
175 * \return the range [first, last) of iterators pointing to the MPDUs transferred
176 * to the container queue storing MPDUs with expired lifetime
177 */
178 std::pair<iterator, iterator> ExtractExpiredMpdus(const WifiContainerQueueId& queueId) const;
179 /**
180 * Transfer non-inflight MPDUs with expired lifetime in all the container queues to the
181 * container queue storing MPDUs with expired lifetime.
182 *
183 * \return the range [first, last) of iterators pointing to the MPDUs transferred
184 * to the container queue storing MPDUs with expired lifetime
185 */
186 std::pair<iterator, iterator> ExtractAllExpiredMpdus() const;
187 /**
188 * Get the range [first, last) of iterators pointing to all the MPDUs queued
189 * in the container queue storing MPDUs with expired lifetime.
190 *
191 * \return the range [first, last) of iterators pointing to all the MPDUs queued
192 * in the container queue storing MPDUs with expired lifetime
193 */
194 std::pair<iterator, iterator> GetAllExpiredMpdus() const;
195
196 private:
197 /**
198 * Transfer non-inflight MPDUs with expired lifetime in the given container queue to the
199 * container queue storing MPDUs with expired lifetime.
200 *
201 * \param queue the given container queue
202 * \return the range [first, last) of iterators pointing to the MPDUs transferred
203 * to the container queue storing MPDUs with expired lifetime
204 */
205 std::pair<iterator, iterator> DoExtractExpiredMpdus(ContainerQueue& queue) const;
206
207 mutable std::unordered_map<WifiContainerQueueId, ContainerQueue>
208 m_queues; //!< the container queues
209 mutable ContainerQueue m_expiredQueue; //!< queue storing MPDUs with expired lifetime
210 mutable std::unordered_map<WifiContainerQueueId, uint32_t>
211 m_nBytesPerQueue; //!< size in bytes of the container queues
212};
213
214} // namespace ns3
215
216#endif /* WIFI_MAC_QUEUE_CONTAINER_H */
Smart pointer class similar to boost::intrusive_ptr.
Class for the container used by WifiMacQueue.
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std:: tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
WifiContainerQueueType
enumeration of container queue types
WifiReceiverAddressType
enumeration of frame directions