A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
single-model-spectrum-channel.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 #include <ns3/object.h>
22 #include <ns3/simulator.h>
23 #include <ns3/log.h>
24 #include <ns3/packet.h>
25 #include <ns3/packet-burst.h>
26 #include <ns3/net-device.h>
27 #include <ns3/node.h>
28 #include <ns3/double.h>
29 #include <ns3/mobility-model.h>
30 #include <ns3/spectrum-phy.h>
31 #include <ns3/spectrum-propagation-loss-model.h>
32 #include <ns3/propagation-loss-model.h>
33 #include <ns3/propagation-delay-model.h>
34 #include <ns3/antenna-model.h>
35 #include <ns3/angles.h>
36 
37 
39 
40 
41 NS_LOG_COMPONENT_DEFINE ("SingleModelSpectrumChannel");
42 
43 
44 namespace ns3 {
45 
46 
47 NS_OBJECT_ENSURE_REGISTERED (SingleModelSpectrumChannel);
48 
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION (this);
58  m_phyList.clear ();
59  m_spectrumModel = 0;
64 }
65 
66 TypeId
68 {
70  static TypeId tid = TypeId ("ns3::SingleModelSpectrumChannel")
72  .AddConstructor<SingleModelSpectrumChannel> ()
73  .AddAttribute ("MaxLossDb",
74  "If a single-frequency PropagationLossModel is used, this value "
75  "represents the maximum loss in dB for which transmissions will be "
76  "passed to the receiving PHY. Signals for which the PropagationLossModel "
77  "returns a loss bigger than this value will not be propagated to the receiver. "
78  "This parameter is to be used to reduce "
79  "the computational load by not propagating signals that are far beyond "
80  "the interference range. Note that the default value corresponds to "
81  "considering all signals for reception. Tune this value with care. ",
82  DoubleValue (1.0e9),
83  MakeDoubleAccessor (&SingleModelSpectrumChannel::m_maxLossDb),
84  MakeDoubleChecker<double> ())
85  .AddTraceSource ("PathLoss",
86  "This trace is fired "
87  "whenever a new path loss value is calculated. The first and second parameters "
88  "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, "
89  "whereas the third parameters is the loss value in dB. Note that the loss value "
90  "reported by this trace is the single-frequency loss value obtained by evaluating "
91  "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that "
92  "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value "
93  "reported in this trace. ",
95  ;
96  return tid;
97 }
98 
99 
100 void
102 {
103  NS_LOG_FUNCTION (this << phy);
104  m_phyList.push_back (phy);
105 }
106 
107 
108 void
110 {
111  NS_LOG_FUNCTION (this << txParams->psd << txParams->duration << txParams->txPhy);
112  NS_ASSERT_MSG (txParams->psd, "NULL txPsd");
113  NS_ASSERT_MSG (txParams->txPhy, "NULL txPhy");
114 
115  // just a sanity check routine. We might want to remove it to save some computational load -- one "if" statement ;-)
116  if (m_spectrumModel == 0)
117  {
118  // first pak, record SpectrumModel
119  m_spectrumModel = txParams->psd->GetSpectrumModel ();
120  }
121  else
122  {
123  // all attached SpectrumPhy instances must use the same SpectrumModel
124  NS_ASSERT (*(txParams->psd->GetSpectrumModel ()) == *m_spectrumModel);
125  }
126 
127 
128 
129 
130  Ptr<MobilityModel> senderMobility = txParams->txPhy->GetMobility ();
131 
132  for (PhyList::const_iterator rxPhyIterator = m_phyList.begin ();
133  rxPhyIterator != m_phyList.end ();
134  ++rxPhyIterator)
135  {
136  if ((*rxPhyIterator) != txParams->txPhy)
137  {
138  Time delay = MicroSeconds (0);
139 
140  Ptr<MobilityModel> receiverMobility = (*rxPhyIterator)->GetMobility ();
141  NS_LOG_LOGIC ("copying signal parameters " << txParams);
142  Ptr<SpectrumSignalParameters> rxParams = txParams->Copy ();
143 
144  if (senderMobility && receiverMobility)
145  {
146  double pathLossDb = 0;
147  if (rxParams->txAntenna != 0)
148  {
149  Angles txAngles (receiverMobility->GetPosition (), senderMobility->GetPosition ());
150  double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
151  NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB");
152  pathLossDb -= txAntennaGain;
153  }
154  Ptr<AntennaModel> rxAntenna = (*rxPhyIterator)->GetRxAntenna ();
155  if (rxAntenna != 0)
156  {
157  Angles rxAngles (senderMobility->GetPosition (), receiverMobility->GetPosition ());
158  double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
159  NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB");
160  pathLossDb -= rxAntennaGain;
161  }
162  if (m_propagationLoss)
163  {
164  double propagationGainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility);
165  NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB");
166  pathLossDb -= propagationGainDb;
167  }
168  NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB");
169  m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb);
170  if ( pathLossDb > m_maxLossDb)
171  {
172  // beyond range
173  continue;
174  }
175  double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
176  *(rxParams->psd) *= pathGainLinear;
177 
179  {
180  rxParams->psd = m_spectrumPropagationLoss->CalcRxPowerSpectralDensity (rxParams->psd, senderMobility, receiverMobility);
181  }
182 
183  if (m_propagationDelay)
184  {
185  delay = m_propagationDelay->GetDelay (senderMobility, receiverMobility);
186  }
187  }
188 
189 
190  Ptr<NetDevice> netDev = (*rxPhyIterator)->GetDevice ();
191  if (netDev)
192  {
193  // the receiver has a NetDevice, so we expect that it is attached to a Node
194  uint32_t dstNode = netDev->GetNode ()->GetId ();
195  Simulator::ScheduleWithContext (dstNode, delay, &SingleModelSpectrumChannel::StartRx, this, rxParams, *rxPhyIterator);
196  }
197  else
198  {
199  // the receiver is not attached to a NetDevice, so we cannot assume that it is attached to a node
201  rxParams, *rxPhyIterator);
202  }
203  }
204  }
205 
206 }
207 
208 void
210 {
211  NS_LOG_FUNCTION (this << params);
212  receiver->StartRx (params);
213 }
214 
215 
216 
217 uint32_t
219 {
220  NS_LOG_FUNCTION (this);
221  return m_phyList.size ();
222 }
223 
224 
227 {
228  NS_LOG_FUNCTION (this << i);
229  return m_phyList.at (i)->GetDevice ()->GetObject<NetDevice> ();
230 }
231 
232 
233 void
235 {
236  NS_LOG_FUNCTION (this << loss);
238  m_propagationLoss = loss;
239 }
240 
241 
242 void
244 {
245  NS_LOG_FUNCTION (this << loss);
248 }
249 
250 void
252 {
253  NS_LOG_FUNCTION (this << delay);
255  m_propagationDelay = delay;
256 }
257 
258 
261 {
262  NS_LOG_FUNCTION (this);
264 }
265 
266 
267 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual Ptr< SpectrumPropagationLossModel > GetSpectrumPropagationLossModel(void)
Ptr< PropagationDelayModel > m_propagationDelay
propagation delay model to be used with this channel
virtual void AddRx(Ptr< SpectrumPhy > phy)
add a SpectrumPhy to a channel, so it can receive packets
virtual void AddSpectrumPropagationLossModel(Ptr< SpectrumPropagationLossModel > loss)
set the frequency-dependent propagation loss model to be used
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Vector GetPosition(void) const
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:825
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
set the single-frequency propagation loss model to be used
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
Ptr< PropagationLossModel > m_propagationLoss
single-frequency propagation loss model to be used with this channel
TracedCallback< Ptr< SpectrumPhy >, Ptr< SpectrumPhy >, double > m_pathLossTrace
void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
used internally to reschedule transmission after the propagation delay
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:905
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual void StartTx(Ptr< SpectrumSignalParameters > params)
Used by attached PHY instances to transmit signals on the channel.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
frequency-dependent propagation loss model to be used with this channel
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:84
Network layer to device interface.
Definition: net-device.h:75
virtual void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
set the propagation delay model to be used
Defines the interface for spectrum-aware channel implementations.
struct holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:71
Hold a floating point type.
Definition: double.h:41
PhyList m_phyList
list of SpectrumPhy instances attached to the channel
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
Ptr< const SpectrumModel > m_spectrumModel
SpectrumModel that this channel instance is supporting.