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
ns3::GetBlockAckSize
uint32_t GetBlockAckSize(BlockAckType type)
Return the total BlockAck size (including FCS trailer).
Definition: wifi-utils.cc:63
ns3::GetRtsSize
uint32_t GetRtsSize(void)
Return the total RTS size (including FCS trailer).
Definition: wifi-utils.cc:100
ns3::WifiMacHeader::GetSize
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
Definition: wifi-mac-header.cc:933
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMacTrailer
Implements the IEEE 802.11 MAC trailer.
Definition: wifi-mac-trailer.h:39
ns3::CtrlBAckRequestHeader
Headers for BlockAckRequest.
Definition: ctrl-headers.h:49
ns3::WToDbm
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:43
ns3::WIFI_MAC_CTL_CTS
@ WIFI_MAC_CTL_CTS
Definition: wifi-mac-header.h:41
ns3::GetSize
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
ns3::MU_BAR_TRIGGER
@ MU_BAR_TRIGGER
Definition: ctrl-headers.h:564
ns3::CtrlTriggerHeader::SetType
void SetType(TriggerFrameType type)
Set the Trigger frame type.
Definition: ctrl-headers.cc:1726
wifi-mac-header.h
ns3::GetAckSize
uint32_t GetAckSize(void)
Return the total Ack size (including FCS trailer).
Definition: wifi-utils.cc:55
ns3::WifiMacTrailer::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition: wifi-mac-trailer.cc:58
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition: wifi-mac-header.h:85
ns3::GetBlockAckRequestSize
uint32_t GetBlockAckRequestSize(BlockAckReqType type)
Return the total BlockAckRequest size (including FCS trailer).
Definition: wifi-utils.cc:73
ns3::Ptr< Packet >
ctrl-headers.h
ns3::BlockAckReqType
The different BlockAckRequest variants.
Definition: block-ack-type.h:75
ns3::CtrlTriggerHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition: ctrl-headers.cc:1632
ns3::BlockAckType
The different BlockAck variants.
Definition: block-ack-type.h:34
ns3::CtrlTriggerHeader::AddUserInfoField
CtrlTriggerUserInfoField & AddUserInfoField(void)
Append a new User Info field to this Trigger frame and return a non-const reference to it.
Definition: ctrl-headers.cc:1994
ns3::CtrlTriggerHeader
Headers for Trigger frames.
Definition: ctrl-headers.h:886
ns3::WIFI_MAC_CTL_TRIGGER
@ WIFI_MAC_CTL_TRIGGER
Definition: wifi-mac-header.h:38
ns3::WIFI_MAC_CTL_ACK
@ WIFI_MAC_CTL_ACK
Definition: wifi-mac-header.h:42
ns3::RatioToDb
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:49
ns3::CtrlBAckResponseHeader::SetType
void SetType(BlockAckType type)
Set the block ack type.
Definition: ctrl-headers.cc:456
ns3::IsInWindow
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:116
ns3::WIFI_MAC_CTL_BACKREQ
@ WIFI_MAC_CTL_BACKREQ
Definition: wifi-mac-header.h:43
ns3::AddWifiMacTrailer
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:122
ns3::DbmToW
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:37
wifi-utils.h
ns3::Packet::AddTrailer
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:307
ns3::DbToRatio
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:31
ns3::WifiMacHeader::SetType
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Definition: wifi-mac-header.cc:132
ns3::WIFI_MAC_CTL_BACKRESP
@ WIFI_MAC_CTL_BACKRESP
Definition: wifi-mac-header.h:44
ns3::WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_RTS
Definition: wifi-mac-header.h:40
ns3::GetMuBarSize
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
Definition: wifi-utils.cc:83
ns3::GetCtsSize
uint32_t GetCtsSize(void)
Return the total CTS size (including FCS trailer).
Definition: wifi-utils.cc:108
wifi-mac-trailer.h
ns3::CtrlBAckRequestHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const override
Definition: ctrl-headers.cc:71
ns3::CtrlBAckResponseHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition: ctrl-headers.cc:322
ns3::CtrlBAckRequestHeader::SetType
void SetType(BlockAckReqType type)
Set the BlockAckRequest type.
Definition: ctrl-headers.cc:202
ns3::CtrlBAckResponseHeader
Headers for BlockAck response.
Definition: ctrl-headers.h:202