A Discrete-Event Network Simulator
API
uan-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 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19  */
20 
21 #include "ns3/object.h"
22 #include "ns3/packet.h"
23 #include "ns3/simulator.h"
24 #include "ns3/mobility-model.h"
25 #include "ns3/net-device.h"
26 #include "ns3/node.h"
27 #include "ns3/log.h"
28 #include "ns3/pointer.h"
29 #include "ns3/string.h"
30 #include "uan-channel.h"
31 #include "uan-phy.h"
32 #include "uan-prop-model.h"
33 #include "uan-tx-mode.h"
34 #include "uan-net-device.h"
35 #include "uan-transducer.h"
37 #include "uan-prop-model-ideal.h"
38 
39 namespace ns3 {
40 
41 NS_LOG_COMPONENT_DEFINE ("UanChannel");
42 
43 NS_OBJECT_ENSURE_REGISTERED (UanChannel);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::UanChannel")
49  .SetParent<Channel> ()
50  .SetGroupName ("Uan")
51  .AddConstructor<UanChannel> ()
52  .AddAttribute ("PropagationModel",
53  "A pointer to the propagation model.",
54  StringValue ("ns3::UanPropModelIdeal"),
56  MakePointerChecker<UanPropModel> ())
57  .AddAttribute ("NoiseModel",
58  "A pointer to the model of the channel ambient noise.",
59  StringValue ("ns3::UanNoiseModelDefault"),
61  MakePointerChecker<UanNoiseModel> ())
62  ;
63 
64  return tid;
65 }
66 
68  : Channel (),
69  m_prop (0),
70  m_cleared (false)
71 {
72 }
73 
75 {
76 }
77 
78 void
80 {
81  if (m_cleared)
82  {
83  return;
84  }
85  m_cleared = true;
86  UanDeviceList::iterator it = m_devList.begin ();
87  for (; it != m_devList.end (); it++)
88  {
89  if (it->first)
90  {
91  it->first->Clear ();
92  it->first = 0;
93  }
94  if (it->second)
95  {
96  it->second->Clear ();
97  it->second = 0;
98  }
99  }
100  m_devList.clear ();
101  if (m_prop)
102  {
103  m_prop->Clear ();
104  m_prop = 0;
105  }
106  if (m_noise)
107  {
108  m_noise->Clear ();
109  m_noise = 0;
110  }
111 
112 }
113 
114 void
116 {
117  Clear ();
119 }
120 void
122 {
123  NS_LOG_DEBUG ("Set Prop Model " << this);
124  m_prop = prop;
125 }
126 
127 std::size_t
129 {
130  return m_devList.size ();
131 }
132 
134 UanChannel::GetDevice (std::size_t i) const
135 {
136  return m_devList[i].first;
137 }
138 
139 void
141 {
142  NS_LOG_DEBUG ("Adding dev/trans pair number " << m_devList.size ());
143  m_devList.push_back (std::make_pair (dev, trans));
144 }
145 
146 void
148  double txPowerDb, UanTxMode txMode)
149 {
150  Ptr<MobilityModel> senderMobility = 0;
151 
152  NS_LOG_DEBUG ("Channel scheduling");
153  for (UanDeviceList::const_iterator i = m_devList.begin (); i
154  != m_devList.end (); i++)
155  {
156 
157  if (src == i->second)
158  {
159  senderMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
160  break;
161  }
162  }
163  NS_ASSERT (senderMobility != 0);
164  uint32_t j = 0;
165  UanDeviceList::const_iterator i = m_devList.begin ();
166  for (; i != m_devList.end (); i++)
167  {
168  if (src != i->second)
169  {
170  NS_LOG_DEBUG ("Scheduling " << i->first->GetMac ()->GetAddress ());
171  Ptr<MobilityModel> rcvrMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
172  Time delay = m_prop->GetDelay (senderMobility, rcvrMobility, txMode);
173  UanPdp pdp = m_prop->GetPdp (senderMobility, rcvrMobility, txMode);
174  double rxPowerDb = txPowerDb - m_prop->GetPathLossDb (senderMobility,
175  rcvrMobility,
176  txMode);
177 
178  NS_LOG_DEBUG ("txPowerDb=" << txPowerDb << "dB, rxPowerDb="
179  << rxPowerDb << "dB, distance="
180  << senderMobility->GetDistanceFrom (rcvrMobility)
181  << "m, delay=" << delay);
182 
183  uint32_t dstNodeId = i->first->GetNode ()->GetId ();
184  Ptr<Packet> copy = packet->Copy ();
185  Simulator::ScheduleWithContext (dstNodeId, delay,
187  this,
188  j,
189  copy,
190  rxPowerDb,
191  txMode,
192  pdp);
193  }
194  j++;
195  }
196 }
197 
198 void
200 {
201  NS_ASSERT (noise);
202  m_noise = noise;
203 }
204 void
205 UanChannel::SendUp (uint32_t i, Ptr<Packet> packet, double rxPowerDb,
206  UanTxMode txMode, UanPdp pdp)
207 {
208  NS_LOG_DEBUG ("Channel: In sendup");
209  m_devList[i].second->Receive (packet, rxPowerDb, txMode, pdp);
210 }
211 
212 double
214 {
215  NS_ASSERT (m_noise);
216  double noise = m_noise->GetNoiseDbHz (fKhz);
217  return noise;
218 }
219 
220 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
uan-channel.h
ns3::Simulator::ScheduleWithContext
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
ns3::UanPdp
The power delay profile returned by propagation models.
Definition: uan-prop-model.h:92
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uan-prop-model.h
ns3::UanChannel::SetNoiseModel
void SetNoiseModel(Ptr< UanNoiseModel > noise)
Set the noise model this channel will use to determine ambient channel noise.
Definition: uan-channel.cc:199
uan-noise-model-default.h
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::MobilityModel::GetDistanceFrom
double GetDistanceFrom(Ptr< const MobilityModel > position) const
Definition: mobility-model.cc:94
uan-prop-model-ideal.h
ns3::UanChannel::AddDevice
void AddDevice(Ptr< UanNetDevice > dev, Ptr< UanTransducer > trans)
Adds device to receiver list for this channel.
Definition: uan-channel.cc:140
ns3::UanChannel::SendUp
void SendUp(uint32_t i, Ptr< Packet > packet, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Send a packet up to the receiving UanTransducer.
Definition: uan-channel.cc:205
ns3::UanChannel::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: uan-channel.cc:115
ns3::UanChannel::GetNDevices
virtual std::size_t GetNDevices(void) const
Definition: uan-channel.cc:128
ns3::UanChannel::GetNoiseDbHz
double GetNoiseDbHz(double fKhz)
Get the noise level on the channel.
Definition: uan-channel.cc:213
ns3::UanChannel::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: uan-channel.cc:46
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::UanChannel::m_prop
Ptr< UanPropModel > m_prop
The propagation model.
Definition: uan-channel.h:116
ns3::UanChannel::~UanChannel
virtual ~UanChannel()
Dummy destructor, see DoDispose.
Definition: uan-channel.cc:74
uan-transducer.h
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::UanChannel::Clear
void Clear(void)
Clear all pointer references.
Definition: uan-channel.cc:79
uan-phy.h
uan-tx-mode.h
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::UanChannel::TxPacket
virtual void TxPacket(Ptr< UanTransducer > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txmode)
Send a packet out on the channel.
Definition: uan-channel.cc:147
ns3::UanTxMode
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
ns3::UanChannel
Channel class used by UAN devices.
Definition: uan-channel.h:46
ns3::MakePointerAccessor
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:227
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
uan-net-device.h
ns3::UanChannel::GetDevice
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
Definition: uan-channel.cc:134
ns3::UanChannel::m_cleared
bool m_cleared
Has Clear ever been called on the channel.
Definition: uan-channel.h:119
ns3::UanChannel::m_devList
UanDeviceList m_devList
The list of devices on this channel.
Definition: uan-channel.h:115
ns3::UanChannel::m_noise
Ptr< UanNoiseModel > m_noise
The noise model.
Definition: uan-channel.h:117
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
ns3::Channel
Abstract Channel Base Class.
Definition: channel.h:44
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition: mobility-model.h:40
ns3::UanChannel::UanChannel
UanChannel()
Constructor.
Definition: uan-channel.cc:67
ns3::UanChannel::SetPropagationModel
void SetPropagationModel(Ptr< UanPropModel > prop)
Set the propagation model this channel will use for path loss/propagation delay.
Definition: uan-channel.cc:121
ns3::Object::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346