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