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 types based on receiver address
34enum class WifiRcvAddr : uint8_t
35{
36 UNICAST = 0,
39 COUNT
40};
41
42/**
43 * Deprecated frame types enums.
44 *
45 * Use `WifiRcvAddr` class enum values instead.
46 * @{
47 */
48NS_DEPRECATED_3_46("Use WifiRcvAddr::UNICAST instead")
49static constexpr auto WIFI_UNICAST = WifiRcvAddr::UNICAST;
51static constexpr auto WIFI_BROADCAST = WifiRcvAddr::BROADCAST;
53static constexpr auto WIFI_GROUPCAST = WifiRcvAddr::GROUPCAST;
54/**@}*/
55
56/**
57 * Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
58 *
59 * @note that Address has a different meaning depending on container queue type:
60 *
61 * - for container queue types holding unicast frames, Address is the Receiver Address (RA)
62 * of the frames stored in the queue. For 11be MLDs, it is expected that:
63 * + the RA of unicast management frames are link addresses (indicating the link on which
64 * they must be sent)
65 * + the RA of unicast QoS data frames are MLD addresses (indicating that they can be sent
66 * on any link)
67 * + if the RA of a unicast control frame is a link address, that control frame can only be
68 * sent on the corresponding link; if the RA is an MLD address, that control frame can be
69 * sent on any link
70 *
71 * - for container queue types holding broadcast frames, Address is the Transmitter Address (TA)
72 * of the frames stored in the queue. For 11be MLDs, it is expected that:
73 * + the TA of broadcast management frames are link addresses (indicating the link on which
74 * they must be sent)
75 * + the TA of broadcast QoS data frames are MLD addresses (indicating that they can be sent
76 * on any link)
77 * + if the TA of a broadcast control frame is a link address, that control frame can only be
78 * sent on the corresponding link; if the TA is an MLD address, that control frame can be
79 * sent on any link
80 *
81 * The TID is only specified for container queue types holding QoS data frames.
82 */
84 std::tuple<WifiContainerQueueType, WifiRcvAddr, Mac48Address, std::optional<uint8_t>>;
85
86} // namespace ns3
87
88/****************************************************
89 * Global Functions (outside namespace ns3)
90 ***************************************************/
91
92/**
93 * @ingroup wifi
94 * Hashing functor taking a QueueId and returning a @c std::size_t.
95 * For use with `unordered_map` and `unordered_set`.
96 */
97template <>
98struct std::hash<ns3::WifiContainerQueueId>
99{
100 /**
101 * The functor.
102 * @param queueId The QueueId value to hash.
103 * @return the hash
104 */
105 std::size_t operator()(ns3::WifiContainerQueueId queueId) const;
106};
107
108namespace ns3
109{
110
111/**
112 * @ingroup wifi
113 * Class for the container used by WifiMacQueue
114 *
115 * This container holds multiple container queues organized in an hash table
116 * whose keys are WifiContainerQueueId tuples identifying the container queues.
117 */
119{
120 public:
121 /// Type of a queue held by the container
122 using ContainerQueue = std::list<WifiMacQueueElem>;
123 /// iterator over elements in a container queue
124 using iterator = ContainerQueue::iterator;
125 /// const iterator over elements in a container queue
126 using const_iterator = ContainerQueue::const_iterator;
127
128 /**
129 * Erase all elements from the container.
130 */
131 void clear();
132
133 /**
134 * Insert the given item at the specified location in the container.
135 *
136 * @param pos iterator before which the item will be inserted
137 * @param item the item to insert in the container
138 * @return iterator pointing to the inserted item
139 */
141
142 /**
143 * Erase the specified elements from the container.
144 *
145 * @param pos iterator to the element to remove
146 * @return iterator following the removed element
147 */
149
150 /**
151 * Return the WifiMpdu included in the element pointed to by the given iterator.
152 *
153 * @param it the given iterator
154 * @return the item included in the element pointed to by the given iterator
155 */
156 Ptr<WifiMpdu> GetItem(const const_iterator it) const;
157
158 /**
159 * Return the QueueId identifying the container queue in which the given MPDU is
160 * (or is to be) enqueued. Note that the given MPDU must not contain a control frame.
161 *
162 * @param mpdu the given MPDU
163 * @return the QueueId identifying the container queue in which the given MPDU
164 * is (or is to be) enqueued
165 */
167
168 /**
169 * Get a const reference to the container queue identified by the given QueueId.
170 * The container queue is created if it does not exist.
171 *
172 * @param queueId the given QueueId
173 * @return a const reference to the container queue identified by the given QueueId
174 */
175 const ContainerQueue& GetQueue(const WifiContainerQueueId& queueId) const;
176
177 /**
178 * Get the total size of the MPDUs stored in the queue identified by the given QueueId.
179 *
180 * @param queueId the given queue ID
181 * @return true if the given queue does not exist in the container or is empty,
182 * false otherwise
183 */
184 uint32_t GetNBytes(const WifiContainerQueueId& queueId) const;
185
186 /**
187 * Transfer non-inflight MPDUs with expired lifetime in the container queue identified by
188 * the given QueueId to the container queue storing MPDUs with expired lifetime.
189 *
190 * @param queueId the QueueId identifying the container queue
191 * @return the range [first, last) of iterators pointing to the MPDUs transferred
192 * to the container queue storing MPDUs with expired lifetime
193 */
194 std::pair<iterator, iterator> ExtractExpiredMpdus(const WifiContainerQueueId& queueId) const;
195 /**
196 * Transfer non-inflight MPDUs with expired lifetime in all the container queues to the
197 * container queue storing MPDUs with expired lifetime.
198 *
199 * @return the range [first, last) of iterators pointing to the MPDUs transferred
200 * to the container queue storing MPDUs with expired lifetime
201 */
202 std::pair<iterator, iterator> ExtractAllExpiredMpdus() const;
203 /**
204 * Get the range [first, last) of iterators pointing to all the MPDUs queued
205 * in the container queue storing MPDUs with expired lifetime.
206 *
207 * @return the range [first, last) of iterators pointing to all the MPDUs queued
208 * in the container queue storing MPDUs with expired lifetime
209 */
210 std::pair<iterator, iterator> GetAllExpiredMpdus() const;
211
212 private:
213 /**
214 * Transfer non-inflight MPDUs with expired lifetime in the given container queue to the
215 * container queue storing MPDUs with expired lifetime.
216 *
217 * @param queue the given container queue
218 * @return the range [first, last) of iterators pointing to the MPDUs transferred
219 * to the container queue storing MPDUs with expired lifetime
220 */
221 std::pair<iterator, iterator> DoExtractExpiredMpdus(ContainerQueue& queue) const;
222
223 mutable std::unordered_map<WifiContainerQueueId, ContainerQueue>
224 m_queues; //!< the container queues
225 mutable ContainerQueue m_expiredQueue; //!< queue storing MPDUs with expired lifetime
226 mutable std::unordered_map<WifiContainerQueueId, uint32_t>
227 m_nBytesPerQueue; //!< size in bytes of the container queues
228};
229
230} // namespace ns3
231
232#endif /* WIFI_MAC_QUEUE_CONTAINER_H */
an EUI-48 address
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...
#define NS_DEPRECATED_3_46(msg)
Tag for things deprecated in version ns-3.46.
Definition deprecated.h:91
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr auto WIFI_UNICAST
Deprecated frame types enums.
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
std::tuple< WifiContainerQueueType, WifiRcvAddr, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
STL namespace.