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