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;
30
31/**
32 * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction
33 * field in IEEE 802.11be D3.1 Figure 9-1002ap
34 */
35enum class WifiDirection : uint8_t
36{
37 DOWNLINK = 0,
38 UPLINK = 1,
40};
41
42/**
43 * @brief Stream insertion operator.
44 *
45 * @param os the stream
46 * @param direction the direction
47 * @returns a reference to the stream
48 */
49inline std::ostream&
50operator<<(std::ostream& os, const WifiDirection& direction)
51{
52 switch (direction)
53 {
55 return (os << "DOWNLINK");
57 return (os << "UPLINK");
59 return (os << "BOTH_DIRECTIONS");
60 default:
61 NS_FATAL_ERROR("Invalid direction");
62 return (os << "INVALID");
63 }
64}
65
66/// @brief TID-indexed map of the link set to which the TID is mapped
67using WifiTidLinkMapping = std::map<uint8_t, std::set<uint8_t>>;
68
69/**
70 * Convert from dBm to Watts.
71 *
72 * @param val the value in dBm
73 *
74 * @return the equivalent Watts for the given dBm
75 */
77/**
78 * Convert from dB to ratio.
79 *
80 * @param val the value in dB
81 *
82 * @return ratio in linear scale
83 */
84double DbToRatio(dB_u val);
85/**
86 * Convert from Watts to dBm.
87 *
88 * @param val the value in Watts
89 *
90 * @return the equivalent dBm for the given Watts
91 */
93/**
94 * Convert from ratio to dB.
95 *
96 * @param ratio the ratio in linear scale
97 *
98 * @return the value in dB
99 */
100dB_u RatioToDb(double ratio);
101
102/**
103 * Convert from MHz to Hz.
104 *
105 * @param val the value in MHz
106 *
107 * @return the value in Hz
108 */
109inline Hz_u
111{
112 return val * 1e6;
113}
114
115/**
116 * Convert from Hz to MHz.
117 *
118 * @param val the value in Hz
119 *
120 * @return the value in MHz
121 */
122inline MHz_u
124{
125 return val * 1e-6;
126}
127
128/**
129 * Return the number of 20 MHz subchannels covering the channel width.
130 *
131 * @param channelWidth the channel width
132 * @return the number of 20 MHz subchannels
133 */
134inline std::size_t
136{
137 NS_ASSERT(static_cast<uint16_t>(channelWidth) % 20 == 0);
138 return channelWidth / MHz_u{20};
139}
140
141/**
142 * Return the number of 20 MHz subchannels covering the channel width between a lower frequency and
143 * an upper frequency. This function should only be called when the channel width between the lower
144 * frequency and the upper frequency is a multiple of 20 MHz.
145 *
146 * @param lower the lower frequency
147 * @param upper the upper frequency
148 * @return the number of 20 MHz subchannels
149 */
150inline std::size_t
152{
153 NS_ASSERT(upper >= lower);
154 const auto width = upper - lower;
155 NS_ASSERT((static_cast<uint16_t>(width) % 20 == 0));
156 return Count20MHzSubchannels(width);
157}
158
159/**
160 * Return the total Ack size (including FCS trailer).
161 *
162 * @return the total Ack size in bytes
163 */
165/**
166 * Return the total BlockAck size (including FCS trailer).
167 *
168 * @param type the BlockAck type
169 * @return the total BlockAck size in bytes
170 */
171uint32_t GetBlockAckSize(BlockAckType type);
172/**
173 * Return the total BlockAckRequest size (including FCS trailer).
174 *
175 * @param type the BlockAckRequest type
176 * @return the total BlockAckRequest size in bytes
177 */
178uint32_t GetBlockAckRequestSize(BlockAckReqType type);
179/**
180 * Return the total MU-BAR size (including FCS trailer).
181 *
182 * @param types the list of Block Ack Request types of the individual BARs
183 * @return the total MU-BAR size in bytes
184 */
185uint32_t GetMuBarSize(std::list<BlockAckReqType> types);
186/**
187 * Return the total RTS size (including FCS trailer).
188 *
189 * @return the total RTS size in bytes
190 */
192/**
193 * Return the total CTS size (including FCS trailer).
194 *
195 * @return the total CTS size in bytes
196 */
198/**
199 * @param seq MPDU sequence number
200 * @param winstart sequence number window start
201 * @param winsize the size of the sequence number window
202 * @returns true if in the window
203 *
204 * This method checks if the MPDU's sequence number is inside the scoreboard boundaries or not
205 */
206bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize);
207/**
208 * Add FCS trailer to a packet.
209 *
210 * @param packet the packet to add a trailer to
211 */
212void AddWifiMacTrailer(Ptr<Packet> packet);
213/**
214 * Return the total size of the packet after WifiMacHeader and FCS trailer
215 * have been added.
216 *
217 * @param packet the packet to be encapsulated with WifiMacHeader and FCS trailer
218 * @param hdr the WifiMacHeader
219 * @param isAmpdu whether packet is part of an A-MPDU
220 * @return the total packet size
221 */
222uint32_t GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu);
223
224/**
225 * Check if the given TID-to-Link Mappings are valid for a negotiation type of 1. Specifically,
226 * it is checked whether all TIDs are mapped to the same set of links.
227 *
228 * @param dlLinkMapping the given TID-to-Link Mapping for Downlink
229 * @param ulLinkMapping the given TID-to-Link Mapping for Uplink
230 * @return whether the given TID-to-Link Mappings are valid for a negotiation type of 1
231 */
233 const WifiTidLinkMapping& ulLinkMapping);
234
235/**
236 * Check whether a MAC destination address corresponds to a groupcast transmission.
237 *
238 * @param adr the MAC address
239 * @return true if the MAC address is a group address that is not a broadcast address
240 */
241bool IsGroupcast(const Mac48Address& adr);
242
243/**
244 * Return whether a given packet is transmitted using the GCR service.
245 *
246 * @param mac a pointer to the wifi MAC
247 * @param hdr the MAC header of the packet to check
248 * @return true if the packet is transmitted using the GCR service, false otherwise
249 */
250bool IsGcr(Ptr<WifiMac> mac, const WifiMacHeader& hdr);
251
252/**
253 * Get the MAC address of the individually addressed recipient to use for a given packet.
254 * If this is a groupcast packet to be transmitted with the GCR service, the GCR manager is
255 * requested to return which individually addressed recipient to use. Otherwise, it corresponds to
256 * the address1 of the MAC header.
257 *
258 * @param mac a pointer to the wifi MAC
259 * @param hdr the MAC header of the packet to check
260 * @return the MAC address of the individually addressed recipient to use
261 */
262Mac48Address GetIndividuallyAddressedRecipient(Ptr<WifiMac> mac, const WifiMacHeader& hdr);
263
264/// Size of the space of sequence numbers
265static constexpr uint16_t SEQNO_SPACE_SIZE = 4096;
266
267/// Size of the half the space of sequence numbers (used to determine old packets)
268static constexpr uint16_t SEQNO_SPACE_HALF_SIZE = SEQNO_SPACE_SIZE / 2;
269
270/// Link ID for single link operations (helps tracking places where correct link
271/// ID is to be used to support multi-link operations)
272static constexpr uint8_t SINGLE_LINK_OP_ID = 0;
273
274/// Invalid link identifier
275static constexpr uint8_t WIFI_LINKID_UNDEFINED = 0xff;
276
277/// Invalid TID identifier
278static constexpr uint8_t WIFI_TID_UNDEFINED = 0xff;
279
280/// Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec. 3.1)
281/// Used to initialize WIFI_TU
282constexpr int WIFI_TU_US = 1024;
283
284/// Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
285extern const Time WIFI_TU;
286
287} // namespace ns3
288
289#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:268
static constexpr uint8_t WIFI_TID_UNDEFINED
Invalid TID identifier.
Definition wifi-utils.h:278
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition wifi-utils.cc:24
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition wifi-utils.cc:97
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:46
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:123
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:39
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:67
std::size_t Count20MHzSubchannels(MHz_u channelWidth)
Return the number of 20 MHz subchannels covering the channel width.
Definition wifi-utils.h:135
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:70
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:272
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:282
double DbToRatio(dB_u val)
Convert from dB to ratio.
Definition wifi-utils.cc:27
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:80
WifiDirection
Wifi direction.
Definition wifi-utils.h:36
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:33
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition wifi-utils.h:265
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:60
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:275
Hz_u MHzToHz(MHz_u val)
Convert from MHz to Hz.
Definition wifi-utils.h:110
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition wifi-utils.cc:52
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)