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
17#include "ns3/packet.h"
18
19#include <cmath>
20
21namespace ns3
22{
23
25
26double
28{
29 return std::pow(10.0, 0.1 * val);
30}
31
34{
35 return std::pow(10.0, 0.1 * (val - 30.0));
36}
37
40{
41 NS_ASSERT(val > 0.);
42 return 10.0 * std::log10(val) + 30.0;
43}
44
45dB_u
46RatioToDb(double ratio)
47{
48 return 10.0 * std::log10(ratio);
49}
50
53{
54 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_ACK).GetSize() + 4;
55
56 return size;
57}
58
61{
62 WifiMacHeader hdr;
65 blockAck.SetType(type);
66 return hdr.GetSize() + blockAck.GetSerializedSize() + 4;
67}
68
71{
72 WifiMacHeader hdr;
75 bar.SetType(type);
76 return hdr.GetSize() + bar.GetSerializedSize() + 4;
77}
78
80GetMuBarSize(std::list<BlockAckReqType> types)
81{
82 WifiMacHeader hdr;
84 CtrlTriggerHeader trigger;
86 for (auto& t : types)
87 {
88 auto userInfo = trigger.AddUserInfoField();
90 bar.SetType(t);
91 userInfo.SetMuBarTriggerDepUserInfo(bar);
92 }
93 return hdr.GetSize() + trigger.GetSerializedSize() + 4;
94}
95
98{
99 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_RTS).GetSize() + 4;
100
101 return size;
102}
103
106{
107 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_CTS).GetSize() + 4;
108
109 return size;
110}
111
112bool
113IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
114{
115 return ((seq - winstart + 4096) % 4096) < winsize;
116}
117
118void
120{
121 WifiMacTrailer fcs;
122 packet->AddTrailer(fcs);
123}
124
126GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu)
127{
128 uint32_t size;
129 WifiMacTrailer fcs;
130 if (isAmpdu)
131 {
132 size = packet->GetSize();
133 }
134 else
135 {
136 size = packet->GetSize() + hdr->GetSize() + fcs.GetSerializedSize();
137 }
138 return size;
139}
140
141bool
143 const WifiTidLinkMapping& ulLinkMapping)
144{
145 if (dlLinkMapping.empty() && ulLinkMapping.empty())
146 {
147 // default mapping is valid
148 return true;
149 }
150
151 if (dlLinkMapping.size() != 8 || ulLinkMapping.size() != 8)
152 {
153 // not all TIDs have been mapped
154 return false;
155 }
156
157 const auto& linkSet = dlLinkMapping.cbegin()->second;
158
159 for (const auto& linkMapping : {std::cref(dlLinkMapping), std::cref(ulLinkMapping)})
160 {
161 for (const auto& [tid, links] : linkMapping.get())
162 {
163 if (links != linkSet)
164 {
165 // distinct link sets
166 return false;
167 }
168 }
169 }
170
171 return true;
172}
173
174bool
176{
177 return adr.IsGroup() && !adr.IsBroadcast();
178}
179
180bool
182{
183 auto apMac = DynamicCast<ApWifiMac>(mac);
184 return apMac && apMac->UseGcr(hdr);
185}
186
187Mac48Address
189{
190 const auto isGcr = IsGcr(mac, hdr);
191 const auto addr1 = hdr.GetAddr1();
192 if (!isGcr)
193 {
194 return addr1;
195 }
196 auto apMac = DynamicCast<ApWifiMac>(mac);
197 return apMac->GetGcrManager()->GetIndividuallyAddressedRecipient(addr1);
198}
199
200} // 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
#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:1368
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:24
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Definition wifi-utils.cc:97
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:46
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:39
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:67
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:70
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:282
double DbToRatio(dB_u val)
Convert from dB to ratio.
Definition wifi-utils.cc:27
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:80
@ 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:33
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:60
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:52
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.
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.