A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
threshold-preamble-detection-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
21
22#include "wifi-utils.h"
23
24#include "ns3/double.h"
25#include "ns3/log.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("ThresholdPreambleDetectionModel");
31
32NS_OBJECT_ENSURE_REGISTERED(ThresholdPreambleDetectionModel);
33
34TypeId
36{
37 static TypeId tid =
38 TypeId("ns3::ThresholdPreambleDetectionModel")
40 .SetGroupName("Wifi")
41 .AddConstructor<ThresholdPreambleDetectionModel>()
42 .AddAttribute("Threshold",
43 "Preamble is successfully detected if the SNR is at or above this value "
44 "(expressed in dB).",
45 DoubleValue(4),
47 MakeDoubleChecker<double>())
48 .AddAttribute("MinimumRssi",
49 "Preamble is dropped if the RSSI is below this value (expressed in dBm).",
50 DoubleValue(-82),
52 MakeDoubleChecker<double>());
53 return tid;
54}
55
57{
58 NS_LOG_FUNCTION(this);
59}
60
62{
63 NS_LOG_FUNCTION(this);
64}
65
66bool
68 double snr,
69 double channelWidth) const
70{
71 NS_LOG_FUNCTION(this << WToDbm(rssi) << RatioToDb(snr) << channelWidth);
72 if (WToDbm(rssi) >= m_rssiMin)
73 {
74 if (RatioToDb(snr) >= m_threshold)
75 {
76 return true;
77 }
78 else
79 {
80 NS_LOG_DEBUG("Received RSSI is above the target RSSI but SNR is too low");
81 return false;
82 }
83 }
84 else
85 {
86 NS_LOG_DEBUG("Received RSSI is below the target RSSI");
87 return false;
88 }
89}
90
91} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
the interface for Wifi's preamble detection models
A threshold-based model for detecting PHY preamble.
double m_threshold
SNR threshold in dB used to decide whether a preamble is successfully received.
bool IsPreambleDetected(double rssi, double snr, double channelWidth) const override
This method returns whether the preamble detection was successful.
double m_rssiMin
Minimum RSSI in dBm that shall be received to start the decision.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
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:52
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:46