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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20#ifndef WIFI_UTILS_H
21#define WIFI_UTILS_H
22
23#include "block-ack-type.h"
24
25#include "ns3/fatal-error.h"
26#include "ns3/nstime.h"
27#include "ns3/ptr.h"
28
29#include <list>
30#include <map>
31#include <set>
32
33namespace ns3
34{
35
36class WifiMacHeader;
37class Packet;
38
39/**
40 * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction
41 * field in IEEE 802.11be D3.1 Figure 9-1002ap
42 */
43enum class WifiDirection : uint8_t
44{
45 DOWNLINK = 0,
46 UPLINK = 1,
48};
49
50/**
51 * \brief Stream insertion operator.
52 *
53 * \param os the stream
54 * \param direction the direction
55 * \returns a reference to the stream
56 */
57inline std::ostream&
58operator<<(std::ostream& os, const WifiDirection& direction)
59{
60 switch (direction)
61 {
63 return (os << "DOWNLINK");
65 return (os << "UPLINK");
67 return (os << "BOTH_DIRECTIONS");
68 default:
69 NS_FATAL_ERROR("Invalid direction");
70 return (os << "INVALID");
71 }
72}
73
74/// @brief TID-indexed map of the link set to which the TID is mapped
75using WifiTidLinkMapping = std::map<uint8_t, std::set<uint8_t>>;
76
77/**
78 * Convert from dBm to Watts.
79 *
80 * \param dbm the power in dBm
81 *
82 * \return the equivalent Watts for the given dBm
83 */
84double DbmToW(double dbm);
85/**
86 * Convert from dB to ratio.
87 *
88 * \param db the value in dB
89 *
90 * \return ratio in linear scale
91 */
92double DbToRatio(double db);
93/**
94 * Convert from Watts to dBm.
95 *
96 * \param w the power in Watts
97 *
98 * \return the equivalent dBm for the given Watts
99 */
100double WToDbm(double w);
101/**
102 * Convert from ratio to dB.
103 *
104 * \param ratio the ratio in linear scale
105 *
106 * \return the value in dB
107 */
108double RatioToDb(double ratio);
109/**
110 * Return the total Ack size (including FCS trailer).
111 *
112 * \return the total Ack size in bytes
113 */
115/**
116 * Return the total BlockAck size (including FCS trailer).
117 *
118 * \param type the BlockAck type
119 * \return the total BlockAck size in bytes
120 */
122/**
123 * Return the total BlockAckRequest size (including FCS trailer).
124 *
125 * \param type the BlockAckRequest type
126 * \return the total BlockAckRequest size in bytes
127 */
129/**
130 * Return the total MU-BAR size (including FCS trailer).
131 *
132 * \param types the list of Block Ack Request types of the individual BARs
133 * \return the total MU-BAR size in bytes
134 */
135uint32_t GetMuBarSize(std::list<BlockAckReqType> types);
136/**
137 * Return the total RTS size (including FCS trailer).
138 *
139 * \return the total RTS size in bytes
140 */
142/**
143 * Return the total CTS size (including FCS trailer).
144 *
145 * \return the total CTS size in bytes
146 */
148/**
149 * \param seq MPDU sequence number
150 * \param winstart sequence number window start
151 * \param winsize the size of the sequence number window
152 * \returns true if in the window
153 *
154 * This method checks if the MPDU's sequence number is inside the scoreboard boundaries or not
155 */
156bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize);
157/**
158 * Add FCS trailer to a packet.
159 *
160 * \param packet the packet to add a trailer to
161 */
162void AddWifiMacTrailer(Ptr<Packet> packet);
163/**
164 * Return the total size of the packet after WifiMacHeader and FCS trailer
165 * have been added.
166 *
167 * \param packet the packet to be encapsulated with WifiMacHeader and FCS trailer
168 * \param hdr the WifiMacHeader
169 * \param isAmpdu whether packet is part of an A-MPDU
170 * \return the total packet size
171 */
172uint32_t GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu);
173
174/**
175 * Check if the given TID-to-Link Mappings are valid for a negotiation type of 1. Specifically,
176 * it is checked whether all TIDs are mapped to the same set of links.
177 *
178 * \param dlLinkMapping the given TID-to-Link Mapping for Downlink
179 * \param ulLinkMapping the given TID-to-Link Mapping for Uplink
180 * \return whether the given TID-to-Link Mappings are valid for a negotiation type of 1
181 */
183 const WifiTidLinkMapping& ulLinkMapping);
184
185/// Size of the space of sequence numbers
186static constexpr uint16_t SEQNO_SPACE_SIZE = 4096;
187
188/// Size of the half the space of sequence numbers (used to determine old packets)
189static constexpr uint16_t SEQNO_SPACE_HALF_SIZE = SEQNO_SPACE_SIZE / 2;
190
191/// Link ID for single link operations (helps tracking places where correct link
192/// ID is to be used to support multi-link operations)
193static constexpr uint8_t SINGLE_LINK_OP_ID = 0;
194
195/// Invalid link identifier
196static constexpr uint8_t WIFI_LINKID_UNDEFINED = 0xff;
197
198/// Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec. 3.1)
199/// Used to initialize WIFI_TU
200constexpr int WIFI_TU_US = 1024;
201
202/// Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
203extern const Time WIFI_TU;
204
205} // namespace ns3
206
207#endif /* WIFI_UTILS_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Implements the IEEE 802.11 MAC header.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
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:189
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:54
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:48
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition: wifi-utils.cc:33
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:105
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:42
uint32_t GetBlockAckRequestSize(BlockAckReqType type)
Return the total BlockAckRequest size (including FCS trailer).
Definition: wifi-utils.cc:78
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:193
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition: wifi-utils.h:200
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition: wifi-utils.cc:88
WifiDirection
Wifi direction.
Definition: wifi-utils.h:44
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:186
bool TidToLinkMappingValidForNegType1(const WifiTidLinkMapping &dlLinkMapping, const WifiTidLinkMapping &ulLinkMapping)
Check if the given TID-to-Link Mappings are valid for a negotiation type of 1.
Definition: wifi-utils.cc:150
uint32_t GetBlockAckSize(BlockAckType type)
Return the total BlockAck size (including FCS trailer).
Definition: wifi-utils.cc:68
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:127
static constexpr uint8_t WIFI_LINKID_UNDEFINED
Invalid link identifier.
Definition: wifi-utils.h:196
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:75
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition: wifi-utils.cc:60
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.
Definition: wifi-utils.cc:134
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:36
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:113
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:121
The different BlockAckRequest variants.
The different BlockAck variants.