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  .AddConstructor<UanChannel> ()
53  .AddAttribute ("PropagationModel",
54  "A pointer to the propagation model.",
55  StringValue ("ns3::UanPropModelIdeal"),
57  MakePointerChecker<UanPropModel> ())
58  .AddAttribute ("NoiseModel",
59  "A pointer to the model of the channel ambient noise.",
60  StringValue ("ns3::UanNoiseModelDefault"),
62  MakePointerChecker<UanNoiseModel> ())
63  ;
64 
65  return tid;
66 }
67 
69  : Channel (),
70  m_prop (0),
71  m_cleared (false)
72 {
73 }
74 
76 {
77 }
78 
79 void
81 {
82  if (m_cleared)
83  {
84  return;
85  }
86  m_cleared = true;
87  UanDeviceList::iterator it = m_devList.begin ();
88  for (; it != m_devList.end (); it++)
89  {
90  if (it->first)
91  {
92  it->first->Clear ();
93  it->first = 0;
94  }
95  if (it->second)
96  {
97  it->second->Clear ();
98  it->second = 0;
99  }
100  }
101  m_devList.clear ();
102  if (m_prop)
103  {
104  m_prop->Clear ();
105  m_prop = 0;
106  }
107  if (m_noise)
108  {
109  m_noise->Clear ();
110  m_noise = 0;
111  }
112 
113 }
114 
115 void
117 {
118  Clear ();
120 }
121 void
123 {
124  NS_LOG_DEBUG ("Set Prop Model " << this);
125  m_prop = prop;
126 }
127 
128 uint32_t
130 {
131  return m_devList.size ();
132 }
133 
135 UanChannel::GetDevice (uint32_t i) const
136 {
137  return m_devList[i].first;
138 }
139 
140 void
142 {
143  NS_LOG_DEBUG ("Adding dev/trans pair number " << m_devList.size ());
144  m_devList.push_back (std::make_pair (dev, trans));
145 }
146 
147 void
149  double txPowerDb, UanTxMode txMode)
150 {
151  Ptr<MobilityModel> senderMobility = 0;
152 
153  NS_LOG_DEBUG ("Channel scheduling");
154  for (UanDeviceList::const_iterator i = m_devList.begin (); i
155  != m_devList.end (); i++)
156  {
157 
158  if (src == i->second)
159  {
160  senderMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
161  break;
162  }
163  }
164  NS_ASSERT (senderMobility != 0);
165  uint32_t j = 0;
166  UanDeviceList::const_iterator i = m_devList.begin ();
167  for (; i != m_devList.end (); i++)
168  {
169  if (src != i->second)
170  {
171  NS_LOG_DEBUG ("Scheduling " << i->first->GetMac ()->GetAddress ());
172  Ptr<MobilityModel> rcvrMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
173  Time delay = m_prop->GetDelay (senderMobility, rcvrMobility, txMode);
174  UanPdp pdp = m_prop->GetPdp (senderMobility, rcvrMobility, txMode);
175  double rxPowerDb = txPowerDb - m_prop->GetPathLossDb (senderMobility,
176  rcvrMobility,
177  txMode);
178 
179  NS_LOG_DEBUG ("txPowerDb=" << txPowerDb << "dB, rxPowerDb="
180  << rxPowerDb << "dB, distance="
181  << senderMobility->GetDistanceFrom (rcvrMobility)
182  << "m, delay=" << delay);
183 
184  uint32_t dstNodeId = i->first->GetNode ()->GetId ();
185  Ptr<Packet> copy = packet->Copy ();
186  Simulator::ScheduleWithContext (dstNodeId, delay,
188  this,
189  j,
190  copy,
191  rxPowerDb,
192  txMode,
193  pdp);
194  }
195  j++;
196  }
197 }
198 
199 void
201 {
202  NS_ASSERT (noise);
203  m_noise = noise;
204 }
205 void
206 UanChannel::SendUp (uint32_t i, Ptr<Packet> packet, double rxPowerDb,
207  UanTxMode txMode, UanPdp pdp)
208 {
209  NS_LOG_DEBUG ("Channel: In sendup");
210  m_devList[i].second->Receive (packet, rxPowerDb, txMode, pdp);
211 }
212 
213 double
215 {
216  NS_ASSERT (m_noise);
217  double noise = m_noise->GetNoiseDbHz (fKhz);
218  return noise;
219 }
220 
221 } // 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:206
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:95
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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Hold variables of type string.
Definition: string.h:41
UanChannel()
Constructor.
Definition: uan-channel.cc:68
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#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:214
Ptr< UanNoiseModel > m_noise
The noise model.
Definition: uan-channel.h:117
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
void SetNoiseModel(Ptr< UanNoiseModel > noise)
Set the noise model this channel will use to determine ambient channel noise.
Definition: uan-channel.cc:200
void TxPacket(Ptr< UanTransducer > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txmode)
Send a packet out on the channel.
Definition: uan-channel.cc:148
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:210
void AddDevice(Ptr< UanNetDevice > dev, Ptr< UanTransducer > trans)
Adds device to receiver list for this channel.
Definition: uan-channel.cc:141
virtual void DoDispose(void)
Destructor implementation.
Definition: uan-channel.cc:116
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:80
virtual uint32_t GetNDevices(void) const
Definition: uan-channel.cc:129
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:899
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
Definition: uan-channel.cc:135
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~UanChannel()
Dummy destructor, see DoDispose.
Definition: uan-channel.cc:75
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
void SetPropagationModel(Ptr< UanPropModel > prop)
Set the propagation model this channel will use for path loss/propagation delay.
Definition: uan-channel.cc:122
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
Ptr< UanPropModel > m_prop
The propagation model.
Definition: uan-channel.h:116