A Discrete-Event Network Simulator
API
phy-tx-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 PhyTxStatsCalculator
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 ("PhyTxStatsCalculator");
31 
32 NS_OBJECT_ENSURE_REGISTERED (PhyTxStatsCalculator);
33 
35  : m_dlTxFirstWrite (true),
36  m_ulTxFirstWrite (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::PhyTxStatsCalculator")
52  .SetGroupName("Lte")
53  .AddConstructor<PhyTxStatsCalculator> ()
54  .AddAttribute ("DlTxOutputFilename",
55  "Name of the file where the downlink results will be saved.",
56  StringValue ("DlTxPhyStats.txt"),
59  .AddAttribute ("UlTxOutputFilename",
60  "Name of the file where the uplink results will be saved.",
61  StringValue ("UlTxPhyStats.txt"),
64  ;
65  return tid;
66 }
67 
68 void
69 PhyTxStatsCalculator::SetUlTxOutputFilename (std::string outputFilename)
70 {
72 }
73 
74 std::string
76 {
78 }
79 
80 void
81 PhyTxStatsCalculator::SetDlTxOutputFilename (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);
96  NS_LOG_INFO ("Write DL Tx Phy Stats in " << GetDlTxOutputFilename ().c_str ());
97 
98  std::ofstream outFile;
99  if ( m_dlTxFirstWrite == true )
100  {
101  outFile.open (GetDlOutputFilename ().c_str ());
102  if (!outFile.is_open ())
103  {
104  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
105  return;
106  }
107  m_dlTxFirstWrite = false;
108  //outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi"; // txMode is not available at dl tx side
109  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
110  outFile << std::endl;
111  }
112  else
113  {
114  outFile.open (GetDlTxOutputFilename ().c_str (), std::ios_base::app);
115  if (!outFile.is_open ())
116  {
117  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
118  return;
119  }
120  }
121 
122 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
123  outFile << params.m_timestamp << "\t";
124  outFile << (uint32_t) params.m_cellId << "\t";
125  outFile << params.m_imsi << "\t";
126  outFile << params.m_rnti << "\t";
127  //outFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
128  outFile << (uint32_t) params.m_layer << "\t";
129  outFile << (uint32_t) params.m_mcs << "\t";
130  outFile << params.m_size << "\t";
131  outFile << (uint32_t) params.m_rv << "\t";
132  outFile << (uint32_t) params.m_ndi << "\t";
133  outFile << (uint32_t) params.m_ccId << std::endl;
134  outFile.close ();
135 }
136 
137 void
139 {
140  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);
141  NS_LOG_INFO ("Write UL Tx Phy Stats in " << GetUlTxOutputFilename ().c_str ());
142 
143  std::ofstream outFile;
144  if ( m_ulTxFirstWrite == true )
145  {
146  outFile.open (GetUlTxOutputFilename ().c_str ());
147  if (!outFile.is_open ())
148  {
149  NS_LOG_ERROR ("Can't open file " << GetUlTxOutputFilename ().c_str ());
150  return;
151  }
152  m_ulTxFirstWrite = false;
153 // outFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi";
154  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
155  outFile << std::endl;
156  }
157  else
158  {
159  outFile.open (GetUlTxOutputFilename ().c_str (), std::ios_base::app);
160  if (!outFile.is_open ())
161  {
162  NS_LOG_ERROR ("Can't open file " << GetUlTxOutputFilename ().c_str ());
163  return;
164  }
165  }
166 
167 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
168  outFile << params.m_timestamp << "\t";
169  outFile << (uint32_t) params.m_cellId << "\t";
170  outFile << params.m_imsi << "\t";
171  outFile << params.m_rnti << "\t";
172  //outFile << (uint32_t) params.m_txMode << "\t";
173  outFile << (uint32_t) params.m_layer << "\t";
174  outFile << (uint32_t) params.m_mcs << "\t";
175  outFile << params.m_size << "\t";
176  outFile << (uint32_t) params.m_rv << "\t";
177  outFile << (uint32_t) params.m_ndi << "\t";
178  outFile << (uint32_t) params.m_ccId << std::endl;
179  outFile.close ();
180 }
181 
182 void
184  std::string path, PhyTransmissionStatParameters params)
185 {
186  NS_LOG_FUNCTION (phyTxStats << path);
187  uint64_t imsi = 0;
188  std::ostringstream pathAndRnti;
189  std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
190  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
191  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
192  {
193  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
194  }
195  else
196  {
197  imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
198  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
199  }
200 
201  params.m_imsi = imsi;
202  phyTxStats->DlPhyTransmission (params);
203 }
204 
205 void
207  std::string path, PhyTransmissionStatParameters params)
208 {
209  NS_LOG_FUNCTION (phyTxStats << path);
210  uint64_t imsi = 0;
211  std::ostringstream pathAndRnti;
212  pathAndRnti << path << "/" << params.m_rnti;
213  std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
214  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
215  {
216  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
217  }
218  else
219  {
220  imsi = FindImsiFromLteNetDevice (pathUePhy);
221  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
222  }
223 
224  params.m_imsi = imsi;
225  phyTxStats->UlPhyTransmission (params);
226 }
227 
228 
229 } // namespace ns3
230 
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Base class for ***StatsCalculator classes.
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
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 "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Hold variables of type string.
Definition: string.h:41
bool m_dlTxFirstWrite
When writing DL TX PHY statistics first time to file, columns description is added.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:196
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:190
void SetDlTxOutputFilename(std::string outputFilename)
Set the name of the file where the DL TX PHY statistics will be stored.
std::string GetDlTxOutputFilename(void)
Get the name of the file where the DL TX PHY statistics will be stored.
void DlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an downlink transmission has occurred.
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:194
std::string GetUlTxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
Takes care of storing the information generated at PHY layer regarding transmission.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool m_ulTxFirstWrite
When writing UL TX PHY statistics first time to file, columns description is added.
static void DlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
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.
uint16_t m_size
Size of transport block.
Definition: lte-common.h:195
virtual ~PhyTxStatsCalculator()
Destructor.
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:197
static void UlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:189
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:193
void SetUlTxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Tx PHY statistics will be stored.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
uint8_t m_ccId
component carrier id
Definition: lte-common.h:198
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
PhyTransmissionStatParameters structure.
Definition: lte-common.h:186
int64_t m_timestamp
in millisecond
Definition: lte-common.h:188
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:191
static TypeId GetTypeId(void)
Register this type.
void UlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an uplink transmission has occurred.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.