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 * 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#include "wifi-utils.h"
21
22#include "ctrl-headers.h"
23#include "wifi-mac-header.h"
24#include "wifi-mac-trailer.h"
25
26#include "ns3/packet.h"
27
28#include <cmath>
29
30namespace ns3
31{
32
34
35double
36DbToRatio(double dB)
37{
38 return std::pow(10.0, 0.1 * dB);
39}
40
41double
42DbmToW(double dBm)
43{
44 return std::pow(10.0, 0.1 * (dBm - 30.0));
45}
46
47double
48WToDbm(double w)
49{
50 return 10.0 * std::log10(w) + 30.0;
51}
52
53double
54RatioToDb(double ratio)
55{
56 return 10.0 * std::log10(ratio);
57}
58
61{
62 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_ACK).GetSize() + 4;
63
64 return size;
65}
66
69{
70 WifiMacHeader hdr;
73 blockAck.SetType(type);
74 return hdr.GetSize() + blockAck.GetSerializedSize() + 4;
75}
76
79{
80 WifiMacHeader hdr;
83 bar.SetType(type);
84 return hdr.GetSize() + bar.GetSerializedSize() + 4;
85}
86
88GetMuBarSize(std::list<BlockAckReqType> types)
89{
90 WifiMacHeader hdr;
92 CtrlTriggerHeader trigger;
94 for (auto& t : types)
95 {
96 auto userInfo = trigger.AddUserInfoField();
98 bar.SetType(t);
99 userInfo.SetMuBarTriggerDepUserInfo(bar);
100 }
101 return hdr.GetSize() + trigger.GetSerializedSize() + 4;
102}
103
106{
107 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_RTS).GetSize() + 4;
108
109 return size;
110}
111
114{
115 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_CTS).GetSize() + 4;
116
117 return size;
118}
119
120bool
121IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
122{
123 return ((seq - winstart + 4096) % 4096) < winsize;
124}
125
126void
128{
129 WifiMacTrailer fcs;
130 packet->AddTrailer(fcs);
131}
132
134GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu)
135{
136 uint32_t size;
137 WifiMacTrailer fcs;
138 if (isAmpdu)
139 {
140 size = packet->GetSize();
141 }
142 else
143 {
144 size = packet->GetSize() + hdr->GetSize() + fcs.GetSerializedSize();
145 }
146 return size;
147}
148
149bool
151 const WifiTidLinkMapping& ulLinkMapping)
152{
153 if (dlLinkMapping.empty() && ulLinkMapping.empty())
154 {
155 // default mapping is valid
156 return true;
157 }
158
159 if (dlLinkMapping.size() != 8 || ulLinkMapping.size() != 8)
160 {
161 // not all TIDs have been mapped
162 return false;
163 }
164
165 const auto& linkSet = dlLinkMapping.cbegin()->second;
166
167 for (const auto& linkMapping : {std::cref(dlLinkMapping), std::cref(ulLinkMapping)})
168 {
169 for (const auto& [tid, links] : linkMapping.get())
170 {
171 if (links != linkSet)
172 {
173 // distinct link sets
174 return false;
175 }
176 }
177 }
178
179 return true;
180}
181
182} // namespace ns3
Headers for BlockAckRequest.
Definition: ctrl-headers.h:52
uint32_t GetSerializedSize() const override
Definition: ctrl-headers.cc:72
void SetType(BlockAckReqType type)
Set the BlockAckRequest type.
Headers for BlockAck response.
Definition: ctrl-headers.h:203
void SetType(BlockAckType type)
Set the block ack type.
uint32_t GetSerializedSize() const override
Headers for Trigger frames.
Definition: ctrl-headers.h:942
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.
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.
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
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1343
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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
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
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
@ WIFI_MAC_CTL_TRIGGER
@ WIFI_MAC_CTL_BACKREQ
@ WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_CTS
@ WIFI_MAC_CTL_ACK
@ WIFI_MAC_CTL_BACKRESP
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
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.