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-helper.cc
Go to the documentation of this file.
1
/*
2
* uan-helper.cc
3
*
4
* Copyright (c) 2008 University of Washington
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Created on: 9-Oct-2008
20
* Author: Leonard Tracy <lentracy@u.washington.edu>
21
*
22
*
23
*/
24
25
#include "
uan-helper.h
"
26
#include "ns3/uan-net-device.h"
27
#include "ns3/uan-mac.h"
28
#include "ns3/uan-phy.h"
29
#include "ns3/uan-channel.h"
30
#include "ns3/uan-prop-model.h"
31
#include "ns3/uan-prop-model-ideal.h"
32
#include "ns3/uan-transducer.h"
33
#include "ns3/mobility-model.h"
34
#include "ns3/log.h"
35
#include "ns3/uan-tx-mode.h"
36
#include "ns3/config.h"
37
#include "ns3/simulator.h"
38
#include "ns3/uan-noise-model-default.h"
39
40
#include <sstream>
41
#include <string>
42
43
NS_LOG_COMPONENT_DEFINE
(
"UanHelper"
);
44
namespace
ns3 {
45
46
static
void
AsciiPhyTxEvent
(std::ostream *os, std::string context,
47
Ptr<const Packet>
packet,
double
txPowerDb,
UanTxMode
mode)
48
{
49
*os <<
"+ "
<<
Simulator::Now
().
GetSeconds
() <<
" "
<< context <<
" "
<< *packet << std::endl;
50
}
51
52
static
void
AsciiPhyRxOkEvent
(std::ostream *os, std::string context,
53
Ptr<const Packet>
packet,
double
snr,
UanTxMode
mode)
54
{
55
*os <<
"r "
<<
Simulator::Now
().
GetSeconds
() <<
" "
<< context <<
" "
<< *packet << std::endl;
56
}
57
58
UanHelper::UanHelper
()
59
{
60
m_mac
.
SetTypeId
(
"ns3::UanMacAloha"
);
61
m_phy
.
SetTypeId
(
"ns3::UanPhyGen"
);
62
m_transducer
.
SetTypeId
(
"ns3::UanTransducerHd"
);
63
64
}
65
66
UanHelper::~UanHelper
()
67
{
68
69
}
70
71
72
void
73
UanHelper::SetMac
(std::string macType,
74
std::string n0,
const
AttributeValue
&v0,
75
std::string n1,
const
AttributeValue
&v1,
76
std::string n2,
const
AttributeValue
&v2,
77
std::string n3,
const
AttributeValue
&v3,
78
std::string n4,
const
AttributeValue
&v4,
79
std::string n5,
const
AttributeValue
&v5,
80
std::string n6,
const
AttributeValue
&v6,
81
std::string n7,
const
AttributeValue
&v7)
82
{
83
m_mac
=
ObjectFactory
();
84
m_mac
.
SetTypeId
(macType);
85
m_mac
.
Set
(n0, v0);
86
m_mac
.
Set
(n1, v1);
87
m_mac
.
Set
(n2, v2);
88
m_mac
.
Set
(n3, v3);
89
m_mac
.
Set
(n4, v4);
90
m_mac
.
Set
(n5, v5);
91
m_mac
.
Set
(n6, v6);
92
m_mac
.
Set
(n7, v7);
93
}
94
95
void
96
UanHelper::SetPhy
(std::string phyType,
97
std::string n0,
const
AttributeValue
&v0,
98
std::string n1,
const
AttributeValue
&v1,
99
std::string n2,
const
AttributeValue
&v2,
100
std::string n3,
const
AttributeValue
&v3,
101
std::string n4,
const
AttributeValue
&v4,
102
std::string n5,
const
AttributeValue
&v5,
103
std::string n6,
const
AttributeValue
&v6,
104
std::string n7,
const
AttributeValue
&v7)
105
{
106
m_phy
=
ObjectFactory
();
107
m_phy
.
SetTypeId
(phyType);
108
m_phy
.
Set
(n0, v0);
109
m_phy
.
Set
(n1, v1);
110
m_phy
.
Set
(n2, v2);
111
m_phy
.
Set
(n3, v3);
112
m_phy
.
Set
(n4, v4);
113
m_phy
.
Set
(n5, v5);
114
m_phy
.
Set
(n6, v6);
115
m_phy
.
Set
(n7, v7);
116
117
}
118
119
void
120
UanHelper::SetTransducer
(std::string type,
121
std::string n0,
const
AttributeValue
&v0,
122
std::string n1,
const
AttributeValue
&v1,
123
std::string n2,
const
AttributeValue
&v2,
124
std::string n3,
const
AttributeValue
&v3,
125
std::string n4,
const
AttributeValue
&v4,
126
std::string n5,
const
AttributeValue
&v5,
127
std::string n6,
const
AttributeValue
&v6,
128
std::string n7,
const
AttributeValue
&v7)
129
{
130
m_transducer
=
ObjectFactory
();
131
m_transducer
.
SetTypeId
(type);
132
m_transducer
.
Set
(n0, v0);
133
m_transducer
.
Set
(n1, v1);
134
m_transducer
.
Set
(n2, v2);
135
m_transducer
.
Set
(n3, v3);
136
m_transducer
.
Set
(n4, v4);
137
m_transducer
.
Set
(n5, v5);
138
m_transducer
.
Set
(n6, v6);
139
m_transducer
.
Set
(n7, v7);
140
141
}
142
143
void
144
UanHelper::EnableAscii
(std::ostream &os, uint32_t nodeid, uint32_t deviceid)
145
{
146
Packet::EnablePrinting
();
147
std::ostringstream oss;
148
149
oss <<
"/NodeList/"
<< nodeid <<
"/DeviceList/"
<< deviceid <<
"/$ns3::UanNetDevice/Phy/RxOk"
;
150
Config::Connect
(oss.str (),
MakeBoundCallback
(&
AsciiPhyRxOkEvent
, &os));
151
152
oss.str (
""
);
153
154
oss <<
"/NodeList/"
<< nodeid <<
"/DeviceList/"
<< deviceid <<
"/$ns3::UanNetDevice/Phy/Tx"
;
155
Config::Connect
(oss.str (),
MakeBoundCallback
(&
AsciiPhyTxEvent
, &os));
156
}
157
158
void
159
UanHelper::EnableAscii
(std::ostream &os,
NetDeviceContainer
d)
160
{
161
for
(
NetDeviceContainer::Iterator
i = d.
Begin
(); i != d.
End
(); ++i)
162
{
163
Ptr<NetDevice>
dev = *i;
164
EnableAscii
(os, dev->
GetNode
()->
GetId
(), dev->
GetIfIndex
());
165
}
166
}
167
168
void
169
UanHelper::EnableAscii
(std::ostream &os,
NodeContainer
n)
170
{
171
NetDeviceContainer
devs;
172
for
(
NodeContainer::Iterator
i = n.
Begin
(); i != n.
End
(); ++i)
173
{
174
Ptr<Node>
node = *i;
175
for
(uint32_t j = 0; j < node->
GetNDevices
(); ++j)
176
{
177
devs.
Add
(node->
GetDevice
(j));
178
}
179
}
180
EnableAscii
(os, devs);
181
}
182
183
void
184
UanHelper::EnableAsciiAll
(std::ostream &os)
185
{
186
EnableAscii
(os,
NodeContainer::GetGlobal
());
187
}
188
189
NetDeviceContainer
190
UanHelper::Install
(
NodeContainer
c)
const
191
{
192
Ptr<UanChannel>
channel = CreateObject<UanChannel> ();
193
Ptr<UanNoiseModelDefault>
noise = CreateObject<UanNoiseModelDefault> ();
194
channel->
SetPropagationModel
(CreateObject<UanPropModelIdeal> ());
195
channel->
SetNoiseModel
(noise);
196
197
return
Install
(c, channel);
198
}
199
200
NetDeviceContainer
201
UanHelper::Install
(
NodeContainer
c,
Ptr<UanChannel>
channel)
const
202
{
203
NetDeviceContainer
devices;
204
for
(
NodeContainer::Iterator
i = c.
Begin
(); i != c.
End
(); i++)
205
{
206
Ptr<Node>
node = *i;
207
208
Ptr<UanNetDevice>
device =
Install
(node, channel);
209
210
devices.
Add
(device);
211
NS_LOG_DEBUG
(
"node="
<< node <<
", mob="
<< node->
GetObject
<
MobilityModel
> ());
212
}
213
return
devices;
214
}
215
216
Ptr<UanNetDevice>
217
UanHelper::Install
(
Ptr<Node>
node,
Ptr<UanChannel>
channel)
const
218
{
219
Ptr<UanNetDevice>
device = CreateObject<UanNetDevice> ();
220
221
Ptr<UanMac>
mac =
m_mac
.
Create
<
UanMac
> ();
222
Ptr<UanPhy>
phy =
m_phy
.
Create
<
UanPhy
> ();
223
Ptr<UanTransducer>
trans =
m_transducer
.
Create
<
UanTransducer
> ();
224
225
mac->SetAddress (
UanAddress::Allocate
());
226
device->
SetMac
(mac);
227
device->
SetPhy
(phy);
228
device->
SetTransducer
(trans);
229
device->
SetChannel
(channel);
230
231
node->
AddDevice
(device);
232
233
return
device;
234
}
235
236
int64_t
237
UanHelper::AssignStreams
(
NetDeviceContainer
c, int64_t stream)
238
{
239
int64_t currentStream = stream;
240
Ptr<NetDevice>
netDevice;
241
for
(
NetDeviceContainer::Iterator
i = c.
Begin
(); i != c.
End
(); ++i)
242
{
243
netDevice = (*i);
244
Ptr<UanNetDevice>
uan = DynamicCast<UanNetDevice> (netDevice);
245
if
(uan)
246
{
247
currentStream += uan->
GetPhy
()->
AssignStreams
(currentStream);
248
currentStream += uan->
GetMac
()->
AssignStreams
(currentStream);
249
}
250
}
251
return
(currentStream - stream);
252
}
253
254
}
// end namespace ns3
src
uan
helper
uan-helper.cc
Generated on Tue Oct 9 2012 16:45:47 for ns-3 by
1.8.1.2