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
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
A threshold-based model for detecting PHY preamble.
double m_rssiMin
Minimum RSSI that shall be received to start the decision.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
the interface for Wifi&#39;s preamble detection models
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:47
double m_threshold
SNR threshold in dB used to decide whether a preamble is successfully received.
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:53
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
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
bool IsPreambleDetected(double rssi, double snr, double channelWidth) const
This method returns whether the preamble detection was successful.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915