A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac-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: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
8 * Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
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("MacStatsCalculator");
21
22NS_OBJECT_ENSURE_REGISTERED(MacStatsCalculator);
23
25 : m_dlFirstWrite(true),
26 m_ulFirstWrite(true)
27{
28 NS_LOG_FUNCTION(this);
29}
30
32{
33 NS_LOG_FUNCTION(this);
34 if (m_dlOutFile.is_open())
35 {
36 m_dlOutFile.close();
37 }
38
39 if (m_ulOutFile.is_open())
40 {
41 m_ulOutFile.close();
42 }
43}
44
47{
48 static TypeId tid =
49 TypeId("ns3::MacStatsCalculator")
51 .SetGroupName("Lte")
52 .AddConstructor<MacStatsCalculator>()
53 .AddAttribute("DlOutputFilename",
54 "Name of the file where the downlink results will be saved.",
55 StringValue("DlMacStats.txt"),
58 .AddAttribute("UlOutputFilename",
59 "Name of the file where the uplink results will be saved.",
60 StringValue("UlMacStats.txt"),
63 return tid;
64}
65
66void
67MacStatsCalculator::SetUlOutputFilename(std::string outputFilename)
68{
70}
71
72std::string
77
78void
79MacStatsCalculator::SetDlOutputFilename(std::string outputFilename)
80{
82}
83
84std::string
89
90void
92 uint64_t imsi,
93 DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
94{
96 this << cellId << imsi << dlSchedulingCallbackInfo.frameNo
97 << dlSchedulingCallbackInfo.subframeNo << dlSchedulingCallbackInfo.rnti
98 << (uint32_t)dlSchedulingCallbackInfo.mcsTb1 << dlSchedulingCallbackInfo.sizeTb1
99 << (uint32_t)dlSchedulingCallbackInfo.mcsTb2 << dlSchedulingCallbackInfo.sizeTb2);
100 NS_LOG_INFO("Write DL Mac Stats in " << GetDlOutputFilename());
101
102 if (m_dlFirstWrite)
103 {
105 if (!m_dlOutFile.is_open())
106 {
107 NS_LOG_ERROR("Can't open file " << GetDlOutputFilename());
108 return;
109 }
110 m_dlFirstWrite = false;
112 << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2\tccId";
113 m_dlOutFile << "\n";
114 }
115
117 m_dlOutFile << (uint32_t)cellId << "\t";
118 m_dlOutFile << imsi << "\t";
119 m_dlOutFile << dlSchedulingCallbackInfo.frameNo << "\t";
120 m_dlOutFile << dlSchedulingCallbackInfo.subframeNo << "\t";
121 m_dlOutFile << dlSchedulingCallbackInfo.rnti << "\t";
122 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.mcsTb1 << "\t";
123 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb1 << "\t";
124 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.mcsTb2 << "\t";
125 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb2 << "\t";
126 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.componentCarrierId << std::endl;
127}
128
129void
131 uint64_t imsi,
132 uint32_t frameNo,
133 uint32_t subframeNo,
134 uint16_t rnti,
135 uint8_t mcsTb,
136 uint16_t size,
137 uint8_t componentCarrierId)
138{
139 NS_LOG_FUNCTION(this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t)mcsTb
140 << size);
141 NS_LOG_INFO("Write UL Mac Stats in " << GetUlOutputFilename());
142
143 if (m_ulFirstWrite)
144 {
146 if (!m_ulOutFile.is_open())
147 {
148 NS_LOG_ERROR("Can't open file " << GetUlOutputFilename());
149 return;
150 }
151 m_ulFirstWrite = false;
152 m_ulOutFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize\tccId";
153 m_ulOutFile << "\n";
154 }
155
157 m_ulOutFile << (uint32_t)cellId << "\t";
158 m_ulOutFile << imsi << "\t";
159 m_ulOutFile << frameNo << "\t";
160 m_ulOutFile << subframeNo << "\t";
161 m_ulOutFile << rnti << "\t";
162 m_ulOutFile << (uint32_t)mcsTb << "\t";
163 m_ulOutFile << size << "\t";
164 m_ulOutFile << (uint32_t)componentCarrierId << std::endl;
165}
166
167void
169 std::string path,
170 DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
171{
172 NS_LOG_FUNCTION(macStats << path);
173 uint64_t imsi = 0;
174 std::ostringstream pathAndRnti;
175 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
176 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << dlSchedulingCallbackInfo.rnti;
177 if (macStats->ExistsImsiPath(pathAndRnti.str()))
178 {
179 imsi = macStats->GetImsiPath(pathAndRnti.str());
180 }
181 else
182 {
183 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
184 macStats->SetImsiPath(pathAndRnti.str(), imsi);
185 }
186 uint16_t cellId = 0;
187 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
188 {
189 cellId = macStats->GetCellIdPath(pathAndRnti.str());
190 }
191 else
192 {
193 cellId = FindCellIdFromEnbRlcPath(pathAndRnti.str());
194 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
195 }
196
197 macStats->DlScheduling(cellId, imsi, dlSchedulingCallbackInfo);
198}
199
200void
202 std::string path,
203 uint32_t frameNo,
204 uint32_t subframeNo,
205 uint16_t rnti,
206 uint8_t mcs,
207 uint16_t size,
208 uint8_t componentCarrierId)
209{
210 NS_LOG_FUNCTION(macStats << path);
211
212 uint64_t imsi = 0;
213 std::ostringstream pathAndRnti;
214 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
215 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << rnti;
216 if (macStats->ExistsImsiPath(pathAndRnti.str()))
217 {
218 imsi = macStats->GetImsiPath(pathAndRnti.str());
219 }
220 else
221 {
222 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
223 macStats->SetImsiPath(pathAndRnti.str(), imsi);
224 }
225 uint16_t cellId = 0;
226 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
227 {
228 cellId = macStats->GetCellIdPath(pathAndRnti.str());
229 }
230 else
231 {
232 cellId = FindCellIdFromEnbRlcPath(pathAndRnti.str());
233 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
234 }
235
236 macStats->UlScheduling(cellId, imsi, frameNo, subframeNo, rnti, mcs, size, componentCarrierId);
237}
238
239} // 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.
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
Retrieves CellId from Enb RLC path in the attribute system.
std::string GetDlOutputFilename()
Get the name of the file where the downlink statistics will be stored.
Takes care of storing the information generated at MAC layer.
~MacStatsCalculator() override
Destructor.
static TypeId GetTypeId()
Register this type.
std::ofstream m_dlOutFile
Downlink output trace file.
void UlScheduling(uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb, uint16_t sizeTb, uint8_t componentCarrierId)
Notifies the stats calculator that an uplink scheduling has occurred.
bool m_dlFirstWrite
When writing DL MAC statistics first time to file, columns description is added.
static void DlSchedulingCallback(Ptr< MacStatsCalculator > macStats, std::string path, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
Trace sink for the ns3::LteEnbMac::DlScheduling trace source.
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
std::ofstream m_ulOutFile
Uplink output trace file.
std::string GetUlOutputFilename()
Get the name of the file where the uplink statistics will be stored.
static void UlSchedulingCallback(Ptr< MacStatsCalculator > macStats, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcs, uint16_t size, uint8_t componentCarrierId)
Trace sink for the ns3::LteEnbMac::UlScheduling trace source.
void DlScheduling(uint16_t cellId, uint64_t imsi, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
Notifies the stats calculator that an downlink scheduling has occurred.
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
bool m_ulFirstWrite
When writing UL MAC statistics first time to file, columns description is added.
std::string GetDlOutputFilename()
Get the name of the file where the downlink statistics will be stored.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Hold variables of type string.
Definition string.h:45
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
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
DlSchedulingCallbackInfo structure.
Definition lte-common.h:226
uint32_t subframeNo
subframe number
Definition lte-common.h:228
uint8_t componentCarrierId
component carrier ID
Definition lte-common.h:234
uint32_t frameNo
frame number
Definition lte-common.h:227