A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
phy-stats-calculator.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Jaume Nin <jnin@cttc.es>
18 * Danilo Abrignani <danilo.abrignani@unibo.it> (Modification due to new Architecture -
19 * Carrier Aggregation - GSoC 2015)
20 */
21
23
24#include "ns3/string.h"
25#include <ns3/log.h>
26#include <ns3/simulator.h>
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("PhyStatsCalculator");
32
33NS_OBJECT_ENSURE_REGISTERED(PhyStatsCalculator);
34
36 : m_RsrpSinrFirstWrite(true),
37 m_UeSinrFirstWrite(true),
38 m_InterferenceFirstWrite(true)
39{
40 NS_LOG_FUNCTION(this);
41}
42
44{
45 NS_LOG_FUNCTION(this);
46 if (m_interferenceOutFile.is_open())
47 {
49 }
50
51 if (m_rsrpOutFile.is_open())
52 {
53 m_rsrpOutFile.close();
54 }
55
56 if (m_ueSinrOutFile.is_open())
57 {
58 m_ueSinrOutFile.close();
59 }
60}
61
64{
65 static TypeId tid =
66 TypeId("ns3::PhyStatsCalculator")
68 .SetGroupName("Lte")
69 .AddConstructor<PhyStatsCalculator>()
70 .AddAttribute("DlRsrpSinrFilename",
71 "Name of the file where the RSRP/SINR statistics will be saved.",
72 StringValue("DlRsrpSinrStats.txt"),
75 .AddAttribute("UlSinrFilename",
76 "Name of the file where the UE SINR statistics will be saved.",
77 StringValue("UlSinrStats.txt"),
80 .AddAttribute("UlInterferenceFilename",
81 "Name of the file where the interference statistics will be saved.",
82 StringValue("UlInterferenceStats.txt"),
85 return tid;
86}
87
88void
90{
91 m_RsrpSinrFilename = filename;
92}
93
94std::string
96{
97 return m_RsrpSinrFilename;
98}
99
100void
102{
103 m_ueSinrFilename = filename;
104}
105
106std::string
108{
109 return m_ueSinrFilename;
110}
111
112void
114{
115 m_interferenceFilename = filename;
116}
117
118std::string
120{
122}
123
124void
126 uint64_t imsi,
127 uint16_t rnti,
128 double rsrp,
129 double sinr,
130 uint8_t componentCarrierId)
131{
132 NS_LOG_FUNCTION(this << cellId << imsi << rnti << rsrp << sinr);
133 NS_LOG_INFO("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename());
134
136 {
138 if (!m_rsrpOutFile.is_open())
139 {
140 NS_LOG_ERROR("Can't open file " << GetCurrentCellRsrpSinrFilename());
141 return;
142 }
143 m_RsrpSinrFirstWrite = false;
144 m_rsrpOutFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr\tComponentCarrierId";
145 m_rsrpOutFile << "\n";
146 }
147
149 m_rsrpOutFile << cellId << "\t";
150 m_rsrpOutFile << imsi << "\t";
151 m_rsrpOutFile << rnti << "\t";
152 m_rsrpOutFile << rsrp << "\t";
153 m_rsrpOutFile << sinr << "\t";
154 m_rsrpOutFile << (uint32_t)componentCarrierId << std::endl;
155}
156
157void
159 uint64_t imsi,
160 uint16_t rnti,
161 double sinrLinear,
162 uint8_t componentCarrierId)
163{
164 NS_LOG_FUNCTION(this << cellId << imsi << rnti << sinrLinear);
165 NS_LOG_INFO("Write SINR Linear Phy Stats in " << GetUeSinrFilename());
166
168 {
170 if (!m_ueSinrOutFile.is_open())
171 {
172 NS_LOG_ERROR("Can't open file " << GetUeSinrFilename());
173 return;
174 }
175 m_UeSinrFirstWrite = false;
176 m_ueSinrOutFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear\tcomponentCarrierId";
177 m_ueSinrOutFile << "\n";
178 }
180 m_ueSinrOutFile << cellId << "\t";
181 m_ueSinrOutFile << imsi << "\t";
182 m_ueSinrOutFile << rnti << "\t";
183 m_ueSinrOutFile << sinrLinear << "\t";
184 m_ueSinrOutFile << (uint32_t)componentCarrierId << std::endl;
185}
186
187void
189{
190 NS_LOG_FUNCTION(this << cellId << interference);
191 NS_LOG_INFO("Write Interference Phy Stats in " << GetInterferenceFilename());
192
194 {
196 if (!m_interferenceOutFile.is_open())
197 {
198 NS_LOG_ERROR("Can't open file " << GetInterferenceFilename());
199 return;
200 }
202 m_interferenceOutFile << "% time\tcellId\tInterference";
203 m_interferenceOutFile << "\n";
204 }
205
207 m_interferenceOutFile << cellId << "\t";
208 m_interferenceOutFile << *interference;
209}
210
211void
213 std::string path,
214 uint16_t cellId,
215 uint16_t rnti,
216 double rsrp,
217 double sinr,
218 uint8_t componentCarrierId)
219{
220 NS_LOG_FUNCTION(phyStats << path);
221 uint64_t imsi = 0;
222 std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
223 if (phyStats->ExistsImsiPath(pathUePhy))
224 {
225 imsi = phyStats->GetImsiPath(pathUePhy);
226 }
227 else
228 {
229 imsi = FindImsiFromLteNetDevice(pathUePhy);
230 phyStats->SetImsiPath(pathUePhy, imsi);
231 }
232
233 phyStats->ReportCurrentCellRsrpSinr(cellId, imsi, rnti, rsrp, sinr, componentCarrierId);
234}
235
236void
238 std::string path,
239 uint16_t cellId,
240 uint16_t rnti,
241 double sinrLinear,
242 uint8_t componentCarrierId)
243{
244 NS_LOG_FUNCTION(phyStats << path);
245
246 uint64_t imsi = 0;
247 std::ostringstream pathAndRnti;
248 pathAndRnti << path << "/" << rnti;
249 std::string pathEnbMac = path.substr(0, path.find("/ComponentCarrierMap"));
250 pathEnbMac += "/LteEnbMac/DlScheduling";
251 if (phyStats->ExistsImsiPath(pathAndRnti.str()))
252 {
253 imsi = phyStats->GetImsiPath(pathAndRnti.str());
254 }
255 else
256 {
257 imsi = FindImsiFromEnbMac(pathEnbMac, rnti);
258 phyStats->SetImsiPath(pathAndRnti.str(), imsi);
259 }
260
261 phyStats->ReportUeSinr(cellId, imsi, rnti, sinrLinear, componentCarrierId);
262}
263
264void
266 std::string path,
267 uint16_t cellId,
268 Ptr<SpectrumValue> interference)
269{
270 NS_LOG_FUNCTION(phyStats << path);
271 phyStats->ReportInterference(cellId, interference);
272}
273
274} // namespace ns3
Base class for ***StatsCalculator classes.
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
Retrieves IMSI from Enb MAC path in the attribute system.
Takes care of storing the information generated at PHY layer.
bool m_UeSinrFirstWrite
When writing UE SINR statistics first time to file, columns description is added.
bool m_InterferenceFirstWrite
When writing interference statistics first time to file, columns description is added.
std::string GetInterferenceFilename()
Get the name of the file where the interference statistics will be stored.
std::string GetUeSinrFilename()
Get the name of the file where the UE SINR statistics will be stored.
void SetInterferenceFilename(std::string filename)
Set the name of the file where the interference statistics will be stored.
void ReportUeSinr(uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
Notifies the stats calculator that an UE SINR report has occurred.
bool m_RsrpSinrFirstWrite
When writing RSRP SINR statistics first time to file, columns description is added.
std::string m_interferenceFilename
Name of the file where the interference statistics will be saved.
std::string m_ueSinrFilename
Name of the file where the UE SINR statistics will be saved.
void SetCurrentCellRsrpSinrFilename(std::string filename)
Set the name of the file where the RSRP/SINR statistics will be stored.
void ReportCurrentCellRsrpSinr(uint16_t cellId, uint64_t imsi, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
Notifies the stats calculator that an RSRP and SINR report has occurred.
void SetUeSinrFilename(std::string filename)
Set the name of the file where the UE SINR statistics will be stored.
std::ofstream m_interferenceOutFile
Interference statistics output trace file.
std::string GetCurrentCellRsrpSinrFilename()
Get the name of the file where the RSRP/SINR statistics will be stored.
static TypeId GetTypeId()
Register this type.
std::ofstream m_ueSinrOutFile
UE SINR statistics output trace file.
std::string m_RsrpSinrFilename
Name of the file where the RSRP/SINR statistics will be saved.
std::ofstream m_rsrpOutFile
RSRP statistics output trace file.
void ReportInterference(uint16_t cellId, Ptr< SpectrumValue > interference)
Notifies the stats calculator that an interference report has occurred.
static void ReportCurrentCellRsrpSinrCallback(Ptr< PhyStatsCalculator > phyStats, std::string path, uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
trace sink
~PhyStatsCalculator() override
Destructor.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Hold variables of type string.
Definition: string.h:56
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
Ptr< const AttributeChecker > MakeStringChecker()
Definition: string.cc:30
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:57
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.