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
simple-ofdm-wimax-channel.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007,2008, 2009 INRIA, UDcast
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: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19
* <amine.ismail@udcast.com>
20
*/
21
22
#include "ns3/simulator.h"
23
#include "ns3/callback.h"
24
#include "ns3/nstime.h"
25
#include "ns3/event-id.h"
26
#include "ns3/assert.h"
27
#include "ns3/net-device.h"
28
#include "ns3/node.h"
29
#include "
wimax-phy.h
"
30
#include "
simple-ofdm-wimax-phy.h
"
31
#include "
simple-ofdm-wimax-channel.h
"
32
#include "ns3/mobility-model.h"
33
#include "ns3/cost231-propagation-loss-model.h"
34
#include "
simple-ofdm-send-param.h
"
35
36
NS_LOG_COMPONENT_DEFINE
(
"simpleOfdmWimaxChannel"
);
37
38
namespace
ns3 {
39
// NS_OBJECT_ENSURE_REGISTERED (simpleOfdmWimaxChannel);
40
41
42
SimpleOfdmWimaxChannel::SimpleOfdmWimaxChannel
(
void
)
43
{
44
m_loss
= 0;
45
}
46
47
SimpleOfdmWimaxChannel::~SimpleOfdmWimaxChannel
(
void
)
48
{
49
m_phyList
.clear ();
50
}
51
52
SimpleOfdmWimaxChannel::SimpleOfdmWimaxChannel
(
PropModel
propModel)
53
{
54
switch
(propModel)
55
{
56
case
RANDOM_PROPAGATION
:
57
m_loss
= CreateObject<RandomPropagationLossModel> ();
58
break
;
59
60
case
FRIIS_PROPAGATION
:
61
m_loss
= CreateObject<FriisPropagationLossModel> ();
62
break
;
63
case
LOG_DISTANCE_PROPAGATION
:
64
m_loss
= CreateObject<LogDistancePropagationLossModel> ();
65
break
;
66
67
case
COST231_PROPAGATION
:
68
m_loss
= CreateObject<Cost231PropagationLossModel> ();
69
break
;
70
71
default
:
72
m_loss
= 0;
73
}
74
75
}
76
77
void
78
SimpleOfdmWimaxChannel::SetPropagationModel
(
PropModel
propModel)
79
{
80
81
switch
(propModel)
82
{
83
case
RANDOM_PROPAGATION
:
84
m_loss
= CreateObject<RandomPropagationLossModel> ();
85
break
;
86
87
case
FRIIS_PROPAGATION
:
88
m_loss
= CreateObject<FriisPropagationLossModel> ();
89
break
;
90
case
LOG_DISTANCE_PROPAGATION
:
91
m_loss
= CreateObject<LogDistancePropagationLossModel> ();
92
break
;
93
94
case
COST231_PROPAGATION
:
95
m_loss
= CreateObject<Cost231PropagationLossModel> ();
96
break
;
97
98
default
:
99
m_loss
= 0;
100
}
101
102
}
103
104
void
105
SimpleOfdmWimaxChannel::DoAttach
(
Ptr<WimaxPhy>
phy)
106
{
107
Ptr<SimpleOfdmWimaxPhy>
o_phy = phy->
GetObject
<
SimpleOfdmWimaxPhy
> ();
108
m_phyList
.push_back (o_phy);
109
}
110
111
uint32_t
112
SimpleOfdmWimaxChannel::DoGetNDevices
(
void
)
const
113
{
114
return
m_phyList
.size ();
115
}
116
117
Ptr<NetDevice>
118
SimpleOfdmWimaxChannel::DoGetDevice
(uint32_t index)
const
119
{
120
uint32_t j = 0;
121
for
(
std::list
<
Ptr<SimpleOfdmWimaxPhy>
>::const_iterator iter =
m_phyList
.begin (); iter !=
m_phyList
.end (); ++iter)
122
{
123
if
(j == index)
124
{
125
return
(*iter)->GetDevice ();
126
}
127
j++;
128
}
129
130
NS_FATAL_ERROR
(
"Unable to get device"
);
131
return
0;
132
}
133
134
void
135
SimpleOfdmWimaxChannel::Send
(
Time
BlockTime,
136
uint32_t burstSize,
137
Ptr<WimaxPhy>
phy,
138
bool
isFirstBlock,
139
bool
isLastBlock,
140
uint64_t frequency,
141
WimaxPhy::ModulationType
modulationType,
142
uint8_t direction,
143
double
txPowerDbm,
144
Ptr<PacketBurst>
burst)
145
{
146
double
rxPowerDbm = 0;
147
Ptr<MobilityModel>
senderMobility = 0;
148
Ptr<MobilityModel>
receiverMobility = 0;
149
senderMobility = phy->
GetDevice
()->
GetNode
()->
GetObject
<
MobilityModel
> ();
150
simpleOfdmSendParam
* param;
151
for
(
std::list
<
Ptr<SimpleOfdmWimaxPhy>
>::iterator iter =
m_phyList
.begin (); iter !=
m_phyList
.end (); ++iter)
152
{
153
Time
delay =
Seconds
(0);
154
if
(phy != *iter)
155
{
156
double
distance = 0;
157
receiverMobility = (*iter)->GetDevice ()->GetNode ()->
GetObject
<
MobilityModel
> ();
158
if
(receiverMobility != 0 && senderMobility != 0 &&
m_loss
!= 0)
159
{
160
distance = senderMobility->
GetDistanceFrom
(receiverMobility);
161
delay =
Seconds
(distance/300000000.0);
162
rxPowerDbm =
m_loss
->
CalcRxPower
(txPowerDbm, senderMobility, receiverMobility);
163
}
164
165
param =
new
simpleOfdmSendParam
(burstSize,
166
isFirstBlock,
167
frequency,
168
modulationType,
169
direction,
170
rxPowerDbm,
171
burst);
172
Ptr<Object>
dstNetDevice = (*iter)->GetDevice ();
173
uint32_t dstNode;
174
if
(dstNetDevice == 0)
175
{
176
dstNode = 0xffffffff;
177
}
178
else
179
{
180
dstNode = dstNetDevice->
GetObject
<
NetDevice
> ()->GetNode ()->GetId ();
181
}
182
Simulator::ScheduleWithContext
(dstNode,
183
delay,
184
&
SimpleOfdmWimaxChannel::EndSendDummyBlock
,
185
this
,
186
*iter,
187
param);
188
}
189
}
190
191
}
192
193
void
194
SimpleOfdmWimaxChannel::EndSendDummyBlock
(
Ptr<SimpleOfdmWimaxPhy>
rxphy,
simpleOfdmSendParam
* param)
195
{
196
rxphy->
StartReceive
(param->
GetBurstSize
(),
197
param->
GetIsFirstBlock
(),
198
param->
GetFrequency
(),
199
param->
GetModulationType
(),
200
param->
GetDirection
(),
201
param->
GetRxPowerDbm
(),
202
param->
GetBurst
());
203
delete
param;
204
}
205
206
int64_t
207
SimpleOfdmWimaxChannel::AssignStreams
(int64_t stream)
208
{
209
int64_t currentStream = stream;
210
typedef
std::list<Ptr<SimpleOfdmWimaxPhy> > PhyList;
211
for
(PhyList::const_iterator i =
m_phyList
.begin (); i !=
m_phyList
.end (); i++)
212
{
213
Ptr<SimpleOfdmWimaxPhy>
simpleOfdm = (*i);
214
currentStream += simpleOfdm->
AssignStreams
(currentStream);
215
}
216
return
(currentStream - stream);
217
}
218
219
}
220
// namespace ns3
src
wimax
model
simple-ofdm-wimax-channel.cc
Generated on Tue May 14 2013 11:08:37 for ns-3 by
1.8.1.2