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;
59 }
60 
61 TypeId
63 {
65  static TypeId tid = TypeId ("ns3::SingleModelSpectrumChannel")
67  .SetGroupName ("Spectrum")
68  .AddConstructor<SingleModelSpectrumChannel> ()
69  ;
70  return tid;
71 }
72 
73 
74 void
76 {
77  NS_LOG_FUNCTION (this << phy);
78  m_phyList.push_back (phy);
79 }
80 
81 
82 void
84 {
85  NS_LOG_FUNCTION (this << txParams->psd << txParams->duration << txParams->txPhy);
86  NS_ASSERT_MSG (txParams->psd, "NULL txPsd");
87  NS_ASSERT_MSG (txParams->txPhy, "NULL txPhy");
88 
89  Ptr<SpectrumSignalParameters> txParamsTrace = txParams->Copy (); // copy it since traced value cannot be const (because of potential underlying DynamicCasts)
90  m_txSigParamsTrace (txParamsTrace);
91 
92  // just a sanity check routine. We might want to remove it to save some computational load -- one "if" statement ;-)
93  if (m_spectrumModel == 0)
94  {
95  // first pak, record SpectrumModel
96  m_spectrumModel = txParams->psd->GetSpectrumModel ();
97  }
98  else
99  {
100  // all attached SpectrumPhy instances must use the same SpectrumModel
101  NS_ASSERT (*(txParams->psd->GetSpectrumModel ()) == *m_spectrumModel);
102  }
103 
104 
105 
106 
107  Ptr<MobilityModel> senderMobility = txParams->txPhy->GetMobility ();
108 
109  for (PhyList::const_iterator rxPhyIterator = m_phyList.begin ();
110  rxPhyIterator != m_phyList.end ();
111  ++rxPhyIterator)
112  {
113  if ((*rxPhyIterator) != txParams->txPhy)
114  {
115  Time delay = MicroSeconds (0);
116 
117  Ptr<MobilityModel> receiverMobility = (*rxPhyIterator)->GetMobility ();
118  NS_LOG_LOGIC ("copying signal parameters " << txParams);
119  Ptr<SpectrumSignalParameters> rxParams = txParams->Copy ();
120 
121  if (senderMobility && receiverMobility)
122  {
123  double pathLossDb = 0;
124  if (rxParams->txAntenna != 0)
125  {
126  Angles txAngles (receiverMobility->GetPosition (), senderMobility->GetPosition ());
127  double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
128  NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB");
129  pathLossDb -= txAntennaGain;
130  }
131  Ptr<AntennaModel> rxAntenna = (*rxPhyIterator)->GetRxAntenna ();
132  if (rxAntenna != 0)
133  {
134  Angles rxAngles (senderMobility->GetPosition (), receiverMobility->GetPosition ());
135  double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
136  NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB");
137  pathLossDb -= rxAntennaGain;
138  }
139  if (m_propagationLoss)
140  {
141  double propagationGainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility);
142  NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB");
143  pathLossDb -= propagationGainDb;
144  }
145  NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB");
146  m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb);
147  if ( pathLossDb > m_maxLossDb)
148  {
149  // beyond range
150  continue;
151  }
152  double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
153  *(rxParams->psd) *= pathGainLinear;
154 
156  {
157  rxParams->psd = m_spectrumPropagationLoss->CalcRxPowerSpectralDensity (rxParams->psd, senderMobility, receiverMobility);
158  }
159 
160  if (m_propagationDelay)
161  {
162  delay = m_propagationDelay->GetDelay (senderMobility, receiverMobility);
163  }
164  }
165 
166 
167  Ptr<NetDevice> netDev = (*rxPhyIterator)->GetDevice ();
168  if (netDev)
169  {
170  // the receiver has a NetDevice, so we expect that it is attached to a Node
171  uint32_t dstNode = netDev->GetNode ()->GetId ();
172  Simulator::ScheduleWithContext (dstNode, delay, &SingleModelSpectrumChannel::StartRx, this, rxParams, *rxPhyIterator);
173  }
174  else
175  {
176  // the receiver is not attached to a NetDevice, so we cannot assume that it is attached to a node
178  rxParams, *rxPhyIterator);
179  }
180  }
181  }
182 }
183 
184 void
186 {
187  NS_LOG_FUNCTION (this << params);
188  receiver->StartRx (params);
189 }
190 
191 std::size_t
193 {
194  NS_LOG_FUNCTION (this);
195  return m_phyList.size ();
196 }
197 
200 {
201  NS_LOG_FUNCTION (this << i);
202  return m_phyList.at (i)->GetDevice ()->GetObject<NetDevice> ();
203 }
204 
205 
206 } // 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 "...
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...
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
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
TracedCallback< Ptr< const SpectrumPhy >, Ptr< const SpectrumPhy >, double > m_pathLossTrace
The PathLoss trace source.
virtual void AddRx(Ptr< SpectrumPhy > phy)
Add a SpectrumPhy to a channel, so it can receive packets.
#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
double m_maxLossDb
Maximum loss [dB].
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
phy
Definition: third.py:86
void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
Used internally to reschedule transmission after the propagation delay.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
virtual void DoDispose()
Destructor implementation.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
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.
virtual std::size_t GetNDevices(void) const
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Vector GetPosition(void) const
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1475
Ptr< PropagationLossModel > m_propagationLoss
Single-frequency propagation loss model to be used with this channel.
Network layer to device interface.
Definition: net-device.h:95
TracedCallback< Ptr< SpectrumSignalParameters > > m_txSigParamsTrace
Traced callback for SpectrumSignalParameters in StartTx requests.
SpectrumChannel implementation which handles a single spectrum model.
Defines the interface for spectrum-aware channel implementations.
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
struct holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:71
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:915
virtual void DoDispose(void)
Destructor implementation.
Ptr< const SpectrumModel > m_spectrumModel
SpectrumModel that this channel instance is supporting.
virtual Ptr< NetDevice > GetDevice(std::size_t i) const