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
phy-stats-calculator.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: Jaume Nin <jnin@cttc.es>
19
*/
20
21
#include "
phy-stats-calculator.h
"
22
#include "ns3/string.h"
23
#include <ns3/simulator.h>
24
#include <ns3/log.h>
25
26
namespace
ns3 {
27
28
NS_LOG_COMPONENT_DEFINE
(
"PhyStatsCalculator"
);
29
30
NS_OBJECT_ENSURE_REGISTERED
(PhyStatsCalculator);
31
32
PhyStatsCalculator::PhyStatsCalculator
()
33
: m_RsrpSinrFirstWrite (true),
34
m_UeSinrFirstWrite (true),
35
m_InterferenceFirstWrite (true)
36
{
37
NS_LOG_FUNCTION
(
this
);
38
39
}
40
41
PhyStatsCalculator::~PhyStatsCalculator
()
42
{
43
NS_LOG_FUNCTION
(
this
);
44
}
45
46
TypeId
47
PhyStatsCalculator::GetTypeId
(
void
)
48
{
49
static
TypeId
tid =
TypeId
(
"ns3::PhyStatsCalculator"
)
50
.
SetParent
<
LteStatsCalculator
> ()
51
.AddConstructor<PhyStatsCalculator> ()
52
.AddAttribute (
"DlRsrpSinrFilename"
,
53
"Name of the file where the RSRP/SINR statistics will be saved."
,
54
StringValue
(
"DlRsrpSinrStats.txt"
),
55
MakeStringAccessor (&
PhyStatsCalculator::SetCurrentCellRsrpSinrFilename
),
56
MakeStringChecker ())
57
.AddAttribute (
"UlSinrFilename"
,
58
"Name of the file where the UE SINR statistics will be saved."
,
59
StringValue
(
"UlSinrStats.txt"
),
60
MakeStringAccessor (&
PhyStatsCalculator::SetUeSinrFilename
),
61
MakeStringChecker ())
62
.AddAttribute (
"UlInterferenceFilename"
,
63
"Name of the file where the interference statistics will be saved."
,
64
StringValue
(
"UlInterferenceStats.txt"
),
65
MakeStringAccessor (&
PhyStatsCalculator::SetInterferenceFilename
),
66
MakeStringChecker ())
67
;
68
return
tid;
69
}
70
71
void
72
PhyStatsCalculator::SetCurrentCellRsrpSinrFilename
(std::string filename)
73
{
74
m_RsrpSinrFilename
= filename;
75
}
76
77
std::string
78
PhyStatsCalculator::GetCurrentCellRsrpSinrFilename
(
void
)
79
{
80
return
m_RsrpSinrFilename
;
81
}
82
83
void
84
PhyStatsCalculator::SetUeSinrFilename
(std::string filename)
85
{
86
m_ueSinrFilename
= filename;
87
}
88
89
std::string
90
PhyStatsCalculator::GetUeSinrFilename
(
void
)
91
{
92
return
m_ueSinrFilename
;
93
}
94
95
void
96
PhyStatsCalculator::SetInterferenceFilename
(std::string filename)
97
{
98
m_interferenceFilename
= filename;
99
}
100
101
std::string
102
PhyStatsCalculator::GetInterferenceFilename
(
void
)
103
{
104
return
m_interferenceFilename
;
105
}
106
107
108
109
void
110
PhyStatsCalculator::ReportCurrentCellRsrpSinr
(uint16_t cellId, uint64_t imsi, uint16_t rnti,
111
double
rsrp,
double
sinr)
112
{
113
NS_LOG_FUNCTION
(
this
<< cellId << imsi << rnti << rsrp << sinr);
114
NS_LOG_INFO
(
"Write RSRP/SINR Phy Stats in "
<<
GetCurrentCellRsrpSinrFilename
().c_str ());
115
116
std::ofstream outFile;
117
if
(
m_RsrpSinrFirstWrite
==
true
)
118
{
119
outFile.open (
GetCurrentCellRsrpSinrFilename
().c_str ());
120
if
(!outFile.is_open ())
121
{
122
NS_LOG_ERROR
(
"Can't open file "
<<
GetCurrentCellRsrpSinrFilename
().c_str ());
123
return
;
124
}
125
m_RsrpSinrFirstWrite
=
false
;
126
outFile <<
"% time\tcellId\tIMSI\tRNTI\trsrp\tsinr"
;
127
outFile << std::endl;
128
}
129
else
130
{
131
outFile.open (
GetCurrentCellRsrpSinrFilename
().c_str (), std::ios_base::app);
132
if
(!outFile.is_open ())
133
{
134
NS_LOG_ERROR
(
"Can't open file "
<<
GetCurrentCellRsrpSinrFilename
().c_str ());
135
return
;
136
}
137
}
138
139
outFile <<
Simulator::Now
().
GetNanoSeconds
() / (double) 1e9 <<
"\t"
;
140
outFile << cellId <<
"\t"
;
141
outFile << imsi <<
"\t"
;
142
outFile << rnti <<
"\t"
;
143
outFile << rsrp <<
"\t"
;
144
outFile << sinr << std::endl;
145
outFile.close ();
146
}
147
148
void
149
PhyStatsCalculator::ReportUeSinr
(uint16_t cellId, uint64_t imsi, uint16_t rnti,
double
sinrLinear)
150
{
151
NS_LOG_FUNCTION
(
this
<< cellId << imsi << rnti << sinrLinear);
152
NS_LOG_INFO
(
"Write SINR Linear Phy Stats in "
<<
GetUeSinrFilename
().c_str ());
153
154
std::ofstream outFile;
155
if
(
m_UeSinrFirstWrite
==
true
)
156
{
157
outFile.open (
GetUeSinrFilename
().c_str ());
158
if
(!outFile.is_open ())
159
{
160
NS_LOG_ERROR
(
"Can't open file "
<<
GetUeSinrFilename
().c_str ());
161
return
;
162
}
163
m_UeSinrFirstWrite
=
false
;
164
outFile <<
"% time\tcellId\tIMSI\tRNTI\tsinrLinear"
;
165
outFile << std::endl;
166
}
167
else
168
{
169
outFile.open (
GetUeSinrFilename
().c_str (), std::ios_base::app);
170
if
(!outFile.is_open ())
171
{
172
NS_LOG_ERROR
(
"Can't open file "
<<
GetUeSinrFilename
().c_str ());
173
return
;
174
}
175
}
176
177
outFile <<
Simulator::Now
().
GetNanoSeconds
() / (double) 1e9 <<
"\t"
;
178
outFile << cellId <<
"\t"
;
179
outFile << imsi <<
"\t"
;
180
outFile << rnti <<
"\t"
;
181
outFile << sinrLinear << std::endl;
182
outFile.close ();
183
}
184
185
void
186
PhyStatsCalculator::ReportInterference
(uint16_t cellId,
Ptr<SpectrumValue>
interference)
187
{
188
NS_LOG_FUNCTION
(
this
<< cellId << interference);
189
NS_LOG_INFO
(
"Write Interference Phy Stats in "
<<
GetInterferenceFilename
().c_str ());
190
191
std::ofstream outFile;
192
if
(
m_InterferenceFirstWrite
==
true
)
193
{
194
outFile.open (
GetInterferenceFilename
().c_str ());
195
if
(!outFile.is_open ())
196
{
197
NS_LOG_ERROR
(
"Can't open file "
<<
GetInterferenceFilename
().c_str ());
198
return
;
199
}
200
m_InterferenceFirstWrite
=
false
;
201
outFile <<
"% time\tcellId\tInterference"
;
202
outFile << std::endl;
203
}
204
else
205
{
206
outFile.open (
GetInterferenceFilename
().c_str (), std::ios_base::app);
207
if
(!outFile.is_open ())
208
{
209
NS_LOG_ERROR
(
"Can't open file "
<<
GetInterferenceFilename
().c_str ());
210
return
;
211
}
212
}
213
214
outFile <<
Simulator::Now
().
GetNanoSeconds
() / (double) 1e9 <<
"\t"
;
215
outFile << cellId <<
"\t"
;
216
outFile << *interference;
217
outFile.close ();
218
}
219
220
}
// namespace ns3
src
lte
helper
phy-stats-calculator.cc
Generated on Tue May 14 2013 11:08:24 for ns-3 by
1.8.1.2