A Discrete-Event Network Simulator
API
phy-rx-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  * modified by: Marco Miozzo <mmiozzo@cttc.es>
20  * Convert MacStatsCalculator in PhyRxStatsCalculator
21  */
22 
24 #include "ns3/string.h"
25 #include <ns3/simulator.h>
26 #include <ns3/log.h>
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("PhyRxStatsCalculator");
31 
32 NS_OBJECT_ENSURE_REGISTERED (PhyRxStatsCalculator);
33 
35  : m_dlRxFirstWrite (true),
36  m_ulRxFirstWrite (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::PhyRxStatsCalculator")
52  .AddConstructor<PhyRxStatsCalculator> ()
53  .AddAttribute ("DlRxOutputFilename",
54  "Name of the file where the downlink results will be saved.",
55  StringValue ("DlRxPhyStats.txt"),
58  .AddAttribute ("UlRxOutputFilename",
59  "Name of the file where the uplink results will be saved.",
60  StringValue ("UlRxPhyStats.txt"),
63  ;
64  return tid;
65 }
66 
67 void
68 PhyRxStatsCalculator::SetUlRxOutputFilename (std::string outputFilename)
69 {
71 }
72 
73 std::string
75 {
77 }
78 
79 void
80 PhyRxStatsCalculator::SetDlRxOutputFilename (std::string outputFilename)
81 {
83 }
84 
85 std::string
87 {
89 }
90 
91 void
93 {
94  NS_LOG_FUNCTION (this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti << params.m_layer << params.m_mcs << params.m_size << params.m_rv << params.m_ndi << params.m_correctness);
95  NS_LOG_INFO ("Write DL Rx Phy Stats in " << GetDlRxOutputFilename ().c_str ());
96 
97  std::ofstream outFile;
98  if ( m_dlRxFirstWrite == true )
99  {
100  outFile.open (GetDlRxOutputFilename ().c_str ());
101  if (!outFile.is_open ())
102  {
103  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
104  return;
105  }
106  m_dlRxFirstWrite = false;
107  outFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect";
108  outFile << std::endl;
109  }
110  else
111  {
112  outFile.open (GetDlRxOutputFilename ().c_str (), std::ios_base::app);
113  if (!outFile.is_open ())
114  {
115  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
116  return;
117  }
118  }
119 
120 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
121  outFile << params.m_timestamp << "\t";
122  outFile << (uint32_t) params.m_cellId << "\t";
123  outFile << params.m_imsi << "\t";
124  outFile << params.m_rnti << "\t";
125  outFile << (uint32_t) params.m_txMode << "\t";
126  outFile << (uint32_t) params.m_layer << "\t";
127  outFile << (uint32_t) params.m_mcs << "\t";
128  outFile << params.m_size << "\t";
129  outFile << (uint32_t) params.m_rv << "\t";
130  outFile << (uint32_t) params.m_ndi << "\t";
131  outFile << (uint32_t) params.m_correctness << std::endl;
132  outFile.close ();
133 }
134 
135 void
137 {
138  NS_LOG_FUNCTION (this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti << params.m_layer << params.m_mcs << params.m_size << params.m_rv << params.m_ndi << params.m_correctness);
139  NS_LOG_INFO ("Write UL Rx Phy Stats in " << GetUlRxOutputFilename ().c_str ());
140 
141  std::ofstream outFile;
142  if ( m_ulRxFirstWrite == true )
143  {
144  outFile.open (GetUlRxOutputFilename ().c_str ());
145  if (!outFile.is_open ())
146  {
147  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
148  return;
149  }
150  m_ulRxFirstWrite = false;
151  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect";
152  outFile << std::endl;
153  }
154  else
155  {
156  outFile.open (GetUlRxOutputFilename ().c_str (), std::ios_base::app);
157  if (!outFile.is_open ())
158  {
159  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
160  return;
161  }
162  }
163 
164 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
165  outFile << params.m_timestamp << "\t";
166  outFile << (uint32_t) params.m_cellId << "\t";
167  outFile << params.m_imsi << "\t";
168  outFile << params.m_rnti << "\t";
169  outFile << (uint32_t) params.m_layer << "\t";
170  outFile << (uint32_t) params.m_mcs << "\t";
171  outFile << params.m_size << "\t";
172  outFile << (uint32_t) params.m_rv << "\t";
173  outFile << (uint32_t) params.m_ndi << "\t";
174  outFile << (uint32_t) params.m_correctness << std::endl;
175  outFile.close ();
176 }
177 
178 void
180  std::string path, PhyReceptionStatParameters params)
181 {
182  NS_LOG_FUNCTION (phyRxStats << path);
183  uint64_t imsi = 0;
184  std::ostringstream pathAndRnti;
185  pathAndRnti << path << "/" << params.m_rnti;
186  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
187  {
188  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
189  }
190  else
191  {
192  imsi = FindImsiForUe (path, params.m_rnti);
193  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
194  }
195 
196  params.m_imsi = imsi;
197  phyRxStats->DlPhyReception (params);
198 }
199 
200 void
202  std::string path, PhyReceptionStatParameters params)
203 {
204  NS_LOG_FUNCTION (phyRxStats << path);
205  uint64_t imsi = 0;
206  std::ostringstream pathAndRnti;
207  pathAndRnti << path << "/" << params.m_rnti;
208  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
209  {
210  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
211  }
212  else
213  {
214  imsi = FindImsiForEnb (path, params.m_rnti);
215  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
216  }
217 
218  params.m_imsi = imsi;
219  phyRxStats->UlPhyReception (params);
220 }
221 
222 } // namespace ns3
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Base class for ***StatsCalculator classes.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:149
#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
bool m_dlRxFirstWrite
When writing DL RX PHY statistics first time to file, columns description is added.
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:151
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void DlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an downlink reception has occurred.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
std::string GetUlRxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
virtual ~PhyRxStatsCalculator()
Destructor.
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
Retrieves IMSI from path for Enb in the attribute system.
void UlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an uplink reception has occurred.
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:148
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:152
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
static uint64_t FindImsiForUe(std::string path, uint16_t rnti)
Retrieves IMSI from path for Ue in the attribute system.
uint8_t m_txMode
the transmission Mode
Definition: lte-common.h:147
uint16_t m_size
Size of transport block.
Definition: lte-common.h:150
static void DlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
static void UlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
uint8_t m_correctness
correctness of the TB received
Definition: lte-common.h:153
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:146
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:144
std::string GetDlRxOutputFilename(void)
Get the name of the file where the DL RX PHY statistics will be stored.
#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
void SetUlRxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Rx PHY statistics will be stored.
void SetDlRxOutputFilename(std::string outputFilename)
Set the name of the file where the DL RX PHY statistics will be stored.
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:145
static TypeId GetTypeId(void)
Register this type.
a unique identifier for an interface.
Definition: type-id.h:51
bool m_ulRxFirstWrite
When writing UL RX PHY statistics first time to file, columns description is added.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.