A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
20
#include "
threshold-preamble-detection-model.h
"
21
22
#include "
wifi-utils.h
"
23
24
#include "ns3/double.h"
25
#include "ns3/log.h"
26
27
namespace
ns3
28
{
29
30
NS_LOG_COMPONENT_DEFINE
(
"ThresholdPreambleDetectionModel"
);
31
32
NS_OBJECT_ENSURE_REGISTERED
(ThresholdPreambleDetectionModel);
33
34
TypeId
35
ThresholdPreambleDetectionModel::GetTypeId
()
36
{
37
static
TypeId
tid =
38
TypeId
(
"ns3::ThresholdPreambleDetectionModel"
)
39
.
SetParent
<
PreambleDetectionModel
>()
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),
46
MakeDoubleAccessor
(&
ThresholdPreambleDetectionModel::m_threshold
),
47
MakeDoubleChecker<double>())
48
.AddAttribute(
"MinimumRssi"
,
49
"Preamble is dropped if the RSSI is below this value (expressed in dBm)."
,
50
DoubleValue
(-82),
51
MakeDoubleAccessor
(&
ThresholdPreambleDetectionModel::m_rssiMin
),
52
MakeDoubleChecker<double>());
53
return
tid;
54
}
55
56
ThresholdPreambleDetectionModel::ThresholdPreambleDetectionModel
()
57
{
58
NS_LOG_FUNCTION
(
this
);
59
}
60
61
ThresholdPreambleDetectionModel::~ThresholdPreambleDetectionModel
()
62
{
63
NS_LOG_FUNCTION
(
this
);
64
}
65
66
bool
67
ThresholdPreambleDetectionModel::IsPreambleDetected
(
double
rssi,
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
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition:
double.h:42
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:36
ns3::ThresholdPreambleDetectionModel::ThresholdPreambleDetectionModel
ThresholdPreambleDetectionModel()
Definition:
threshold-preamble-detection-model.cc:56
ns3::ThresholdPreambleDetectionModel::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
threshold-preamble-detection-model.cc: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::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:67
ns3::ThresholdPreambleDetectionModel::~ThresholdPreambleDetectionModel
~ThresholdPreambleDetectionModel() override
Definition:
threshold-preamble-detection-model.cc:61
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:62
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:60
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:935
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:43
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition:
log.h:268
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:238
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RatioToDb
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition:
wifi-utils.cc:52
ns3::WToDbm
double WToDbm(double w)
Convert from Watts to dBm.
Definition:
wifi-utils.cc:46
threshold-preamble-detection-model.h
wifi-utils.h
src
wifi
model
threshold-preamble-detection-model.cc
Generated on Fri Mar 31 2023 13:30:54 for ns-3 by
1.9.1