A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-psdu.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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_PSDU_H
10#define WIFI_PSDU_H
11
12#include "wifi-mac-header.h"
13#include "wifi-mpdu.h"
14
15#include "ns3/nstime.h"
16
17#include <set>
18#include <unordered_map>
19#include <vector>
20
21namespace ns3
22{
23
24class Packet;
25
26/**
27 * @ingroup wifi
28 *
29 * WifiPsdu stores an MPDU, S-MPDU or A-MPDU, by keeping header(s) and
30 * payload(s) separate for each constituent MPDU.
31 */
32class WifiPsdu : public SimpleRefCount<WifiPsdu>
33{
34 public:
35 /**
36 * Create a PSDU storing an MPDU. Typically used for control and management
37 * frames that do not have to keep an associated lifetime and are not stored
38 * in an S-MPDU.
39 *
40 * @param p the payload of the MPDU.
41 * @param header the Wifi MAC header of the MPDU.
42 */
44
45 /**
46 * Create a PSDU storing an MPDU or S-MPDU. Typically used for QoS data
47 * frames that have to keep an associated lifetime.
48 *
49 * @param mpdu the MPDU.
50 * @param isSingle true for an S-MPDU
51 */
52 WifiPsdu(Ptr<WifiMpdu> mpdu, bool isSingle);
53
54 /**
55 * Create a PSDU storing an MPDU or S-MPDU. Typically used for QoS data
56 * frames that have to keep an associated lifetime.
57 *
58 * @param mpdu the MPDU.
59 * @param isSingle true for an S-MPDU
60 */
61 WifiPsdu(Ptr<const WifiMpdu> mpdu, bool isSingle);
62
63 /**
64 * Create a PSDU storing an S-MPDU or A-MPDU.
65 *
66 * @param mpduList the list of constituent MPDUs.
67 */
68 WifiPsdu(std::vector<Ptr<WifiMpdu>> mpduList);
69
70 virtual ~WifiPsdu();
71
72 /**
73 * Return true if the PSDU is an S-MPDU
74 * @return true if the PSDU is an S-MPDU.
75 */
76 bool IsSingle() const;
77
78 /**
79 * Return true if the PSDU is an S-MPDU or A-MPDU
80 * @return true if the PSDU is an S-MPDU or A-MPDU.
81 */
82 bool IsAggregate() const;
83
84 /**
85 * @brief Get the PSDU as a single packet
86 * @return the PSDU.
87 */
89
90 /**
91 * @brief Get the header of the i-th MPDU
92 * @param i index in the list of MPDUs
93 * @return the header of the i-th MPDU.
94 */
95 const WifiMacHeader& GetHeader(std::size_t i) const;
96
97 /**
98 * @brief Get the header of the i-th MPDU
99 * @param i index in the list of MPDUs
100 * @return the header of the i-th MPDU.
101 */
102 WifiMacHeader& GetHeader(std::size_t i);
103
104 /**
105 * @brief Get the payload of the i-th MPDU
106 * @param i index in the list of MPDUs
107 * @return the payload of the i-th MPDU.
108 */
109 Ptr<const Packet> GetPayload(std::size_t i) const;
110
111 /**
112 * @brief Get a copy of the i-th A-MPDU subframe (includes subframe header, MPDU, and possibly
113 * padding)
114 * @param i the index in the list of A-MPDU subframes \return the i-th A-MPDU subframe.
115 */
116 Ptr<Packet> GetAmpduSubframe(std::size_t i) const;
117
118 /**
119 * @brief Return the size of the i-th A-MPDU subframe.
120 * @param i the index in the list of A-MPDU subframes
121 * @return the size of the i-th A-MPDU subframe.
122 */
123 std::size_t GetAmpduSubframeSize(std::size_t i) const;
124
125 /**
126 * Get the Receiver Address (RA), which is common to all the MPDUs
127 * @return the Receiver Address.
128 */
129 Mac48Address GetAddr1() const;
130
131 /**
132 * Get the Transmitter Address (TA), which is common to all the MPDUs
133 * @return the Transmitter Address.
134 */
135 Mac48Address GetAddr2() const;
136
137 /**
138 * @return true if the Duration/ID field contains a value for setting the NAV
139 */
140 bool HasNav() const;
141
142 /**
143 * Get the duration from the Duration/ID field, which is common to all the MPDUs
144 * @return the duration from the Duration/ID field.
145 */
146 Time GetDuration() const;
147
148 /**
149 * Set the Duration/ID field on all the MPDUs
150 * @param duration the value for the Duration/ID field.
151 */
152 void SetDuration(Time duration);
153
154 /**
155 * Increment the frame retry count for all the MPDUs.
156 */
157 void IncrementRetryCount();
158
159 /**
160 * Get the set of TIDs of the QoS Data frames included in the PSDU. Note that
161 * only single-TID A-MPDUs are currently supported, hence the returned set
162 * contains at most one TID value.
163 *
164 * @return the set of TIDs of the QoS Data frames included in the PSDU.
165 */
166 std::set<uint8_t> GetTids() const;
167
168 /**
169 * Get the QoS Ack Policy of the QoS Data frames included in the PSDU that
170 * have the given TID. Also, check that all the QoS Data frames having the
171 * given TID have the same QoS Ack Policy. Do not call this method if there
172 * is no QoS Date frame in the PSDU.
173 *
174 * @param tid the given TID
175 * @return the QoS Ack Policy common to all QoS Data frames having the given TID.
176 */
178
179 /**
180 * Set the QoS Ack Policy of the QoS Data frames included in the PSDU that
181 * have the given TID to the given policy.
182 *
183 * @param tid the given TID
184 * @param policy the given QoS Ack policy
185 */
186 void SetAckPolicyForTid(uint8_t tid, WifiMacHeader::QosAckPolicy policy);
187
188 /**
189 * Get the maximum distance between the sequence number of any QoS Data frame
190 * included in this PSDU that is not an old frame and the given starting
191 * sequence number. If this PSDU does not contain any QoS Data frame that
192 * is not an old frame, an invalid distance (4096) is returned.
193 *
194 * @param startingSeq the given starting sequence number.
195 * @return the maximum distance between the sequence numbers included in the
196 * PSDU and the given starting sequence number
197 */
198 uint16_t GetMaxDistFromStartingSeq(uint16_t startingSeq) const;
199
200 /**
201 * @brief Return the size of the PSDU in bytes
202 *
203 * @return the size of the PSDU.
204 */
205 uint32_t GetSize() const;
206
207 /**
208 * @brief Return the number of MPDUs constituting the PSDU
209 *
210 * @return the number of MPDUs constituting the PSDU.
211 */
212 std::size_t GetNMpdus() const;
213
214 /**
215 * @brief Return a const iterator to the first MPDU
216 *
217 * @return a const iterator to the first MPDU.
218 */
219 std::vector<Ptr<WifiMpdu>>::const_iterator begin() const;
220
221 /**
222 * @brief Return an iterator to the first MPDU
223 *
224 * @return an iterator to the first MPDU.
225 */
226 std::vector<Ptr<WifiMpdu>>::iterator begin();
227
228 /**
229 * @brief Return a const iterator to past-the-last MPDU
230 *
231 * @return a const iterator to past-the-last MPDU.
232 */
233 std::vector<Ptr<WifiMpdu>>::const_iterator end() const;
234
235 /**
236 * @brief Return an iterator to past-the-last MPDU
237 *
238 * @return an iterator to past-the-last MPDU.
239 */
240 std::vector<Ptr<WifiMpdu>>::iterator end();
241
242 /**
243 * @brief Print the PSDU contents.
244 * @param os output stream in which the data should be printed.
245 */
246 void Print(std::ostream& os) const;
247
248 private:
249 bool m_isSingle; //!< true for an S-MPDU
250 std::vector<Ptr<WifiMpdu>> m_mpduList; //!< list of constituent MPDUs
251 uint32_t m_size; //!< the size of the PSDU in bytes
252};
253
254/**
255 * @brief Stream insertion operator.
256 *
257 * @param os the stream
258 * @param psdu the PSDU
259 * @returns a reference to the stream
260 */
261std::ostream& operator<<(std::ostream& os, const WifiPsdu& psdu);
262
263/// Map of PSDUs indexed by STA-ID
264using WifiPsduMap = std::unordered_map<uint16_t /* staId */, Ptr<WifiPsdu> /* PSDU */>;
265
266/// Map of const PSDUs indexed by STA-ID
267using WifiConstPsduMap = std::unordered_map<uint16_t /* staId */, Ptr<const WifiPsdu> /* PSDU */>;
268
269/**
270 * @brief Stream insertion operator.
271 *
272 * @param os the stream
273 * @param psduMap the PSDU map
274 * @returns a reference to the stream
275 */
276std::ostream& operator<<(std::ostream& os, const WifiPsduMap& psduMap);
277
278/**
279 * @brief Stream insertion operator.
280 *
281 * @param os the stream
282 * @param psduMap the PSDU map
283 * @returns a reference to the stream
284 */
285std::ostream& operator<<(std::ostream& os, const WifiConstPsduMap& psduMap);
286
287} // namespace ns3
288
289#endif /* WIFI_PSDU_H */
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Implements the IEEE 802.11 MAC header.
QosAckPolicy
Ack policy for QoS frames.
WifiPsdu stores an MPDU, S-MPDU or A-MPDU, by keeping header(s) and payload(s) separate for each cons...
Definition wifi-psdu.h:33
std::set< uint8_t > GetTids() const
Get the set of TIDs of the QoS Data frames included in the PSDU.
Definition wifi-psdu.cc:177
void SetAckPolicyForTid(uint8_t tid, WifiMacHeader::QosAckPolicy policy)
Set the QoS Ack Policy of the QoS Data frames included in the PSDU that have the given TID to the giv...
Definition wifi-psdu.cc:225
const WifiMacHeader & GetHeader(std::size_t i) const
Get the header of the i-th MPDU.
Definition wifi-psdu.cc:278
void Print(std::ostream &os) const
Print the PSDU contents.
Definition wifi-psdu.cc:356
Time GetDuration() const
Get the duration from the Duration/ID field, which is common to all the MPDUs.
Definition wifi-psdu.cc:142
Ptr< const Packet > GetPacket() const
Get the PSDU as a single packet.
Definition wifi-psdu.cc:78
Ptr< Packet > GetAmpduSubframe(std::size_t i) const
Get a copy of the i-th A-MPDU subframe (includes subframe header, MPDU, and possibly padding)
Definition wifi-psdu.cc:296
std::vector< Ptr< WifiMpdu > >::const_iterator end() const
Return a const iterator to past-the-last MPDU.
Definition wifi-psdu.cc:344
std::vector< Ptr< WifiMpdu > >::const_iterator begin() const
Return a const iterator to the first MPDU.
Definition wifi-psdu.cc:332
WifiPsdu(Ptr< const Packet > p, const WifiMacHeader &header)
Create a PSDU storing an MPDU.
Definition wifi-psdu.cc:24
Mac48Address GetAddr2() const
Get the Transmitter Address (TA), which is common to all the MPDUs.
Definition wifi-psdu.cc:117
bool HasNav() const
Definition wifi-psdu.cc:132
uint32_t m_size
the size of the PSDU in bytes
Definition wifi-psdu.h:251
virtual ~WifiPsdu()
Definition wifi-psdu.cc:61
uint32_t GetSize() const
Return the size of the PSDU in bytes.
Definition wifi-psdu.cc:272
Ptr< const Packet > GetPayload(std::size_t i) const
Get the payload of the i-th MPDU.
Definition wifi-psdu.cc:290
std::size_t GetAmpduSubframeSize(std::size_t i) const
Return the size of the i-th A-MPDU subframe.
Definition wifi-psdu.cc:313
bool m_isSingle
true for an S-MPDU
Definition wifi-psdu.h:249
WifiPsdu(Ptr< const WifiMpdu > mpdu, bool isSingle)
Create a PSDU storing an MPDU or S-MPDU.
Mac48Address GetAddr1() const
Get the Receiver Address (RA), which is common to all the MPDUs.
Definition wifi-psdu.cc:102
bool IsAggregate() const
Return true if the PSDU is an S-MPDU or A-MPDU.
Definition wifi-psdu.cc:72
bool IsSingle() const
Return true if the PSDU is an S-MPDU.
Definition wifi-psdu.cc:66
void SetDuration(Time duration)
Set the Duration/ID field on all the MPDUs.
Definition wifi-psdu.cc:157
void IncrementRetryCount()
Increment the frame retry count for all the MPDUs.
Definition wifi-psdu.cc:167
std::vector< Ptr< WifiMpdu > > m_mpduList
list of constituent MPDUs
Definition wifi-psdu.h:250
uint16_t GetMaxDistFromStartingSeq(uint16_t startingSeq) const
Get the maximum distance between the sequence number of any QoS Data frame included in this PSDU that...
Definition wifi-psdu.cc:238
std::size_t GetNMpdus() const
Return the number of MPDUs constituting the PSDU.
Definition wifi-psdu.cc:326
WifiMacHeader::QosAckPolicy GetAckPolicyForTid(uint8_t tid) const
Get the QoS Ack Policy of the QoS Data frames included in the PSDU that have the given TID.
Definition wifi-psdu.cc:191
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
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.
Definition wifi-mac.h:78
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:38