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