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 WifiMacHeader;
27class Packet;
28
29/**
30 * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction
31 * field in IEEE 802.11be D3.1 Figure 9-1002ap
32 */
33enum class WifiDirection : uint8_t
34{
35 DOWNLINK = 0,
36 UPLINK = 1,
38};
39
40/**
41 * \brief Stream insertion operator.
42 *
43 * \param os the stream
44 * \param direction the direction
45 * \returns a reference to the stream
46 */
47inline std::ostream&
48operator<<(std::ostream& os, const WifiDirection& direction)
49{
50 switch (direction)
51 {
53 return (os << "DOWNLINK");
55 return (os << "UPLINK");
57 return (os << "BOTH_DIRECTIONS");
58 default:
59 NS_FATAL_ERROR("Invalid direction");
60 return (os << "INVALID");
61 }
62}
63
64/// @brief TID-indexed map of the link set to which the TID is mapped
65using WifiTidLinkMapping = std::map<uint8_t, std::set<uint8_t>>;
66
67/**
68 * Convert from dBm to Watts.
69 *
70 * \param val the value in dBm
71 *
72 * \return the equivalent Watts for the given dBm
73 */
75/**
76 * Convert from dB to ratio.
77 *
78 * \param val the value in dB
79 *
80 * \return ratio in linear scale
81 */
82double DbToRatio(dB_u val);
83/**
84 * Convert from Watts to dBm.
85 *
86 * \param val the value in Watts
87 *
88 * \return the equivalent dBm for the given Watts
89 */
91/**
92 * Convert from ratio to dB.
93 *
94 * \param ratio the ratio in linear scale
95 *
96 * \return the value in dB
97 */
98dB_u RatioToDb(double ratio);
99/**
100 * Return the total Ack size (including FCS trailer).
101 *
102 * \return the total Ack size in bytes
103 */
105/**
106 * Return the total BlockAck size (including FCS trailer).
107 *
108 * \param type the BlockAck type
109 * \return the total BlockAck size in bytes
110 */
112/**
113 * Return the total BlockAckRequest size (including FCS trailer).
114 *
115 * \param type the BlockAckRequest type
116 * \return the total BlockAckRequest size in bytes
117 */
119/**
120 * Return the total MU-BAR size (including FCS trailer).
121 *
122 * \param types the list of Block Ack Request types of the individual BARs
123 * \return the total MU-BAR size in bytes
124 */
125uint32_t GetMuBarSize(std::list<BlockAckReqType> types);
126/**
127 * Return the total RTS size (including FCS trailer).
128 *
129 * \return the total RTS size in bytes
130 */
132/**
133 * Return the total CTS size (including FCS trailer).
134 *
135 * \return the total CTS size in bytes
136 */
138/**
139 * \param seq MPDU sequence number
140 * \param winstart sequence number window start
141 * \param winsize the size of the sequence number window
142 * \returns true if in the window
143 *
144 * This method checks if the MPDU's sequence number is inside the scoreboard boundaries or not
145 */
146bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize);
147/**
148 * Add FCS trailer to a packet.
149 *
150 * \param packet the packet to add a trailer to
151 */
152void AddWifiMacTrailer(Ptr<Packet> packet);
153/**
154 * Return the total size of the packet after WifiMacHeader and FCS trailer
155 * have been added.
156 *
157 * \param packet the packet to be encapsulated with WifiMacHeader and FCS trailer
158 * \param hdr the WifiMacHeader
159 * \param isAmpdu whether packet is part of an A-MPDU
160 * \return the total packet size
161 */
162uint32_t GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu);
163
164/**
165 * Check if the given TID-to-Link Mappings are valid for a negotiation type of 1. Specifically,
166 * it is checked whether all TIDs are mapped to the same set of links.
167 *
168 * \param dlLinkMapping the given TID-to-Link Mapping for Downlink
169 * \param ulLinkMapping the given TID-to-Link Mapping for Uplink
170 * \return whether the given TID-to-Link Mappings are valid for a negotiation type of 1
171 */
173 const WifiTidLinkMapping& ulLinkMapping);
174
175/// Size of the space of sequence numbers
176static constexpr uint16_t SEQNO_SPACE_SIZE = 4096;
177
178/// Size of the half the space of sequence numbers (used to determine old packets)
179static constexpr uint16_t SEQNO_SPACE_HALF_SIZE = SEQNO_SPACE_SIZE / 2;
180
181/// Link ID for single link operations (helps tracking places where correct link
182/// ID is to be used to support multi-link operations)
183static constexpr uint8_t SINGLE_LINK_OP_ID = 0;
184
185/// Invalid link identifier
186static constexpr uint8_t WIFI_LINKID_UNDEFINED = 0xff;
187
188/// Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec. 3.1)
189/// Used to initialize WIFI_TU
190constexpr int WIFI_TU_US = 1024;
191
192/// Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
193extern const Time WIFI_TU;
194
195} // namespace ns3
196
197#endif /* WIFI_UTILS_H */
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Implements the IEEE 802.11 MAC header.
#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:179
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition wifi-utils.cc:22
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition wifi-utils.cc:95
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:44
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:37
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:65
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:68
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:183
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:190
double DbToRatio(dB_u val)
Convert from dB to ratio.
Definition wifi-utils.cc:25
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:78
WifiDirection
Wifi direction.
Definition wifi-utils.h:34
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:31
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition wifi-utils.h:176
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:58
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:186
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition wifi-utils.cc:50
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.
double Watt_u
Watt weak type.
Definition wifi-units.h:25
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
double dB_u
dB weak type
Definition wifi-units.h:28
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
The different BlockAckRequest variants.
The different BlockAck variants.