A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
33 NS_OBJECT_ENSURE_REGISTERED (PhyRxStatsCalculator)
34  ;
35 
37  : m_dlRxFirstWrite (true),
38  m_ulRxFirstWrite (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::PhyRxStatsCalculator")
54  .AddConstructor<PhyRxStatsCalculator> ()
55  .AddAttribute ("DlRxOutputFilename",
56  "Name of the file where the downlink results will be saved.",
57  StringValue ("DlRxPhyStats.txt"),
58  MakeStringAccessor (&PhyRxStatsCalculator::SetDlRxOutputFilename),
59  MakeStringChecker ())
60  .AddAttribute ("UlRxOutputFilename",
61  "Name of the file where the uplink results will be saved.",
62  StringValue ("UlRxPhyStats.txt"),
63  MakeStringAccessor (&PhyRxStatsCalculator::SetUlRxOutputFilename),
64  MakeStringChecker ())
65  ;
66  return tid;
67 }
68 
69 void
70 PhyRxStatsCalculator::SetUlRxOutputFilename (std::string outputFilename)
71 {
73 }
74 
75 std::string
77 {
79 }
80 
81 void
82 PhyRxStatsCalculator::SetDlRxOutputFilename (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 << params.m_correctness);
97  NS_LOG_INFO ("Write DL Rx Phy Stats in " << GetDlRxOutputFilename ().c_str ());
98 
99  std::ofstream outFile;
100  if ( m_dlRxFirstWrite == true )
101  {
102  outFile.open (GetDlRxOutputFilename ().c_str ());
103  if (!outFile.is_open ())
104  {
105  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
106  return;
107  }
108  m_dlRxFirstWrite = false;
109  outFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect";
110  outFile << std::endl;
111  }
112  else
113  {
114  outFile.open (GetDlRxOutputFilename ().c_str (), std::ios_base::app);
115  if (!outFile.is_open ())
116  {
117  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().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";
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_correctness << 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 << params.m_correctness);
141  NS_LOG_INFO ("Write UL Rx Phy Stats in " << GetUlRxOutputFilename ().c_str ());
142 
143  std::ofstream outFile;
144  if ( m_ulRxFirstWrite == true )
145  {
146  outFile.open (GetUlRxOutputFilename ().c_str ());
147  if (!outFile.is_open ())
148  {
149  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
150  return;
151  }
152  m_ulRxFirstWrite = false;
153  outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect";
154  outFile << std::endl;
155  }
156  else
157  {
158  outFile.open (GetUlRxOutputFilename ().c_str (), std::ios_base::app);
159  if (!outFile.is_open ())
160  {
161  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
162  return;
163  }
164  }
165 
166 // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
167  outFile << params.m_timestamp << "\t";
168  outFile << (uint32_t) params.m_cellId << "\t";
169  outFile << params.m_imsi << "\t";
170  outFile << params.m_rnti << "\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 << "\t";
176  outFile << (uint32_t) params.m_correctness << std::endl;
177  outFile.close ();
178 }
179 
180 void
182  std::string path, PhyReceptionStatParameters params)
183 {
184  NS_LOG_FUNCTION (phyRxStats << path);
185  uint64_t imsi = 0;
186  std::ostringstream pathAndRnti;
187  pathAndRnti << path << "/" << params.m_rnti;
188  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
189  {
190  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
191  }
192  else
193  {
194  imsi = FindImsiForUe (path, params.m_rnti);
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  pathAndRnti << path << "/" << params.m_rnti;
210  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
211  {
212  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
213  }
214  else
215  {
216  imsi = FindImsiForEnb (path, params.m_rnti);
217  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
218  }
219 
220  params.m_imsi = imsi;
221  phyRxStats->UlPhyReception (params);
222 }
223 
224 } // namespace ns3
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
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:141
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
hold variables of type string
Definition: string.h:19
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:143
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void DlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an downlink reception has occurred.
#define NS_LOG_INFO(msg)
Definition: log.h:298
std::string GetUlRxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
virtual ~PhyRxStatsCalculator()
Destructor.
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
void UlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an uplink reception has occurred.
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:140
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:144
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)
uint8_t m_txMode
the transmission Mode
Definition: lte-common.h:139
uint16_t m_size
Size of transport block.
Definition: lte-common.h:142
static void DlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
static void UlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
uint8_t m_correctness
correctness of the TB received
Definition: lte-common.h:145
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:138
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:136
std::string GetDlRxOutputFilename(void)
Get the name of the file where the DL RX PHY statistics will be stored.
#define NS_LOG_ERROR(msg)
Definition: log.h:271
void SetUlRxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Rx PHY statistics will be stored.
void SetDlRxOutputFilename(std::string outputFilename)
Set the name of the file where the DL RX PHY statistics will be stored.
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:137
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.