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