A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
phy-tx-stats-calculator.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jaume Nin <jnin@cttc.es>
7 * modified by: Marco Miozzo <mmiozzo@cttc.es>
8 * Convert MacStatsCalculator in PhyTxStatsCalculator
9 */
10
12
13#include "ns3/string.h"
14#include <ns3/log.h>
15#include <ns3/simulator.h>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("PhyTxStatsCalculator");
21
22NS_OBJECT_ENSURE_REGISTERED(PhyTxStatsCalculator);
23
25 : m_dlTxFirstWrite(true),
26 m_ulTxFirstWrite(true)
27{
28 NS_LOG_FUNCTION(this);
29}
30
32{
33 NS_LOG_FUNCTION(this);
34 if (m_dlTxOutFile.is_open())
35 {
36 m_dlTxOutFile.close();
37 }
38
39 if (m_ulTxOutFile.is_open())
40 {
41 m_ulTxOutFile.close();
42 }
43}
44
47{
48 static TypeId tid =
49 TypeId("ns3::PhyTxStatsCalculator")
51 .SetGroupName("Lte")
52 .AddConstructor<PhyTxStatsCalculator>()
53 .AddAttribute("DlTxOutputFilename",
54 "Name of the file where the downlink results will be saved.",
55 StringValue("DlTxPhyStats.txt"),
58 .AddAttribute("UlTxOutputFilename",
59 "Name of the file where the uplink results will be saved.",
60 StringValue("UlTxPhyStats.txt"),
63 return tid;
64}
65
66void
68{
70}
71
72std::string
77
78void
80{
82}
83
84std::string
89
90void
92{
93 NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
94 << params.m_layer << params.m_mcs << params.m_size << params.m_rv
95 << params.m_ndi);
96 NS_LOG_INFO("Write DL Tx Phy Stats in " << GetDlTxOutputFilename());
97
99 {
101 if (!m_dlTxOutFile.is_open())
102 {
103 NS_LOG_ERROR("Can't open file " << GetDlTxOutputFilename());
104 return;
105 }
106 m_dlTxFirstWrite = false;
107 m_dlTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
108 m_dlTxOutFile << "\n";
109 }
110
111 m_dlTxOutFile << params.m_timestamp << "\t";
112 m_dlTxOutFile << (uint32_t)params.m_cellId << "\t";
113 m_dlTxOutFile << params.m_imsi << "\t";
114 m_dlTxOutFile << params.m_rnti << "\t";
115 // m_dlTxOutFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side
116 m_dlTxOutFile << (uint32_t)params.m_layer << "\t";
117 m_dlTxOutFile << (uint32_t)params.m_mcs << "\t";
118 m_dlTxOutFile << params.m_size << "\t";
119 m_dlTxOutFile << (uint32_t)params.m_rv << "\t";
120 m_dlTxOutFile << (uint32_t)params.m_ndi << "\t";
121 m_dlTxOutFile << (uint32_t)params.m_ccId << std::endl;
122}
123
124void
126{
127 NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
128 << params.m_layer << params.m_mcs << params.m_size << params.m_rv
129 << params.m_ndi);
130 NS_LOG_INFO("Write UL Tx Phy Stats in " << GetUlTxOutputFilename());
131
133 {
135 if (!m_ulTxOutFile.is_open())
136 {
137 NS_LOG_ERROR("Can't open file " << GetUlTxOutputFilename());
138 return;
139 }
140 m_ulTxFirstWrite = false;
141 // m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi";
142 m_ulTxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tccId";
143 m_ulTxOutFile << "\n";
144 }
145
146 m_ulTxOutFile << params.m_timestamp << "\t";
147 m_ulTxOutFile << (uint32_t)params.m_cellId << "\t";
148 m_ulTxOutFile << params.m_imsi << "\t";
149 m_ulTxOutFile << params.m_rnti << "\t";
150 // m_ulTxOutFile << (uint32_t) params.m_txMode << "\t";
151 m_ulTxOutFile << (uint32_t)params.m_layer << "\t";
152 m_ulTxOutFile << (uint32_t)params.m_mcs << "\t";
153 m_ulTxOutFile << params.m_size << "\t";
154 m_ulTxOutFile << (uint32_t)params.m_rv << "\t";
155 m_ulTxOutFile << (uint32_t)params.m_ndi << "\t";
156 m_ulTxOutFile << (uint32_t)params.m_ccId << std::endl;
157}
158
159void
161 std::string path,
163{
164 NS_LOG_FUNCTION(phyTxStats << path);
165 uint64_t imsi = 0;
166 std::ostringstream pathAndRnti;
167 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
168 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
169 if (phyTxStats->ExistsImsiPath(pathAndRnti.str()))
170 {
171 imsi = phyTxStats->GetImsiPath(pathAndRnti.str());
172 }
173 else
174 {
175 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
176 phyTxStats->SetImsiPath(pathAndRnti.str(), imsi);
177 }
178
179 params.m_imsi = imsi;
180 phyTxStats->DlPhyTransmission(params);
181}
182
183void
185 std::string path,
187{
188 NS_LOG_FUNCTION(phyTxStats << path);
189 uint64_t imsi = 0;
190 std::ostringstream pathAndRnti;
191 pathAndRnti << path << "/" << params.m_rnti;
192 std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
193 if (phyTxStats->ExistsImsiPath(pathAndRnti.str()))
194 {
195 imsi = phyTxStats->GetImsiPath(pathAndRnti.str());
196 }
197 else
198 {
199 imsi = FindImsiFromLteNetDevice(pathUePhy);
200 phyTxStats->SetImsiPath(pathAndRnti.str(), imsi);
201 }
202
203 params.m_imsi = imsi;
204 phyTxStats->UlPhyTransmission(params);
205}
206
207} // namespace ns3
Base class for ***StatsCalculator classes.
std::string GetUlOutputFilename()
Get the name of the file where the uplink 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 GetDlOutputFilename()
Get the name of the file where the downlink 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.
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.
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::string GetDlTxOutputFilename()
Get the name of the file where the DL TX PHY statistics will be stored.
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 GetUlTxOutputFilename()
Get the name of the file where the UL RX PHY statistics will be stored.
static TypeId GetTypeId()
Register this type.
static void UlPhyTransmissionCallback(Ptr< PhyTxStatsCalculator > phyTxStats, std::string path, PhyTransmissionStatParameters params)
trace sink
~PhyTxStatsCalculator() override
Destructor.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Definition string.h:45
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
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:46
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PhyTransmissionStatParameters structure.
Definition lte-common.h:177