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 
31 NS_OBJECT_ENSURE_REGISTERED (PhyStatsCalculator)
32  ;
33 
35  : m_RsrpSinrFirstWrite (true),
36  m_UeSinrFirstWrite (true),
37  m_InterferenceFirstWrite (true)
38 {
39  NS_LOG_FUNCTION (this);
40 
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::PhyStatsCalculator")
53  .AddConstructor<PhyStatsCalculator> ()
54  .AddAttribute ("DlRsrpSinrFilename",
55  "Name of the file where the RSRP/SINR statistics will be saved.",
56  StringValue ("DlRsrpSinrStats.txt"),
58  MakeStringChecker ())
59  .AddAttribute ("UlSinrFilename",
60  "Name of the file where the UE SINR statistics will be saved.",
61  StringValue ("UlSinrStats.txt"),
62  MakeStringAccessor (&PhyStatsCalculator::SetUeSinrFilename),
63  MakeStringChecker ())
64  .AddAttribute ("UlInterferenceFilename",
65  "Name of the file where the interference statistics will be saved.",
66  StringValue ("UlInterferenceStats.txt"),
67  MakeStringAccessor (&PhyStatsCalculator::SetInterferenceFilename),
68  MakeStringChecker ())
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)
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";
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 << std::endl;
147  outFile.close ();
148 }
149 
150 void
151 PhyStatsCalculator::ReportUeSinr (uint16_t cellId, uint64_t imsi, uint16_t rnti, double sinrLinear)
152 {
153  NS_LOG_FUNCTION (this << cellId << imsi << rnti << sinrLinear);
154  NS_LOG_INFO ("Write SINR Linear Phy Stats in " << GetUeSinrFilename ().c_str ());
155 
156  std::ofstream outFile;
157  if ( m_UeSinrFirstWrite == true )
158  {
159  outFile.open (GetUeSinrFilename ().c_str ());
160  if (!outFile.is_open ())
161  {
162  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
163  return;
164  }
165  m_UeSinrFirstWrite = false;
166  outFile << "% time\tcellId\tIMSI\tRNTI\tsinrLinear";
167  outFile << std::endl;
168  }
169  else
170  {
171  outFile.open (GetUeSinrFilename ().c_str (), std::ios_base::app);
172  if (!outFile.is_open ())
173  {
174  NS_LOG_ERROR ("Can't open file " << GetUeSinrFilename ().c_str ());
175  return;
176  }
177  }
178 
179  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
180  outFile << cellId << "\t";
181  outFile << imsi << "\t";
182  outFile << rnti << "\t";
183  outFile << sinrLinear << std::endl;
184  outFile.close ();
185 }
186 
187 void
189 {
190  NS_LOG_FUNCTION (this << cellId << interference);
191  NS_LOG_INFO ("Write Interference Phy Stats in " << GetInterferenceFilename ().c_str ());
192 
193  std::ofstream outFile;
194  if ( m_InterferenceFirstWrite == true )
195  {
196  outFile.open (GetInterferenceFilename ().c_str ());
197  if (!outFile.is_open ())
198  {
199  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
200  return;
201  }
202  m_InterferenceFirstWrite = false;
203  outFile << "% time\tcellId\tInterference";
204  outFile << std::endl;
205  }
206  else
207  {
208  outFile.open (GetInterferenceFilename ().c_str (), std::ios_base::app);
209  if (!outFile.is_open ())
210  {
211  NS_LOG_ERROR ("Can't open file " << GetInterferenceFilename ().c_str ());
212  return;
213  }
214  }
215 
216  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
217  outFile << cellId << "\t";
218  outFile << *interference;
219  outFile.close ();
220 }
221 
222 
223 void
225  std::string path, uint16_t cellId, uint16_t rnti,
226  double rsrp, double sinr)
227 {
228  NS_LOG_FUNCTION (phyStats << path);
229  uint64_t imsi = 0;
230  std::string pathUePhy = path.substr (0, path.find ("/ReportCurrentCellRsrpSinr"));
231  if (phyStats->ExistsImsiPath (pathUePhy) == true)
232  {
233  imsi = phyStats->GetImsiPath (pathUePhy);
234  }
235  else
236  {
237  imsi = FindImsiFromUePhy (pathUePhy);
238  phyStats->SetImsiPath (pathUePhy, imsi);
239  }
240 
241  phyStats->ReportCurrentCellRsrpSinr (cellId, imsi, rnti, rsrp,sinr);
242 }
243 
244 void
246  uint16_t cellId, uint16_t rnti, double sinrLinear)
247 {
248  NS_LOG_FUNCTION (phyStats << path);
249 
250  uint64_t imsi = 0;
251  std::ostringstream pathAndRnti;
252  pathAndRnti << path << "/" << rnti;
253  std::string pathEnbMac = path.substr (0, path.find ("LteEnbPhy/ReportUeSinr"));
254  pathEnbMac += "LteEnbMac/DlScheduling";
255  if (phyStats->ExistsImsiPath (pathAndRnti.str ()) == true)
256  {
257  imsi = phyStats->GetImsiPath (pathAndRnti.str ());
258  }
259  else
260  {
261  imsi = FindImsiFromEnbMac (pathEnbMac, rnti);
262  phyStats->SetImsiPath (pathAndRnti.str (), imsi);
263  }
264 
265  phyStats->ReportUeSinr (cellId, imsi, rnti, sinrLinear);
266 }
267 
268 void
270  uint16_t cellId, Ptr<SpectrumValue> interference)
271 {
272  NS_LOG_FUNCTION (phyStats << path);
273  phyStats->ReportInterference (cellId, interference);
274 }
275 
276 
277 } // namespace ns3
Doxygen introspection did not find any typical Config paths.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
static uint64_t FindImsiFromUePhy(std::string path)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
hold variables of type string
Definition: string.h:19
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.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_INFO(msg)
Definition: log.h:298
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:299
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)
Definition: log.h:271
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
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.