A Discrete-Event Network Simulator
API
threshold-preamble-detection-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 University of Washington
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 "ns3/log.h"
22 #include "ns3/double.h"
24 #include "wifi-utils.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("ThresholdPreambleDetectionModel");
29 
30 NS_OBJECT_ENSURE_REGISTERED (ThresholdPreambleDetectionModel);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::ThresholdPreambleDetectionModel")
37  .SetGroupName ("Wifi")
38  .AddConstructor<ThresholdPreambleDetectionModel> ()
39  .AddAttribute ("Threshold",
40  "Preamble is successfully detection if the SNR is at or above this value (expressed in dB).",
41  DoubleValue (4),
43  MakeDoubleChecker<double> ())
44  .AddAttribute ("MinimumRssi",
45  "Preamble is dropped if the RSSI is below this value (expressed in dBm).",
46  DoubleValue (-82),
48  MakeDoubleChecker<double> ())
49  ;
50  return tid;
51 }
52 
54 {
55  NS_LOG_FUNCTION (this);
56 }
57 
59 {
60  NS_LOG_FUNCTION (this);
61 }
62 
63 bool
64 ThresholdPreambleDetectionModel::IsPreambleDetected (double rssi, double snr, double channelWidth) const
65 {
66  NS_LOG_FUNCTION (this << WToDbm (rssi) << RatioToDb (snr) << channelWidth);
67  if (WToDbm (rssi) >= m_rssiMin)
68  {
69  if (RatioToDb (snr) >= m_threshold)
70  {
71  return true;
72  }
73  else
74  {
75  NS_LOG_DEBUG ("Received RSSI is above the target RSSI but SNR is too low");
76  return false;
77  }
78  }
79  else
80  {
81  NS_LOG_DEBUG ("Received RSSI is below the target RSSI");
82  return false;
83  }
84 
85 }
86 
87 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::ThresholdPreambleDetectionModel::ThresholdPreambleDetectionModel
ThresholdPreambleDetectionModel()
Definition: threshold-preamble-detection-model.cc:53
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ThresholdPreambleDetectionModel::m_rssiMin
double m_rssiMin
Minimum RSSI in dBm that shall be received to start the decision.
Definition: threshold-preamble-detection-model.h:61
ns3::ThresholdPreambleDetectionModel::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: threshold-preamble-detection-model.cc:33
ns3::WToDbm
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:43
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::PreambleDetectionModel
the interface for Wifi's preamble detection models
Definition: preamble-detection-model.h:34
ns3::ThresholdPreambleDetectionModel
A threshold-based model for detecting PHY preamble.
Definition: threshold-preamble-detection-model.h:35
ns3::ThresholdPreambleDetectionModel::m_threshold
double m_threshold
SNR threshold in dB used to decide whether a preamble is successfully received.
Definition: threshold-preamble-detection-model.h:60
ns3::RatioToDb
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:49
ns3::MakeDoubleAccessor
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
ns3::ThresholdPreambleDetectionModel::IsPreambleDetected
bool IsPreambleDetected(double rssi, double snr, double channelWidth) const override
This method returns whether the preamble detection was successful.
Definition: threshold-preamble-detection-model.cc:64
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
wifi-utils.h
threshold-preamble-detection-model.h
ns3::ThresholdPreambleDetectionModel::~ThresholdPreambleDetectionModel
~ThresholdPreambleDetectionModel()
Definition: threshold-preamble-detection-model.cc:58
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244