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
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("PhyTxStatsCalculator");
31
32NS_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 if (m_dlTxOutFile.is_open())
46 {
47 m_dlTxOutFile.close();
48 }
49
50 if (m_ulTxOutFile.is_open())
51 {
52 m_ulTxOutFile.close();
53 }
54}
57{
58 static TypeId tid = TypeId ("ns3::PhyTxStatsCalculator")
60 .SetGroupName ("Lte")
61 .AddConstructor<PhyTxStatsCalculator> ()
62 .AddAttribute ("DlTxOutputFilename",
63 "Name of the file where the downlink results will be saved.",
64 StringValue ("DlTxPhyStats.txt"),
67 .AddAttribute ("UlTxOutputFilename",
68 "Name of the file where the uplink results will be saved.",
69 StringValue ("UlTxPhyStats.txt"),
72 ;
73 return tid;
74}
75
76void
78{
80}
81
82std::string
84{
86}
87
88void
90{
92}
93
94std::string
96{
98}
99
100void
102{
103 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);
104 NS_LOG_INFO ("Write DL Tx Phy Stats in " << GetDlTxOutputFilename ().c_str ());
105
106 if ( m_dlTxFirstWrite == true )
107 {
108 m_dlTxOutFile.open (GetDlOutputFilename ().c_str ());
109 if (!m_dlTxOutFile.is_open ())
110 {
111 NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ());
112 return;
113 }
114 m_dlTxFirstWrite = false;
115 m_dlTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
116 m_dlTxOutFile << "\n";
117 }
118
119 m_dlTxOutFile << params.m_timestamp << "\t";
120 m_dlTxOutFile << (uint32_t) params.m_cellId << "\t";
121 m_dlTxOutFile << params.m_imsi << "\t";
122 m_dlTxOutFile << params.m_rnti << "\t";
123 //m_dlTxOutFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
124 m_dlTxOutFile << (uint32_t) params.m_layer << "\t";
125 m_dlTxOutFile << (uint32_t) params.m_mcs << "\t";
126 m_dlTxOutFile << params.m_size << "\t";
127 m_dlTxOutFile << (uint32_t) params.m_rv << "\t";
128 m_dlTxOutFile << (uint32_t) params.m_ndi << "\t";
129 m_dlTxOutFile << (uint32_t) params.m_ccId << std::endl;
130}
131
132void
134{
135 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);
136 NS_LOG_INFO ("Write UL Tx Phy Stats in " << GetUlTxOutputFilename ().c_str ());
137
138 if ( m_ulTxFirstWrite == true )
139 {
140 m_ulTxOutFile.open (GetUlTxOutputFilename ().c_str ());
141 if (!m_ulTxOutFile.is_open ())
142 {
143 NS_LOG_ERROR ("Can't open file " << GetUlTxOutputFilename ().c_str ());
144 return;
145 }
146 m_ulTxFirstWrite = false;
147 //m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi";
148 m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
149 m_ulTxOutFile << "\n";
150 }
151
152 m_ulTxOutFile << params.m_timestamp << "\t";
153 m_ulTxOutFile << (uint32_t) params.m_cellId << "\t";
154 m_ulTxOutFile << params.m_imsi << "\t";
155 m_ulTxOutFile << params.m_rnti << "\t";
156 //m_ulTxOutFile << (uint32_t) params.m_txMode << "\t";
157 m_ulTxOutFile << (uint32_t) params.m_layer << "\t";
158 m_ulTxOutFile << (uint32_t) params.m_mcs << "\t";
159 m_ulTxOutFile << params.m_size << "\t";
160 m_ulTxOutFile << (uint32_t) params.m_rv << "\t";
161 m_ulTxOutFile << (uint32_t) params.m_ndi << "\t";
162 m_ulTxOutFile << (uint32_t) params.m_ccId << std::endl;
163}
164
165void
167 std::string path, PhyTransmissionStatParameters params)
168{
169 NS_LOG_FUNCTION (phyTxStats << path);
170 uint64_t imsi = 0;
171 std::ostringstream pathAndRnti;
172 std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
173 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
174 if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
175 {
176 imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
177 }
178 else
179 {
180 imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
181 phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
182 }
183
184 params.m_imsi = imsi;
185 phyTxStats->DlPhyTransmission (params);
186}
187
188void
190 std::string path, PhyTransmissionStatParameters params)
191{
192 NS_LOG_FUNCTION (phyTxStats << path);
193 uint64_t imsi = 0;
194 std::ostringstream pathAndRnti;
195 pathAndRnti << path << "/" << params.m_rnti;
196 std::string pathUePhy = path.substr (0, path.find ("/ComponentCarrierMapUe"));
197 if (phyTxStats->ExistsImsiPath (pathAndRnti.str ()) == true)
198 {
199 imsi = phyTxStats->GetImsiPath (pathAndRnti.str ());
200 }
201 else
202 {
203 imsi = FindImsiFromLteNetDevice (pathUePhy);
204 phyTxStats->SetImsiPath (pathAndRnti.str (), imsi);
205 }
206
207 params.m_imsi = imsi;
208 phyTxStats->UlPhyTransmission (params);
209}
210
211
212} // namespace ns3
213
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 transmission.
static TypeId GetTypeId(void)
Register this type.
bool m_ulTxFirstWrite
When writing UL TX PHY statistics first time to file, columns description is added.
void SetDlTxOutputFilename(std::string outputFilename)
Set the name of the file where the DL TX PHY statistics will be stored.
virtual ~PhyTxStatsCalculator()
Destructor.
void SetUlTxOutputFilename(std::string outputFilename)
Set the name of the file where the UL Tx PHY statistics will be stored.
bool m_dlTxFirstWrite
When writing DL TX PHY statistics first time to file, columns description is added.
static void DlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
std::ofstream m_ulTxOutFile
UL TX PHY statistics output trace file.
void DlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an downlink transmission has occurred.
std::ofstream m_dlTxOutFile
DL TX PHY statistics output trace file.
void UlPhyTransmission(PhyTransmissionStatParameters params)
Notifies the stats calculator that an uplink transmission has occurred.
std::string GetDlTxOutputFilename(void)
Get the name of the file where the DL TX PHY statistics will be stored.
std::string GetUlTxOutputFilename(void)
Get the name of the file where the UL RX PHY statistics will be stored.
static void UlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
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)
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.
PhyTransmissionStatParameters structure.
Definition: lte-common.h:187
uint8_t m_ndi
new data indicator flag
Definition: lte-common.h:197
int64_t m_timestamp
in millisecond
Definition: lte-common.h:188
uint8_t m_layer
the layer (cw) of the transmission
Definition: lte-common.h:193
uint16_t m_size
Size of transport block.
Definition: lte-common.h:195
uint64_t m_imsi
IMSI of the scheduled UE.
Definition: lte-common.h:190
uint16_t m_rnti
C-RNTI scheduled.
Definition: lte-common.h:191
uint8_t m_rv
the redundancy version (HARQ)
Definition: lte-common.h:196
uint16_t m_cellId
Cell ID of the attached Enb.
Definition: lte-common.h:189
uint8_t m_ccId
component carrier id
Definition: lte-common.h:198
uint8_t m_mcs
MCS for transport block.
Definition: lte-common.h:194