A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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/log.h"
30
31
#include "
uan-channel.h
"
32
#include "
uan-phy.h
"
33
#include "
uan-prop-model.h
"
34
#include "
uan-tx-mode.h
"
35
#include "
uan-net-device.h
"
36
#include "
uan-transducer.h
"
37
#include "
uan-noise-model-default.h
"
38
#include "
uan-prop-model-ideal.h
"
39
40
NS_LOG_COMPONENT_DEFINE
(
"UanChannel"
);
41
namespace
ns3 {
42
43
NS_OBJECT_ENSURE_REGISTERED
(UanChannel);
44
45
TypeId
46
UanChannel::GetTypeId
()
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::UanChannel"
)
49
.
SetParent
<
Channel
> ()
50
.AddConstructor<UanChannel> ()
51
.AddAttribute (
"PropagationModel"
,
52
"A pointer to the propagation model."
,
53
PointerValue
(CreateObject<UanPropModelIdeal> ()),
54
MakePointerAccessor (&
UanChannel::m_prop
),
55
MakePointerChecker<UanPropModel> ())
56
.AddAttribute (
"NoiseModel"
,
57
"A pointer to the model of the channel ambient noise."
,
58
PointerValue
(CreateObject<UanNoiseModelDefault> ()),
59
MakePointerAccessor (&
UanChannel::m_noise
),
60
MakePointerChecker<UanNoiseModel> ())
61
;
62
63
return
tid;
64
}
65
66
UanChannel::UanChannel
()
67
:
Channel
(),
68
m_prop (0),
69
m_cleared (false)
70
{
71
}
72
73
UanChannel::~UanChannel
()
74
{
75
}
76
77
void
78
UanChannel::Clear
()
79
{
80
if
(
m_cleared
)
81
{
82
return
;
83
}
84
m_cleared
=
true
;
85
UanDeviceList::iterator it =
m_devList
.begin ();
86
for
(; it !=
m_devList
.end (); it++)
87
{
88
if
(it->first)
89
{
90
it->first->Clear ();
91
it->first = 0;
92
}
93
if
(it->second)
94
{
95
it->second->Clear ();
96
it->second = 0;
97
}
98
}
99
m_devList
.clear ();
100
if
(
m_prop
)
101
{
102
m_prop
->
Clear
();
103
m_prop
= 0;
104
}
105
if
(
m_noise
)
106
{
107
m_noise
->
Clear
();
108
m_noise
= 0;
109
}
110
111
}
112
113
void
114
UanChannel::DoDispose
()
115
{
116
Clear
();
117
Channel::DoDispose
();
118
}
119
void
120
UanChannel::SetPropagationModel
(
Ptr<UanPropModel>
prop)
121
{
122
NS_LOG_DEBUG
(
"Set Prop Model "
<<
this
);
123
m_prop
= prop;
124
}
125
126
uint32_t
127
UanChannel::GetNDevices
()
const
128
{
129
return
m_devList
.size ();
130
}
131
132
Ptr<NetDevice>
133
UanChannel::GetDevice
(uint32_t i)
const
134
{
135
return
m_devList
[i].first;
136
}
137
138
void
139
UanChannel::AddDevice
(
Ptr<UanNetDevice>
dev,
Ptr<UanTransducer>
trans)
140
{
141
NS_LOG_DEBUG
(
"Adding dev/trans pair number "
<<
m_devList
.size ());
142
m_devList
.push_back (std::make_pair (dev, trans));
143
}
144
145
void
146
UanChannel::TxPacket
(
Ptr<UanTransducer>
src,
Ptr<Packet>
packet,
147
double
txPowerDb,
UanTxMode
txMode)
148
{
149
Ptr<MobilityModel>
senderMobility = 0;
150
151
NS_LOG_DEBUG
(
"Channel scheduling"
);
152
for
(UanDeviceList::const_iterator i =
m_devList
.begin (); i
153
!=
m_devList
.end (); i++)
154
{
155
156
if
(src == i->second)
157
{
158
senderMobility = i->first->GetNode ()->
GetObject
<
MobilityModel
> ();
159
break
;
160
}
161
}
162
NS_ASSERT
(senderMobility != 0);
163
uint32_t j = 0;
164
UanDeviceList::const_iterator i =
m_devList
.begin ();
165
for
(; i !=
m_devList
.end (); i++)
166
{
167
if
(src != i->second)
168
{
169
NS_LOG_DEBUG
(
"Scheduling "
<< i->first->GetMac ()->GetAddress ());
170
Ptr<MobilityModel>
rcvrMobility = i->first->GetNode ()->
GetObject
<
MobilityModel
> ();
171
Time
delay =
m_prop
->
GetDelay
(senderMobility, rcvrMobility, txMode);
172
UanPdp
pdp =
m_prop
->
GetPdp
(senderMobility, rcvrMobility, txMode);
173
double
rxPowerDb = txPowerDb -
m_prop
->
GetPathLossDb
(senderMobility,
174
rcvrMobility,
175
txMode);
176
177
NS_LOG_DEBUG
(
"txPowerDb="
<< txPowerDb <<
"dB, rxPowerDb="
178
<< rxPowerDb <<
"dB, distance="
179
<< senderMobility->
GetDistanceFrom
(rcvrMobility)
180
<<
"m, delay="
<< delay);
181
182
uint32_t dstNodeId = i->first->GetNode ()->GetId ();
183
Ptr<Packet>
copy = packet->
Copy
();
184
Simulator::ScheduleWithContext
(dstNodeId, delay,
185
&
UanChannel::SendUp
,
186
this
,
187
j,
188
copy,
189
rxPowerDb,
190
txMode,
191
pdp);
192
}
193
j++;
194
}
195
}
196
197
void
198
UanChannel::SetNoiseModel
(
Ptr<UanNoiseModel>
noise)
199
{
200
NS_ASSERT
(noise);
201
m_noise
= noise;
202
}
203
void
204
UanChannel::SendUp
(uint32_t i,
Ptr<Packet>
packet,
double
rxPowerDb,
205
UanTxMode
txMode,
UanPdp
pdp)
206
{
207
NS_LOG_DEBUG
(
"Channel: In sendup"
);
208
m_devList
[i].second->Receive (packet, rxPowerDb, txMode, pdp);
209
}
210
211
double
212
UanChannel::GetNoiseDbHz
(
double
fKhz)
213
{
214
NS_ASSERT
(
m_noise
);
215
double
noise =
m_noise
->
GetNoiseDbHz
(fKhz);
216
return
noise;
217
}
218
219
}
// namespace ns3
src
uan
model
uan-channel.cc
Generated on Tue Oct 9 2012 16:45:47 for ns-3 by
1.8.1.2