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 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  .AddConstructor<PhyTxStatsCalculator> ()
53  .AddAttribute ("DlTxOutputFilename",
54  "Name of the file where the downlink results will be saved.",
55  StringValue ("DlTxPhyStats.txt"),
56  MakeStringAccessor (&PhyTxStatsCalculator::SetDlTxOutputFilename),
57  MakeStringChecker ())
58  .AddAttribute ("UlTxOutputFilename",
59  "Name of the file where the uplink results will be saved.",
60  StringValue ("UlTxPhyStats.txt"),
61  MakeStringAccessor (&PhyTxStatsCalculator::SetUlTxOutputFilename),
62  MakeStringChecker ())
63  ;
64  return tid;
65 }
66 
67 void
68 PhyTxStatsCalculator::SetUlTxOutputFilename (std::string outputFilename)
69 {
71 }
72 
73 std::string
75 {
77 }
78 
79 void
80 PhyTxStatsCalculator::SetDlTxOutputFilename (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);
95  NS_LOG_INFO ("Write DL Tx Phy Stats in " << GetDlTxOutputFilename ().c_str ());
96 
97  std::ofstream outFile;
98  if ( m_dlTxFirstWrite == true )
99  {
100  outFile.open (GetDlOutputFilename ().c_str ());
101  if (!outFile.is_open ())
102  {
103  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
104  return;
105  }
106  m_dlTxFirstWrite = false;
107  //outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi"; // txMode is not available at dl tx side
108  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi";
109  outFile << std::endl;
110  }
111  else
112  {
113  outFile.open (GetDlTxOutputFilename ().c_str (), std::ios_base::app);
114  if (!outFile.is_open ())
115  {
116  NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
117  return;
118  }
119  }
120 
121 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
122  outFile << params.m_timestamp << "\t";
123  outFile << (uint32_t) params.m_cellId << "\t";
124  outFile << params.m_imsi << "\t";
125  outFile << params.m_rnti << "\t";
126  //outFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
127  outFile << (uint32_t) params.m_layer << "\t";
128  outFile << (uint32_t) params.m_mcs << "\t";
129  outFile << params.m_size << "\t";
130  outFile << (uint32_t) params.m_rv << "\t";
131  outFile << (uint32_t) params.m_ndi << 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);
139  NS_LOG_INFO ("Write UL Tx Phy Stats in " << GetUlTxOutputFilename ().c_str ());
140 
141  std::ofstream outFile;
142  if ( m_ulTxFirstWrite == true )
143  {
144  outFile.open (GetUlTxOutputFilename ().c_str ());
145  if (!outFile.is_open ())
146  {
147  NS_LOG_ERROR ("Can't open file " << GetUlTxOutputFilename ().c_str ());
148  return;
149  }
150  m_ulTxFirstWrite = false;
151 // outFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi";
152  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi";
153  outFile << std::endl;
154  }
155  else
156  {
157  outFile.open (GetUlTxOutputFilename ().c_str (), std::ios_base::app);
158  if (!outFile.is_open ())
159  {
160  NS_LOG_ERROR ("Can't open file " << GetUlTxOutputFilename ().c_str ());
161  return;
162  }
163  }
164 
165 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
166  outFile << params.m_timestamp << "\t";
167  outFile << (uint32_t) params.m_cellId << "\t";
168  outFile << params.m_imsi << "\t";
169  outFile << params.m_rnti << "\t";
170  //outFile << (uint32_t) params.m_txMode << "\t";
171  outFile << (uint32_t) params.m_layer << "\t";
172  outFile << (uint32_t) params.m_mcs << "\t";
173  outFile << params.m_size << "\t";
174  outFile << (uint32_t) params.m_rv << "\t";
175  outFile << (uint32_t) params.m_ndi << std::endl;
176  outFile.close ();
177 }
178 
179 void
181  std::string path, PhyTransmissionStatParameters params)
182 {
183  NS_LOG_FUNCTION (phyTxStats << path);
184  uint64_t imsi = 0;
185  std::ostringstream pathAndRnti;
186  pathAndRnti << path << "/" << params.m_rnti;
187  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
188  {
189  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
190  }
191  else
192  {
193  imsi = FindImsiForEnb (path, params.m_rnti);
194  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
195  }
196 
197  params.m_imsi = imsi;
198  phyTxStats->DlPhyTransmission (params);
199 }
200 
201 void
203  std::string path, PhyTransmissionStatParameters params)
204 {
205  NS_LOG_FUNCTION (phyTxStats << path);
206  uint64_t imsi = 0;
207  std::ostringstream pathAndRnti;
208  pathAndRnti << path << "/" << params.m_rnti;
209  if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
210  {
211  imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
212  }
213  else
214  {
215  imsi = FindImsiForUe (path, params.m_rnti);
216  phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
217  }
218 
219  params.m_imsi = imsi;
220  phyTxStats->UlPhyTransmission (params);
221 }
222 
223 
224 } // namespace ns3
225 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
hold variables of type string
Definition: string.h:19
#define NS_LOG_INFO(msg)
Definition: log.h:264
void SetUlOutputFilename(std::string outputFilename)
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
void SetDlTxOutputFilename(std::string outputFilename)
void DlPhyTransmission(PhyTransmissionStatParameters params)
std::string GetUlOutputFilename(void)
static void DlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
void SetDlOutputFilename(std::string outputFilename)
static uint64_t FindImsiForUe(std::string path, uint16_t rnti)
static void UlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
void SetUlTxOutputFilename(std::string outputFilename)
#define NS_LOG_ERROR(msg)
Definition: log.h:237
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void UlPhyTransmission(PhyTransmissionStatParameters params)
std::string GetDlOutputFilename(void)