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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
20#ifndef WIFI_MAC_QUEUE_CONTAINER_H
21#define WIFI_MAC_QUEUE_CONTAINER_H
22
23#include "wifi-mac-queue-elem.h"
24
25#include "ns3/mac48-address.h"
26
27#include <list>
28#include <optional>
29#include <tuple>
30#include <unordered_map>
31
32namespace ns3
33{
34
35/// enumeration of container queue types
37{
42};
43
44/// enumeration of frame directions
46{
49};
50
51/**
52 * Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
53 *
54 * \note that Address has a different meaning depending on container queue type:
55 *
56 * - for container queue types holding unicast frames, Address is the Receiver Address (RA)
57 * of the frames stored in the queue. For 11be MLDs, it is expected that:
58 * + the RA of unicast management frames are link addresses (indicating the link on which
59 * they must be sent)
60 * + the RA of unicast QoS data frames are MLD addresses (indicating that they can be sent
61 * on any link)
62 * + if the RA of a unicast control frame is a link address, that control frame can only be
63 * sent on the corresponding link; if the RA is an MLD address, that control frame can be
64 * sent on any link
65 *
66 * - for container queue types holding broadcast frames, Address is the Transmitter Address (TA)
67 * of the frames stored in the queue. For 11be MLDs, it is expected that:
68 * + the TA of broadcast management frames are link addresses (indicating the link on which
69 * they must be sent)
70 * + the TA of broadcast QoS data frames are MLD addresses (indicating that they can be sent
71 * on any link)
72 * + if the TA of a broadcast control frame is a link address, that control frame can only be
73 * sent on the corresponding link; if the TA is an MLD address, that control frame can be
74 * sent on any link
75 *
76 * The TID is only specified for container queue types holding QoS data frames.
77 */
79 tuple<WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional<uint8_t>>;
80
81} // namespace ns3
82
83/****************************************************
84 * Global Functions (outside namespace ns3)
85 ***************************************************/
86
87/**
88 * \ingroup wifi
89 * Hashing functor taking a QueueId and returning a @c std::size_t.
90 * For use with `unordered_map` and `unordered_set`.
91 */
92template <>
93struct std::hash<ns3::WifiContainerQueueId>
94{
95 /**
96 * The functor.
97 * \param queueId The QueueId value to hash.
98 * \return the hash
99 */
100 std::size_t operator()(ns3::WifiContainerQueueId queueId) const;
101};
102
103namespace ns3
104{
105
106/**
107 * \ingroup wifi
108 * Class for the container used by WifiMacQueue
109 *
110 * This container holds multiple container queues organized in an hash table
111 * whose keys are WifiContainerQueueId tuples identifying the container queues.
112 */
114{
115 public:
116 /// Type of a queue held by the container
117 using ContainerQueue = std::list<WifiMacQueueElem>;
118 /// iterator over elements in a container queue
119 using iterator = ContainerQueue::iterator;
120 /// const iterator over elements in a container queue
121 using const_iterator = ContainerQueue::const_iterator;
122
123 /**
124 * Erase all elements from the container.
125 */
126 void clear();
127
128 /**
129 * Insert the given item at the specified location in the container.
130 *
131 * \param pos iterator before which the item will be inserted
132 * \param item the item to insert in the container
133 * \return iterator pointing to the inserted item
134 */
136
137 /**
138 * Erase the specified elements from the container.
139 *
140 * \param pos iterator to the element to remove
141 * \return iterator following the removed element
142 */
144
145 /**
146 * Return the WifiMpdu included in the element pointed to by the given iterator.
147 *
148 * \param it the given iterator
149 * \return the item included in the element pointed to by the given iterator
150 */
151 Ptr<WifiMpdu> GetItem(const const_iterator it) const;
152
153 /**
154 * Return the QueueId identifying the container queue in which the given MPDU is
155 * (or is to be) enqueued. Note that the given MPDU must not contain a control frame.
156 *
157 * \param mpdu the given MPDU
158 * \return the QueueId identifying the container queue in which the given MPDU
159 * is (or is to be) enqueued
160 */
162
163 /**
164 * Get a const reference to the container queue identified by the given QueueId.
165 * The container queue is created if it does not exist.
166 *
167 * \param queueId the given QueueId
168 * \return a const reference to the container queue identified by the given QueueId
169 */
170 const ContainerQueue& GetQueue(const WifiContainerQueueId& queueId) const;
171
172 /**
173 * Get the total size of the MPDUs stored in the queue identified by the given QueueId.
174 *
175 * \param queueId the given queue ID
176 * \return true if the given queue does not exist in the container or is empty,
177 * false otherwise
178 */
179 uint32_t GetNBytes(const WifiContainerQueueId& queueId) const;
180
181 /**
182 * Transfer non-inflight MPDUs with expired lifetime in the container queue identified by
183 * the given QueueId to the container queue storing MPDUs with expired lifetime.
184 *
185 * \param queueId the QueueId identifying the container queue
186 * \return the range [first, last) of iterators pointing to the MPDUs transferred
187 * to the container queue storing MPDUs with expired lifetime
188 */
189 std::pair<iterator, iterator> ExtractExpiredMpdus(const WifiContainerQueueId& queueId) const;
190 /**
191 * Transfer non-inflight MPDUs with expired lifetime in all the container queues to the
192 * container queue storing MPDUs with expired lifetime.
193 *
194 * \return the range [first, last) of iterators pointing to the MPDUs transferred
195 * to the container queue storing MPDUs with expired lifetime
196 */
197 std::pair<iterator, iterator> ExtractAllExpiredMpdus() const;
198 /**
199 * Get the range [first, last) of iterators pointing to all the MPDUs queued
200 * in the container queue storing MPDUs with expired lifetime.
201 *
202 * \return the range [first, last) of iterators pointing to all the MPDUs queued
203 * in the container queue storing MPDUs with expired lifetime
204 */
205 std::pair<iterator, iterator> GetAllExpiredMpdus() const;
206
207 private:
208 /**
209 * Transfer non-inflight MPDUs with expired lifetime in the given container queue to the
210 * container queue storing MPDUs with expired lifetime.
211 *
212 * \param queue the given container queue
213 * \return the range [first, last) of iterators pointing to the MPDUs transferred
214 * to the container queue storing MPDUs with expired lifetime
215 */
216 std::pair<iterator, iterator> DoExtractExpiredMpdus(ContainerQueue& queue) const;
217
218 mutable std::unordered_map<WifiContainerQueueId, ContainerQueue>
219 m_queues; //!< the container queues
220 mutable ContainerQueue m_expiredQueue; //!< queue storing MPDUs with expired lifetime
221 mutable std::unordered_map<WifiContainerQueueId, uint32_t>
222 m_nBytesPerQueue; //!< size in bytes of the container queues
223};
224
225} // namespace ns3
226
227#endif /* WIFI_MAC_QUEUE_CONTAINER_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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