A Discrete-Event Network Simulator
API
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  * Danilo Abrignani <danilo.abrignani@unibo.it> (Modification due to new Architecture - Carrier Aggregation - GSoC 2015)
20  */
21 
22 #include "phy-stats-calculator.h"
23 #include "ns3/string.h"
24 #include <ns3/simulator.h>
25 #include <ns3/log.h>
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("PhyStatsCalculator");
30 
31 NS_OBJECT_ENSURE_REGISTERED (PhyStatsCalculator);
32 
34  : m_RsrpSinrFirstWrite (true),
35  m_UeSinrFirstWrite (true),
36  m_InterferenceFirstWrite (true)
37 {
38  NS_LOG_FUNCTION (this);
39 
40 }
41 
43 {
44  NS_LOG_FUNCTION (this);
45  if (m_interferenceOutFile.is_open())
46  {
47  m_interferenceOutFile.close();
48  }
49 
50  if (m_rsrpOutFile.is_open())
51  {
52  m_rsrpOutFile.close();
53  }
54 
55  if (m_ueSinrOutFile.is_open())
56  {
57  m_ueSinrOutFile.close();
58  }
59 }
60 
61 TypeId
63 {
64  static TypeId tid = TypeId ("ns3::PhyStatsCalculator")
66  .SetGroupName ("Lte")
67  .AddConstructor<PhyStatsCalculator> ()
68  .AddAttribute ("DlRsrpSinrFilename",
69  "Name of the file where the RSRP/SINR statistics will be saved.",
70  StringValue ("DlRsrpSinrStats.txt"),
73  .AddAttribute ("UlSinrFilename",
74  "Name of the file where the UE SINR statistics will be saved.",
75  StringValue ("UlSinrStats.txt"),
78  .AddAttribute ("UlInterferenceFilename",
79  "Name of the file where the interference statistics will be saved.",
80  StringValue ("UlInterferenceStats.txt"),
83  ;
84  return tid;
85 }
86 
87 void
89 {
90  m_RsrpSinrFilename = filename;
91 }
92 
93 std::string
95 {
96  return m_RsrpSinrFilename;
97 }
98 
99 void
101 {
102  m_ueSinrFilename = filename;
103 }
104 
105 std::string
107 {
108  return m_ueSinrFilename;
109 }
110 
111 void
113 {
114  m_interferenceFilename = filename;
115 }
116 
117 std::string
119 {
120  return m_interferenceFilename;
121 }
122 
123 
124 
125 void
126 PhyStatsCalculator::ReportCurrentCellRsrpSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti,
127  double rsrp, double sinr, uint8_t componentCarrierId)
128 {
129  NS_LOG_FUNCTION (this << cellId << imsi << rnti << rsrp << sinr);
130  NS_LOG_INFO ("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename ().c_str ());
131 
132  if ( m_RsrpSinrFirstWrite == true )
133  {
135  if (!m_rsrpOutFile.is_open ())
136  {
137  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
138  return;
139  }
140  m_RsrpSinrFirstWrite = false;
141  m_rsrpOutFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr\tComponentCarrierId";
142  m_rsrpOutFile << "\n";
143  }
144 
145  m_rsrpOutFile << Simulator::Now ().GetSeconds () << "\t";
146  m_rsrpOutFile << cellId << "\t";
147  m_rsrpOutFile << imsi << "\t";
148  m_rsrpOutFile << rnti << "\t";
149  m_rsrpOutFile << rsrp << "\t";
150  m_rsrpOutFile << sinr << "\t";
151  m_rsrpOutFile << (uint32_t)componentCarrierId << std::endl;
152 }
153 
154 void
155 PhyStatsCalculator::ReportUeSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
156 {
157  NS_LOG_FUNCTION (this << cellId << imsi << rnti << sinrLinear);
158  NS_LOG_INFO ("Write SINR Linear Phy Stats in " << GetUeSinrFilename ().c_str ());
159 
160  if ( m_UeSinrFirstWrite == true )
161  {
162  m_ueSinrOutFile.open (GetUeSinrFilename ().c_str ());
163  if (!m_ueSinrOutFile.is_open ())
164  {
165  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
166  return;
167  }
168  m_UeSinrFirstWrite = false;
169  m_ueSinrOutFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear\tcomponentCarrierId";
170  m_ueSinrOutFile << "\n";
171  }
172  m_ueSinrOutFile << Simulator::Now ().GetSeconds () << "\t";
173  m_ueSinrOutFile << cellId << "\t";
174  m_ueSinrOutFile << imsi << "\t";
175  m_ueSinrOutFile << rnti << "\t";
176  m_ueSinrOutFile << sinrLinear << "\t";
177  m_ueSinrOutFile << (uint32_t)componentCarrierId << std::endl;
178 }
179 
180 void
182 {
183  NS_LOG_FUNCTION (this << cellId << interference);
184  NS_LOG_INFO ("Write Interference Phy Stats in " << GetInterferenceFilename ().c_str ());
185 
186  if ( m_InterferenceFirstWrite == true )
187  {
189  if (!m_interferenceOutFile.is_open ())
190  {
191  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
192  return;
193  }
194  m_InterferenceFirstWrite = false;
195  m_interferenceOutFile << "% time\tcellId\tInterference";
196  m_interferenceOutFile << "\n";
197  }
198 
200  m_interferenceOutFile << cellId << "\t";
201  m_interferenceOutFile << *interference;
202 }
203 
204 
205 void
207  std::string path, uint16_t cellId, uint16_t rnti,
208  double rsrp, double sinr, uint8_t componentCarrierId)
209 {
210  NS_LOG_FUNCTION (phyStats << path);
211  uint64_t imsi = 0;
212  std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
213  if (phyStats->ExistsImsiPath (pathUePhy) == true)
214  {
215  imsi = phyStats->GetImsiPath (pathUePhy);
216  }
217  else
218  {
219  imsi = FindImsiFromLteNetDevice (pathUePhy);
220  phyStats->SetImsiPath (pathUePhy, imsi);
221  }
222 
223  phyStats->ReportCurrentCellRsrpSinr (cellId, imsi, rnti, rsrp, sinr, componentCarrierId);
224 }
225 
226 void
228  uint16_t cellId, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
229 {
230  NS_LOG_FUNCTION (phyStats << path);
231 
232  uint64_t imsi = 0;
233  std::ostringstream pathAndRnti;
234  pathAndRnti << path << "/" << rnti;
235  std::string pathEnbMac = path.substr (0, path.find ("/ComponentCarrierMap"));
236  pathEnbMac += "/LteEnbMac/DlScheduling";
237  if (phyStats->ExistsImsiPath (pathAndRnti.str ()) == true)
238  {
239  imsi = phyStats->GetImsiPath (pathAndRnti.str ());
240  }
241  else
242  {
243  imsi = FindImsiFromEnbMac (pathEnbMac, rnti);
244  phyStats->SetImsiPath (pathAndRnti.str (), imsi);
245  }
246 
247  phyStats->ReportUeSinr (cellId, imsi, rnti, sinrLinear, componentCarrierId);
248 }
249 
250 void
252  uint16_t cellId, Ptr<SpectrumValue> interference)
253 {
254  NS_LOG_FUNCTION (phyStats << path);
255  phyStats->ReportInterference (cellId, interference);
256 }
257 
258 
259 } // 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 GetUeSinrFilename(void)
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.
virtual ~PhyStatsCalculator()
Destructor.
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::string GetInterferenceFilename(void)
Get the name of the file where the interference statistics will be stored.
std::ofstream m_interferenceOutFile
Interference statistics output trace file.
std::ofstream m_ueSinrOutFile
UE SINR statistics output trace file.
static TypeId GetTypeId(void)
Register this type.
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
std::string GetCurrentCellRsrpSinrFilename(void)
Get the name of the file where the RSRP/SINR statistics will be stored.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Hold variables of type string.
Definition: string.h:41
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: string.h:42
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.