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  ;
49 
51 {
52  NS_LOG_FUNCTION (this);
53 }
54 
55 void
57 {
58  NS_LOG_FUNCTION (this);
59  m_phyList.clear ();
60  m_spectrumModel = 0;
65 }
66 
67 TypeId
69 {
71  static TypeId tid = TypeId ("ns3::SingleModelSpectrumChannel")
73  .AddConstructor<SingleModelSpectrumChannel> ()
74  .AddAttribute ("MaxLossDb",
75  "If a single-frequency PropagationLossModel is used, this value "
76  "represents the maximum loss in dB for which transmissions will be "
77  "passed to the receiving PHY. Signals for which the PropagationLossModel "
78  "returns a loss bigger than this value will not be propagated to the receiver. "
79  "This parameter is to be used to reduce "
80  "the computational load by not propagating signals that are far beyond "
81  "the interference range. Note that the default value corresponds to "
82  "considering all signals for reception. Tune this value with care. ",
83  DoubleValue (1.0e9),
84  MakeDoubleAccessor (&SingleModelSpectrumChannel::m_maxLossDb),
85  MakeDoubleChecker<double> ())
86  .AddTraceSource ("PathLoss",
87  "This trace is fired "
88  "whenever a new path loss value is calculated. The first and second parameters "
89  "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, "
90  "whereas the third parameters is the loss value in dB. Note that the loss value "
91  "reported by this trace is the single-frequency loss value obtained by evaluating "
92  "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that "
93  "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value "
94  "reported in this trace. ",
96  ;
97  return tid;
98 }
99 
100 
101 void
103 {
104  NS_LOG_FUNCTION (this << phy);
105  m_phyList.push_back (phy);
106 }
107 
108 
109 void
111 {
112  NS_LOG_FUNCTION (this << txParams->psd << txParams->duration << txParams->txPhy);
113  NS_ASSERT_MSG (txParams->psd, "NULL txPsd");
114  NS_ASSERT_MSG (txParams->txPhy, "NULL txPhy");
115 
116  // just a sanity check routine. We might want to remove it to save some computational load -- one "if" statement ;-)
117  if (m_spectrumModel == 0)
118  {
119  // first pak, record SpectrumModel
120  m_spectrumModel = txParams->psd->GetSpectrumModel ();
121  }
122  else
123  {
124  // all attached SpectrumPhy instances must use the same SpectrumModel
125  NS_ASSERT (*(txParams->psd->GetSpectrumModel ()) == *m_spectrumModel);
126  }
127 
128 
129 
130 
131  Ptr<MobilityModel> senderMobility = txParams->txPhy->GetMobility ();
132 
133  for (PhyList::const_iterator rxPhyIterator = m_phyList.begin ();
134  rxPhyIterator != m_phyList.end ();
135  ++rxPhyIterator)
136  {
137  if ((*rxPhyIterator) != txParams->txPhy)
138  {
139  Time delay = MicroSeconds (0);
140 
141  Ptr<MobilityModel> receiverMobility = (*rxPhyIterator)->GetMobility ();
142  NS_LOG_LOGIC ("copying signal parameters " << txParams);
143  Ptr<SpectrumSignalParameters> rxParams = txParams->Copy ();
144 
145  if (senderMobility && receiverMobility)
146  {
147  double pathLossDb = 0;
148  if (rxParams->txAntenna != 0)
149  {
150  Angles txAngles (receiverMobility->GetPosition (), senderMobility->GetPosition ());
151  double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
152  NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB");
153  pathLossDb -= txAntennaGain;
154  }
155  Ptr<AntennaModel> rxAntenna = (*rxPhyIterator)->GetRxAntenna ();
156  if (rxAntenna != 0)
157  {
158  Angles rxAngles (senderMobility->GetPosition (), receiverMobility->GetPosition ());
159  double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
160  NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB");
161  pathLossDb -= rxAntennaGain;
162  }
163  if (m_propagationLoss)
164  {
165  double propagationGainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility);
166  NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB");
167  pathLossDb -= propagationGainDb;
168  }
169  NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB");
170  m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb);
171  if ( pathLossDb > m_maxLossDb)
172  {
173  // beyond range
174  continue;
175  }
176  double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
177  *(rxParams->psd) *= pathGainLinear;
178 
180  {
181  rxParams->psd = m_spectrumPropagationLoss->CalcRxPowerSpectralDensity (rxParams->psd, senderMobility, receiverMobility);
182  }
183 
184  if (m_propagationDelay)
185  {
186  delay = m_propagationDelay->GetDelay (senderMobility, receiverMobility);
187  }
188  }
189 
190 
191  Ptr<NetDevice> netDev = (*rxPhyIterator)->GetDevice ();
192  if (netDev)
193  {
194  // the receiver has a NetDevice, so we expect that it is attached to a Node
195  uint32_t dstNode = netDev->GetNode ()->GetId ();
196  Simulator::ScheduleWithContext (dstNode, delay, &SingleModelSpectrumChannel::StartRx, this, rxParams, *rxPhyIterator);
197  }
198  else
199  {
200  // the receiver is not attached to a NetDevice, so we cannot assume that it is attached to a node
202  rxParams, *rxPhyIterator);
203  }
204  }
205  }
206 
207 }
208 
209 void
211 {
212  NS_LOG_FUNCTION (this << params);
213  receiver->StartRx (params);
214 }
215 
216 
217 
218 uint32_t
220 {
221  NS_LOG_FUNCTION (this);
222  return m_phyList.size ();
223 }
224 
225 
228 {
229  NS_LOG_FUNCTION (this << i);
230  return m_phyList.at (i)->GetDevice ()->GetObject<NetDevice> ();
231 }
232 
233 
234 void
236 {
237  NS_LOG_FUNCTION (this << loss);
239  m_propagationLoss = loss;
240 }
241 
242 
243 void
245 {
246  NS_LOG_FUNCTION (this << loss);
249 }
250 
251 void
253 {
254  NS_LOG_FUNCTION (this << delay);
256  m_propagationDelay = delay;
257 }
258 
259 
262 {
263  NS_LOG_FUNCTION (this);
265 }
266 
267 
268 } // namespace ns3
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
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
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)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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:336
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
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
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
set the single-frequency propagation loss model to be used
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
NS_LOG_COMPONENT_DEFINE("SingleModelSpectrumChannel")
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:904
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
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)
Definition: assert.h:86
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:611
Ptr< const SpectrumModel > m_spectrumModel
SpectrumModel that this channel instance is supporting.