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  .SetGroupName ("Lte")
53  .AddConstructor<PhyRxStatsCalculator> ()
54  .AddAttribute ("DlRxOutputFilename",
55  "Name of the file where the downlink results will be saved.",
56  StringValue ("DlRxPhyStats.txt"),
59  .AddAttribute ("UlRxOutputFilename",
60  "Name of the file where the uplink results will be saved.",
61  StringValue ("UlRxPhyStats.txt"),
64  ;
65  return tid;
66 }
67 
68 void
69 PhyRxStatsCalculator::SetUlRxOutputFilename (std::string outputFilename)
70 {
72 }
73 
74 std::string
76 {
78 }
79 
80 void
81 PhyRxStatsCalculator::SetDlRxOutputFilename (std::string outputFilename)
82 {
84 }
85 
86 std::string
88 {
90 }
91 
92 void
94 {
95  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);
96  NS_LOG_INFO ("Write DL Rx Phy Stats in " << GetDlRxOutputFilename ().c_str ());
97 
98  std::ofstream outFile;
99  if ( m_dlRxFirstWrite == true )
100  {
101  outFile.open (GetDlRxOutputFilename ().c_str ());
102  if (!outFile.is_open ())
103  {
104  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
105  return;
106  }
107  m_dlRxFirstWrite = false;
108  outFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
109  outFile << std::endl;
110  }
111  else
112  {
113  outFile.open (GetDlRxOutputFilename ().c_str (), std::ios_base::app);
114  if (!outFile.is_open ())
115  {
116  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
117  return;
118  }
119  }
120 
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 << "\t";
132  outFile << (uint32_t) params.m_ccId << std::endl;
133  outFile.close ();
134 }
135 
136 void
138 {
139  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);
140  NS_LOG_INFO ("Write UL Rx Phy Stats in " << GetUlRxOutputFilename ().c_str ());
141 
142  std::ofstream outFile;
143  if ( m_ulRxFirstWrite == true )
144  {
145  outFile.open (GetUlRxOutputFilename ().c_str ());
146  if (!outFile.is_open ())
147  {
148  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
149  return;
150  }
151  m_ulRxFirstWrite = false;
152  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
153  outFile << std::endl;
154  }
155  else
156  {
157  outFile.open (GetUlRxOutputFilename ().c_str (), std::ios_base::app);
158  if (!outFile.is_open ())
159  {
160  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
161  return;
162  }
163  }
164 
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 << "\t";
175  outFile << (uint32_t) params.m_ccId << std::endl;
176  outFile.close ();
177 }
178 
179 void
181  std::string path, PhyReceptionStatParameters params)
182 {
183  NS_LOG_FUNCTION (phyRxStats << path);
184  uint64_t imsi = 0;
185  std::ostringstream pathAndRnti;
186  pathAndRnti << path << "/" << params.m_rnti;
187  std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
188  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
189  {
190  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
191  }
192  else
193  {
194  imsi = FindImsiFromLteNetDevice (pathUePhy);
195  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
196  }
197 
198  params.m_imsi = imsi;
199  phyRxStats->DlPhyReception (params);
200 }
201 
202 void
204  std::string path, PhyReceptionStatParameters params)
205 {
206  NS_LOG_FUNCTION (phyRxStats << path);
207  uint64_t imsi = 0;
208  std::ostringstream pathAndRnti;
209  std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
210  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
211  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
212  {
213  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
214  }
215  else
216  {
217  imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
218  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
219  }
220 
221  params.m_imsi = imsi;
222  phyRxStats->UlPhyReception (params);
223 }
224 
225 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::PhyReceptionStatParameters::m_imsi
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:216
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::PhyReceptionStatParameters::m_rv
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:222
ns3::PhyRxStatsCalculator
Takes care of storing the information generated at PHY layer regarding reception.
Definition: phy-rx-stats-calculator.h:51
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::LteStatsCalculator::SetDlOutputFilename
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
Definition: lte-stats-calculator.cc:75
ns3::PhyReceptionStatParameters::m_mcs
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:220
ns3::PhyRxStatsCalculator::SetDlRxOutputFilename
void SetDlRxOutputFilename(std::string outputFilename)
Set the name of the file where the DL RX PHY statistics will be stored.
Definition: phy-rx-stats-calculator.cc:81
ns3::LteStatsCalculator::FindImsiFromLteNetDevice
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
Definition: lte-stats-calculator.cc:189
ns3::PhyRxStatsCalculator::SetUlRxOutputFilename
void SetUlRxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Rx PHY statistics will be stored.
Definition: phy-rx-stats-calculator.cc:69
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::PhyReceptionStatParameters::m_timestamp
int64_t m_timestamp
in millisecond
Definition: lte-common.h:214
ns3::PhyRxStatsCalculator::PhyRxStatsCalculator
PhyRxStatsCalculator()
Constructor.
Definition: phy-rx-stats-calculator.cc:34
ns3::LteStatsCalculator
Base class for ***StatsCalculator classes.
Definition: lte-stats-calculator.h:39
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::PhyRxStatsCalculator::~PhyRxStatsCalculator
virtual ~PhyRxStatsCalculator()
Destructor.
Definition: phy-rx-stats-calculator.cc:42
ns3::PhyRxStatsCalculator::DlPhyReception
void DlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an downlink reception has occurred.
Definition: phy-rx-stats-calculator.cc:93
ns3::PhyRxStatsCalculator::GetDlRxOutputFilename
std::string GetDlRxOutputFilename(void)
Get the name of the file where the DL RX PHY statistics will be stored.
Definition: phy-rx-stats-calculator.cc:87
ns3::PhyRxStatsCalculator::m_ulRxFirstWrite
bool m_ulRxFirstWrite
When writing UL RX PHY statistics first time to file, columns description is added.
Definition: phy-rx-stats-calculator.h:143
phy-rx-stats-calculator.h
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::PhyRxStatsCalculator::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: phy-rx-stats-calculator.cc:48
ns3::PhyReceptionStatParameters::m_ndi
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:223
ns3::PhyRxStatsCalculator::m_dlRxFirstWrite
bool m_dlRxFirstWrite
When writing DL RX PHY statistics first time to file, columns description is added.
Definition: phy-rx-stats-calculator.h:135
ns3::PhyRxStatsCalculator::UlPhyReception
void UlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an uplink reception has occurred.
Definition: phy-rx-stats-calculator.cc:137
ns3::PhyRxStatsCalculator::DlPhyReceptionCallback
static void DlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
Definition: phy-rx-stats-calculator.cc:180
ns3::PhyReceptionStatParameters::m_layer
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:219
ns3::LteStatsCalculator::GetUlOutputFilename
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
Definition: lte-stats-calculator.cc:69
ns3::PhyRxStatsCalculator::UlPhyReceptionCallback
static void UlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
Definition: phy-rx-stats-calculator.cc:203
ns3::PhyReceptionStatParameters::m_ccId
uint8_t m_ccId
component carrier id
Definition: lte-common.h:225
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
NS_LOG_ERROR
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
ns3::LteStatsCalculator::GetDlOutputFilename
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.
Definition: lte-stats-calculator.cc:81
ns3::PhyReceptionStatParameters::m_size
uint16_t m_size
Size of transport block.
Definition: lte-common.h:221
ns3::PhyReceptionStatParameters::m_rnti
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:217
ns3::PhyReceptionStatParameters::m_correctness
uint8_t m_correctness
correctness of the TB received
Definition: lte-common.h:224
ns3::PhyRxStatsCalculator::GetUlRxOutputFilename
std::string GetUlRxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
Definition: phy-rx-stats-calculator.cc:75
ns3::PhyReceptionStatParameters::m_txMode
uint8_t m_txMode
the transmission Mode
Definition: lte-common.h:218
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::LteStatsCalculator::FindImsiFromEnbRlcPath
static uint64_t FindImsiFromEnbRlcPath(std::string path)
Retrieves IMSI from Enb RLC path in the attribute system.
Definition: lte-stats-calculator.cc:141
ns3::MakeStringChecker
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
ns3::PhyReceptionStatParameters
PhyReceptionStatParameters structure.
Definition: lte-common.h:213
ns3::LteStatsCalculator::SetUlOutputFilename
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
Definition: lte-stats-calculator.cc:63
ns3::PhyReceptionStatParameters::m_cellId
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:215
ns3::MakeStringAccessor
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