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/ptr.h"
27
28#include <list>
29#include <map>
30#include <set>
31
32namespace ns3
33{
34
35class WifiMacHeader;
36class Packet;
37
38/**
39 * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction
40 * field in IEEE 802.11be D3.1 Figure 9-1002ap
41 */
42enum class WifiDirection : uint8_t
43{
44 DOWNLINK = 0,
45 UPLINK = 1,
47};
48
49/**
50 * \brief Stream insertion operator.
51 *
52 * \param os the stream
53 * \param direction the direction
54 * \returns a reference to the stream
55 */
56inline std::ostream&
57operator<<(std::ostream& os, const WifiDirection& direction)
58{
59 switch (direction)
60 {
62 return (os << "DOWNLINK");
64 return (os << "UPLINK");
66 return (os << "BOTH_DIRECTIONS");
67 default:
68 NS_FATAL_ERROR("Invalid direction");
69 return (os << "INVALID");
70 }
71}
72
73/// @brief TID-indexed map of the link set to which the TID is mapped
74using WifiTidLinkMapping = std::map<uint8_t, std::set<uint8_t>>;
75
76/**
77 * Convert from dBm to Watts.
78 *
79 * \param dbm the power in dBm
80 *
81 * \return the equivalent Watts for the given dBm
82 */
83double DbmToW(double dbm);
84/**
85 * Convert from dB to ratio.
86 *
87 * \param db the value in dB
88 *
89 * \return ratio in linear scale
90 */
91double DbToRatio(double db);
92/**
93 * Convert from Watts to dBm.
94 *
95 * \param w the power in Watts
96 *
97 * \return the equivalent dBm for the given Watts
98 */
99double WToDbm(double w);
100/**
101 * Convert from ratio to dB.
102 *
103 * \param ratio the ratio in linear scale
104 *
105 * \return the value in dB
106 */
107double RatioToDb(double ratio);
108/**
109 * Return the total Ack size (including FCS trailer).
110 *
111 * \return the total Ack size in bytes
112 */
114/**
115 * Return the total BlockAck size (including FCS trailer).
116 *
117 * \param type the BlockAck type
118 * \return the total BlockAck size in bytes
119 */
121/**
122 * Return the total BlockAckRequest size (including FCS trailer).
123 *
124 * \param type the BlockAckRequest type
125 * \return the total BlockAckRequest size in bytes
126 */
128/**
129 * Return the total MU-BAR size (including FCS trailer).
130 *
131 * \param types the list of Block Ack Request types of the individual BARs
132 * \return the total MU-BAR size in bytes
133 */
134uint32_t GetMuBarSize(std::list<BlockAckReqType> types);
135/**
136 * Return the total RTS size (including FCS trailer).
137 *
138 * \return the total RTS size in bytes
139 */
141/**
142 * Return the total CTS size (including FCS trailer).
143 *
144 * \return the total CTS size in bytes
145 */
147/**
148 * \param seq MPDU sequence number
149 * \param winstart sequence number window start
150 * \param winsize the size of the sequence number window
151 * \returns true if in the window
152 *
153 * This method checks if the MPDU's sequence number is inside the scoreboard boundaries or not
154 */
155bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize);
156/**
157 * Add FCS trailer to a packet.
158 *
159 * \param packet the packet to add a trailer to
160 */
161void AddWifiMacTrailer(Ptr<Packet> packet);
162/**
163 * Return the total size of the packet after WifiMacHeader and FCS trailer
164 * have been added.
165 *
166 * \param packet the packet to be encapsulated with WifiMacHeader and FCS trailer
167 * \param hdr the WifiMacHeader
168 * \param isAmpdu whether packet is part of an A-MPDU
169 * \return the total packet size
170 */
171uint32_t GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu);
172
173/**
174 * Check if the given TID-to-Link Mappings are valid for a negotiation type of 1. Specifically,
175 * it is checked whether all TIDs are mapped to the same set of links.
176 *
177 * \param dlLinkMapping the given TID-to-Link Mapping for Downlink
178 * \param ulLinkMapping the given TID-to-Link Mapping for Uplink
179 * \return whether the given TID-to-Link Mappings are valid for a negotiation type of 1
180 */
182 const WifiTidLinkMapping& ulLinkMapping);
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} // namespace ns3
198
199#endif /* WIFI_UTILS_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:188
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:52
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:46
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:103
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:40
uint32_t GetBlockAckRequestSize(BlockAckReqType type)
Return the total BlockAckRequest size (including FCS trailer).
Definition: wifi-utils.cc:76
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
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition: wifi-utils.cc:86
WifiDirection
Wifi direction.
Definition: wifi-utils.h:43
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.
Definition: wifi-utils.cc:148
uint32_t GetBlockAckSize(BlockAckType type)
Return the total BlockAck size (including FCS trailer).
Definition: wifi-utils.cc:66
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:125
static constexpr uint8_t WIFI_LINKID_UNDEFINED
Invalid link identifier.
Definition: wifi-utils.h:195
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:74
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition: wifi-utils.cc:58
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:132
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:34
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:111
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:119
The different BlockAckRequest variants.
The different BlockAck variants.