A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spectrum-interference.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 #include "spectrum-interference.h"
23 #include "spectrum-error-model.h"
24 
25 #include <ns3/simulator.h>
26 #include <ns3/log.h>
27 
28 
29 NS_LOG_COMPONENT_DEFINE ("SpectrumInterference");
30 
31 namespace ns3 {
32 
33 
35  : m_receiving (false),
36  m_rxSignal (0),
37  m_allSignals (0),
38  m_noise (0),
39  m_errorModel (0)
40 {
41  NS_LOG_FUNCTION (this);
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
49 void
51 {
52  NS_LOG_FUNCTION (this);
53  m_rxSignal = 0;
54  m_allSignals = 0;
55  m_noise = 0;
56  m_errorModel = 0;
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION (this << p << *rxPsd);
64  m_rxSignal = rxPsd;
65  m_lastChangeTime = Now ();
66  m_receiving = true;
67  m_errorModel->StartRx (p);
68 }
69 
70 void
72 {
73  m_receiving = false;
74 }
75 
76 bool
78 {
79  NS_LOG_FUNCTION (this);
81  m_receiving = false;
82  return m_errorModel->IsRxCorrect ();
83 }
84 
85 
86 void
88 {
89  NS_LOG_FUNCTION (this << *spd << duration);
90  DoAddSignal (spd);
92 }
93 
94 
95 void
97 {
98  NS_LOG_FUNCTION (this << *spd);
100  (*m_allSignals) += (*spd);
101  m_lastChangeTime = Now ();
102 }
103 
104 void
106 {
107  NS_LOG_FUNCTION (this << *spd);
109  (*m_allSignals) -= (*spd);
110  m_lastChangeTime = Now ();
111 }
112 
113 
114 void
116 {
117  NS_LOG_FUNCTION (this);
118  NS_LOG_LOGIC ("m_receiving: " << m_receiving );
119  NS_LOG_LOGIC ("m_lastChangeTime: " << m_lastChangeTime << " Now: " << Now ());
120  bool condition = m_receiving && (Now () > m_lastChangeTime);
121  NS_LOG_LOGIC ("if condition: " << condition);
122  if (condition)
123  {
124  SpectrumValue sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
125  Time duration = Now () - m_lastChangeTime;
126  NS_LOG_LOGIC ("calling m_errorModel->EvaluateChunk (sinr, duration)");
127  m_errorModel->EvaluateChunk (sinr, duration);
128  }
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION (this << noisePsd);
135  m_noise = noisePsd;
136  // we can initialize m_allSignal only now, because earlier we
137  // didn't know what spectrum model was going to be used.
138  // we'll now create a zeroed SpectrumValue using the same
139  // SpectrumModel which is being specified for the noise.
140  m_allSignals = Create<SpectrumValue> (noisePsd->GetSpectrumModel ());
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION (this << e);
147  m_errorModel = e;
148 }
149 
150 
151 
152 
153 } // namespace ns3
154 
155 
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("SpectrumInterference")
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
notify that a new signal is being perceived in the medium.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
void AbortRx()
notify that the PHY has aborted RX
Ptr< const SpectrumValue > m_noise
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
notify that the PHY is starting a RX attempt
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Time m_lastChangeTime
the time of the last change in m_TotalPower
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
Ptr< SpectrumValue > m_allSignals
stores the spectral power density of the sum of incoming signals; does not include noise...
bool EndRx()
notify that the RX attempt has ended.
Ptr< const SpectrumValue > m_rxSignal
stores the power spectral density of the signal whose RX is being attempted
Ptr< SpectrumErrorModel > m_errorModel
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void DoAddSignal(Ptr< const SpectrumValue > spd)
void SetErrorModel(Ptr< SpectrumErrorModel > e)
set the SpectrumErrorModel to be used.
void DoSubtractSignal(Ptr< const SpectrumValue > spd)
Set of values corresponding to a given SpectrumModel.