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 }
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::PhyStatsCalculator")
52  .SetGroupName("Lte")
53  .AddConstructor<PhyStatsCalculator> ()
54  .AddAttribute ("DlRsrpSinrFilename",
55  "Name of the file where the RSRP/SINR statistics will be saved.",
56  StringValue ("DlRsrpSinrStats.txt"),
59  .AddAttribute ("UlSinrFilename",
60  "Name of the file where the UE SINR statistics will be saved.",
61  StringValue ("UlSinrStats.txt"),
64  .AddAttribute ("UlInterferenceFilename",
65  "Name of the file where the interference statistics will be saved.",
66  StringValue ("UlInterferenceStats.txt"),
69  ;
70  return tid;
71 }
72 
73 void
75 {
76  m_RsrpSinrFilename = filename;
77 }
78 
79 std::string
81 {
82  return m_RsrpSinrFilename;
83 }
84 
85 void
87 {
88  m_ueSinrFilename = filename;
89 }
90 
91 std::string
93 {
94  return m_ueSinrFilename;
95 }
96 
97 void
99 {
100  m_interferenceFilename = filename;
101 }
102 
103 std::string
105 {
106  return m_interferenceFilename;
107 }
108 
109 
110 
111 void
112 PhyStatsCalculator::ReportCurrentCellRsrpSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti,
113  double rsrp, double sinr, uint8_t componentCarrierId)
114 {
115  NS_LOG_FUNCTION (this << cellId << imsi << rnti << rsrp << sinr);
116  NS_LOG_INFO ("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename ().c_str ());
117 
118  std::ofstream outFile;
119  if ( m_RsrpSinrFirstWrite == true )
120  {
121  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str ());
122  if (!outFile.is_open ())
123  {
124  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
125  return;
126  }
127  m_RsrpSinrFirstWrite = false;
128  outFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr\tComponentCarrierId";
129  outFile << std::endl;
130  }
131  else
132  {
133  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str (), std::ios_base::app);
134  if (!outFile.is_open ())
135  {
136  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
137  return;
138  }
139  }
140 
141  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
142  outFile << cellId << "\t";
143  outFile << imsi << "\t";
144  outFile << rnti << "\t";
145  outFile << rsrp << "\t";
146  outFile << sinr << "\t";
147  outFile << (uint32_t)componentCarrierId << std::endl;
148  outFile.close ();
149 }
150 
151 void
152 PhyStatsCalculator::ReportUeSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
153 {
154  NS_LOG_FUNCTION (this << cellId << imsi << rnti << sinrLinear);
155  NS_LOG_INFO ("Write SINR Linear Phy Stats in " << GetUeSinrFilename ().c_str ());
156 
157  std::ofstream outFile;
158  if ( m_UeSinrFirstWrite == true )
159  {
160  outFile.open (GetUeSinrFilename ().c_str ());
161  if (!outFile.is_open ())
162  {
163  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
164  return;
165  }
166  m_UeSinrFirstWrite = false;
167  outFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear\tcomponentCarrierId";
168  outFile << std::endl;
169  }
170  else
171  {
172  outFile.open (GetUeSinrFilename ().c_str (), std::ios_base::app);
173  if (!outFile.is_open ())
174  {
175  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
176  return;
177  }
178  }
179 
180  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
181  outFile << cellId << "\t";
182  outFile << imsi << "\t";
183  outFile << rnti << "\t";
184  outFile << sinrLinear << "\t";
185  outFile << (uint32_t)componentCarrierId << std::endl;
186  outFile.close ();
187 }
188 
189 void
191 {
192  NS_LOG_FUNCTION (this << cellId << interference);
193  NS_LOG_INFO ("Write Interference Phy Stats in " << GetInterferenceFilename ().c_str ());
194 
195  std::ofstream outFile;
196  if ( m_InterferenceFirstWrite == true )
197  {
198  outFile.open (GetInterferenceFilename ().c_str ());
199  if (!outFile.is_open ())
200  {
201  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
202  return;
203  }
204  m_InterferenceFirstWrite = false;
205  outFile << "% time\tcellId\tInterference";
206  outFile << std::endl;
207  }
208  else
209  {
210  outFile.open (GetInterferenceFilename ().c_str (), std::ios_base::app);
211  if (!outFile.is_open ())
212  {
213  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
214  return;
215  }
216  }
217 
218  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
219  outFile << cellId << "\t";
220  outFile << *interference;
221  outFile.close ();
222 }
223 
224 
225 void
227  std::string path, uint16_t cellId, uint16_t rnti,
228  double rsrp, double sinr, uint8_t componentCarrierId)
229 {
230  NS_LOG_FUNCTION (phyStats << path);
231  uint64_t imsi = 0;
232  std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
233  if (phyStats->ExistsImsiPath (pathUePhy) == true)
234  {
235  imsi = phyStats->GetImsiPath (pathUePhy);
236  }
237  else
238  {
239  imsi = FindImsiFromLteNetDevice (pathUePhy);
240  phyStats->SetImsiPath (pathUePhy, imsi);
241  }
242 
243  phyStats->ReportCurrentCellRsrpSinr (cellId, imsi, rnti, rsrp, sinr, componentCarrierId);
244 }
245 
246 void
248  uint16_t cellId, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
249 {
250  NS_LOG_FUNCTION (phyStats << path);
251 
252  uint64_t imsi = 0;
253  std::ostringstream pathAndRnti;
254  pathAndRnti << path << "/" << rnti;
255  std::string pathEnbMac = path.substr (0, path.find ("/ComponentCarrierMap"));
256  pathEnbMac += "/LteEnbMac/DlScheduling";
257  if (phyStats->ExistsImsiPath (pathAndRnti.str ()) == true)
258  {
259  imsi = phyStats->GetImsiPath (pathAndRnti.str ());
260  }
261  else
262  {
263  imsi = FindImsiFromEnbMac (pathEnbMac, rnti);
264  phyStats->SetImsiPath (pathAndRnti.str (), imsi);
265  }
266 
267  phyStats->ReportUeSinr (cellId, imsi, rnti, sinrLinear, componentCarrierId);
268 }
269 
270 void
272  uint16_t cellId, Ptr<SpectrumValue> interference)
273 {
274  NS_LOG_FUNCTION (phyStats << path);
275  phyStats->ReportInterference (cellId, interference);
276 }
277 
278 
279 } // namespace ns3
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Base class for ***StatsCalculator classes.
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
Retrieves IMSI from Enb MAC path in the attribute system.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Hold variables of type string.
Definition: string.h:41
std::string GetInterferenceFilename(void)
Get the name of the file where the interference statistics will be stored.
std::string m_ueSinrFilename
Name of the file where the UE SINR statistics will be saved.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
void SetCurrentCellRsrpSinrFilename(std::string filename)
Set the name of the file where the RSRP/SINR statistics will be stored.
bool m_RsrpSinrFirstWrite
When writing RSRP SINR statistics first time to file, columns description is added.
static TypeId GetTypeId(void)
Register this type.
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.
std::string m_interferenceFilename
Name of the file where the interference statistics will be saved.
bool m_InterferenceFirstWrite
When writing interference statistics first time to file, columns description is added.
void SetUeSinrFilename(std::string filename)
Set the name of the file where the UE SINR statistics will be stored.
Takes care of storing the information generated at PHY layer.
virtual ~PhyStatsCalculator()
Destructor.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
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.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
std::string m_RsrpSinrFilename
Name of the file where the RSRP/SINR statistics will be saved.
void SetInterferenceFilename(std::string filename)
Set the name of the file where the interference statistics will be stored.
std::string GetUeSinrFilename(void)
Get the name of the file where the UE SINR statistics will be stored.
static void ReportCurrentCellRsrpSinrCallback(Ptr< PhyStatsCalculator > phyStats, std::string path, uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
trace sink
void ReportInterference(uint16_t cellId, Ptr< SpectrumValue > interference)
Notifies the stats calculator that an interference report has occurred.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
std::string GetCurrentCellRsrpSinrFilename(void)
Get the name of the file where the RSRP/SINR statistics will be stored.
bool m_UeSinrFirstWrite
When writing UE SINR statistics first time to file, columns description is added. ...