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 * 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: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
19 * Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
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("MacStatsCalculator");
32
33NS_OBJECT_ENSURE_REGISTERED(MacStatsCalculator);
34
36 : m_dlFirstWrite(true),
37 m_ulFirstWrite(true)
38{
39 NS_LOG_FUNCTION(this);
40}
41
43{
44 NS_LOG_FUNCTION(this);
45 if (m_dlOutFile.is_open())
46 {
47 m_dlOutFile.close();
48 }
49
50 if (m_ulOutFile.is_open())
51 {
52 m_ulOutFile.close();
53 }
54}
55
58{
59 static TypeId tid =
60 TypeId("ns3::MacStatsCalculator")
62 .SetGroupName("Lte")
63 .AddConstructor<MacStatsCalculator>()
64 .AddAttribute("DlOutputFilename",
65 "Name of the file where the downlink results will be saved.",
66 StringValue("DlMacStats.txt"),
69 .AddAttribute("UlOutputFilename",
70 "Name of the file where the uplink results will be saved.",
71 StringValue("UlMacStats.txt"),
74 return tid;
75}
76
77void
78MacStatsCalculator::SetUlOutputFilename(std::string outputFilename)
79{
81}
82
83std::string
85{
87}
88
89void
90MacStatsCalculator::SetDlOutputFilename(std::string outputFilename)
91{
93}
94
95std::string
97{
99}
100
101void
103 uint64_t imsi,
104 DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
105{
107 this << cellId << imsi << dlSchedulingCallbackInfo.frameNo
108 << dlSchedulingCallbackInfo.subframeNo << dlSchedulingCallbackInfo.rnti
109 << (uint32_t)dlSchedulingCallbackInfo.mcsTb1 << dlSchedulingCallbackInfo.sizeTb1
110 << (uint32_t)dlSchedulingCallbackInfo.mcsTb2 << dlSchedulingCallbackInfo.sizeTb2);
111 NS_LOG_INFO("Write DL Mac Stats in " << GetDlOutputFilename());
112
113 if (m_dlFirstWrite)
114 {
116 if (!m_dlOutFile.is_open())
117 {
118 NS_LOG_ERROR("Can't open file " << GetDlOutputFilename());
119 return;
120 }
121 m_dlFirstWrite = false;
123 << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2\tccId";
124 m_dlOutFile << "\n";
125 }
126
128 m_dlOutFile << (uint32_t)cellId << "\t";
129 m_dlOutFile << imsi << "\t";
130 m_dlOutFile << dlSchedulingCallbackInfo.frameNo << "\t";
131 m_dlOutFile << dlSchedulingCallbackInfo.subframeNo << "\t";
132 m_dlOutFile << dlSchedulingCallbackInfo.rnti << "\t";
133 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.mcsTb1 << "\t";
134 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb1 << "\t";
135 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.mcsTb2 << "\t";
136 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb2 << "\t";
137 m_dlOutFile << (uint32_t)dlSchedulingCallbackInfo.componentCarrierId << std::endl;
138}
139
140void
142 uint64_t imsi,
143 uint32_t frameNo,
144 uint32_t subframeNo,
145 uint16_t rnti,
146 uint8_t mcsTb,
147 uint16_t size,
148 uint8_t componentCarrierId)
149{
150 NS_LOG_FUNCTION(this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t)mcsTb
151 << size);
152 NS_LOG_INFO("Write UL Mac Stats in " << GetUlOutputFilename());
153
154 if (m_ulFirstWrite)
155 {
157 if (!m_ulOutFile.is_open())
158 {
159 NS_LOG_ERROR("Can't open file " << GetUlOutputFilename());
160 return;
161 }
162 m_ulFirstWrite = false;
163 m_ulOutFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize\tccId";
164 m_ulOutFile << "\n";
165 }
166
168 m_ulOutFile << (uint32_t)cellId << "\t";
169 m_ulOutFile << imsi << "\t";
170 m_ulOutFile << frameNo << "\t";
171 m_ulOutFile << subframeNo << "\t";
172 m_ulOutFile << rnti << "\t";
173 m_ulOutFile << (uint32_t)mcsTb << "\t";
174 m_ulOutFile << size << "\t";
175 m_ulOutFile << (uint32_t)componentCarrierId << std::endl;
176}
177
178void
180 std::string path,
181 DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
182{
183 NS_LOG_FUNCTION(macStats << path);
184 uint64_t imsi = 0;
185 std::ostringstream pathAndRnti;
186 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
187 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << dlSchedulingCallbackInfo.rnti;
188 if (macStats->ExistsImsiPath(pathAndRnti.str()))
189 {
190 imsi = macStats->GetImsiPath(pathAndRnti.str());
191 }
192 else
193 {
194 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
195 macStats->SetImsiPath(pathAndRnti.str(), imsi);
196 }
197 uint16_t cellId = 0;
198 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
199 {
200 cellId = macStats->GetCellIdPath(pathAndRnti.str());
201 }
202 else
203 {
204 cellId = FindCellIdFromEnbRlcPath(pathAndRnti.str());
205 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
206 }
207
208 macStats->DlScheduling(cellId, imsi, dlSchedulingCallbackInfo);
209}
210
211void
213 std::string path,
214 uint32_t frameNo,
215 uint32_t subframeNo,
216 uint16_t rnti,
217 uint8_t mcs,
218 uint16_t size,
219 uint8_t componentCarrierId)
220{
221 NS_LOG_FUNCTION(macStats << path);
222
223 uint64_t imsi = 0;
224 std::ostringstream pathAndRnti;
225 std::string pathEnb = path.substr(0, path.find("/ComponentCarrierMap"));
226 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << rnti;
227 if (macStats->ExistsImsiPath(pathAndRnti.str()))
228 {
229 imsi = macStats->GetImsiPath(pathAndRnti.str());
230 }
231 else
232 {
233 imsi = FindImsiFromEnbRlcPath(pathAndRnti.str());
234 macStats->SetImsiPath(pathAndRnti.str(), imsi);
235 }
236 uint16_t cellId = 0;
237 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
238 {
239 cellId = macStats->GetCellIdPath(pathAndRnti.str());
240 }
241 else
242 {
243 cellId = FindCellIdFromEnbRlcPath(pathAndRnti.str());
244 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
245 }
246
247 macStats->UlScheduling(cellId, imsi, frameNo, subframeNo, rnti, mcs, size, componentCarrierId);
248}
249
250} // 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.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Hold variables of type string.
Definition: string.h:56
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
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.
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:237
uint32_t subframeNo
subframe number
Definition: lte-common.h:239
uint16_t sizeTb2
size TB2
Definition: lte-common.h:244
uint16_t sizeTb1
size TB1
Definition: lte-common.h:242
uint8_t componentCarrierId
component carrier ID
Definition: lte-common.h:245
uint32_t frameNo
frame number
Definition: lte-common.h:238