A Discrete-Event Network Simulator
API
wifi-utils.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include <cmath>
22 #include "ns3/packet.h"
23 #include "wifi-utils.h"
24 #include "ctrl-headers.h"
25 #include "wifi-mac-header.h"
26 #include "wifi-mac-trailer.h"
27 
28 namespace ns3 {
29 
30 double
31 DbToRatio (double dB)
32 {
33  return std::pow (10.0, 0.1 * dB);
34 }
35 
36 double
37 DbmToW (double dBm)
38 {
39  return std::pow (10.0, 0.1 * (dBm - 30.0));
40 }
41 
42 double
43 WToDbm (double w)
44 {
45  return 10.0 * std::log10 (w) + 30.0;
46 }
47 
48 double
49 RatioToDb (double ratio)
50 {
51  return 10.0 * std::log10 (ratio);
52 }
53 
54 uint32_t
55 GetAckSize (void)
56 {
57  WifiMacHeader ack;
59  return ack.GetSize () + 4;
60 }
61 
62 uint32_t
64 {
65  WifiMacHeader hdr;
67  CtrlBAckResponseHeader blockAck;
68  blockAck.SetType (type);
69  return hdr.GetSize () + blockAck.GetSerializedSize () + 4;
70 }
71 
72 uint32_t
74 {
75  WifiMacHeader hdr;
78  bar.SetType (type);
79  return hdr.GetSize () + bar.GetSerializedSize () + 4;
80 }
81 
82 uint32_t
83 GetMuBarSize (std::list<BlockAckReqType> types)
84 {
85  WifiMacHeader hdr;
87  CtrlTriggerHeader trigger;
88  trigger.SetType (MU_BAR_TRIGGER);
89  for (auto& t : types)
90  {
91  auto userInfo = trigger.AddUserInfoField ();
93  bar.SetType (t);
94  userInfo.SetMuBarTriggerDepUserInfo (bar);
95  }
96  return hdr.GetSize () + trigger.GetSerializedSize () + 4;
97 }
98 
99 uint32_t
101 {
102  WifiMacHeader rts;
104  return rts.GetSize () + 4;
105 }
106 
107 uint32_t
109 {
110  WifiMacHeader cts;
112  return cts.GetSize () + 4;
113 }
114 
115 bool
116 IsInWindow (uint16_t seq, uint16_t winstart, uint16_t winsize)
117 {
118  return ((seq - winstart + 4096) % 4096) < winsize;
119 }
120 
121 void
123 {
124  WifiMacTrailer fcs;
125  packet->AddTrailer (fcs);
126 }
127 
128 uint32_t
129 GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr, bool isAmpdu)
130 {
131  uint32_t size;
132  WifiMacTrailer fcs;
133  if (isAmpdu)
134  {
135  size = packet->GetSize ();
136  }
137  else
138  {
139  size = packet->GetSize () + hdr->GetSize () + fcs.GetSerializedSize ();
140  }
141  return size;
142 }
143 
144 } //namespace ns3
Headers for BlockAckRequest.
Definition: ctrl-headers.h:49
void SetType(BlockAckReqType type)
Set the BlockAckRequest type.
uint32_t GetSerializedSize(void) const override
Definition: ctrl-headers.cc:71
Headers for BlockAck response.
Definition: ctrl-headers.h:202
uint32_t GetSerializedSize(void) const
void SetType(BlockAckType type)
Set the block ack type.
Headers for Trigger frames.
Definition: ctrl-headers.h:886
CtrlTriggerUserInfoField & AddUserInfoField(void)
Append a new User Info field to this Trigger frame and return a non-const reference to it.
uint32_t GetSerializedSize(void) const
void SetType(TriggerFrameType type)
Set the Trigger frame type.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:307
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Implements the IEEE 802.11 MAC header.
uint32_t GetSize(void) 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(void) const
@ MU_BAR_TRIGGER
Definition: ctrl-headers.h:564
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:49
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:43
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:37
uint32_t GetAckSize(void)
Return the total Ack size (including FCS trailer).
Definition: wifi-utils.cc:55
uint32_t GetRtsSize(void)
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:100
uint32_t GetBlockAckRequestSize(BlockAckReqType type)
Return the total BlockAckRequest size (including FCS trailer).
Definition: wifi-utils.cc:73
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition: wifi-utils.cc:83
uint32_t GetCtsSize(void)
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:108
@ 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:63
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:122
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:129
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:31
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:116
The different BlockAckRequest variants.
The different BlockAck variants.