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