A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qos-utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
18 */
19
20#ifndef QOS_UTILS_H
21#define QOS_UTILS_H
22
23#include "ns3/fatal-error.h"
24#include "ns3/ptr.h"
25
26#include <map>
27
28namespace ns3
29{
30
31class Packet;
32class WifiMacHeader;
33class QueueItem;
34class Mac48Address;
35
36typedef std::pair<Mac48Address, uint8_t> WifiAddressTidPair; //!< (MAC address, TID) pair
37
38/**
39 * Function object to compute the hash of a (MAC address, TID) pair
40 */
42{
43 /**
44 * Functional operator for (MAC address, TID) hash computation.
45 *
46 * \param addressTidPair the (MAC address, TID) pair
47 * \return the hash
48 */
49 std::size_t operator()(const WifiAddressTidPair& addressTidPair) const;
50};
51
52/**
53 * Function object to compute the hash of a MAC address
54 */
56{
57 /**
58 * Functional operator for MAC address hash computation.
59 *
60 * \param address the MAC address
61 * \return the hash
62 */
63 std::size_t operator()(const Mac48Address& address) const;
64};
65
66/**
67 * \ingroup wifi
68 * This enumeration defines the Access Categories as an enumeration
69 * with values corresponding to the AC index (ACI) values specified
70 * (Table 8-104 "ACI-to-AC coding"; IEEE 802.11-2012).
71 */
72enum AcIndex : uint8_t
73{
74 /** Best Effort */
75 AC_BE = 0,
76 /** Background */
77 AC_BK = 1,
78 /** Video */
79 AC_VI = 2,
80 /** Voice */
81 AC_VO = 3,
82 /** Non-QoS */
84 /** Beacon queue */
86 /** Total number of ACs */
88};
89
90/**
91 * \brief Stream insertion operator.
92 *
93 * \param os the stream
94 * \param acIndex the AC index
95 * \returns a reference to the stream
96 */
97inline std::ostream&
98operator<<(std::ostream& os, const AcIndex& acIndex)
99{
100 switch (acIndex)
101 {
102 case AC_BE:
103 return (os << "AC BE");
104 case AC_BK:
105 return (os << "AC BK");
106 case AC_VI:
107 return (os << "AC VI");
108 case AC_VO:
109 return (os << "AC VO");
110 case AC_BE_NQOS:
111 return (os << "AC BE NQOS");
112 case AC_BEACON:
113 return (os << "AC BEACON");
114 case AC_UNDEF:
115 return (os << "AC Undefined");
116 default:
117 NS_FATAL_ERROR("Unknown AC index");
118 return (os << "Unknown");
119 }
120}
121
122/**
123 * \ingroup wifi
124 * This class stores the pair of TIDs of an Access Category.
125 */
127{
128 public:
129 /**
130 * Constructor.
131 *
132 * \param lowTid the TID with lower priority
133 * \param highTid the TID with higher priority
134 */
135 WifiAc(uint8_t lowTid, uint8_t highTid);
136 /**
137 * Get the TID with lower priority
138 *
139 * \return the TID with lower priority
140 */
141 uint8_t GetLowTid() const;
142 /**
143 * Get the TID with higher priority
144 *
145 * \return the TID with higher priority
146 */
147 uint8_t GetHighTid() const;
148 /**
149 * Given a TID belonging to this Access Category, get the other TID of this AC.
150 *
151 * \param tid a TID belonging to this AC
152 * \return the other TID belonging to this AC
153 */
154 uint8_t GetOtherTid(uint8_t tid) const;
155
156 private:
157 uint8_t m_lowTid; //!< the TID with lower priority
158 uint8_t m_highTid; //!< the TID with higher priority
159};
160
161/**
162 * \ingroup wifi
163 * Operator> overload returning true if the AC on the left has higher priority
164 * than the AC on the right.
165 *
166 * \param left the AC on the left of operator>
167 * \param right the AC on the right of operator>
168 * \return true if the AC on the left has higher priority than the AC on the right
169 */
170bool operator>(AcIndex left, AcIndex right);
171
172/**
173 * \ingroup wifi
174 * Operator>= overload returning true if the AC on the left has higher or the same
175 * priority than the AC on the right.
176 *
177 * \param left the AC on the left of operator>=
178 * \param right the AC on the right of operator>=
179 * \return true if the AC on the left has higher or the same priority than the AC on the right
180 */
181bool operator>=(AcIndex left, AcIndex right);
182
183/**
184 * \ingroup wifi
185 * Operator< overload returning true if the AC on the left has lower priority
186 * than the AC on the right.
187 *
188 * \param left the AC on the left of operator<
189 * \param right the AC on the right of operator<
190 * \return true if the AC on the left has lower priority than the AC on the right
191 */
192bool operator<(AcIndex left, AcIndex right);
193
194/**
195 * \ingroup wifi
196 * Operator<= overload returning true if the AC on the left has lower or the same
197 * priority than the AC on the right.
198 *
199 * \param left the AC on the left of operator<=
200 * \param right the AC on the right of operator<=
201 * \return true if the AC on the left has lower or the same priority than the AC on the right
202 */
203bool operator<=(AcIndex left, AcIndex right);
204
205/**
206 * Map containing the four ACs in increasing order of priority (according to
207 * Table 10-1 "UP-to-AC Mappings" of 802.11-2016)
208 */
209extern const std::map<AcIndex, WifiAc> wifiAcList;
210
211/**
212 * \ingroup wifi
213 * Maps TID (Traffic ID) to Access classes.
214 * For more details see (Table 9-1 "UP-to-AC mapping"; IEEE 802.11-2012).
215 *
216 * \param tid the Traffic ID to be mapped to Access class
217 * \return the access class for the given TID
218 */
219AcIndex QosUtilsMapTidToAc(uint8_t tid);
220
221/**
222 * \ingroup wifi
223 * If a QoS tag is attached to the packet, returns a value < 8.
224 * A value >= 8 is returned otherwise.
225 *
226 * \param packet the packet to checked for a QoS tag
227 *
228 * \return a value less than 8 if QoS tag was present, a value >= 8
229 * is returned if no QoS tag was present
230 */
232
233/**
234 * \ingroup wifi
235 * Next function is useful to correctly sort buffered packets under block ack.
236 * When an BAR is received from originator station, completed "old"
237 * (see section 9.10.3 in IEEE 802.11e) packets must be forwarded up before "new" packets.
238 *
239 * \param seqControl the sequence control field
240 * \param endSequence the sequence number ending the acknowledgment window
241 *
242 * \return a unique integer for the given sequence control and end sequence
243 */
244uint32_t QosUtilsMapSeqControlToUniqueInteger(uint16_t seqControl, uint16_t endSequence);
245
246/**
247 * \ingroup wifi
248 * This function checks if packet with sequence number <i>seqNumber</i> is an "old" packet.
249 * The sequence number space is considered divided into two parts, one of which is "old" and
250 * one of which is "new" by means of a boundary created by adding half the sequence number
251 * range to the starting sequence number <i>startingSeq</i>. So this function works fine also
252 * when <i>seqNumber</i> is smaller than <i>startingSeq</i> and <i>startingSeq</i> + 2048 is greater
253 * than 4096 because all comparison are circular modulo 2^12. The following are possible scenarios:
254 *
255 * ----- = old packets
256 * +++++ = new packets
257 *
258 * CASE A:
259 *
260 * 0 4095
261 * |++++++|----------------|++++++|
262 * ^ ^
263 * | endSeq | startingSeq
264 *
265 *
266 * CASE B:
267 *
268 * 0 4095
269 * |------|++++++++++++++++|-----|
270 * ^ ^
271 * | startingSeq | endSeq
272 *
273 * Here in the examples endSeq is the sequenceNumber of the "last" new packet.
274 * So this function, when specified a starting sequence and a sequence number, returns true
275 * if that packet (with sequence number <i>numberSeq</i>)) belongs to the section of the
276 * sequence number space marked with '-' characters. The function returns false otherwise.
277 *
278 * \param startingSeq the starting sequence number
279 * \param seqNumber the sequence number to be checked
280 *
281 * \return true if the packet is old, false otherwise
282 */
283bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber);
284
285/**
286 * \ingroup wifi
287 * This function is useful to get traffic id of different packet types.
288 *
289 * \param packet packet to check
290 * \param hdr 802.11 header for packet to check
291 * \return the TID of different packet types
292 */
293uint8_t GetTid(Ptr<const Packet> packet, const WifiMacHeader hdr);
294
295/**
296 * \ingroup wifi
297 * \brief Determine the TX queue for a given packet
298 * \param item the packet
299 * \returns the access category
300 *
301 * Modeled after the Linux function ieee80211_select_queue (net/mac80211/wme.c).
302 * A SocketPriority tag is attached to the packet (or the existing one is
303 * replaced) to carry the user priority, which is set to the three most
304 * significant bits of the DS field (TOS field in case of IPv4 and Traffic
305 * Class field in case of IPv6). The Access Category corresponding to the
306 * user priority according to the QosUtilsMapTidToAc function is returned.
307 *
308 * The following table shows the mapping for the Diffserv Per Hop Behaviors.
309 *
310 * PHB | TOS (binary) | UP | Access Category
311 * -----|--------------|-----|-----------------
312 * EF | 101110xx | 5 | AC_VI
313 * AF11 | 001010xx | 1 | AC_BK
314 * AF21 | 010010xx | 2 | AC_BK
315 * AF31 | 011010xx | 3 | AC_BE
316 * AF41 | 100010xx | 4 | AC_VI
317 * AF12 | 001100xx | 1 | AC_BK
318 * AF22 | 010100xx | 2 | AC_BK
319 * AF32 | 011100xx | 3 | AC_BE
320 * AF42 | 100100xx | 4 | AC_VI
321 * AF13 | 001110xx | 1 | AC_BK
322 * AF23 | 010110xx | 2 | AC_BK
323 * AF33 | 011110xx | 3 | AC_BE
324 * AF43 | 100110xx | 4 | AC_VI
325 * CS0 | 000000xx | 0 | AC_BE
326 * CS1 | 001000xx | 1 | AC_BK
327 * CS2 | 010000xx | 2 | AC_BK
328 * CS3 | 011000xx | 3 | AC_BE
329 * CS4 | 100000xx | 4 | AC_VI
330 * CS5 | 101000xx | 5 | AC_VI
331 * CS6 | 110000xx | 6 | AC_VO
332 * CS7 | 111000xx | 7 | AC_VO
333 *
334 * This method is called by the traffic control layer before enqueuing a
335 * packet in the queue disc, if a queue disc is installed on the outgoing
336 * device, or passing a packet to the device, otherwise.
337 */
339
340} // namespace ns3
341
342#endif /* QOS_UTILS_H */
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
This class stores the pair of TIDs of an Access Category.
Definition: qos-utils.h:127
uint8_t GetOtherTid(uint8_t tid) const
Given a TID belonging to this Access Category, get the other TID of this AC.
Definition: qos-utils.cc:73
uint8_t m_highTid
the TID with higher priority
Definition: qos-utils.h:158
uint8_t GetHighTid() const
Get the TID with higher priority.
Definition: qos-utils.cc:67
uint8_t GetLowTid() const
Get the TID with lower priority.
Definition: qos-utils.cc:61
uint8_t m_lowTid
the TID with lower priority
Definition: qos-utils.h:157
Implements the IEEE 802.11 MAC header.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition: int64x64.h:174
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition: int64x64.h:161
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition: length.cc:421
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:134
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet.
Definition: qos-utils.cc:182
uint32_t QosUtilsMapSeqControlToUniqueInteger(uint16_t seqControl, uint16_t endSequence)
Next function is useful to correctly sort buffered packets under block ack.
Definition: qos-utils.cc:171
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
This function is useful to get traffic id of different packet types.
Definition: qos-utils.cc:191
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a QoS tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:156
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
uint8_t SelectQueueByDSField(Ptr< QueueItem > item)
Determine the TX queue for a given packet.
Definition: qos-utils.cc:253
@ AC_BE_NQOS
Non-QoS.
Definition: qos-utils.h:83
@ AC_BE
Best Effort.
Definition: qos-utils.h:75
@ AC_VO
Voice.
Definition: qos-utils.h:81
@ AC_VI
Video.
Definition: qos-utils.h:79
@ AC_BK
Background.
Definition: qos-utils.h:77
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:87
@ AC_BEACON
Beacon queue.
Definition: qos-utils.h:85
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:159
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
const std::map< AcIndex, WifiAc > wifiAcList
Map containing the four ACs in increasing order of priority (according to Table 10-1 "UP-to-AC Mappin...
Definition: qos-utils.cc:126
std::pair< Mac48Address, uint8_t > WifiAddressTidPair
(MAC address, TID) pair
Definition: qos-utils.h:36
Function object to compute the hash of a MAC address.
Definition: qos-utils.h:56
std::size_t operator()(const Mac48Address &address) const
Functional operator for MAC address hash computation.
Definition: qos-utils.cc:45
Function object to compute the hash of a (MAC address, TID) pair.
Definition: qos-utils.h:42
std::size_t operator()(const WifiAddressTidPair &addressTidPair) const
Functional operator for (MAC address, TID) hash computation.
Definition: qos-utils.cc:34