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#include "wifi-utils.h"
14
15#include "ns3/deprecated.h"
16#include "ns3/mac48-address.h"
17
18#include <list>
19#include <optional>
20#include <tuple>
21#include <unordered_map>
22
23namespace ns3
24{
25
26/// enumeration of container queue types
34
35/// enumeration of frame types based on receiver address
36enum class WifiRcvAddr : uint8_t
37{
42};
43
44/**
45 * Deprecated frame types enums.
46 *
47 * Use `WifiRcvAddr` class enum values instead.
48 * @{
49 */
50NS_DEPRECATED_3_46("Use WifiRcvAddr::UNICAST instead")
51static constexpr auto WIFI_UNICAST = WifiRcvAddr::UNICAST;
52NS_DEPRECATED_3_46("Use WifiRcvAddr::BROADCAST instead")
53static constexpr auto WIFI_BROADCAST = WifiRcvAddr::BROADCAST;
54NS_DEPRECATED_3_46("Use WifiRcvAddr::GROUPCAST instead")
55static constexpr auto WIFI_GROUPCAST = WifiRcvAddr::GROUPCAST;
56
57/**@}*/
58
59/**
60 * Structure identifying a container queue.
61 *
62 * - for container queue types holding unicast frames, the Receiver Address (RA) of the frames
63 * stored in the queue needs to be specified. For 11be MLDs, it is expected that:
64 * + the RA of unicast management frames are link addresses (indicating the link on which
65 * they must be sent)
66 * + the RA of unicast QoS data frames are MLD addresses (indicating that they can be sent
67 * on any link)
68 * + if the RA of a unicast control frame is a link address, that control frame can only be
69 * sent on the corresponding link; if the RA is an MLD address, that control frame can be
70 * sent on any link
71 *
72 * - for container queue types holding broadcast frames, the Transmitter Address (TA) of the frames
73 * stored in the queue needs to be specified. For 11be MLDs, it is expected that:
74 * + the TA of broadcast management frames are link addresses (indicating the link on which
75 * they must be sent)
76 * + the TA of broadcast QoS data frames are MLD addresses (indicating that they can be sent
77 * on any link)
78 * + if the TA of a broadcast control frame is a link address, that control frame can only be
79 * sent on the corresponding link; if the TA is an MLD address, that control frame can be
80 * sent on any link
81 *
82 * - for container queue types holding groupcast frames, both the RA and TA of the frames
83 * stored in the queue need to be specified. The RA is used to identify the group address, while
84 * the TA is used to identify the link on which the frames must be sent (and is always a link
85 * address).
86 *
87 * The TID is only specified for container queue types holding QoS data frames.
88 */
90{
91 /**
92 * Constructor.
93 * @param type the container queue type
94 * @param addrType the type of receiver address (unicast, broadcast, or groupcast)
95 * @param addr1 the RA for unicast and groupcast queues, or nullopt otherwise
96 * @param addr2 the TA for broadcast and groupcast queues, or nullopt otherwise
97 * @param tid the TID for QoS data queues, or nullopt otherwise
98 */
101 std::optional<Mac48Address> addr1,
102 std::optional<Mac48Address> addr2,
103 std::optional<tid_t> tid)
104 : type(type),
106 addr1(addr1),
107 addr2(addr2),
108 tid(tid)
109 {
110 }
111
112 /**
113 * Three-way comparison operator
114 *
115 * @param rhs right hand side
116 * @return deduced comparison type
117 */
118 auto operator<=>(const WifiContainerQueueId& rhs) const = default;
119
120 WifiContainerQueueType type; ///< the container queue type
121 WifiRcvAddr addrType; ///< the type of receiver address
122 std::optional<Mac48Address> addr1; ///< the receiver address for unicast and groupcast queues,
123 ///< or nullopt otherwise
124 std::optional<Mac48Address> addr2; ///< the transmitter address for broadcast and groupcast
125 ///< queues, or nullopt otherwise
126 std::optional<tid_t> tid; ///< the TID for QoS data queues, or nullopt otherwise
127};
128
129/**
130 * @ingroup wifi
131 * Helper function to create WifiContainerQueueId for unicast queues.
132 *
133 * @param type the container queue type
134 * @param addr1 the receiver address for unicast queues
135 * @param tid the TID for QoS data queues, or nullopt otherwise
136 * @return the created WifiContainerQueueId
137 */
140 Mac48Address addr1,
141 std::optional<tid_t> tid = std::nullopt)
142{
143 return WifiContainerQueueId(type, WifiRcvAddr::UNICAST, addr1, std::nullopt, tid);
144}
145
146/**
147 * @ingroup wifi
148 * Helper function to create WifiContainerQueueId for broadcast queues.
149 *
150 * @param type the container queue type
151 * @param addr2 the transmitter address for broadcast queues
152 * @param tid the TID for QoS data queues, or nullopt otherwise
153 * @return the created WifiContainerQueueId
154 */
155inline WifiContainerQueueId
157 Mac48Address addr2,
158 std::optional<tid_t> tid = std::nullopt)
159{
160 return WifiContainerQueueId(type, WifiRcvAddr::BROADCAST, std::nullopt, addr2, tid);
161}
162
163/**
164 * @ingroup wifi
165 * Helper function to create WifiContainerQueueId for groupcast queues.
166 *
167 * @param type the container queue type
168 * @param addr1 the receiver address for groupcast queues
169 * @param addr2 the transmitter address for groupcast queues (always a link address)
170 * @param tid the TID for QoS data queues, or nullopt otherwise
171 * @return the created WifiContainerQueueId
172 */
173inline WifiContainerQueueId
175 Mac48Address addr1,
176 Mac48Address addr2,
177 std::optional<tid_t> tid = std::nullopt)
178{
179 return WifiContainerQueueId(type, WifiRcvAddr::GROUPCAST, addr1, addr2, tid);
180}
181
182} // namespace ns3
183
184/****************************************************
185 * Global Functions (outside namespace ns3)
186 ***************************************************/
187
188/**
189 * @ingroup wifi
190 * Hashing functor taking a QueueId and returning a @c std::size_t.
191 * For use with `unordered_map` and `unordered_set`.
192 */
193template <>
194struct std::hash<ns3::WifiContainerQueueId>
195{
196 /**
197 * The functor.
198 * @param queueId The QueueId value to hash.
199 * @return the hash
200 */
201 std::size_t operator()(ns3::WifiContainerQueueId queueId) const;
202};
203
204namespace ns3
205{
206
207/**
208 * @ingroup wifi
209 * Class for the container used by WifiMacQueue
210 *
211 * This container holds multiple container queues organized in an hash table
212 * whose keys are WifiContainerQueueId tuples identifying the container queues.
213 */
215{
216 public:
217 /// Type of a queue held by the container
218 using ContainerQueue = std::list<WifiMacQueueElem>;
219 /// iterator over elements in a container queue
220 using iterator = ContainerQueue::iterator;
221 /// const iterator over elements in a container queue
222 using const_iterator = ContainerQueue::const_iterator;
223
224 /**
225 * Erase all elements from the container.
226 */
227 void clear();
228
229 /**
230 * Insert the given item at the specified location in the container.
231 *
232 * @param pos iterator before which the item will be inserted
233 * @param item the item to insert in the container
234 * @return iterator pointing to the inserted item
235 */
237
238 /**
239 * Erase the specified elements from the container.
240 *
241 * @param pos iterator to the element to remove
242 * @return iterator following the removed element
243 */
245
246 /**
247 * Return the WifiMpdu included in the element pointed to by the given iterator.
248 *
249 * @param it the given iterator
250 * @return the item included in the element pointed to by the given iterator
251 */
252 Ptr<WifiMpdu> GetItem(const const_iterator it) const;
253
254 /**
255 * Return the QueueId identifying the container queue in which the given MPDU is
256 * (or is to be) enqueued. Note that the given MPDU must not contain a control frame.
257 *
258 * @param mpdu the given MPDU
259 * @return the QueueId identifying the container queue in which the given MPDU
260 * is (or is to be) enqueued
261 */
263
264 /**
265 * Get a const reference to the container queue identified by the given QueueId.
266 * The container queue is created if it does not exist.
267 *
268 * @param queueId the given QueueId
269 * @return a const reference to the container queue identified by the given QueueId
270 */
271 const ContainerQueue& GetQueue(const WifiContainerQueueId& queueId) const;
272
273 /**
274 * Get the total size of the MPDUs stored in the queue identified by the given QueueId.
275 *
276 * @param queueId the given queue ID
277 * @return true if the given queue does not exist in the container or is empty,
278 * false otherwise
279 */
280 uint32_t GetNBytes(const WifiContainerQueueId& queueId) const;
281
282 /**
283 * Transfer non-inflight MPDUs with expired lifetime in the container queue identified by
284 * the given QueueId to the container queue storing MPDUs with expired lifetime.
285 *
286 * @param queueId the QueueId identifying the container queue
287 * @return the range [first, last) of iterators pointing to the MPDUs transferred
288 * to the container queue storing MPDUs with expired lifetime
289 */
290 std::pair<iterator, iterator> ExtractExpiredMpdus(const WifiContainerQueueId& queueId) const;
291 /**
292 * Transfer non-inflight MPDUs with expired lifetime in all the container queues to the
293 * container queue storing MPDUs with expired lifetime.
294 *
295 * @return the range [first, last) of iterators pointing to the MPDUs transferred
296 * to the container queue storing MPDUs with expired lifetime
297 */
298 std::pair<iterator, iterator> ExtractAllExpiredMpdus() const;
299 /**
300 * Get the range [first, last) of iterators pointing to all the MPDUs queued
301 * in the container queue storing MPDUs with expired lifetime.
302 *
303 * @return the range [first, last) of iterators pointing to all the MPDUs queued
304 * in the container queue storing MPDUs with expired lifetime
305 */
306 std::pair<iterator, iterator> GetAllExpiredMpdus() const;
307
308 private:
309 /**
310 * Transfer non-inflight MPDUs with expired lifetime in the given container queue to the
311 * container queue storing MPDUs with expired lifetime.
312 *
313 * @param queue the given container queue
314 * @return the range [first, last) of iterators pointing to the MPDUs transferred
315 * to the container queue storing MPDUs with expired lifetime
316 */
317 std::pair<iterator, iterator> DoExtractExpiredMpdus(ContainerQueue& queue) const;
318
319 mutable std::unordered_map<WifiContainerQueueId, ContainerQueue>
320 m_queues; //!< the container queues
321 mutable ContainerQueue m_expiredQueue; //!< queue storing MPDUs with expired lifetime
322 mutable std::unordered_map<WifiContainerQueueId, uint32_t>
323 m_nBytesPerQueue; //!< size in bytes of the container queues
324};
325
326/**
327 * @brief Stream insertion operator.
328 * @param [in] os the reference to the output stream
329 * @param [in] queueType the container queue type
330 * @return a reference to the output stream
331 */
332std::ostream& operator<<(std::ostream& os, WifiContainerQueueType queueType);
333
334/**
335 * @brief Stream insertion operator.
336 * @param [in] os the reference to the output stream
337 * @param [in] rcvAddrType the receiver address type
338 * @return a reference to the output stream
339 */
340std::ostream& operator<<(std::ostream& os, WifiRcvAddr rcvAddrType);
341
342/**
343 * @brief Stream insertion operator.
344 * @param [in] os the reference to the output stream
345 * @param [in] queueId the container queue ID
346 * @return a reference to the output stream
347 */
348std::ostream& operator<<(std::ostream& os, const WifiContainerQueueId& queueId);
349
350} // namespace ns3
351
352#endif /* WIFI_MAC_QUEUE_CONTAINER_H */
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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...
#define NS_DEPRECATED_3_46(msg)
Tag for things deprecated in version ns-3.46.
Definition deprecated.h:105
WifiContainerQueueId MakeWifiUnicastQueueId(WifiContainerQueueType type, Mac48Address addr1, std::optional< tid_t > tid=std::nullopt)
Helper function to create WifiContainerQueueId for unicast queues.
WifiContainerQueueId MakeWifiGroupcastQueueId(WifiContainerQueueType type, Mac48Address addr1, Mac48Address addr2, std::optional< tid_t > tid=std::nullopt)
Helper function to create WifiContainerQueueId for groupcast queues.
WifiContainerQueueId MakeWifiBroadcastQueueId(WifiContainerQueueType type, Mac48Address addr2, std::optional< tid_t > tid=std::nullopt)
Helper function to create WifiContainerQueueId for broadcast queues.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr auto WIFI_UNICAST
Deprecated frame types enums.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
static constexpr auto WIFI_GROUPCAST
static constexpr auto WIFI_BROADCAST
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
auto operator<=>(const WifiContainerQueueId &rhs) const =default
Three-way comparison operator.
std::optional< tid_t > tid
the TID for QoS data queues, or nullopt otherwise
WifiContainerQueueId(WifiContainerQueueType type, WifiRcvAddr addrType, std::optional< Mac48Address > addr1, std::optional< Mac48Address > addr2, std::optional< tid_t > tid)
Constructor.
WifiContainerQueueType type
the container queue type
WifiRcvAddr addrType
the type of receiver address
std::size_t operator()(ns3::WifiContainerQueueId queueId) const
The functor.