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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Jaume Nin <jnin@cttc.es>
18 * modified by: Marco Miozzo <mmiozzo@cttc.es>
19 * Convert MacStatsCalculator in PhyRxStatsCalculator
20 */
21
23
24#include "ns3/string.h"
25#include <ns3/log.h>
26#include <ns3/simulator.h>
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("PhyRxStatsCalculator");
32
33NS_OBJECT_ENSURE_REGISTERED(PhyRxStatsCalculator);
34
36 : m_dlRxFirstWrite(true),
37 m_ulRxFirstWrite(true)
38{
39 NS_LOG_FUNCTION(this);
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
58{
59 static TypeId tid =
60 TypeId("ns3::PhyRxStatsCalculator")
62 .SetGroupName("Lte")
63 .AddConstructor<PhyRxStatsCalculator>()
64 .AddAttribute("DlRxOutputFilename",
65 "Name of the file where the downlink results will be saved.",
66 StringValue("DlRxPhyStats.txt"),
69 .AddAttribute("UlRxOutputFilename",
70 "Name of the file where the uplink results will be saved.",
71 StringValue("UlRxPhyStats.txt"),
74 return tid;
75}
76
77void
79{
81}
82
83std::string
85{
87}
88
89void
91{
93}
94
95std::string
97{
99}
100
101void
103{
104 NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
105 << params.m_layer << params.m_mcs << params.m_size << params.m_rv
106 << params.m_ndi << params.m_correctness);
107 NS_LOG_INFO("Write DL Rx Phy Stats in " << GetDlRxOutputFilename());
108
110 {
112 if (!m_dlRxOutFile.is_open())
113 {
114 NS_LOG_ERROR("Can't open file " << GetDlRxOutputFilename());
115 return;
116 }
117 m_dlRxFirstWrite = false;
119 << "% time\tcellId\tIMSI\tRNTI\ttxMode\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
120 m_dlRxOutFile << "\n";
121 }
122
123 m_dlRxOutFile << params.m_timestamp << "\t";
124 m_dlRxOutFile << (uint32_t)params.m_cellId << "\t";
125 m_dlRxOutFile << params.m_imsi << "\t";
126 m_dlRxOutFile << params.m_rnti << "\t";
127 m_dlRxOutFile << (uint32_t)params.m_txMode << "\t";
128 m_dlRxOutFile << (uint32_t)params.m_layer << "\t";
129 m_dlRxOutFile << (uint32_t)params.m_mcs << "\t";
130 m_dlRxOutFile << params.m_size << "\t";
131 m_dlRxOutFile << (uint32_t)params.m_rv << "\t";
132 m_dlRxOutFile << (uint32_t)params.m_ndi << "\t";
133 m_dlRxOutFile << (uint32_t)params.m_correctness << "\t";
134 m_dlRxOutFile << (uint32_t)params.m_ccId << std::endl;
135}
136
137void
139{
140 NS_LOG_FUNCTION(this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti
141 << params.m_layer << params.m_mcs << params.m_size << params.m_rv
142 << params.m_ndi << params.m_correctness);
143 NS_LOG_INFO("Write UL Rx Phy Stats in " << GetUlRxOutputFilename());
144
146 {
148 if (!m_ulRxOutFile.is_open())
149 {
150 NS_LOG_ERROR("Can't open file " << GetUlRxOutputFilename());
151 return;
152 }
153 m_ulRxFirstWrite = false;
154 m_ulRxOutFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi\tcorrect\tccId";
155 m_ulRxOutFile << "\n";
156 }
157
158 m_ulRxOutFile << params.m_timestamp << "\t";
159 m_ulRxOutFile << (uint32_t)params.m_cellId << "\t";
160 m_ulRxOutFile << params.m_imsi << "\t";
161 m_ulRxOutFile << params.m_rnti << "\t";
162 m_ulRxOutFile << (uint32_t)params.m_layer << "\t";
163 m_ulRxOutFile << (uint32_t)params.m_mcs << "\t";
164 m_ulRxOutFile << params.m_size << "\t";
165 m_ulRxOutFile << (uint32_t)params.m_rv << "\t";
166 m_ulRxOutFile << (uint32_t)params.m_ndi << "\t";
167 m_ulRxOutFile << (uint32_t)params.m_correctness << "\t";
168 m_ulRxOutFile << (uint32_t)params.m_ccId << std::endl;
169}
170
171void
173 std::string path,
175{
176 NS_LOG_FUNCTION(phyRxStats << path);
177 uint64_t imsi = 0;
178 std::ostringstream pathAndRnti;
179 pathAndRnti << path << "/" << params.m_rnti;
180 std::string pathUePhy = path.substr(0, path.find("/ComponentCarrierMapUe"));
181 if (phyRxStats->ExistsImsiPath(pathAndRnti.str()))
182 {
183 imsi = phyRxStats->GetImsiPath(pathAndRnti.str());
184 }
185 else
186 {
187 imsi = FindImsiFromLteNetDevice(pathUePhy);
188 phyRxStats->SetImsiPath(pathAndRnti.str(), imsi);
189 }
190
191 params.m_imsi = imsi;
192 phyRxStats->DlPhyReception(params);
193}
194
195void
197 std::string path,
199{
200 NS_LOG_FUNCTION(phyRxStats << path);
201 uint64_t imsi = 0;
202 std::ostringstream pathAndRnti;
203 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
204 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << params.m_rnti;
205 if (phyRxStats->ExistsImsiPath(pathAndRnti.str()))
206 {
207 imsi = phyRxStats->GetImsiPath(pathAndRnti.str());
208 }
209 else
210 {
211 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
212 phyRxStats->SetImsiPath(pathAndRnti.str(), imsi);
213 }
214
215 params.m_imsi = imsi;
216 phyRxStats->UlPhyReception(params);
217}
218
219} // 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.
Definition: ptr.h:78
Hold variables of type string.
Definition: string.h:56
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
Ptr< const AttributeChecker > MakeStringChecker()
Definition: string.cc:30
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:57
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PhyReceptionStatParameters structure.
Definition: lte-common.h:212