A Discrete-Event Network Simulator
API
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 NS_OBJECT_ENSURE_REGISTERED (PhyRxStatsCalculator);
33 
35  : m_dlRxFirstWrite (true),
36  m_ulRxFirstWrite (true)
37 {
38  NS_LOG_FUNCTION (this);
39 
40 }
41 
43 {
44  NS_LOG_FUNCTION (this);
45  if (m_dlRxOutFile.is_open())
46  {
47  m_dlRxOutFile.close();
48  }
49 
50  if (m_ulRxOutFile.is_open())
51  {
52  m_ulRxOutFile.close();
53  }
54 }
55 
56 TypeId
58 {
59  static TypeId tid = TypeId ("ns3::PhyRxStatsCalculator")
61  .SetGroupName ("Lte")
62  .AddConstructor<PhyRxStatsCalculator> ()
63  .AddAttribute ("DlRxOutputFilename",
64  "Name of the file where the downlink results will be saved.",
65  StringValue ("DlRxPhyStats.txt"),
68  .AddAttribute ("UlRxOutputFilename",
69  "Name of the file where the uplink results will be saved.",
70  StringValue ("UlRxPhyStats.txt"),
73  ;
74  return tid;
75 }
76 
77 void
78 PhyRxStatsCalculator::SetUlRxOutputFilename (std::string outputFilename)
79 {
81 }
82 
83 std::string
85 {
87 }
88 
89 void
90 PhyRxStatsCalculator::SetDlRxOutputFilename (std::string outputFilename)
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 << params.m_layer << params.m_mcs << params.m_size << params.m_rv << params.m_ndi << params.m_correctness);
105  NS_LOG_INFO ("Write DL Rx Phy Stats in " << GetDlRxOutputFilename ().c_str ());
106 
107  if ( m_dlRxFirstWrite == true )
108  {
109  m_dlRxOutFile.open (GetDlRxOutputFilename ().c_str ());
110  if (!m_dlRxOutFile.is_open ())
111  {
112  NS_LOG_ERROR ("Can't open file " << GetDlRxOutputFilename ().c_str ());
113  return;
114  }
115  m_dlRxFirstWrite = false;
116  m_dlRxOutFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
117  m_dlRxOutFile << "\n";
118  }
119 
120  m_dlRxOutFile << params.m_timestamp << "\t";
121  m_dlRxOutFile << (uint32_t) params.m_cellId << "\t";
122  m_dlRxOutFile << params.m_imsi << "\t";
123  m_dlRxOutFile << params.m_rnti << "\t";
124  m_dlRxOutFile << (uint32_t) params.m_txMode << "\t";
125  m_dlRxOutFile << (uint32_t) params.m_layer << "\t";
126  m_dlRxOutFile << (uint32_t) params.m_mcs << "\t";
127  m_dlRxOutFile << params.m_size << "\t";
128  m_dlRxOutFile << (uint32_t) params.m_rv << "\t";
129  m_dlRxOutFile << (uint32_t) params.m_ndi << "\t";
130  m_dlRxOutFile << (uint32_t) params.m_correctness << "\t";
131  m_dlRxOutFile << (uint32_t) params.m_ccId << std::endl;
132 }
133 
134 void
136 {
137  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);
138  NS_LOG_INFO ("Write UL Rx Phy Stats in " << GetUlRxOutputFilename ().c_str ());
139 
140  if ( m_ulRxFirstWrite == true )
141  {
142  m_ulRxOutFile.open (GetUlRxOutputFilename ().c_str ());
143  if (!m_ulRxOutFile.is_open ())
144  {
145  NS_LOG_ERROR ("Can't open file " << GetUlRxOutputFilename ().c_str ());
146  return;
147  }
148  m_ulRxFirstWrite = false;
149  m_ulRxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
150  m_ulRxOutFile << "\n";
151  }
152 
153  m_ulRxOutFile << params.m_timestamp << "\t";
154  m_ulRxOutFile << (uint32_t) params.m_cellId << "\t";
155  m_ulRxOutFile << params.m_imsi << "\t";
156  m_ulRxOutFile << params.m_rnti << "\t";
157  m_ulRxOutFile << (uint32_t) params.m_layer << "\t";
158  m_ulRxOutFile << (uint32_t) params.m_mcs << "\t";
159  m_ulRxOutFile << params.m_size << "\t";
160  m_ulRxOutFile << (uint32_t) params.m_rv << "\t";
161  m_ulRxOutFile << (uint32_t) params.m_ndi << "\t";
162  m_ulRxOutFile << (uint32_t) params.m_correctness << "\t";
163  m_ulRxOutFile << (uint32_t) params.m_ccId << std::endl;
164 }
165 
166 void
168  std::string path, PhyReceptionStatParameters params)
169 {
170  NS_LOG_FUNCTION (phyRxStats << path);
171  uint64_t imsi = 0;
172  std::ostringstream pathAndRnti;
173  pathAndRnti << path << "/" << params.m_rnti;
174  std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
175  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
176  {
177  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
178  }
179  else
180  {
181  imsi = FindImsiFromLteNetDevice (pathUePhy);
182  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
183  }
184 
185  params.m_imsi = imsi;
186  phyRxStats->DlPhyReception (params);
187 }
188 
189 void
191  std::string path, PhyReceptionStatParameters params)
192 {
193  NS_LOG_FUNCTION (phyRxStats << path);
194  uint64_t imsi = 0;
195  std::ostringstream pathAndRnti;
196  std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
197  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
198  if (phyRxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
199  {
200  imsi = phyRxStats->GetImsiPath (pathAndRnti.str ());
201  }
202  else
203  {
204  imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
205  phyRxStats->SetImsiPath (pathAndRnti.str (), imsi);
206  }
207 
208  params.m_imsi = imsi;
209  phyRxStats->UlPhyReception (params);
210 }
211 
212 } // namespace ns3
Base class for ***StatsCalculator classes.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink 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 GetUlOutputFilename(void)
Get the name of the file where the uplink 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 reception.
std::string GetUlRxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
bool m_dlRxFirstWrite
When writing DL RX PHY statistics first time to file, columns description is added.
std::ofstream m_ulRxOutFile
UL RX PHY output trace file.
static TypeId GetTypeId(void)
Register this type.
bool m_ulRxFirstWrite
When writing UL RX PHY statistics first time to file, columns description is added.
virtual ~PhyRxStatsCalculator()
Destructor.
static void UlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
std::string GetDlRxOutputFilename(void)
Get the name of the file where the DL RX PHY statistics will be stored.
void DlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an downlink reception has occurred.
void SetDlRxOutputFilename(std::string outputFilename)
Set the name of the file where the DL RX PHY statistics will be stored.
static void DlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
void UlPhyReception(PhyReceptionStatParameters params)
Notifies the stats calculator that an uplink reception has occurred.
void SetUlRxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Rx PHY statistics will be stored.
std::ofstream m_dlRxOutFile
DL RX PHY output trace file.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Hold variables of type string.
Definition: string.h:41
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
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
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PhyReceptionStatParameters structure.
Definition: lte-common.h:213
uint8_t m_txMode
the transmission Mode
Definition: lte-common.h:218
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:222
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:219
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:216
uint8_t m_correctness
correctness of the TB received
Definition: lte-common.h:224
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:217
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:215
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:223
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:220
int64_t m_timestamp
in millisecond
Definition: lte-common.h:214
uint16_t m_size
Size of transport block.
Definition: lte-common.h:221
uint8_t m_ccId
component carrier id
Definition: lte-common.h:225