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
lena-pathloss-traces.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Manuel Requena <manuel.requena@cttc.es>
19
* Nicola Baldo <nbaldo@cttc.es>
20
*/
21
22
23
#include "ns3/core-module.h"
24
#include "ns3/network-module.h"
25
#include "ns3/mobility-module.h"
26
#include "ns3/lte-module.h"
27
#include "ns3/config-store.h"
28
#include "ns3/radio-bearer-stats-calculator.h"
29
30
#include <iomanip>
31
#include <string>
32
33
#include <ns3/log.h>
34
35
using namespace
ns3;
36
37
38
NS_LOG_COMPONENT_DEFINE
(
"InterCellInterference"
);
39
40
47
class
GlobalPathlossDatabase
48
{
49
public
:
50
59
virtual
void
UpdatePathloss (std::string context,
Ptr<SpectrumPhy>
txPhy,
Ptr<SpectrumPhy>
rxPhy,
double
lossDb) = 0;
60
65
void
Print ();
66
67
protected
:
68
69
// CELL ID IMSI PATHLOSS
70
std::map<uint16_t, std::map<uint64_t, double> >
m_pathlossMap
;
71
};
72
73
void
74
GlobalPathlossDatabase::Print
()
75
{
76
NS_LOG_FUNCTION
(
this
);
77
for
(std::map<uint16_t, std::map<uint64_t, double> >::const_iterator cellIdIt = m_pathlossMap.begin ();
78
cellIdIt != m_pathlossMap.end ();
79
++cellIdIt)
80
{
81
for
(std::map<uint64_t, double>::const_iterator imsiIt = cellIdIt->second.begin ();
82
imsiIt != cellIdIt->second.end ();
83
++imsiIt)
84
{
85
std::cout <<
"CellId: "
<< cellIdIt->first <<
" IMSI: "
<< imsiIt->first <<
" pathloss: "
<< imsiIt->second <<
" dB"
<< std::endl;
86
}
87
}
88
}
89
90
class
DownlinkGlobalPathlossDatabase
:
public
GlobalPathlossDatabase
91
{
92
public
:
93
// inherited from GlobalPathlossDatabase
94
virtual
void
UpdatePathloss (std::string context,
Ptr<SpectrumPhy>
txPhy,
Ptr<SpectrumPhy>
rxPhy,
double
lossDb);
95
};
96
97
void
98
DownlinkGlobalPathlossDatabase::UpdatePathloss
(std::string context,
99
Ptr<SpectrumPhy>
txPhy,
100
Ptr<SpectrumPhy>
rxPhy,
101
double
lossDb)
102
{
103
NS_LOG_FUNCTION
(
this
<< lossDb);
104
uint16_t cellId = txPhy->
GetDevice
()->
GetObject
<
LteEnbNetDevice
> ()->GetCellId ();
105
uint16_t imsi = rxPhy->
GetDevice
()->
GetObject
<
LteUeNetDevice
> ()->GetImsi ();
106
m_pathlossMap[cellId][imsi] = lossDb;
107
}
108
109
110
class
UplinkGlobalPathlossDatabase
:
public
GlobalPathlossDatabase
111
{
112
public
:
113
// inherited from GlobalPathlossDatabase
114
virtual
void
UpdatePathloss (std::string context,
Ptr<SpectrumPhy>
txPhy,
Ptr<SpectrumPhy>
rxPhy,
double
lossDb);
115
};
116
117
void
118
UplinkGlobalPathlossDatabase::UpdatePathloss
(std::string context,
119
Ptr<SpectrumPhy>
txPhy,
120
Ptr<SpectrumPhy>
rxPhy,
121
double
lossDb)
122
{
123
NS_LOG_FUNCTION
(
this
<< lossDb);
124
uint16_t imsi = txPhy->
GetDevice
()->
GetObject
<
LteUeNetDevice
> ()->GetImsi ();
125
uint16_t cellId = rxPhy->
GetDevice
()->
GetObject
<
LteEnbNetDevice
> ()->GetCellId ();
126
m_pathlossMap[cellId][imsi] = lossDb;
127
}
128
129
130
int
main
(
int
argc,
char
*argv[])
131
{
132
double
enbDist = 20.0;
133
double
radius = 10.0;
134
uint32_t numUes = 1;
135
136
137
CommandLine
cmd;
138
cmd.
AddValue
(
"enbDist"
,
"distance between the two eNBs"
, enbDist);
139
cmd.
AddValue
(
"radius"
,
"the radius of the disc where UEs are placed around an eNB"
, radius);
140
cmd.
AddValue
(
"numUes"
,
"how many UEs are attached to each eNB"
, numUes);
141
cmd.
Parse
(argc, argv);
142
143
ConfigStore
inputConfig;
144
inputConfig.
ConfigureDefaults
();
145
146
// parse again so you can override default values from the command line
147
cmd.
Parse
(argc, argv);
148
149
// determine the string tag that identifies this simulation run
150
// this tag is then appended to all filenames
151
152
IntegerValue
runValue;
153
GlobalValue::GetValueByName
(
"RngRun"
, runValue);
154
155
std::ostringstream tag;
156
tag <<
"_enbDist"
<< std::setw (3) << std::setfill (
'0'
) << std::fixed << std::setprecision (0) << enbDist
157
<<
"_radius"
<< std::setw (3) << std::setfill (
'0'
) << std::fixed << std::setprecision (0) << radius
158
<<
"_numUes"
<< std::setw (3) << std::setfill (
'0'
) << numUes
159
<<
"_rngRun"
<< std::setw (3) << std::setfill (
'0'
) << runValue.
Get
() ;
160
161
Ptr<LteHelper>
lteHelper = CreateObject<LteHelper> ();
162
163
164
// NOTE: the PropagationLoss trace source of the SpectrumChannel
165
// works only for single-frequency path loss model.
166
// e.g., it will work with the following models:
167
// ns3::FriisPropagationLossModel,
168
// ns3::TwoRayGroundPropagationLossModel,
169
// ns3::LogDistancePropagationLossModel,
170
// ns3::ThreeLogDistancePropagationLossModel,
171
// ns3::NakagamiPropagationLossModel
172
// ns3::BuildingsPropagationLossModel
173
// etc.
174
// but it WON'T work if you ONLY use SpectrumPropagationLossModels such as:
175
// ns3::FriisSpectrumPropagationLossModel
176
// ns3::ConstantSpectrumPropagationLossModel
177
lteHelper->
SetAttribute
(
"PathlossModel"
,
StringValue
(
"ns3::Cost231PropagationLossModel"
));
178
179
180
// Create Nodes: eNodeB and UE
181
NodeContainer
enbNodes;
182
NodeContainer
ueNodes1, ueNodes2;
183
enbNodes.
Create
(2);
184
ueNodes1.
Create
(numUes);
185
ueNodes2.
Create
(numUes);
186
187
// Position of eNBs
188
Ptr<ListPositionAllocator>
positionAlloc = CreateObject<ListPositionAllocator> ();
189
positionAlloc->
Add
(
Vector
(0.0, 0.0, 0.0));
190
positionAlloc->
Add
(
Vector
(enbDist, 0.0, 0.0));
191
MobilityHelper
enbMobility;
192
enbMobility.
SetMobilityModel
(
"ns3::ConstantPositionMobilityModel"
);
193
enbMobility.
SetPositionAllocator
(positionAlloc);
194
enbMobility.
Install
(enbNodes);
195
196
// Position of UEs attached to eNB 1
197
MobilityHelper
ue1mobility;
198
ue1mobility.
SetPositionAllocator
(
"ns3::UniformDiscPositionAllocator"
,
199
"X"
,
DoubleValue
(0.0),
200
"Y"
,
DoubleValue
(0.0),
201
"rho"
,
DoubleValue
(radius));
202
ue1mobility.
SetMobilityModel
(
"ns3::ConstantPositionMobilityModel"
);
203
ue1mobility.
Install
(ueNodes1);
204
205
// Position of UEs attached to eNB 2
206
MobilityHelper
ue2mobility;
207
ue2mobility.
SetPositionAllocator
(
"ns3::UniformDiscPositionAllocator"
,
208
"X"
,
DoubleValue
(enbDist),
209
"Y"
,
DoubleValue
(0.0),
210
"rho"
,
DoubleValue
(radius));
211
ue2mobility.
SetMobilityModel
(
"ns3::ConstantPositionMobilityModel"
);
212
ue2mobility.
Install
(ueNodes2);
213
214
// Create Devices and install them in the Nodes (eNB and UE)
215
NetDeviceContainer
enbDevs;
216
NetDeviceContainer
ueDevs1;
217
NetDeviceContainer
ueDevs2;
218
enbDevs = lteHelper->
InstallEnbDevice
(enbNodes);
219
ueDevs1 = lteHelper->
InstallUeDevice
(ueNodes1);
220
ueDevs2 = lteHelper->
InstallUeDevice
(ueNodes2);
221
222
// Attach UEs to a eNB
223
lteHelper->
Attach
(ueDevs1, enbDevs.
Get
(0));
224
lteHelper->
Attach
(ueDevs2, enbDevs.
Get
(1));
225
226
// Activate an EPS bearer on all UEs
227
enum
EpsBearer::Qci
q =
EpsBearer::GBR_CONV_VOICE
;
228
EpsBearer
bearer (q);
229
lteHelper->
ActivateEpsBearer
(ueDevs1, bearer,
EpcTft::Default
());
230
lteHelper->
ActivateEpsBearer
(ueDevs2, bearer,
EpcTft::Default
());
231
232
Simulator::Stop
(
Seconds
(0.5));
233
234
// Insert RLC Performance Calculator
235
std::string dlOutFname =
"DlRlcStats"
;
236
dlOutFname.append (tag.str ());
237
std::string ulOutFname =
"UlRlcStats"
;
238
ulOutFname.append (tag.str ());
239
240
lteHelper->
EnableMacTraces
();
241
lteHelper->
EnableRlcTraces
();
242
243
244
245
// keep track of all path loss values in a global object
246
DownlinkGlobalPathlossDatabase
dlPathlossDb;
247
UplinkGlobalPathlossDatabase
ulPathlossDb;
248
// we rely on the fact that LteHelper creates the DL channel object first, then the UL channel object,
249
// hence the former will have index 0 and the latter 1
250
Config::Connect
(
"/ChannelList/0/PathLoss"
,
251
MakeCallback
(&
DownlinkGlobalPathlossDatabase::UpdatePathloss
, &dlPathlossDb));
252
Config::Connect
(
"/ChannelList/1/PathLoss"
,
253
MakeCallback
(&
UplinkGlobalPathlossDatabase::UpdatePathloss
, &ulPathlossDb));
254
255
Simulator::Run
();
256
257
258
// print the pathloss values at the end of the simulation
259
std::cout << std::endl <<
"Downlink pathloss:"
<< std::endl;
260
dlPathlossDb.
Print
();
261
std::cout << std::endl <<
"Uplink pathloss:"
<< std::endl;
262
ulPathlossDb.
Print
();
263
264
265
Simulator::Destroy
();
266
return
0;
267
}
src
lte
examples
lena-pathloss-traces.cc
Generated on Fri Dec 21 2012 19:00:38 for ns-3 by
1.8.1.2