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