A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
phy-rx-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 PhyRxStatsCalculator
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("PhyRxStatsCalculator");
21
22NS_OBJECT_ENSURE_REGISTERED(PhyRxStatsCalculator);
23
25 : m_dlRxFirstWrite(true),
26 m_ulRxFirstWrite(true)
27{
28 NS_LOG_FUNCTION(this);
29}
30
32{
33 NS_LOG_FUNCTION(this);
34 if (m_dlRxOutFile.is_open())
35 {
36 m_dlRxOutFile.close();
37 }
38
39 if (m_ulRxOutFile.is_open())
40 {
41 m_ulRxOutFile.close();
42 }
43}
44
47{
48 static TypeId tid =
49 TypeId("ns3::PhyRxStatsCalculator")
51 .SetGroupName("Lte")
52 .AddConstructor<PhyRxStatsCalculator>()
53 .AddAttribute("DlRxOutputFilename",
54 "Name of the file where the downlink results will be saved.",
55 StringValue("DlRxPhyStats.txt"),
58 .AddAttribute("UlRxOutputFilename",
59 "Name of the file where the uplink results will be saved.",
60 StringValue("UlRxPhyStats.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 << params.m_correctness);
96 NS_LOG_INFO("Write DL Rx Phy Stats in " << GetDlRxOutputFilename());
97
99 {
101 if (!m_dlRxOutFile.is_open())
102 {
103 NS_LOG_ERROR("Can't open file " << GetDlRxOutputFilename());
104 return;
105 }
106 m_dlRxFirstWrite = false;
108 << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
109 m_dlRxOutFile << "\n";
110 }
111
112 m_dlRxOutFile << params.m_timestamp << "\t";
113 m_dlRxOutFile << (uint32_t)params.m_cellId << "\t";
114 m_dlRxOutFile << params.m_imsi << "\t";
115 m_dlRxOutFile << params.m_rnti << "\t";
116 m_dlRxOutFile << (uint32_t)params.m_txMode << "\t";
117 m_dlRxOutFile << (uint32_t)params.m_layer << "\t";
118 m_dlRxOutFile << (uint32_t)params.m_mcs << "\t";
119 m_dlRxOutFile << params.m_size << "\t";
120 m_dlRxOutFile << (uint32_t)params.m_rv << "\t";
121 m_dlRxOutFile << (uint32_t)params.m_ndi << "\t";
122 m_dlRxOutFile << (uint32_t)params.m_correctness << "\t";
123 m_dlRxOutFile << (uint32_t)params.m_ccId << std::endl;
124}
125
126void
128{
129 NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
130 << params.m_layer << params.m_mcs << params.m_size << params.m_rv
131 << params.m_ndi << params.m_correctness);
132 NS_LOG_INFO("Write UL Rx Phy Stats in " << GetUlRxOutputFilename());
133
135 {
137 if (!m_ulRxOutFile.is_open())
138 {
139 NS_LOG_ERROR("Can't open file " << GetUlRxOutputFilename());
140 return;
141 }
142 m_ulRxFirstWrite = false;
143 m_ulRxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
144 m_ulRxOutFile << "\n";
145 }
146
147 m_ulRxOutFile << params.m_timestamp << "\t";
148 m_ulRxOutFile << (uint32_t)params.m_cellId << "\t";
149 m_ulRxOutFile << params.m_imsi << "\t";
150 m_ulRxOutFile << params.m_rnti << "\t";
151 m_ulRxOutFile << (uint32_t)params.m_layer << "\t";
152 m_ulRxOutFile << (uint32_t)params.m_mcs << "\t";
153 m_ulRxOutFile << params.m_size << "\t";
154 m_ulRxOutFile << (uint32_t)params.m_rv << "\t";
155 m_ulRxOutFile << (uint32_t)params.m_ndi << "\t";
156 m_ulRxOutFile << (uint32_t)params.m_correctness << "\t";
157 m_ulRxOutFile << (uint32_t)params.m_ccId << std::endl;
158}
159
160void
162 std::string path,
164{
165 NS_LOG_FUNCTION(phyRxStats << path);
166 uint64_t imsi = 0;
167 std::ostringstream pathAndRnti;
168 pathAndRnti << path << "/" << params.m_rnti;
169 std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
170 if (phyRxStats->ExistsImsiPath(pathAndRnti.str()))
171 {
172 imsi = phyRxStats->GetImsiPath(pathAndRnti.str());
173 }
174 else
175 {
176 imsi = FindImsiFromLteNetDevice(pathUePhy);
177 phyRxStats->SetImsiPath(pathAndRnti.str(), imsi);
178 }
179
180 params.m_imsi = imsi;
181 phyRxStats->DlPhyReception(params);
182}
183
184void
186 std::string path,
188{
189 NS_LOG_FUNCTION(phyRxStats << path);
190 uint64_t imsi = 0;
191 std::ostringstream pathAndRnti;
192 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
193 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
194 if (phyRxStats->ExistsImsiPath(pathAndRnti.str()))
195 {
196 imsi = phyRxStats->GetImsiPath(pathAndRnti.str());
197 }
198 else
199 {
200 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
201 phyRxStats->SetImsiPath(pathAndRnti.str(), imsi);
202 }
203
204 params.m_imsi = imsi;
205 phyRxStats->UlPhyReception(params);
206}
207
208} // 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 reception.
static TypeId GetTypeId()
Register this type.
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.
bool m_ulRxFirstWrite
When writing UL RX PHY statistics first time to file, columns description is added.
static void UlPhyReceptionCallback(Ptr< PhyRxStatsCalculator > phyRxStats, std::string path, PhyReceptionStatParameters params)
trace sink
std::string GetUlRxOutputFilename()
Get the name of the file where the UL 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.
std::string GetDlRxOutputFilename()
Get the name of the file where the DL RX PHY statistics will be stored.
~PhyRxStatsCalculator() override
Destructor.
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.
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
#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.
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition string.h:46
PhyReceptionStatParameters structure.
Definition lte-common.h:201