A Discrete-Event Network Simulator
API
simple-frame-capture-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017
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 
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/double.h"
25 #include "wifi-utils.h"
26 #include "wifi-phy.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("SimpleFrameCaptureModel");
31 
32 NS_OBJECT_ENSURE_REGISTERED (SimpleFrameCaptureModel);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::SimpleFrameCaptureModel")
39  .SetGroupName ("Wifi")
40  .AddConstructor<SimpleFrameCaptureModel> ()
41  .AddAttribute ("Margin",
42  "Reception is switched if the newly arrived frame has a power higher than "
43  "this value above the frame currently being received (expressed in dB).",
44  DoubleValue (10),
47  MakeDoubleChecker<double> ())
48  ;
49  return tid;
50 }
51 
53 {
54  NS_LOG_FUNCTION (this);
55 }
56 
58 {
59  NS_LOG_FUNCTION (this);
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION (this << margin);
66  m_margin = margin;
67 }
68 
69 double
71 {
72  return m_margin;
73 }
74 
75 bool
77 {
78  NS_LOG_FUNCTION (this);
79  if (newEvent->GetTxVector ().GetPreambleType () != WIFI_PREAMBLE_NONE
80  && (WToDbm (currentEvent->GetRxPowerW ()) + m_margin) < WToDbm (newEvent->GetRxPowerW ())
81  && ((currentEvent->GetStartTime () + WifiPhy::CalculatePlcpPreambleAndHeaderDuration (currentEvent->GetTxVector ())) > Simulator::Now ()))
82  {
83  return true;
84  }
85  return false;
86 }
87 
88 } //namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
A simple threshold-based model for frame capture effect.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool CaptureNewFrame(Ptr< InterferenceHelper::Event > currentEvent, Ptr< InterferenceHelper::Event > newEvent) const
This method returns whether the reception should be switched to a new incoming frame.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
static TypeId GetTypeId(void)
Get the type ID.
the interface for Wifi's frame capture models
static Time CalculatePlcpPreambleAndHeaderDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:2240
double GetMargin(void) const
Return the frame capture margin (dB).
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
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
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
void SetMargin(double margin)
Sets the frame capture margin (dB).
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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:914
double m_margin
margin for determining if a new frame