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  */
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 
33  : m_RsrpSinrFirstWrite (true),
34  m_UeSinrFirstWrite (true),
35  m_InterferenceFirstWrite (true)
36 {
37  NS_LOG_FUNCTION (this);
38 
39 }
40 
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 TypeId
48 {
49  static TypeId tid = TypeId ("ns3::PhyStatsCalculator")
51  .SetGroupName("Lte")
52  .AddConstructor<PhyStatsCalculator> ()
53  .AddAttribute ("DlRsrpSinrFilename",
54  "Name of the file where the RSRP/SINR statistics will be saved.",
55  StringValue ("DlRsrpSinrStats.txt"),
58  .AddAttribute ("UlSinrFilename",
59  "Name of the file where the UE SINR statistics will be saved.",
60  StringValue ("UlSinrStats.txt"),
63  .AddAttribute ("UlInterferenceFilename",
64  "Name of the file where the interference statistics will be saved.",
65  StringValue ("UlInterferenceStats.txt"),
68  ;
69  return tid;
70 }
71 
72 void
74 {
75  m_RsrpSinrFilename = filename;
76 }
77 
78 std::string
80 {
81  return m_RsrpSinrFilename;
82 }
83 
84 void
86 {
87  m_ueSinrFilename = filename;
88 }
89 
90 std::string
92 {
93  return m_ueSinrFilename;
94 }
95 
96 void
98 {
99  m_interferenceFilename = filename;
100 }
101 
102 std::string
104 {
105  return m_interferenceFilename;
106 }
107 
108 
109 
110 void
111 PhyStatsCalculator::ReportCurrentCellRsrpSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti,
112  double rsrp, double sinr)
113 {
114  NS_LOG_FUNCTION (this << cellId << imsi << rnti << rsrp << sinr);
115  NS_LOG_INFO ("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename ().c_str ());
116 
117  std::ofstream outFile;
118  if ( m_RsrpSinrFirstWrite == true )
119  {
120  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str ());
121  if (!outFile.is_open ())
122  {
123  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
124  return;
125  }
126  m_RsrpSinrFirstWrite = false;
127  outFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr";
128  outFile << std::endl;
129  }
130  else
131  {
132  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str (), std::ios_base::app);
133  if (!outFile.is_open ())
134  {
135  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
136  return;
137  }
138  }
139 
140  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
141  outFile << cellId << "\t";
142  outFile << imsi << "\t";
143  outFile << rnti << "\t";
144  outFile << rsrp << "\t";
145  outFile << sinr << std::endl;
146  outFile.close ();
147 }
148 
149 void
150 PhyStatsCalculator::ReportUeSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear)
151 {
152  NS_LOG_FUNCTION (this << cellId << imsi << rnti << sinrLinear);
153  NS_LOG_INFO ("Write SINR Linear Phy Stats in " << GetUeSinrFilename ().c_str ());
154 
155  std::ofstream outFile;
156  if ( m_UeSinrFirstWrite == true )
157  {
158  outFile.open (GetUeSinrFilename ().c_str ());
159  if (!outFile.is_open ())
160  {
161  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
162  return;
163  }
164  m_UeSinrFirstWrite = false;
165  outFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear";
166  outFile << std::endl;
167  }
168  else
169  {
170  outFile.open (GetUeSinrFilename ().c_str (), std::ios_base::app);
171  if (!outFile.is_open ())
172  {
173  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
174  return;
175  }
176  }
177 
178  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
179  outFile << cellId << "\t";
180  outFile << imsi << "\t";
181  outFile << rnti << "\t";
182  outFile << sinrLinear << std::endl;
183  outFile.close ();
184 }
185 
186 void
188 {
189  NS_LOG_FUNCTION (this << cellId << interference);
190  NS_LOG_INFO ("Write Interference Phy Stats in " << GetInterferenceFilename ().c_str ());
191 
192  std::ofstream outFile;
193  if ( m_InterferenceFirstWrite == true )
194  {
195  outFile.open (GetInterferenceFilename ().c_str ());
196  if (!outFile.is_open ())
197  {
198  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
199  return;
200  }
201  m_InterferenceFirstWrite = false;
202  outFile << "% time\tcellId\tInterference";
203  outFile << std::endl;
204  }
205  else
206  {
207  outFile.open (GetInterferenceFilename ().c_str (), std::ios_base::app);
208  if (!outFile.is_open ())
209  {
210  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
211  return;
212  }
213  }
214 
215  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
216  outFile << cellId << "\t";
217  outFile << *interference;
218  outFile.close ();
219 }
220 
221 
222 void
224  std::string path, uint16_t cellId, uint16_t rnti,
225  double rsrp, double sinr)
226 {
227  NS_LOG_FUNCTION (phyStats << path);
228  uint64_t imsi = 0;
229  std::string pathUePhy = path.substr (0, path.find ("/ReportCurrentCellRsrpSinr"));
230  if (phyStats->ExistsImsiPath (pathUePhy) == true)
231  {
232  imsi = phyStats->GetImsiPath (pathUePhy);
233  }
234  else
235  {
236  imsi = FindImsiFromUePhy (pathUePhy);
237  phyStats->SetImsiPath (pathUePhy, imsi);
238  }
239 
240  phyStats->ReportCurrentCellRsrpSinr (cellId, imsi, rnti, rsrp,sinr);
241 }
242 
243 void
245  uint16_t cellId, uint16_t rnti, double sinrLinear)
246 {
247  NS_LOG_FUNCTION (phyStats << path);
248 
249  uint64_t imsi = 0;
250  std::ostringstream pathAndRnti;
251  pathAndRnti << path << "/" << rnti;
252  std::string pathEnbMac = path.substr (0, path.find ("LteEnbPhy/ReportUeSinr"));
253  pathEnbMac += "LteEnbMac/DlScheduling";
254  if (phyStats->ExistsImsiPath (pathAndRnti.str ()) == true)
255  {
256  imsi = phyStats->GetImsiPath (pathAndRnti.str ());
257  }
258  else
259  {
260  imsi = FindImsiFromEnbMac (pathEnbMac, rnti);
261  phyStats->SetImsiPath (pathAndRnti.str (), imsi);
262  }
263 
264  phyStats->ReportUeSinr (cellId, imsi, rnti, sinrLinear);
265 }
266 
267 void
269  uint16_t cellId, Ptr<SpectrumValue> interference)
270 {
271  NS_LOG_FUNCTION (phyStats << path);
272  phyStats->ReportInterference (cellId, interference);
273 }
274 
275 
276 } // namespace ns3
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Base class for ***StatsCalculator classes.
static uint64_t FindImsiFromUePhy(std::string path)
Retrieves IMSI from Ue PHY 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:44
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.
void ReportUeSinr(uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear)
Notifies the stats calculator that an UE SINR report has occurred.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
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.
static void ReportCurrentCellRsrpSinrCallback(Ptr< PhyStatsCalculator > phyStats, std::string path, uint16_t cellId, uint16_t rnti, double rsrp, double sinr)
trace sink
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.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
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.
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:220
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:904
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. ...
void ReportCurrentCellRsrpSinr(uint16_t cellId, uint64_t imsi, uint16_t rnti, double rsrp, double sinr)
Notifies the stats calculator that an RSRP and SINR report has occurred.