A Discrete-Event Network Simulator
API
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 namespace ns3 {
42 
43 NS_LOG_COMPONENT_DEFINE ("SingleModelSpectrumChannel");
44 
45 NS_OBJECT_ENSURE_REGISTERED (SingleModelSpectrumChannel);
46 
48 {
49  NS_LOG_FUNCTION (this);
50 }
51 
52 void
54 {
55  NS_LOG_FUNCTION (this);
56  m_phyList.clear ();
57  m_spectrumModel = 0;
62 }
63 
64 TypeId
66 {
68  static TypeId tid = TypeId ("ns3::SingleModelSpectrumChannel")
70  .SetGroupName ("Spectrum")
71  .AddConstructor<SingleModelSpectrumChannel> ()
72  .AddAttribute ("MaxLossDb",
73  "If a single-frequency PropagationLossModel is used, "
74  "this value represents the maximum loss in dB for which "
75  "transmissions will be passed to the receiving PHY. "
76  "Signals for which the PropagationLossModel returns "
77  "a loss bigger than this value will not be propagated "
78  "to the receiver. This parameter is to be used to reduce "
79  "the computational load by not propagating signals "
80  "that are far beyond the interference range. Note that "
81  "the default value corresponds to considering all signals "
82  "for reception. Tune this value with care. ",
83  DoubleValue (1.0e9),
85  MakeDoubleChecker<double> ())
86  .AddTraceSource ("PathLoss",
87  "This trace is fired whenever a new path loss value "
88  "is calculated. The first and second parameters "
89  "to the trace are pointers respectively to the TX and "
90  "RX SpectrumPhy instances, whereas the third parameters "
91  "is the loss value in dB. Note that the loss value "
92  "reported by this trace is the single-frequency loss "
93  "value obtained by evaluating only the TX and RX "
94  "AntennaModels and the PropagationLossModel. "
95  "In particular, note that SpectrumPropagationLossModel "
96  "(even if present) is never used to evaluate the "
97  "loss value reported in this trace. ",
99  "ns3::SpectrumChannel::LossTracedCallback")
100  ;
101  return tid;
102 }
103 
104 
105 void
107 {
108  NS_LOG_FUNCTION (this << phy);
109  m_phyList.push_back (phy);
110 }
111 
112 
113 void
115 {
116  NS_LOG_FUNCTION (this << txParams->psd << txParams->duration << txParams->txPhy);
117  NS_ASSERT_MSG (txParams->psd, "NULL txPsd");
118  NS_ASSERT_MSG (txParams->txPhy, "NULL txPhy");
119 
120  // just a sanity check routine. We might want to remove it to save some computational load -- one "if" statement ;-)
121  if (m_spectrumModel == 0)
122  {
123  // first pak, record SpectrumModel
124  m_spectrumModel = txParams->psd->GetSpectrumModel ();
125  }
126  else
127  {
128  // all attached SpectrumPhy instances must use the same SpectrumModel
129  NS_ASSERT (*(txParams->psd->GetSpectrumModel ()) == *m_spectrumModel);
130  }
131 
132 
133 
134 
135  Ptr<MobilityModel> senderMobility = txParams->txPhy->GetMobility ();
136 
137  for (PhyList::const_iterator rxPhyIterator = m_phyList.begin ();
138  rxPhyIterator != m_phyList.end ();
139  ++rxPhyIterator)
140  {
141  if ((*rxPhyIterator) != txParams->txPhy)
142  {
143  Time delay = MicroSeconds (0);
144 
145  Ptr<MobilityModel> receiverMobility = (*rxPhyIterator)->GetMobility ();
146  NS_LOG_LOGIC ("copying signal parameters " << txParams);
147  Ptr<SpectrumSignalParameters> rxParams = txParams->Copy ();
148 
149  if (senderMobility && receiverMobility)
150  {
151  double pathLossDb = 0;
152  if (rxParams->txAntenna != 0)
153  {
154  Angles txAngles (receiverMobility->GetPosition (), senderMobility->GetPosition ());
155  double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
156  NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB");
157  pathLossDb -= txAntennaGain;
158  }
159  Ptr<AntennaModel> rxAntenna = (*rxPhyIterator)->GetRxAntenna ();
160  if (rxAntenna != 0)
161  {
162  Angles rxAngles (senderMobility->GetPosition (), receiverMobility->GetPosition ());
163  double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
164  NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB");
165  pathLossDb -= rxAntennaGain;
166  }
167  if (m_propagationLoss)
168  {
169  double propagationGainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility);
170  NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB");
171  pathLossDb -= propagationGainDb;
172  }
173  NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB");
174  m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb);
175  if ( pathLossDb > m_maxLossDb)
176  {
177  // beyond range
178  continue;
179  }
180  double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
181  *(rxParams->psd) *= pathGainLinear;
182 
184  {
185  rxParams->psd = m_spectrumPropagationLoss->CalcRxPowerSpectralDensity (rxParams->psd, senderMobility, receiverMobility);
186  }
187 
188  if (m_propagationDelay)
189  {
190  delay = m_propagationDelay->GetDelay (senderMobility, receiverMobility);
191  }
192  }
193 
194 
195  Ptr<NetDevice> netDev = (*rxPhyIterator)->GetDevice ();
196  if (netDev)
197  {
198  // the receiver has a NetDevice, so we expect that it is attached to a Node
199  uint32_t dstNode = netDev->GetNode ()->GetId ();
200  Simulator::ScheduleWithContext (dstNode, delay, &SingleModelSpectrumChannel::StartRx, this, rxParams, *rxPhyIterator);
201  }
202  else
203  {
204  // the receiver is not attached to a NetDevice, so we cannot assume that it is attached to a node
206  rxParams, *rxPhyIterator);
207  }
208  }
209  }
210 
211 }
212 
213 void
215 {
216  NS_LOG_FUNCTION (this << params);
217  receiver->StartRx (params);
218 }
219 
220 
221 
222 uint32_t
224 {
225  NS_LOG_FUNCTION (this);
226  return m_phyList.size ();
227 }
228 
229 
232 {
233  NS_LOG_FUNCTION (this << i);
234  return m_phyList.at (i)->GetDevice ()->GetObject<NetDevice> ();
235 }
236 
237 
238 void
240 {
241  NS_LOG_FUNCTION (this << loss);
242  if (m_propagationLoss)
243  {
244  loss->SetNext (m_propagationLoss);
245  }
246  m_propagationLoss = loss;
247 }
248 
249 
250 void
252 {
253  NS_LOG_FUNCTION (this << loss);
255  {
256  loss->SetNext (m_spectrumPropagationLoss);
257  }
259 }
260 
261 void
263 {
264  NS_LOG_FUNCTION (this << delay);
266  m_propagationDelay = delay;
267 }
268 
269 
272 {
273  NS_LOG_FUNCTION (this);
275 }
276 
277 
278 } // namespace ns3
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 "...
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
virtual Ptr< SpectrumPropagationLossModel > GetSpectrumPropagationLossModel(void)
Get the frequency-dependent propagation loss model.
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)
Add 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:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Vector GetPosition(void) const
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add 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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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.
tuple phy
Definition: third.py:86
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
virtual void DoDispose()
Destructor implementation.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
virtual void StartTx(Ptr< SpectrumSignalParameters > params)
Used by attached PHY instances to transmit signals on the channel.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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:90
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
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1469
Network layer to device interface.
Definition: net-device.h:95
SpectrumChannel implementation which handles a single spectrum model.
virtual void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
Defines the interface for spectrum-aware channel implementations.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
struct holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:71
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
Ptr< const SpectrumModel > m_spectrumModel
SpectrumModel that this channel instance is supporting.