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 "wifi-utils.h"
22 #include <cmath>
23 
24 namespace ns3 {
25 
26 double
27 Log2 (double val)
28 {
29  return std::log (val) / std::log (2.0);
30 }
31 
32 
33 double
34 DbToRatio (double dB)
35 {
36  double ratio = std::pow (10.0, dB / 10.0);
37  return ratio;
38 }
39 
40 double
41 DbmToW (double dBm)
42 {
43  double mW = std::pow (10.0, dBm / 10.0);
44  return mW / 1000.0;
45 }
46 
47 double
48 WToDbm (double w)
49 {
50  return 10.0 * std::log10 (w * 1000.0);
51 }
52 
53 double
54 RatioToDb (double ratio)
55 {
56  return 10.0 * std::log10 (ratio);
57 }
58 
59 uint16_t
60 ConvertGuardIntervalToNanoSeconds (WifiMode mode, bool htShortGuardInterval, Time heGuardInterval)
61 {
62  uint16_t gi;
64  {
65  gi = heGuardInterval.GetNanoSeconds ();
66  }
68  {
69  gi = htShortGuardInterval ? 400 : 800;
70  }
71  else
72  {
73  gi = 800;
74  }
75  return gi;
76 }
77 
78 } //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint16_t ConvertGuardIntervalToNanoSeconds(WifiMode mode, bool htShortGuardInterval, Time heGuardInterval)
Convert the guard interval to nanoseconds based on the wifimode.
Definition: wifi-utils.cc:60
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:41
VHT PHY (Clause 22)
Definition: wifi-mode.h:60
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
HT PHY (Clause 20)
Definition: wifi-mode.h:58
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:48
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:34
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:54
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:487
SpectrumValue Log2(const SpectrumValue &arg)
HE PHY (Clause 26)
Definition: wifi-mode.h:62