A Discrete-Event Network Simulator
API
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 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("SpectrumInterference");
32 
34  : m_receiving (false),
35  m_rxSignal (0),
36  m_allSignals (0),
37  m_noise (0),
38  m_errorModel (0)
39 {
40  NS_LOG_FUNCTION (this);
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::SpectrumInterference")
52  .SetParent<Object> ()
53  .SetGroupName ("Spectrum")
54  .AddConstructor<SpectrumInterference> ()
55  ;
56  return tid;
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION (this);
63  m_rxSignal = 0;
64  m_allSignals = 0;
65  m_noise = 0;
66  m_errorModel = 0;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this << p << *rxPsd);
74  m_rxSignal = rxPsd;
75  m_lastChangeTime = Now ();
76  m_receiving = true;
77  m_errorModel->StartRx (p);
78 }
79 
80 void
82 {
83  m_receiving = false;
84 }
85 
86 bool
88 {
89  NS_LOG_FUNCTION (this);
91  m_receiving = false;
92  return m_errorModel->IsRxCorrect ();
93 }
94 
95 
96 void
98 {
99  NS_LOG_FUNCTION (this << *spd << duration);
100  DoAddSignal (spd);
102 }
103 
104 
105 void
107 {
108  NS_LOG_FUNCTION (this << *spd);
110  (*m_allSignals) += (*spd);
111  m_lastChangeTime = Now ();
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION (this << *spd);
119  (*m_allSignals) -= (*spd);
120  m_lastChangeTime = Now ();
121 }
122 
123 
124 void
126 {
127  NS_LOG_FUNCTION (this);
128  NS_LOG_LOGIC ("m_receiving: " << m_receiving );
129  NS_LOG_LOGIC ("m_lastChangeTime: " << m_lastChangeTime << " Now: " << Now ());
130  bool condition = m_receiving && (Now () > m_lastChangeTime);
131  NS_LOG_LOGIC ("if condition: " << condition);
132  if (condition)
133  {
134  SpectrumValue sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
135  Time duration = Now () - m_lastChangeTime;
136  NS_LOG_LOGIC ("calling m_errorModel->EvaluateChunk (sinr, duration)");
137  m_errorModel->EvaluateChunk (sinr, duration);
138  }
139 }
140 
141 void
143 {
144  NS_LOG_FUNCTION (this << noisePsd);
145  m_noise = noisePsd;
146  // we can initialize m_allSignal only now, because earlier we
147  // didn't know what spectrum model was going to be used.
148  // we'll now create a zeroed SpectrumValue using the same
149  // SpectrumModel which is being specified for the noise.
150  m_allSignals = Create<SpectrumValue> (noisePsd->GetSpectrumModel ());
151 }
152 
153 void
155 {
156  NS_LOG_FUNCTION (this << e);
157  m_errorModel = e;
158 }
159 
160 
161 
162 
163 } // namespace ns3
164 
165 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool m_receiving
True if in Rx status.
static TypeId GetTypeId(void)
Register this type.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the Noise Power Spectral Density.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
Notify that a new signal is being perceived in the medium.
void AbortRx()
Notify that the PHY has aborted RX.
Ptr< const SpectrumValue > m_noise
Noise spectral power density.
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
Notify that the PHY is starting a RX attempt.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
void DoDispose()
Destructor implementation.
Time m_lastChangeTime
the time of the last change in m_TotalPower
Ptr< SpectrumValue > m_allSignals
Stores the spectral power density of the sum of incoming signals; does not include noise...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool EndRx()
Notify that the RX attempt has ended.
This class implements a gaussian interference model, i.e., all incoming signals are added to the tota...
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Ptr< const SpectrumValue > m_rxSignal
Stores the power spectral density of the signal whose RX is being attempted.
Ptr< SpectrumErrorModel > m_errorModel
Error model.
void DoAddSignal(Ptr< const SpectrumValue > spd)
Adds a signal perceived in the medium.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
void SetErrorModel(Ptr< SpectrumErrorModel > e)
Set the SpectrumErrorModel to be used.
void DoSubtractSignal(Ptr< const SpectrumValue > spd)
Removes a signal perceived in the medium.
A base class which provides memory management and object aggregation.
Definition: object.h:87
Set of values corresponding to a given SpectrumModel.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void ConditionallyEvaluateChunk()
Evaluate a Chunk, depending on the Rx status and the last update time.