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
33double
34DbToRatio(double dB)
35{
36 return std::pow(10.0, 0.1 * dB);
37}
38
39double
40DbmToW(double dBm)
41{
42 return std::pow(10.0, 0.1 * (dBm - 30.0));
43}
44
45double
46WToDbm(double w)
47{
48 return 10.0 * std::log10(w) + 30.0;
49}
50
51double
52RatioToDb(double ratio)
53{
54 return 10.0 * std::log10(ratio);
55}
56
59{
60 WifiMacHeader ack;
62 return ack.GetSize() + 4;
63}
64
67{
68 WifiMacHeader hdr;
71 blockAck.SetType(type);
72 return hdr.GetSize() + blockAck.GetSerializedSize() + 4;
73}
74
77{
78 WifiMacHeader hdr;
81 bar.SetType(type);
82 return hdr.GetSize() + bar.GetSerializedSize() + 4;
83}
84
86GetMuBarSize(std::list<BlockAckReqType> types)
87{
88 WifiMacHeader hdr;
90 CtrlTriggerHeader trigger;
92 for (auto& t : types)
93 {
94 auto userInfo = trigger.AddUserInfoField();
96 bar.SetType(t);
97 userInfo.SetMuBarTriggerDepUserInfo(bar);
98 }
99 return hdr.GetSize() + trigger.GetSerializedSize() + 4;
100}
101
104{
105 WifiMacHeader rts;
107 return rts.GetSize() + 4;
108}
109
112{
113 WifiMacHeader cts;
115 return cts.GetSize() + 4;
116}
117
118bool
119IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
120{
121 return ((seq - winstart + 4096) % 4096) < winsize;
122}
123
124void
126{
127 WifiMacTrailer fcs;
128 packet->AddTrailer(fcs);
129}
130
132GetSize(Ptr<const Packet> packet, const WifiMacHeader* hdr, bool isAmpdu)
133{
134 uint32_t size;
135 WifiMacTrailer fcs;
136 if (isAmpdu)
137 {
138 size = packet->GetSize();
139 }
140 else
141 {
142 size = packet->GetSize() + hdr->GetSize() + fcs.GetSerializedSize();
143 }
144 return size;
145}
146
147} // 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:78
Implements the IEEE 802.11 MAC header.
uint32_t GetSize() const
Return the size of the WifiMacHeader in octets.
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
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: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
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
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition: wifi-utils.cc:86
@ WIFI_MAC_CTL_TRIGGER
@ WIFI_MAC_CTL_BACKREQ
@ WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_CTS
@ WIFI_MAC_CTL_ACK
@ WIFI_MAC_CTL_BACKRESP
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
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.