A Discrete-Event Network Simulator
API
phy-tx-stats-calculator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Jaume Nin <jnin@cttc.es>
18  * modified by: Marco Miozzo <mmiozzo@cttc.es>
19  * Convert MacStatsCalculator in PhyTxStatsCalculator
20  */
21 
23 
24 #include "ns3/string.h"
25 #include <ns3/log.h>
26 #include <ns3/simulator.h>
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("PhyTxStatsCalculator");
32 
33 NS_OBJECT_ENSURE_REGISTERED(PhyTxStatsCalculator);
34 
36  : m_dlTxFirstWrite(true),
37  m_ulTxFirstWrite(true)
38 {
39  NS_LOG_FUNCTION(this);
40 }
41 
43 {
44  NS_LOG_FUNCTION(this);
45  if (m_dlTxOutFile.is_open())
46  {
47  m_dlTxOutFile.close();
48  }
49 
50  if (m_ulTxOutFile.is_open())
51  {
52  m_ulTxOutFile.close();
53  }
54 }
55 
56 TypeId
58 {
59  static TypeId tid =
60  TypeId("ns3::PhyTxStatsCalculator")
62  .SetGroupName("Lte")
63  .AddConstructor<PhyTxStatsCalculator>()
64  .AddAttribute("DlTxOutputFilename",
65  "Name of the file where the downlink results will be saved.",
66  StringValue("DlTxPhyStats.txt"),
69  .AddAttribute("UlTxOutputFilename",
70  "Name of the file where the uplink results will be saved.",
71  StringValue("UlTxPhyStats.txt"),
74  return tid;
75 }
76 
77 void
79 {
81 }
82 
83 std::string
85 {
87 }
88 
89 void
91 {
93 }
94 
95 std::string
97 {
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
105  << params.m_layer << params.m_mcs << params.m_size << params.m_rv
106  << params.m_ndi);
107  NS_LOG_INFO("Write DL Tx Phy Stats in " << GetDlTxOutputFilename());
108 
109  if (m_dlTxFirstWrite)
110  {
112  if (!m_dlTxOutFile.is_open())
113  {
114  NS_LOG_ERROR("Can't open file " << GetDlTxOutputFilename());
115  return;
116  }
117  m_dlTxFirstWrite = false;
118  m_dlTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
119  m_dlTxOutFile << "\n";
120  }
121 
122  m_dlTxOutFile << params.m_timestamp << "\t";
123  m_dlTxOutFile << (uint32_t)params.m_cellId << "\t";
124  m_dlTxOutFile << params.m_imsi << "\t";
125  m_dlTxOutFile << params.m_rnti << "\t";
126  // m_dlTxOutFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
127  m_dlTxOutFile << (uint32_t)params.m_layer << "\t";
128  m_dlTxOutFile << (uint32_t)params.m_mcs << "\t";
129  m_dlTxOutFile << params.m_size << "\t";
130  m_dlTxOutFile << (uint32_t)params.m_rv << "\t";
131  m_dlTxOutFile << (uint32_t)params.m_ndi << "\t";
132  m_dlTxOutFile << (uint32_t)params.m_ccId << std::endl;
133 }
134 
135 void
137 {
138  NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
139  << params.m_layer << params.m_mcs << params.m_size << params.m_rv
140  << params.m_ndi);
141  NS_LOG_INFO("Write UL Tx Phy Stats in " << GetUlTxOutputFilename());
142 
143  if (m_ulTxFirstWrite)
144  {
146  if (!m_ulTxOutFile.is_open())
147  {
148  NS_LOG_ERROR("Can't open file " << GetUlTxOutputFilename());
149  return;
150  }
151  m_ulTxFirstWrite = false;
152  // m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi";
153  m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
154  m_ulTxOutFile << "\n";
155  }
156 
157  m_ulTxOutFile << params.m_timestamp << "\t";
158  m_ulTxOutFile << (uint32_t)params.m_cellId << "\t";
159  m_ulTxOutFile << params.m_imsi << "\t";
160  m_ulTxOutFile << params.m_rnti << "\t";
161  // m_ulTxOutFile << (uint32_t) params.m_txMode << "\t";
162  m_ulTxOutFile << (uint32_t)params.m_layer << "\t";
163  m_ulTxOutFile << (uint32_t)params.m_mcs << "\t";
164  m_ulTxOutFile << params.m_size << "\t";
165  m_ulTxOutFile << (uint32_t)params.m_rv << "\t";
166  m_ulTxOutFile << (uint32_t)params.m_ndi << "\t";
167  m_ulTxOutFile << (uint32_t)params.m_ccId << std::endl;
168 }
169 
170 void
172  std::string path,
174 {
175  NS_LOG_FUNCTION(phyTxStats << path);
176  uint64_t imsi = 0;
177  std::ostringstream pathAndRnti;
178  std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
179  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
180  if (phyTxStats->ExistsImsiPath(pathAndRnti.str()))
181  {
182  imsi = phyTxStats->GetImsiPath(pathAndRnti.str());
183  }
184  else
185  {
186  imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
187  phyTxStats->SetImsiPath(pathAndRnti.str(), imsi);
188  }
189 
190  params.m_imsi = imsi;
191  phyTxStats->DlPhyTransmission(params);
192 }
193 
194 void
196  std::string path,
198 {
199  NS_LOG_FUNCTION(phyTxStats << path);
200  uint64_t imsi = 0;
201  std::ostringstream pathAndRnti;
202  pathAndRnti << path << "/" << params.m_rnti;
203  std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
204  if (phyTxStats->ExistsImsiPath(pathAndRnti.str()))
205  {
206  imsi = phyTxStats->GetImsiPath(pathAndRnti.str());
207  }
208  else
209  {
210  imsi = FindImsiFromLteNetDevice(pathUePhy);
211  phyTxStats->SetImsiPath(pathAndRnti.str(), imsi);
212  }
213 
214  params.m_imsi = imsi;
215  phyTxStats->UlPhyTransmission(params);
216 }
217 
218 } // namespace ns3
Base class for ***StatsCalculator classes.
std::string GetUlOutputFilename()
Get the name of the file where the uplink statistics will be stored.
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
static uint64_t FindImsiFromEnbRlcPath(std::string path)
Retrieves IMSI from Enb RLC path in the attribute system.
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
std::string GetDlOutputFilename()
Get the name of the file where the downlink statistics will be stored.
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
Takes care of storing the information generated at PHY layer regarding transmission.
bool m_ulTxFirstWrite
When writing UL TX PHY statistics first time to file, columns description is added.
void SetDlTxOutputFilename(std::string outputFilename)
Set the name of the file where the DL TX PHY statistics will be stored.
void SetUlTxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Tx PHY statistics will be stored.
bool m_dlTxFirstWrite
When writing DL TX PHY statistics first time to file, columns description is added.
static void DlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
std::ofstream m_ulTxOutFile
UL TX PHY statistics output trace file.
void DlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an downlink transmission has occurred.
std::string GetDlTxOutputFilename()
Get the name of the file where the DL TX PHY statistics will be stored.
std::ofstream m_dlTxOutFile
DL TX PHY statistics output trace file.
void UlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an uplink transmission has occurred.
std::string GetUlTxOutputFilename()
Get the name of the file where the UL RX PHY statistics will be stored.
static TypeId GetTypeId()
Register this type.
static void UlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
~PhyTxStatsCalculator() override
Destructor.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Hold variables of type string.
Definition: string.h:56
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeStringChecker()
Definition: string.cc:30
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:57
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
PhyTransmissionStatParameters structure.
Definition: lte-common.h:188