A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#ifndef WIFI_UTILS_H
10#define WIFI_UTILS_H
11
12#include "block-ack-type.h"
13#include "wifi-types.h"
14
15#include "ns3/fatal-error.h"
16#include "ns3/nstime.h"
17#include "ns3/ptr.h"
18
19#include <list>
20#include <map>
21#include <set>
22
23namespace ns3
24{
25
26class Mac48Address;
27class WifiMacHeader;
28class Packet;
29class WifiMac;
30class WifiTxVector;
31
32/**
33 * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction
34 * field in IEEE 802.11be D3.1 Figure 9-1002ap
35 */
36enum class WifiDirection : uint8_t
37{
38 DOWNLINK = 0,
39 UPLINK = 1,
41};
42
43/**
44 * @brief Stream insertion operator.
45 *
46 * @param os the stream
47 * @param direction the direction
48 * @returns a reference to the stream
49 */
50inline std::ostream&
51operator<<(std::ostream& os, const WifiDirection& direction)
52{
53 switch (direction)
54 {
56 return (os << "DOWNLINK");
58 return (os << "UPLINK");
60 return (os << "BOTH_DIRECTIONS");
61 default:
62 NS_FATAL_ERROR("Invalid direction");
63 return (os << "INVALID");
64 }
65}
66
67/// @brief TID-indexed map of the link set to which the TID is mapped
68using WifiTidLinkMapping = std::map<uint8_t, std::set<uint8_t>>;
69
70/**
71 * Convert from dBm to Watts.
72 *
73 * @param val the value in dBm
74 *
75 * @return the equivalent Watts for the given dBm
76 */
78/**
79 * Convert from dB to ratio.
80 *
81 * @param val the value in dB
82 *
83 * @return ratio in linear scale
84 */
85double DbToRatio(dB_u val);
86/**
87 * Convert from Watts to dBm.
88 *
89 * @param val the value in Watts
90 *
91 * @return the equivalent dBm for the given Watts
92 */
94/**
95 * Convert from ratio to dB.
96 *
97 * @param ratio the ratio in linear scale
98 *
99 * @return the value in dB
100 */
101dB_u RatioToDb(double ratio);
102
103/**
104 * Convert from MHz to Hz.
105 *
106 * @param val the value in MHz
107 *
108 * @return the value in Hz
109 */
110inline Hz_u
112{
113 return val * 1e6;
114}
115
116/**
117 * Convert from Hz to MHz.
118 *
119 * @param val the value in Hz
120 *
121 * @return the value in MHz
122 */
123inline MHz_u
125{
126 return val * 1e-6;
127}
128
129/**
130 * Return the number of 20 MHz subchannels covering the channel width.
131 *
132 * @param channelWidth the channel width
133 * @return the number of 20 MHz subchannels
134 */
135inline std::size_t
137{
138 NS_ASSERT(static_cast<uint16_t>(channelWidth) % 20 == 0);
139 return channelWidth / MHz_u{20};
140}
141
142/**
143 * Return the number of 20 MHz subchannels covering the channel width between a lower frequency and
144 * an upper frequency. This function should only be called when the channel width between the lower
145 * frequency and the upper frequency is a multiple of 20 MHz.
146 *
147 * @param lower the lower frequency
148 * @param upper the upper frequency
149 * @return the number of 20 MHz subchannels
150 */
151inline std::size_t
153{
154 NS_ASSERT(upper >= lower);
155 const auto width = upper - lower;
156 NS_ASSERT((static_cast<uint16_t>(width) % 20 == 0));
157 return Count20MHzSubchannels(width);
158}
159
160/**
161 * Return the total Ack size (including FCS trailer).
162 *
163 * @return the total Ack size in bytes
164 */
166/**
167 * Return the total BlockAck size (including FCS trailer).
168 *
169 * @param type the BlockAck type
170 * @return the total BlockAck size in bytes
171 */
172uint32_t GetBlockAckSize(BlockAckType type);
173/**
174 * Return the total BlockAckRequest size (including FCS trailer).
175 *
176 * @param type the BlockAckRequest type
177 * @return the total BlockAckRequest size in bytes
178 */
179uint32_t GetBlockAckRequestSize(BlockAckReqType type);
180/**
181 * Return the total MU-BAR size (including FCS trailer).
182 *
183 * @param types the list of Block Ack Request types of the individual BARs
184 * @return the total MU-BAR size in bytes
185 */
186uint32_t GetMuBarSize(std::list<BlockAckReqType> types);
187/**
188 * Return the total RTS size (including FCS trailer).
189 *
190 * @return the total RTS size in bytes
191 */
193/**
194 * Return the total CTS size (including FCS trailer).
195 *
196 * @return the total CTS size in bytes
197 */
199
200/**
201 * @param txVector the TXVECTOR used to transmit a frame whose reception failed
202 * @return the estimated Ack TX time, based on Table 10-8 of IEEE 802.11REVme D7.0
203 */
204Time GetEstimatedAckTxTime(const WifiTxVector& txVector);
205
206/**
207 * @param seq MPDU sequence number
208 * @param winstart sequence number window start
209 * @param winsize the size of the sequence number window
210 * @returns true if in the window
211 *
212 * This method checks if the MPDU's sequence number is inside the scoreboard boundaries or not
213 */
214bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize);
215/**
216 * Add FCS trailer to a packet.
217 *
218 * @param packet the packet to add a trailer to
219 */
220void AddWifiMacTrailer(Ptr<Packet> packet);
221/**
222 * Return the total size of the packet after WifiMacHeader and FCS trailer
223 * have been added.
224 *
225 * @param packet the packet to be encapsulated with WifiMacHeader and FCS trailer
226 * @param hdr the WifiMacHeader
227 * @param isAmpdu whether packet is part of an A-MPDU
228 * @return the total packet size
229 */
230uint32_t GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu);
231
232/**
233 * Check if the given TID-to-Link Mappings are valid for a negotiation type of 1. Specifically,
234 * it is checked whether all TIDs are mapped to the same set of links.
235 *
236 * @param dlLinkMapping the given TID-to-Link Mapping for Downlink
237 * @param ulLinkMapping the given TID-to-Link Mapping for Uplink
238 * @return whether the given TID-to-Link Mappings are valid for a negotiation type of 1
239 */
241 const WifiTidLinkMapping& ulLinkMapping);
242
243/**
244 * Check whether a MAC destination address corresponds to a groupcast transmission.
245 *
246 * @param adr the MAC address
247 * @return true if the MAC address is a group address that is not a broadcast address
248 */
249bool IsGroupcast(const Mac48Address& adr);
250
251/**
252 * Return whether a given packet is transmitted using the GCR service.
253 *
254 * @param mac a pointer to the wifi MAC
255 * @param hdr the MAC header of the packet to check
256 * @return true if the packet is transmitted using the GCR service, false otherwise
257 */
258bool IsGcr(Ptr<WifiMac> mac, const WifiMacHeader& hdr);
259
260/**
261 * Get the MAC address of the individually addressed recipient to use for a given packet.
262 * If this is a groupcast packet to be transmitted with the GCR service, the GCR manager is
263 * requested to return which individually addressed recipient to use. Otherwise, it corresponds to
264 * the address1 of the MAC header.
265 *
266 * @param mac a pointer to the wifi MAC
267 * @param hdr the MAC header of the packet to check
268 * @return the MAC address of the individually addressed recipient to use
269 */
270Mac48Address GetIndividuallyAddressedRecipient(Ptr<WifiMac> mac, const WifiMacHeader& hdr);
271
272/// Size of the space of sequence numbers
273static constexpr uint16_t SEQNO_SPACE_SIZE = 4096;
274
275/// Size of the half the space of sequence numbers (used to determine old packets)
276static constexpr uint16_t SEQNO_SPACE_HALF_SIZE = SEQNO_SPACE_SIZE / 2;
277
278/// Link ID for single link operations (helps tracking places where correct link
279/// ID is to be used to support multi-link operations)
280static constexpr uint8_t SINGLE_LINK_OP_ID = 0;
281
282/// Invalid link identifier
283static constexpr uint8_t WIFI_LINKID_UNDEFINED = 0xff;
284
285/// Invalid TID identifier
286static constexpr uint8_t WIFI_TID_UNDEFINED = 0xff;
287
288/// Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec. 3.1)
289/// Used to initialize WIFI_TU
290constexpr int WIFI_TU_US = 1024;
291
292/// Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
293extern const Time WIFI_TU;
294
295} // namespace ns3
296
297#endif /* WIFI_UTILS_H */
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr uint16_t SEQNO_SPACE_HALF_SIZE
Size of the half the space of sequence numbers (used to determine old packets)
Definition wifi-utils.h:276
static constexpr uint8_t WIFI_TID_UNDEFINED
Invalid TID identifier.
Definition wifi-utils.h:286
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition wifi-utils.cc:25
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition wifi-utils.cc:98
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:47
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
double Hz_u
Hz weak type.
Definition wifi-units.h:30
MHz_u HzToMHz(Hz_u val)
Convert from Hz to MHz.
Definition wifi-utils.h:124
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:40
double MHz_u
MHz weak type.
Definition wifi-units.h:31
bool IsGroupcast(const Mac48Address &adr)
Check whether a MAC destination address corresponds to a groupcast transmission.
std::map< uint8_t, std::set< uint8_t > > WifiTidLinkMapping
TID-indexed map of the link set to which the TID is mapped.
Definition wifi-utils.h:68
Time GetEstimatedAckTxTime(const WifiTxVector &txVector)
std::size_t Count20MHzSubchannels(MHz_u channelWidth)
Return the number of 20 MHz subchannels covering the channel width.
Definition wifi-utils.h:136
double dBm_u
dBm weak type
Definition wifi-units.h:27
uint32_t GetBlockAckRequestSize(BlockAckReqType type)
Return the total BlockAckRequest size (including FCS trailer).
Definition wifi-utils.cc:71
static constexpr uint8_t SINGLE_LINK_OP_ID
Link ID for single link operations (helps tracking places where correct link ID is to be used to supp...
Definition wifi-utils.h:280
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:290
double DbToRatio(dB_u val)
Convert from dB to ratio.
Definition wifi-utils.cc:28
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:81
WifiDirection
Wifi direction.
Definition wifi-utils.h:37
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:34
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition wifi-utils.h:273
bool TidToLinkMappingValidForNegType1(const WifiTidLinkMapping &dlLinkMapping, const WifiTidLinkMapping &ulLinkMapping)
Check if the given TID-to-Link Mappings are valid for a negotiation type of 1.
uint32_t GetBlockAckSize(BlockAckType type)
Return the total BlockAck size (including FCS trailer).
Definition wifi-utils.cc:61
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
static constexpr uint8_t WIFI_LINKID_UNDEFINED
Invalid link identifier.
Definition wifi-utils.h:283
Hz_u MHzToHz(MHz_u val)
Convert from MHz to Hz.
Definition wifi-utils.h:111
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition wifi-utils.cc:53
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.
bool IsGcr(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Return whether a given packet is transmitted using the GCR service.
double Watt_u
Watt weak type.
Definition wifi-units.h:25
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Mac48Address GetIndividuallyAddressedRecipient(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Get the MAC address of the individually addressed recipient to use for a given packet.
double dB_u
dB weak type
Definition wifi-units.h:28
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)