A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-mpdu.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005, 2009 INRIA
3 * Copyright (c) 2009 MIRKO BANCHI
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Mirko Banchi <mk.banchi@gmail.com>
9 * Stefano Avallone <stavallo@unina.it>
10 */
11
12#ifndef WIFI_MPDU_H
13#define WIFI_MPDU_H
14
16#include "wifi-mac-header.h"
17#include "wifi-mac-queue-elem.h"
18
19#include "ns3/packet.h"
20#include "ns3/simulator.h"
21#include "ns3/wifi-export.h"
22
23#include <list>
24#include <optional>
25#include <set>
26#include <variant>
27
28namespace ns3
29{
30
31/**
32 * @ingroup wifi
33 *
34 * Tag used to allow (only) WifiMacQueue to access the queue iterator stored
35 * by a WifiMpdu.
36 */
37class WIFI_EXPORT WmqIteratorTag
38{
39 friend class WifiMacQueue;
40 WmqIteratorTag() = default;
41};
42
43/**
44 * @ingroup wifi
45 *
46 * WifiMpdu stores a (const) packet along with a MAC header. To support 802.11be
47 * Multi-Link Operation (MLO), a WifiMpdu variant, referred to as WifiMpdu alias,
48 * is added. A WifiMpdu alias stores its own MAC header and a pointer to the original
49 * copy of the WifiMpdu.
50 */
51class WIFI_EXPORT WifiMpdu : public SimpleRefCount<WifiMpdu>
52{
53 public:
54 /**
55 * @brief Create a Wifi MAC queue item containing a packet and a Wifi MAC header.
56 * @param p the const packet included in the created item.
57 * @param header the Wifi MAC header included in the created item.
58 * @param stamp the timestamp to associate with the MPDU
59 */
60 WifiMpdu(Ptr<const Packet> p, const WifiMacHeader& header, Time stamp = Simulator::Now());
61
62 virtual ~WifiMpdu();
63
64 /**
65 * @return whether this is the original version of the MPDU
66 */
67 bool IsOriginal() const;
68
69 /**
70 * @return the original version of this MPDU
71 */
73
74 /**
75 * @brief Get the packet stored in this item
76 * @return the packet stored in this item.
77 */
79
80 /**
81 * @brief Get the header stored in this item
82 * @return the header stored in this item.
83 */
84 const WifiMacHeader& GetHeader() const;
85
86 /**
87 * @brief Get the header stored in this item
88 * @return the header stored in this item.
89 */
91
92 /**
93 * @brief Return the destination address present in the header
94 * @return the destination address
95 */
97
98 /**
99 * @brief Return the size of the packet stored by this item, including header
100 * size and trailer size
101 *
102 * @return the size of the packet stored by this item in bytes.
103 */
104 uint32_t GetSize() const;
105
106 /**
107 * @brief Return the size in bytes of the packet or control header or management
108 * header stored by this item.
109 *
110 * @return the size in bytes of the packet or control header or management header
111 * stored by this item
112 */
113 uint32_t GetPacketSize() const;
114
115 /**
116 * Return true if this item contains an MSDU fragment, false otherwise
117 * @return true if this item contains an MSDU fragment, false otherwise
118 */
119 bool IsFragment() const;
120
121 /**
122 * @brief Aggregate the MSDU contained in the given MPDU to this MPDU (thus
123 * constituting an A-MSDU). Note that the given MPDU cannot contain
124 * an A-MSDU. If the given MPDU is a null pointer, the effect of this
125 * call is to add only an A-MSDU subframe header, thus producing an A-MSDU
126 * containing a single MSDU.
127 * @param msdu the MPDU containing the MSDU to aggregate
128 */
130
131 /// DeaggregatedMsdus typedef
132 typedef std::list<std::pair<Ptr<const Packet>, AmsduSubframeHeader>> DeaggregatedMsdus;
133 /// DeaggregatedMsdusCI typedef
134 typedef std::list<std::pair<Ptr<const Packet>, AmsduSubframeHeader>>::const_iterator
136
137 /**
138 * @brief Get a constant iterator pointing to the first MSDU in the list of aggregated MSDUs.
139 *
140 * @return a constant iterator pointing to the first MSDU in the list of aggregated MSDUs
141 */
143 /**
144 * @brief Get a constant iterator indicating past-the-last MSDU in the list of aggregated MSDUs.
145 *
146 * @return a constant iterator indicating past-the-last MSDU in the list of aggregated MSDUs
147 */
148 DeaggregatedMsdusCI end() const;
149
150 /// Const iterator typedef
151 typedef std::list<WifiMacQueueElem>::iterator Iterator;
152
153 /**
154 * Set the queue iterator stored by this object.
155 *
156 * @param queueIt the queue iterator for this object
157 * @param tag a wifi MAC queue iterator tag (allows only WifiMacQueue to call this method)
158 */
159 void SetQueueIt(std::optional<Iterator> queueIt, WmqIteratorTag tag);
160 /**
161 * @param tag a wifi MAC queue iterator tag (allows only WifiMacQueue to call this method)
162 * @return the queue iterator stored by this object
163 */
165
166 /**
167 * Return true if this item is stored in some queue, false otherwise.
168 *
169 * @return true if this item is stored in some queue, false otherwise
170 */
171 bool IsQueued() const;
172 /**
173 * Get the AC of the queue this item is stored into. Abort if this item
174 * is not stored in a queue.
175 *
176 * @return the AC of the queue this item is stored into
177 */
178 AcIndex GetQueueAc() const;
179 /**
180 * @return the time this MPDU was constructed
181 */
182 Time GetTimestamp() const;
183 /**
184 * @return the expiry time of this MPDU
185 */
186 Time GetExpiryTime() const;
187
188 /**
189 * @return the frame retry count
190 */
191 uint32_t GetRetryCount() const;
192
193 /**
194 * Increment the frame retry count.
195 */
196 void IncrementRetryCount();
197
198 /**
199 * @brief Get the MAC protocol data unit (MPDU) corresponding to this item
200 * (i.e. a copy of the packet stored in this item wrapped with MAC
201 * header and trailer)
202 * @return the MAC protocol data unit corresponding to this item.
203 */
205
206 /**
207 * Mark this MPDU as being in flight on the given link.
208 *
209 * @param linkId the ID of the given link
210 */
211 void SetInFlight(uint8_t linkId) const;
212 /**
213 * Mark this MPDU as not being in flight on the given link.
214 *
215 * @param linkId the ID of the given link
216 */
217 void ResetInFlight(uint8_t linkId) const;
218 /**
219 * @return the set of IDs of the links on which this MPDU is currently in flight
220 */
221 std::set<uint8_t> GetInFlightLinkIds() const;
222 /**
223 * @return true if this MPDU is in flight on any link, false otherwise
224 */
225 bool IsInFlight() const;
226
227 /**
228 * Set the sequence number of this MPDU (and of the original copy, if this is an alias)
229 * to the given value. Also, record that a sequence number has been assigned to this MPDU.
230 *
231 * @param seqNo the given sequence number
232 */
233 void AssignSeqNo(uint16_t seqNo);
234 /**
235 * @return whether a sequence number has been assigned to this MPDU
236 */
237 bool HasSeqNoAssigned() const;
238 /**
239 * Record that a sequence number is no (longer) assigned to this MPDU.
240 */
241 void UnassignSeqNo();
242
243 /**
244 * Create an alias for this MPDU (which must be an original copy) for transmission
245 * on the link with the given ID. Aliases have their own copy of the MAC header and
246 * cannot be used to perform non-const operations on the frame body.
247 *
248 * @param linkId the ID of the given link
249 * @return an alias for this MPDU
250 */
251 Ptr<WifiMpdu> CreateAlias(uint8_t linkId) const;
252
253 /**
254 * @brief Print the item contents.
255 * @param os output stream in which the data should be printed.
256 */
257 virtual void Print(std::ostream& os) const;
258
259 private:
260 /**
261 * @brief Aggregate the MSDU contained in the given MPDU to this MPDU (thus
262 * constituting an A-MSDU). Note that the given MPDU cannot contain
263 * an A-MSDU.
264 * @param msdu the MPDU containing the MSDU to aggregate
265 */
267
268 /**
269 * @return the queue iterator stored by this object
270 */
271 Iterator GetQueueIt() const;
272
273 /**
274 * Private default constructor (used to construct aliases).
275 */
276 WifiMpdu() = default;
277
278 /**
279 * Information stored by both the original copy and the aliases
280 */
281 WifiMacHeader m_header; //!< Wifi MAC header associated with the packet
282
283 /**
284 * Information stored by the original copy only.
285 */
286 struct WIFI_EXPORT OriginalInfo
287 {
288 Ptr<const Packet> m_packet; //!< MSDU or A-MSDU contained in this queue item
289 Time m_timestamp; //!< construction time
290 DeaggregatedMsdus m_msduList; //!< list of aggregated MSDUs included in this MPDU
291 std::optional<Iterator> m_queueIt; //!< Queue iterator pointing to this MPDU, if queued
292 bool m_seqNoAssigned; //!< whether a sequence number has been assigned
293 uint32_t m_retryCount; //!< the frame retry count maintained for each MSDU, A-MSDU or MMPDU
294 };
295
296 /**
297 * @return a reference to the information held by the original copy of the MPDU.
298 */
300 /**
301 * @return a const reference to the information held by the original copy of the MPDU.
302 */
303 const OriginalInfo& GetOriginalInfo() const;
304
305 /// Information stored by the original copy and an alias, respectively
306 using InstanceInfo = std::variant<OriginalInfo, Ptr<WifiMpdu>>;
307
308 InstanceInfo m_instanceInfo; //!< information associated with the instance type
309 static constexpr std::size_t ORIGINAL =
310 0; //!< index of original copy in the InstanceInfo variant
311 static constexpr std::size_t ALIAS = 1; //!< index of an alias in the InstanceInfo variant
312};
313
314/**
315 * @brief Stream insertion operator.
316 *
317 * @param os the output stream
318 * @param item the WifiMpdu
319 * @returns a reference to the stream
320 */
321WIFI_EXPORT std::ostream& operator<<(std::ostream& os, const WifiMpdu& item);
322
323} // namespace ns3
324
325#endif /* WIFI_MPDU_H */
Headers for A-MSDU subframes.
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Implements the IEEE 802.11 MAC header.
WifiMpdu stores a (const) packet along with a MAC header.
Definition wifi-mpdu.h:52
bool IsOriginal() const
Definition wifi-mpdu.cc:47
InstanceInfo m_instanceInfo
information associated with the instance type
Definition wifi-mpdu.h:308
Time GetTimestamp() const
Definition wifi-mpdu.cc:107
bool HasSeqNoAssigned() const
Definition wifi-mpdu.cc:384
Time GetExpiryTime() const
Definition wifi-mpdu.cc:331
bool IsInFlight() const
Definition wifi-mpdu.cc:364
static constexpr std::size_t ALIAS
index of an alias in the InstanceInfo variant
Definition wifi-mpdu.h:311
uint32_t GetRetryCount() const
Definition wifi-mpdu.cc:118
void ResetInFlight(uint8_t linkId) const
Mark this MPDU as not being in flight on the given link.
Definition wifi-mpdu.cc:343
void IncrementRetryCount()
Increment the frame retry count.
Definition wifi-mpdu.cc:129
WifiMacHeader m_header
Information stored by both the original copy and the aliases.
Definition wifi-mpdu.h:281
void SetInFlight(uint8_t linkId) const
Mark this MPDU as being in flight on the given link.
Definition wifi-mpdu.cc:337
std::list< std::pair< Ptr< constPacket >, AmsduSubframeHeader > >::const_iterator DeaggregatedMsdusCI
DeaggregatedMsdusCI typedef.
Definition wifi-mpdu.h:135
const WifiMacHeader & GetHeader() const
Get the header stored in this item.
Definition wifi-mpdu.cc:153
void Aggregate(Ptr< const WifiMpdu > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU).
Definition wifi-mpdu.cc:198
OriginalInfo & GetOriginalInfo()
Definition wifi-mpdu.cc:79
uint32_t GetSize() const
Return the size of the packet stored by this item, including header size and trailer size.
Definition wifi-mpdu.cc:177
Ptr< Packet > GetProtocolDataUnit() const
Get the MAC protocol data unit (MPDU) corresponding to this item (i.e.
Definition wifi-mpdu.cc:189
std::variant< OriginalInfo, Ptr< WifiMpdu > > InstanceInfo
Information stored by the original copy and an alias, respectively.
Definition wifi-mpdu.h:306
void DoAggregate(Ptr< const WifiMpdu > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU).
Definition wifi-mpdu.cc:246
std::list< std::pair< Ptr< const Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
DeaggregatedMsdus typedef.
Definition wifi-mpdu.h:132
void UnassignSeqNo()
Record that a sequence number is no (longer) assigned to this MPDU.
Definition wifi-mpdu.cc:390
WifiMpdu(Ptr< const Packet > p, const WifiMacHeader &header, Time stamp=Simulator::Now())
Create a Wifi MAC queue item containing a packet and a Wifi MAC header.
Definition wifi-mpdu.cc:26
Iterator GetQueueIt(WmqIteratorTag tag) const
Definition wifi-mpdu.cc:312
WifiMpdu()=default
Private default constructor (used to construct aliases).
Ptr< const Packet > GetPacket() const
Get the packet stored in this item.
Definition wifi-mpdu.cc:101
DeaggregatedMsdusCI end() const
Get a constant iterator indicating past-the-last MSDU in the list of aggregated MSDUs.
Definition wifi-mpdu.cc:402
DeaggregatedMsdusCI begin() const
Get a constant iterator pointing to the first MSDU in the list of aggregated MSDUs.
Definition wifi-mpdu.cc:396
uint32_t GetPacketSize() const
Return the size in bytes of the packet or control header or management header stored by this item.
Definition wifi-mpdu.cc:171
AcIndex GetQueueAc() const
Get the AC of the queue this item is stored into.
Definition wifi-mpdu.cc:325
std::list< WifiMacQueueElem >::iterator Iterator
Const iterator typedef.
Definition wifi-mpdu.h:151
Mac48Address GetDestinationAddress() const
Return the destination address present in the header.
Definition wifi-mpdu.cc:165
bool IsQueued() const
Return true if this item is stored in some queue, false otherwise.
Definition wifi-mpdu.cc:296
void SetQueueIt(std::optional< Iterator > queueIt, WmqIteratorTag tag)
Set the queue iterator stored by this object.
Definition wifi-mpdu.cc:302
bool IsFragment() const
Return true if this item contains an MSDU fragment, false otherwise.
Definition wifi-mpdu.cc:183
std::set< uint8_t > GetInFlightLinkIds() const
Definition wifi-mpdu.cc:349
Ptr< const WifiMpdu > GetOriginal() const
Definition wifi-mpdu.cc:53
void AssignSeqNo(uint16_t seqNo)
Set the sequence number of this MPDU (and of the original copy, if this is an alias) to the given val...
Definition wifi-mpdu.cc:370
Ptr< WifiMpdu > CreateAlias(uint8_t linkId) const
Create an alias for this MPDU (which must be an original copy) for transmission on the link with the ...
Definition wifi-mpdu.cc:63
static constexpr std::size_t ORIGINAL
index of original copy in the InstanceInfo variant
Definition wifi-mpdu.h:309
Tag used to allow (only) WifiMacQueue to access the queue iterator stored by a WifiMpdu.
Definition wifi-mpdu.h:38
WmqIteratorTag()=default
friend class WifiMacQueue
Definition wifi-mpdu.h:39
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition qos-utils.h:64
void Print(ComponentCarrier cc)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Information stored by the original copy only.
Definition wifi-mpdu.h:287
Time m_timestamp
construction time
Definition wifi-mpdu.h:289
uint32_t m_retryCount
the frame retry count maintained for each MSDU, A-MSDU or MMPDU
Definition wifi-mpdu.h:293
bool m_seqNoAssigned
whether a sequence number has been assigned
Definition wifi-mpdu.h:292
DeaggregatedMsdus m_msduList
list of aggregated MSDUs included in this MPDU
Definition wifi-mpdu.h:290
Ptr< const Packet > m_packet
MSDU or A-MSDU contained in this queue item.
Definition wifi-mpdu.h:288
std::optional< Iterator > m_queueIt
Queue iterator pointing to this MPDU, if queued.
Definition wifi-mpdu.h:291