A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-utils.cc
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#include "wifi-utils.h"
10
11#include "ap-wifi-mac.h"
12#include "ctrl-headers.h"
13#include "gcr-manager.h"
14#include "wifi-mac-header.h"
15#include "wifi-mac-trailer.h"
16#include "wifi-tx-vector.h"
17
18#include "ns3/packet.h"
19
20#include <cmath>
21
22namespace ns3
23{
24
26
27double
29{
30 return std::pow(10.0, 0.1 * val);
31}
32
35{
36 return std::pow(10.0, 0.1 * (val - 30.0));
37}
38
41{
42 NS_ASSERT(val > 0.);
43 return 10.0 * std::log10(val) + 30.0;
44}
45
46dB_u
47RatioToDb(double ratio)
48{
49 return 10.0 * std::log10(ratio);
50}
51
54{
55 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_ACK).GetSize() + 4;
56
57 return size;
58}
59
62{
63 WifiMacHeader hdr;
66 blockAck.SetType(type);
67 return hdr.GetSize() + blockAck.GetSerializedSize() + 4;
68}
69
72{
73 WifiMacHeader hdr;
76 bar.SetType(type);
77 return hdr.GetSize() + bar.GetSerializedSize() + 4;
78}
79
81GetMuBarSize(std::list<BlockAckReqType> types)
82{
83 WifiMacHeader hdr;
85 CtrlTriggerHeader trigger;
87 for (auto& t : types)
88 {
89 auto userInfo = trigger.AddUserInfoField();
91 bar.SetType(t);
92 userInfo.SetMuBarTriggerDepUserInfo(bar);
93 }
94 return hdr.GetSize() + trigger.GetSerializedSize() + 4;
95}
96
99{
100 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_RTS).GetSize() + 4;
101
102 return size;
103}
104
107{
108 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_CTS).GetSize() + 4;
109
110 return size;
111}
112
113Time
115{
116 auto modClass = txVector.GetModulationClass();
117
118 switch (modClass)
119 {
122 if (txVector.GetMode().GetDataRate(txVector) == 1e6)
123 {
124 return MicroSeconds(304);
125 }
126 else if (txVector.GetPreambleType() == WIFI_PREAMBLE_LONG)
127 {
128 return MicroSeconds(248);
129 }
130 else
131 {
132 return MicroSeconds(152);
133 }
134 break;
137 if (auto constSize = txVector.GetMode().GetConstellationSize(); constSize == 2)
138 {
139 return MicroSeconds(44);
140 }
141 else if (constSize == 4)
142 {
143 return MicroSeconds(32);
144 }
145 else
146 {
147 return MicroSeconds(28);
148 }
149 break;
150 default: {
151 auto staId = (txVector.IsMu() ? txVector.GetHeMuUserInfoMap().begin()->first : SU_STA_ID);
152 if (const auto constSize = txVector.GetMode(staId).GetConstellationSize(); constSize == 2)
153 {
154 return MicroSeconds(68);
155 }
156 else if (constSize == 4)
157 {
158 return MicroSeconds(44);
159 }
160 else
161 {
162 return MicroSeconds(32);
163 }
164 }
165 }
166}
167
168bool
169IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
170{
171 return ((seq - winstart + 4096) % 4096) < winsize;
172}
173
174void
176{
177 WifiMacTrailer fcs;
178 packet->AddTrailer(fcs);
179}
180
182GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu)
183{
184 uint32_t size;
185 WifiMacTrailer fcs;
186 if (isAmpdu)
187 {
188 size = packet->GetSize();
189 }
190 else
191 {
192 size = packet->GetSize() + hdr->GetSize() + fcs.GetSerializedSize();
193 }
194 return size;
195}
196
197bool
199 const WifiTidLinkMapping& ulLinkMapping)
200{
201 if (dlLinkMapping.empty() && ulLinkMapping.empty())
202 {
203 // default mapping is valid
204 return true;
205 }
206
207 if (dlLinkMapping.size() != 8 || ulLinkMapping.size() != 8)
208 {
209 // not all TIDs have been mapped
210 return false;
211 }
212
213 const auto& linkSet = dlLinkMapping.cbegin()->second;
214
215 for (const auto& linkMapping : {std::cref(dlLinkMapping), std::cref(ulLinkMapping)})
216 {
217 for (const auto& [tid, links] : linkMapping.get())
218 {
219 if (links != linkSet)
220 {
221 // distinct link sets
222 return false;
223 }
224 }
225 }
226
227 return true;
228}
229
230bool
232{
233 return adr.IsGroup() && !adr.IsBroadcast();
234}
235
236bool
238{
239 auto apMac = DynamicCast<ApWifiMac>(mac);
240 return apMac && apMac->UseGcr(hdr);
241}
242
243Mac48Address
245{
246 const auto isGcr = IsGcr(mac, hdr);
247 const auto addr1 = hdr.GetAddr1();
248 if (!isGcr)
249 {
250 return addr1;
251 }
252 auto apMac = DynamicCast<ApWifiMac>(mac);
253 return apMac->GetGcrManager()->GetIndividuallyAddressedRecipient(addr1);
254}
255
256} // namespace ns3
Headers for BlockAckRequest.
uint32_t GetSerializedSize() const override
void SetType(BlockAckReqType type)
Set the BlockAckRequest type.
Headers for BlockAck response.
void SetType(BlockAckType type)
Set the block ack type.
uint32_t GetSerializedSize() const override
Headers for Trigger frames.
CtrlTriggerUserInfoField & AddUserInfoField()
Append a new User Info field to this Trigger frame and return a non-const reference to it.
uint32_t GetSerializedSize() const override
void SetType(TriggerFrameType type)
Set the Trigger frame type.
an EUI-48 address
bool IsGroup() const
bool IsBroadcast() const
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.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
virtual uint32_t GetSize() const
Return the size of the WifiMacHeader in octets.
virtual void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Implements the IEEE 802.11 MAC trailer.
uint32_t GetSerializedSize() const override
uint16_t GetConstellationSize() const
Definition wifi-mode.cc:129
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
WifiPreamble GetPreambleType() const
const HeMuUserInfoMap & GetHeMuUserInfoMap() const
Get a const reference to the map HE MU user-specific transmission information indexed by STA-ID.
WifiModulationClass GetModulationClass() const
Get the modulation class specified by this TXVECTOR.
#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
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
@ WIFI_PREAMBLE_LONG
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition wifi-utils.cc:25
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition wifi-utils.cc:98
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:47
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:40
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
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:68
Time GetEstimatedAckTxTime(const WifiTxVector &txVector)
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:71
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:290
double DbToRatio(dB_u val)
Convert from dB to ratio.
Definition wifi-utils.cc:28
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:81
@ WIFI_MAC_CTL_TRIGGER
@ WIFI_MAC_CTL_BACKREQ
@ WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_CTS
@ WIFI_MAC_CTL_ACK
@ WIFI_MAC_CTL_BACKRESP
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:34
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:61
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
uint32_t GetAckSize()
Return the total Ack size (including FCS trailer).
Definition wifi-utils.cc:53
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.
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition wifi-mode.h:24
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)
The different BlockAckRequest variants.
The different BlockAck variants.