A Discrete-Event Network Simulator
API
mac-stats-calculator.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Jaume Nin <jnin@cttc.es>
19 * Modified by: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
20 * Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
21 */
22
24#include "ns3/string.h"
25#include <ns3/simulator.h>
26#include <ns3/log.h>
27
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("MacStatsCalculator");
31
32NS_OBJECT_ENSURE_REGISTERED (MacStatsCalculator);
33
35 : m_dlFirstWrite (true),
36 m_ulFirstWrite (true)
37{
38 NS_LOG_FUNCTION (this);
39
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 = TypeId ("ns3::MacStatsCalculator")
61 .SetGroupName ("Lte")
62 .AddConstructor<MacStatsCalculator> ()
63 .AddAttribute ("DlOutputFilename",
64 "Name of the file where the downlink results will be saved.",
65 StringValue ("DlMacStats.txt"),
68 .AddAttribute ("UlOutputFilename",
69 "Name of the file where the uplink results will be saved.",
70 StringValue ("UlMacStats.txt"),
73 ;
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
102MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
103{
104 NS_LOG_FUNCTION (this << cellId << imsi << dlSchedulingCallbackInfo.frameNo << dlSchedulingCallbackInfo.subframeNo <<
105 dlSchedulingCallbackInfo.rnti << (uint32_t) dlSchedulingCallbackInfo.mcsTb1 << dlSchedulingCallbackInfo.sizeTb1 << (uint32_t) dlSchedulingCallbackInfo.mcsTb2 << dlSchedulingCallbackInfo.sizeTb2);
106 NS_LOG_INFO ("Write DL Mac Stats in " << GetDlOutputFilename ().c_str ());
107
108 if ( m_dlFirstWrite == true )
109 {
110 m_dlOutFile.open (GetDlOutputFilename ().c_str ());
111 if (!m_dlOutFile.is_open ())
112 {
113 NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
114 return;
115 }
116 m_dlFirstWrite = false;
117 m_dlOutFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2\tccId";
118 m_dlOutFile << "\n";
119 }
120
121 m_dlOutFile << Simulator::Now ().GetSeconds () << "\t";
122 m_dlOutFile << (uint32_t) cellId << "\t";
123 m_dlOutFile << imsi << "\t";
124 m_dlOutFile << dlSchedulingCallbackInfo.frameNo << "\t";
125 m_dlOutFile << dlSchedulingCallbackInfo.subframeNo << "\t";
126 m_dlOutFile << dlSchedulingCallbackInfo.rnti << "\t";
127 m_dlOutFile << (uint32_t) dlSchedulingCallbackInfo.mcsTb1 << "\t";
128 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb1 << "\t";
129 m_dlOutFile << (uint32_t) dlSchedulingCallbackInfo.mcsTb2 << "\t";
130 m_dlOutFile << dlSchedulingCallbackInfo.sizeTb2 << "\t";
131 m_dlOutFile << (uint32_t) dlSchedulingCallbackInfo.componentCarrierId << std::endl;
132}
133
134void
135MacStatsCalculator::UlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo,
136 uint32_t subframeNo, uint16_t rnti,uint8_t mcsTb, uint16_t size, uint8_t componentCarrierId)
137{
138 NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcsTb << size);
139 NS_LOG_INFO ("Write UL Mac Stats in " << GetUlOutputFilename ().c_str ());
140
141 if ( m_ulFirstWrite == true )
142 {
143 m_ulOutFile.open (GetUlOutputFilename ().c_str ());
144 if (!m_ulOutFile.is_open ())
145 {
146 NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
147 return;
148 }
149 m_ulFirstWrite = false;
150 m_ulOutFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize\tccId";
151 m_ulOutFile << "\n";
152 }
153
154 m_ulOutFile << Simulator::Now ().GetSeconds () << "\t";
155 m_ulOutFile << (uint32_t) cellId << "\t";
156 m_ulOutFile << imsi << "\t";
157 m_ulOutFile << frameNo << "\t";
158 m_ulOutFile << subframeNo << "\t";
159 m_ulOutFile << rnti << "\t";
160 m_ulOutFile << (uint32_t) mcsTb << "\t";
161 m_ulOutFile << size << "\t";
162 m_ulOutFile << (uint32_t) componentCarrierId << std::endl;
163}
164
165void
167{
168 NS_LOG_FUNCTION (macStats << path);
169 uint64_t imsi = 0;
170 std::ostringstream pathAndRnti;
171 std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
172 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << dlSchedulingCallbackInfo.rnti;
173 if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
174 {
175 imsi = macStats->GetImsiPath (pathAndRnti.str ());
176 }
177 else
178 {
179 imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
180 macStats->SetImsiPath (pathAndRnti.str (), imsi);
181 }
182 uint16_t cellId = 0;
183 if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
184 {
185 cellId = macStats->GetCellIdPath (pathAndRnti.str ());
186 }
187 else
188 {
189 cellId = FindCellIdFromEnbRlcPath (pathAndRnti.str ());
190 macStats->SetCellIdPath (pathAndRnti.str (), cellId);
191 }
192
193 macStats->DlScheduling (cellId, imsi, dlSchedulingCallbackInfo);
194}
195
196void
198 uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
199 uint8_t mcs, uint16_t size, uint8_t componentCarrierId)
200{
201 NS_LOG_FUNCTION (macStats << path);
202
203 uint64_t imsi = 0;
204 std::ostringstream pathAndRnti;
205 std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
206 pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << rnti;
207 if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
208 {
209 imsi = macStats->GetImsiPath (pathAndRnti.str ());
210 }
211 else
212 {
213 imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
214 macStats->SetImsiPath (pathAndRnti.str (), imsi);
215 }
216 uint16_t cellId = 0;
217 if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
218 {
219 cellId = macStats->GetCellIdPath (pathAndRnti.str ());
220 }
221 else
222 {
223 cellId = FindCellIdFromEnbRlcPath (pathAndRnti.str ());
224 macStats->SetCellIdPath (pathAndRnti.str (), cellId);
225 }
226
227 macStats->UlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcs, size, componentCarrierId);
228}
229
230
231} // namespace ns3
Base class for ***StatsCalculator classes.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink 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 GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
Takes care of storing the information generated at MAC layer.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.
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(void)
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.
virtual ~MacStatsCalculator()
Destructor.
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.
static TypeId GetTypeId(void)
Register this type.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Hold variables of type string.
Definition: string.h:41
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition: string.h:42
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:240
uint32_t subframeNo
subframe number
Definition: lte-common.h:242
uint16_t sizeTb2
size TB2
Definition: lte-common.h:247
uint16_t sizeTb1
size TB1
Definition: lte-common.h:245
uint8_t componentCarrierId
component carrier ID
Definition: lte-common.h:248
uint32_t frameNo
frame number
Definition: lte-common.h:241