A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
33 NS_OBJECT_ENSURE_REGISTERED (PhyTxStatsCalculator)
34  ;
35 
37  : m_dlTxFirstWrite (true),
38  m_ulTxFirstWrite (true)
39 {
40  NS_LOG_FUNCTION (this);
41 
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::PhyTxStatsCalculator")
54  .AddConstructor<PhyTxStatsCalculator> ()
55  .AddAttribute ("DlTxOutputFilename",
56  "Name of the file where the downlink results will be saved.",
57  StringValue ("DlTxPhyStats.txt"),
58  MakeStringAccessor (&PhyTxStatsCalculator::SetDlTxOutputFilename),
59  MakeStringChecker ())
60  .AddAttribute ("UlTxOutputFilename",
61  "Name of the file where the uplink results will be saved.",
62  StringValue ("UlTxPhyStats.txt"),
63  MakeStringAccessor (&PhyTxStatsCalculator::SetUlTxOutputFilename),
64  MakeStringChecker ())
65  ;
66  return tid;
67 }
68 
69 void
70 PhyTxStatsCalculator::SetUlTxOutputFilename (std::string outputFilename)
71 {
73 }
74 
75 std::string
77 {
79 }
80 
81 void
82 PhyTxStatsCalculator::SetDlTxOutputFilename (std::string outputFilename)
83 {
85 }
86 
87 std::string
89 {
91 }
92 
93 void
95 {
96  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);
97  NS_LOG_INFO ("Write DL Tx Phy Stats in " << GetDlTxOutputFilename ().c_str ());
98 
99  std::ofstream outFile;
100  if ( m_dlTxFirstWrite == true )
101  {
102  outFile.open (GetDlOutputFilename ().c_str ());
103  if (!outFile.is_open ())
104  {
105  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
106  return;
107  }
108  m_dlTxFirstWrite = false;
109  //outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi"; // txMode is not available at dl tx side
110  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi";
111  outFile << std::endl;
112  }
113  else
114  {
115  outFile.open (GetDlTxOutputFilename ().c_str (), std::ios_base::app);
116  if (!outFile.is_open ())
117  {
118  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
119  return;
120  }
121  }
122 
123 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
124  outFile << params.m_timestamp << "\t";
125  outFile << (uint32_t) params.m_cellId << "\t";
126  outFile << params.m_imsi << "\t";
127  outFile << params.m_rnti << "\t";
128  //outFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
129  outFile << (uint32_t) params.m_layer << "\t";
130  outFile << (uint32_t) params.m_mcs << "\t";
131  outFile << params.m_size << "\t";
132  outFile << (uint32_t) params.m_rv << "\t";
133  outFile << (uint32_t) params.m_ndi << 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";
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 << std::endl;
178  outFile.close ();
179 }
180 
181 void
183  std::string path, PhyTransmissionStatParameters params)
184 {
185  NS_LOG_FUNCTION (phyTxStats << path);
186  uint64_t imsi = 0;
187  std::ostringstream pathAndRnti;
188  pathAndRnti << path << "/" << params.m_rnti;
189  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
190  {
191  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
192  }
193  else
194  {
195  imsi = FindImsiForEnb (path, params.m_rnti);
196  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
197  }
198 
199  params.m_imsi = imsi;
200  phyTxStats->DlPhyTransmission (params);
201 }
202 
203 void
205  std::string path, PhyTransmissionStatParameters params)
206 {
207  NS_LOG_FUNCTION (phyTxStats << path);
208  uint64_t imsi = 0;
209  std::ostringstream pathAndRnti;
210  pathAndRnti << path << "/" << params.m_rnti;
211  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
212  {
213  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
214  }
215  else
216  {
217  imsi = FindImsiForUe (path, params.m_rnti);
218  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
219  }
220 
221  params.m_imsi = imsi;
222  phyTxStats->UlPhyTransmission (params);
223 }
224 
225 
226 } // namespace ns3
227 
Doxygen introspection did not find any typical Config paths.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
hold variables of type string
Definition: string.h:19
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_INFO(msg)
Definition: log.h:298
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:128
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:122
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
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 trasmission has occurred.
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:126
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.
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 FindImsiForUe(std::string path, uint16_t rnti)
uint16_t m_size
Size of transport block.
Definition: lte-common.h:127
virtual ~PhyTxStatsCalculator()
Destructor.
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:129
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:121
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:125
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)
Definition: log.h:271
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:123
void UlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an uplink trasmission has occurred.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.