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 
23 #include "mac-stats-calculator.h"
24 #include "ns3/string.h"
25 #include <ns3/simulator.h>
26 #include <ns3/log.h>
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("MacStatsCalculator");
31 
32 NS_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 }
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::MacStatsCalculator")
52  .SetGroupName("Lte")
53  .AddConstructor<MacStatsCalculator> ()
54  .AddAttribute ("DlOutputFilename",
55  "Name of the file where the downlink results will be saved.",
56  StringValue ("DlMacStats.txt"),
59  .AddAttribute ("UlOutputFilename",
60  "Name of the file where the uplink results will be saved.",
61  StringValue ("UlMacStats.txt"),
64  ;
65  return tid;
66 }
67 
68 void
69 MacStatsCalculator::SetUlOutputFilename (std::string outputFilename)
70 {
72 }
73 
74 std::string
76 {
78 }
79 
80 void
81 MacStatsCalculator::SetDlOutputFilename (std::string outputFilename)
82 {
84 }
85 
86 std::string
88 {
90 }
91 
92 void
93 MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
94 {
95  NS_LOG_FUNCTION (this << cellId << imsi << dlSchedulingCallbackInfo.frameNo << dlSchedulingCallbackInfo.subframeNo <<
96  dlSchedulingCallbackInfo.rnti << (uint32_t) dlSchedulingCallbackInfo.mcsTb1 << dlSchedulingCallbackInfo.sizeTb1 << (uint32_t) dlSchedulingCallbackInfo.mcsTb2 << dlSchedulingCallbackInfo.sizeTb2);
97  NS_LOG_INFO ("Write DL Mac Stats in " << GetDlOutputFilename ().c_str ());
98 
99  std::ofstream outFile;
100  if ( m_dlFirstWrite == true )
101  {
102  outFile.open (GetDlOutputFilename ().c_str ());
103  if (!outFile.is_open ())
104  {
105  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
106  return;
107  }
108  m_dlFirstWrite = false;
109  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2\tccId";
110  outFile << std::endl;
111  }
112  else
113  {
114  outFile.open (GetDlOutputFilename ().c_str (), std::ios_base::app);
115  if (!outFile.is_open ())
116  {
117  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
118  return;
119  }
120  }
121 
122  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
123  outFile << (uint32_t) cellId << "\t";
124  outFile << imsi << "\t";
125  outFile << dlSchedulingCallbackInfo.frameNo << "\t";
126  outFile << dlSchedulingCallbackInfo.subframeNo << "\t";
127  outFile << dlSchedulingCallbackInfo.rnti << "\t";
128  outFile << (uint32_t) dlSchedulingCallbackInfo.mcsTb1 << "\t";
129  outFile << dlSchedulingCallbackInfo.sizeTb1 << "\t";
130  outFile << (uint32_t) dlSchedulingCallbackInfo.mcsTb2 << "\t";
131  outFile << dlSchedulingCallbackInfo.sizeTb2 << "\t";
132  outFile << (uint32_t) dlSchedulingCallbackInfo.componentCarrierId << std::endl;
133  outFile.close ();
134 }
135 
136 void
137 MacStatsCalculator::UlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo,
138  uint32_t subframeNo, uint16_t rnti,uint8_t mcsTb, uint16_t size, uint8_t componentCarrierId)
139 {
140  NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcsTb << size);
141  NS_LOG_INFO ("Write UL Mac Stats in " << GetUlOutputFilename ().c_str ());
142 
143  std::ofstream outFile;
144  if ( m_ulFirstWrite == true )
145  {
146  outFile.open (GetUlOutputFilename ().c_str ());
147  if (!outFile.is_open ())
148  {
149  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
150  return;
151  }
152  m_ulFirstWrite = false;
153  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize\tccId";
154  outFile << std::endl;
155  }
156  else
157  {
158  outFile.open (GetUlOutputFilename ().c_str (), std::ios_base::app);
159  if (!outFile.is_open ())
160  {
161  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
162  return;
163  }
164  }
165 
166  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
167  outFile << (uint32_t) cellId << "\t";
168  outFile << imsi << "\t";
169  outFile << frameNo << "\t";
170  outFile << subframeNo << "\t";
171  outFile << rnti << "\t";
172  outFile << (uint32_t) mcsTb << "\t";
173  outFile << size << "\t";
174  outFile << (uint32_t) componentCarrierId << std::endl;
175  outFile.close ();
176 }
177 
178 void
180 {
181  NS_LOG_FUNCTION (macStats << path);
182  uint64_t imsi = 0;
183  std::ostringstream pathAndRnti;
184  std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
185  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << dlSchedulingCallbackInfo.rnti;
186  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
187  {
188  imsi = macStats->GetImsiPath (pathAndRnti.str ());
189  }
190  else
191  {
192  imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
193  macStats->SetImsiPath (pathAndRnti.str (), imsi);
194  }
195  uint16_t cellId = 0;
196  if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
197  {
198  cellId = macStats->GetCellIdPath (pathAndRnti.str ());
199  }
200  else
201  {
202  cellId = FindCellIdFromEnbRlcPath (pathAndRnti.str ());
203  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
204  }
205 
206  macStats->DlScheduling (cellId, imsi, dlSchedulingCallbackInfo);
207 }
208 
209 void
211  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
212  uint8_t mcs, uint16_t size, uint8_t componentCarrierId)
213 {
214  NS_LOG_FUNCTION (macStats << path);
215 
216  uint64_t imsi = 0;
217  std::ostringstream pathAndRnti;
218  std::string pathEnb = path.substr (0, path.find ("/ComponentCarrierMap"));
219  pathAndRnti << pathEnb << "/LteEnbRrc/UeMap/" << rnti;
220  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
221  {
222  imsi = macStats->GetImsiPath (pathAndRnti.str ());
223  }
224  else
225  {
226  imsi = FindImsiFromEnbRlcPath (pathAndRnti.str ());
227  macStats->SetImsiPath (pathAndRnti.str (), imsi);
228  }
229  uint16_t cellId = 0;
230  if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
231  {
232  cellId = macStats->GetCellIdPath (pathAndRnti.str ());
233  }
234  else
235  {
236  cellId = FindCellIdFromEnbRlcPath (pathAndRnti.str ());
237  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
238  }
239 
240  macStats->UlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcs, size, componentCarrierId);
241 }
242 
243 
244 } // namespace ns3
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
Base class for ***StatsCalculator classes.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint16_t sizeTb2
size TB2
Definition: lte-common.h:247
Hold variables of type string.
Definition: string.h:41
uint32_t frameNo
frame number
Definition: lte-common.h:241
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
Retrieves CellId from Enb RLC path in the attribute system.
Takes care of storing the information generated at MAC layer.
uint16_t sizeTb1
size TB1
Definition: lte-common.h:245
uint8_t componentCarrierId
component carrier ID
Definition: lte-common.h:248
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.
bool m_ulFirstWrite
When writing UL MAC statistics first time to file, columns description is added.
void SetUlOutputFilename(std::string outputFilename)
Set 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 TypeId GetTypeId(void)
Register this type.
uint32_t subframeNo
subframe number
Definition: lte-common.h:242
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:373
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.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.
bool m_dlFirstWrite
When writing DL MAC statistics first time to file, columns description is added.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
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.
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
static void DlSchedulingCallback(Ptr< MacStatsCalculator > macStats, std::string path, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
Trace sink for the ns3::LteEnbMac::DlScheduling trace source.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
virtual ~MacStatsCalculator()
Destructor.
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:239
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: string.h:42
a unique identifier for an interface.
Definition: type-id.h:58
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
void DlScheduling(uint16_t cellId, uint64_t imsi, DlSchedulingCallbackInfo dlSchedulingCallbackInfo)
Notifies the stats calculator that an downlink scheduling has occurred.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.