A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  .AddConstructor<PhyStatsCalculator> ()
52  .AddAttribute ("DlRsrpSinrFilename",
53  "Name of the file where the RSRP/SINR statistics will be saved.",
54  StringValue ("DlRsrpSinrStats.txt"),
56  MakeStringChecker ())
57  .AddAttribute ("UlSinrFilename",
58  "Name of the file where the UE SINR statistics will be saved.",
59  StringValue ("UlSinrStats.txt"),
60  MakeStringAccessor (&PhyStatsCalculator::SetUeSinrFilename),
61  MakeStringChecker ())
62  .AddAttribute ("UlInterferenceFilename",
63  "Name of the file where the interference statistics will be saved.",
64  StringValue ("UlInterferenceStats.txt"),
65  MakeStringAccessor (&PhyStatsCalculator::SetInterferenceFilename),
66  MakeStringChecker ())
67  ;
68  return tid;
69 }
70 
71 void
73 {
74  m_RsrpSinrFilename = filename;
75 }
76 
77 std::string
79 {
80  return m_RsrpSinrFilename;
81 }
82 
83 void
85 {
86  m_ueSinrFilename = filename;
87 }
88 
89 std::string
91 {
92  return m_ueSinrFilename;
93 }
94 
95 void
97 {
98  m_interferenceFilename = filename;
99 }
100 
101 std::string
103 {
104  return m_interferenceFilename;
105 }
106 
107 
108 
109 void
110 PhyStatsCalculator::ReportCurrentCellRsrpSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti,
111  double rsrp, double sinr)
112 {
113  NS_LOG_FUNCTION (this << cellId << imsi << rnti << rsrp << sinr);
114  NS_LOG_INFO ("Write RSRP/SINR Phy Stats in " << GetCurrentCellRsrpSinrFilename ().c_str ());
115 
116  std::ofstream outFile;
117  if ( m_RsrpSinrFirstWrite == true )
118  {
119  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str ());
120  if (!outFile.is_open ())
121  {
122  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
123  return;
124  }
125  m_RsrpSinrFirstWrite = false;
126  outFile << "% time\tcellId\tIMSI\tRNTI\trsrp\tsinr";
127  outFile << std::endl;
128  }
129  else
130  {
131  outFile.open (GetCurrentCellRsrpSinrFilename ().c_str (), std::ios_base::app);
132  if (!outFile.is_open ())
133  {
134  NS_LOG_ERROR ("Can't open file " << GetCurrentCellRsrpSinrFilename ().c_str ());
135  return;
136  }
137  }
138 
139  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
140  outFile << cellId << "\t";
141  outFile << imsi << "\t";
142  outFile << rnti << "\t";
143  outFile << rsrp << "\t";
144  outFile << sinr << std::endl;
145  outFile.close ();
146 }
147 
148 void
149 PhyStatsCalculator::ReportUeSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear)
150 {
151  NS_LOG_FUNCTION (this << cellId << imsi << rnti << sinrLinear);
152  NS_LOG_INFO ("Write SINR Linear Phy Stats in " << GetUeSinrFilename ().c_str ());
153 
154  std::ofstream outFile;
155  if ( m_UeSinrFirstWrite == true )
156  {
157  outFile.open (GetUeSinrFilename ().c_str ());
158  if (!outFile.is_open ())
159  {
160  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
161  return;
162  }
163  m_UeSinrFirstWrite = false;
164  outFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear";
165  outFile << std::endl;
166  }
167  else
168  {
169  outFile.open (GetUeSinrFilename ().c_str (), std::ios_base::app);
170  if (!outFile.is_open ())
171  {
172  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
173  return;
174  }
175  }
176 
177  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
178  outFile << cellId << "\t";
179  outFile << imsi << "\t";
180  outFile << rnti << "\t";
181  outFile << sinrLinear << std::endl;
182  outFile.close ();
183 }
184 
185 void
187 {
188  NS_LOG_FUNCTION (this << cellId << interference);
189  NS_LOG_INFO ("Write Interference Phy Stats in " << GetInterferenceFilename ().c_str ());
190 
191  std::ofstream outFile;
192  if ( m_InterferenceFirstWrite == true )
193  {
194  outFile.open (GetInterferenceFilename ().c_str ());
195  if (!outFile.is_open ())
196  {
197  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
198  return;
199  }
200  m_InterferenceFirstWrite = false;
201  outFile << "% time\tcellId\tInterference";
202  outFile << std::endl;
203  }
204  else
205  {
206  outFile.open (GetInterferenceFilename ().c_str (), std::ios_base::app);
207  if (!outFile.is_open ())
208  {
209  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
210  return;
211  }
212  }
213 
214  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
215  outFile << cellId << "\t";
216  outFile << *interference;
217  outFile.close ();
218 }
219 
220 
221 void
223  std::string path, uint16_t cellId, uint16_t rnti,
224  double rsrp, double sinr)
225 {
226  NS_LOG_FUNCTION (phyStats << path);
227  uint64_t imsi = 0;
228  std::string pathUePhy = path.substr (0, path.find ("/ReportCurrentCellRsrpSinr"));
229  if (phyStats->ExistsImsiPath (pathUePhy) == true)
230  {
231  imsi = phyStats->GetImsiPath (pathUePhy);
232  }
233  else
234  {
235  imsi = FindImsiFromUePhy (pathUePhy);
236  phyStats->SetImsiPath (pathUePhy, imsi);
237  }
238 
239  phyStats->ReportCurrentCellRsrpSinr (cellId, imsi, rnti, rsrp,sinr);
240 }
241 
242 void
244  uint16_t cellId, uint16_t rnti, double sinrLinear)
245 {
246  NS_LOG_FUNCTION (phyStats << path);
247 
248  uint64_t imsi = 0;
249  std::ostringstream pathAndRnti;
250  pathAndRnti << path << "/" << rnti;
251  std::string pathEnbMac = path.substr (0, path.find ("LteEnbPhy/ReportUeSinr"));
252  pathEnbMac += "LteEnbMac/DlScheduling";
253  if (phyStats->ExistsImsiPath (pathAndRnti.str ()) == true)
254  {
255  imsi = phyStats->GetImsiPath (pathAndRnti.str ());
256  }
257  else
258  {
259  imsi = FindImsiFromEnbMac (pathEnbMac, rnti);
260  phyStats->SetImsiPath (pathAndRnti.str (), imsi);
261  }
262 
263  phyStats->ReportUeSinr (cellId, imsi, rnti, sinrLinear);
264 }
265 
266 void
268  uint16_t cellId, Ptr<SpectrumValue> interference)
269 {
270  NS_LOG_FUNCTION (phyStats << path);
271  phyStats->ReportInterference (cellId, interference);
272 }
273 
274 
275 } // namespace ns3
Doxygen introspection did not find any typical Config paths.
static uint64_t FindImsiFromUePhy(std::string path)
#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)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
hold variables of type string
Definition: string.h:18
std::string GetInterferenceFilename(void)
Get 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)
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:170
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
void SetCurrentCellRsrpSinrFilename(std::string filename)
Set the name of the file where the RSRP/SINR statistics will be stored.
static TypeId GetTypeId(void)
static void ReportCurrentCellRsrpSinrCallback(Ptr< PhyStatsCalculator > phyStats, std::string path, uint16_t cellId, uint16_t rnti, double rsrp, double sinr)
trace sink
void SetUeSinrFilename(std::string filename)
Set the name of the file where the UE SINR statistics will be stored.
virtual ~PhyStatsCalculator()
Destructor.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
int64_t GetNanoSeconds(void) const
Definition: nstime.h:297
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:193
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::string GetCurrentCellRsrpSinrFilename(void)
Get 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)
Notifies the stats calculator that an RSRP and SINR report has occurred.