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 "ctrl-headers.h"
12#include "wifi-mac-header.h"
13#include "wifi-mac-trailer.h"
14
15#include "ns3/packet.h"
16
17#include <cmath>
18
19namespace ns3
20{
21
23
24double
26{
27 return std::pow(10.0, 0.1 * val);
28}
29
32{
33 return std::pow(10.0, 0.1 * (val - 30.0));
34}
35
38{
39 NS_ASSERT(val > 0.);
40 return 10.0 * std::log10(val) + 30.0;
41}
42
43dB_u
44RatioToDb(double ratio)
45{
46 return 10.0 * std::log10(ratio);
47}
48
51{
52 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_ACK).GetSize() + 4;
53
54 return size;
55}
56
59{
60 WifiMacHeader hdr;
63 blockAck.SetType(type);
64 return hdr.GetSize() + blockAck.GetSerializedSize() + 4;
65}
66
69{
70 WifiMacHeader hdr;
73 bar.SetType(type);
74 return hdr.GetSize() + bar.GetSerializedSize() + 4;
75}
76
78GetMuBarSize(std::list<BlockAckReqType> types)
79{
80 WifiMacHeader hdr;
82 CtrlTriggerHeader trigger;
84 for (auto& t : types)
85 {
86 auto userInfo = trigger.AddUserInfoField();
88 bar.SetType(t);
89 userInfo.SetMuBarTriggerDepUserInfo(bar);
90 }
91 return hdr.GetSize() + trigger.GetSerializedSize() + 4;
92}
93
96{
97 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_RTS).GetSize() + 4;
98
99 return size;
100}
101
104{
105 static const uint32_t size = WifiMacHeader(WIFI_MAC_CTL_CTS).GetSize() + 4;
106
107 return size;
108}
109
110bool
111IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
112{
113 return ((seq - winstart + 4096) % 4096) < winsize;
114}
115
116void
118{
119 WifiMacTrailer fcs;
120 packet->AddTrailer(fcs);
121}
122
124GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu)
125{
126 uint32_t size;
127 WifiMacTrailer fcs;
128 if (isAmpdu)
129 {
130 size = packet->GetSize();
131 }
132 else
133 {
134 size = packet->GetSize() + hdr->GetSize() + fcs.GetSerializedSize();
135 }
136 return size;
137}
138
139bool
141 const WifiTidLinkMapping& ulLinkMapping)
142{
143 if (dlLinkMapping.empty() && ulLinkMapping.empty())
144 {
145 // default mapping is valid
146 return true;
147 }
148
149 if (dlLinkMapping.size() != 8 || ulLinkMapping.size() != 8)
150 {
151 // not all TIDs have been mapped
152 return false;
153 }
154
155 const auto& linkSet = dlLinkMapping.cbegin()->second;
156
157 for (const auto& linkMapping : {std::cref(dlLinkMapping), std::cref(ulLinkMapping)})
158 {
159 for (const auto& [tid, links] : linkMapping.get())
160 {
161 if (links != linkSet)
162 {
163 // distinct link sets
164 return false;
165 }
166 }
167 }
168
169 return true;
170}
171
172} // 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.
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.
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:1332
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: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
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
Definition wifi-utils.cc:37
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:65
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
constexpr int WIFI_TU_US
Wi-Fi Time Unit value in microseconds (see IEEE 802.11-2020 sec.
Definition wifi-utils.h:190
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
@ 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:31
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.
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.