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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jaume Nin <jnin@cttc.es>
7 * Danilo Abrignani <danilo.abrignani@unibo.it> (Modification due to new Architecture -
8 * Carrier Aggregation - GSoC 2015)
9 */
10
12
13#include "ns3/string.h"
14#include <ns3/log.h>
15#include <ns3/simulator.h>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("PhyStatsCalculator");
21
22NS_OBJECT_ENSURE_REGISTERED(PhyStatsCalculator);
23
25 : m_RsrpSinrFirstWrite(true),
26 m_UeSinrFirstWrite(true),
27 m_InterferenceFirstWrite(true)
28{
29 NS_LOG_FUNCTION(this);
30}
31
33{
34 NS_LOG_FUNCTION(this);
35 if (m_interferenceOutFile.is_open())
36 {
38 }
39
40 if (m_rsrpOutFile.is_open())
41 {
42 m_rsrpOutFile.close();
43 }
44
45 if (m_ueSinrOutFile.is_open())
46 {
47 m_ueSinrOutFile.close();
48 }
49}
50
53{
54 static TypeId tid =
55 TypeId("ns3::PhyStatsCalculator")
57 .SetGroupName("Lte")
58 .AddConstructor<PhyStatsCalculator>()
59 .AddAttribute("DlRsrpSinrFilename",
60 "Name of the file where the RSRP/SINR statistics will be saved.",
61 StringValue("DlRsrpSinrStats.txt"),
64 .AddAttribute("UlSinrFilename",
65 "Name of the file where the UE SINR statistics will be saved.",
66 StringValue("UlSinrStats.txt"),
69 .AddAttribute("UlInterferenceFilename",
70 "Name of the file where the interference statistics will be saved.",
71 StringValue("UlInterferenceStats.txt"),
74 return tid;
75}
76
77void
82
83std::string
88
89void
91{
92 m_ueSinrFilename = filename;
93}
94
95std::string
100
101void
103{
104 m_interferenceFilename = filename;
105}
106
107std::string
112
113void
115 uint64_t imsi,
116 uint16_t rnti,
117 double rsrp,
118 double sinr,
119 uint8_t componentCarrierId)
120{
121 NS_LOG_FUNCTION(this << cellId << imsi << rnti << rsrp << sinr);
122 NS_LOG_INFO("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename());
123
125 {
127 if (!m_rsrpOutFile.is_open())
128 {
129 NS_LOG_ERROR("Can't open file " << GetCurrentCellRsrpSinrFilename());
130 return;
131 }
132 m_RsrpSinrFirstWrite = false;
133 m_rsrpOutFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr\tComponentCarrierId";
134 m_rsrpOutFile << "\n";
135 }
136
138 m_rsrpOutFile << cellId << "\t";
139 m_rsrpOutFile << imsi << "\t";
140 m_rsrpOutFile << rnti << "\t";
141 m_rsrpOutFile << rsrp << "\t";
142 m_rsrpOutFile << sinr << "\t";
143 m_rsrpOutFile << (uint32_t)componentCarrierId << std::endl;
144}
145
146void
148 uint64_t imsi,
149 uint16_t rnti,
150 double sinrLinear,
151 uint8_t componentCarrierId)
152{
153 NS_LOG_FUNCTION(this << cellId << imsi << rnti << sinrLinear);
154 NS_LOG_INFO("Write SINR Linear Phy Stats in " << GetUeSinrFilename());
155
157 {
159 if (!m_ueSinrOutFile.is_open())
160 {
161 NS_LOG_ERROR("Can't open file " << GetUeSinrFilename());
162 return;
163 }
164 m_UeSinrFirstWrite = false;
165 m_ueSinrOutFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear\tcomponentCarrierId";
166 m_ueSinrOutFile << "\n";
167 }
169 m_ueSinrOutFile << cellId << "\t";
170 m_ueSinrOutFile << imsi << "\t";
171 m_ueSinrOutFile << rnti << "\t";
172 m_ueSinrOutFile << sinrLinear << "\t";
173 m_ueSinrOutFile << (uint32_t)componentCarrierId << std::endl;
174}
175
176void
178{
179 NS_LOG_FUNCTION(this << cellId << interference);
180 NS_LOG_INFO("Write Interference Phy Stats in " << GetInterferenceFilename());
181
183 {
185 if (!m_interferenceOutFile.is_open())
186 {
187 NS_LOG_ERROR("Can't open file " << GetInterferenceFilename());
188 return;
189 }
191 m_interferenceOutFile << "% time\tcellId\tInterference";
192 m_interferenceOutFile << "\n";
193 }
194
196 m_interferenceOutFile << cellId << "\t";
197 m_interferenceOutFile << *interference;
198}
199
200void
202 std::string path,
203 uint16_t cellId,
204 uint16_t rnti,
205 double rsrp,
206 double sinr,
207 uint8_t componentCarrierId)
208{
209 NS_LOG_FUNCTION(phyStats << path);
210 uint64_t imsi = 0;
211 std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
212 if (phyStats->ExistsImsiPath(pathUePhy))
213 {
214 imsi = phyStats->GetImsiPath(pathUePhy);
215 }
216 else
217 {
218 imsi = FindImsiFromLteNetDevice(pathUePhy);
219 phyStats->SetImsiPath(pathUePhy, imsi);
220 }
221
222 phyStats->ReportCurrentCellRsrpSinr(cellId, imsi, rnti, rsrp, sinr, componentCarrierId);
223}
224
225void
227 std::string path,
228 uint16_t cellId,
229 uint16_t rnti,
230 double sinrLinear,
231 uint8_t componentCarrierId)
232{
233 NS_LOG_FUNCTION(phyStats << path);
234
235 uint64_t imsi = 0;
236 std::ostringstream pathAndRnti;
237 pathAndRnti << path << "/" << rnti;
238 std::string pathEnbMac = path.substr(0, path.find("/ComponentCarrierMap"));
239 pathEnbMac += "/LteEnbMac/DlScheduling";
240 if (phyStats->ExistsImsiPath(pathAndRnti.str()))
241 {
242 imsi = phyStats->GetImsiPath(pathAndRnti.str());
243 }
244 else
245 {
246 imsi = FindImsiFromEnbMac(pathEnbMac, rnti);
247 phyStats->SetImsiPath(pathAndRnti.str(), imsi);
248 }
249
250 phyStats->ReportUeSinr(cellId, imsi, rnti, sinrLinear, componentCarrierId);
251}
252
253void
255 std::string path,
256 uint16_t cellId,
257 Ptr<SpectrumValue> interference)
258{
259 NS_LOG_FUNCTION(phyStats << path);
260 phyStats->ReportInterference(cellId, interference);
261}
262
263} // 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.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Hold variables of type string.
Definition string.h:45
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition string.h:46