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  */
20 
21 #include "mac-stats-calculator.h"
22 #include "ns3/string.h"
23 #include <ns3/simulator.h>
24 #include <ns3/log.h>
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("MacStatsCalculator");
29 
30 NS_OBJECT_ENSURE_REGISTERED (MacStatsCalculator);
31 
33  : m_dlFirstWrite (true),
34  m_ulFirstWrite (true)
35 {
36  NS_LOG_FUNCTION (this);
37 
38 }
39 
41 {
42  NS_LOG_FUNCTION (this);
43 }
44 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::MacStatsCalculator")
50  .AddConstructor<MacStatsCalculator> ()
51  .AddAttribute ("DlOutputFilename",
52  "Name of the file where the downlink results will be saved.",
53  StringValue ("DlMacStats.txt"),
56  .AddAttribute ("UlOutputFilename",
57  "Name of the file where the uplink results will be saved.",
58  StringValue ("UlMacStats.txt"),
61  ;
62  return tid;
63 }
64 
65 void
66 MacStatsCalculator::SetUlOutputFilename (std::string outputFilename)
67 {
69 }
70 
71 std::string
73 {
75 }
76 
77 void
78 MacStatsCalculator::SetDlOutputFilename (std::string outputFilename)
79 {
81 }
82 
83 std::string
85 {
87 }
88 
89 void
90 MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo,
91  uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
92 {
93  NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcsTb1 << sizeTb1 << (uint32_t) mcsTb2 << sizeTb2);
94  NS_LOG_INFO ("Write DL Mac Stats in " << GetDlOutputFilename ().c_str ());
95 
96  std::ofstream outFile;
97  if ( m_dlFirstWrite == true )
98  {
99  outFile.open (GetDlOutputFilename ().c_str ());
100  if (!outFile.is_open ())
101  {
102  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
103  return;
104  }
105  m_dlFirstWrite = false;
106  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2";
107  outFile << std::endl;
108  }
109  else
110  {
111  outFile.open (GetDlOutputFilename ().c_str (), std::ios_base::app);
112  if (!outFile.is_open ())
113  {
114  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
115  return;
116  }
117  }
118 
119  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
120  outFile << (uint32_t) cellId << "\t";
121  outFile << imsi << "\t";
122  outFile << frameNo << "\t";
123  outFile << subframeNo << "\t";
124  outFile << rnti << "\t";
125  outFile << (uint32_t) mcsTb1 << "\t";
126  outFile << sizeTb1 << "\t";
127  outFile << (uint32_t) mcsTb2 << "\t";
128  outFile << sizeTb2 << std::endl;
129  outFile.close ();
130 }
131 
132 void
133 MacStatsCalculator::UlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo,
134  uint32_t subframeNo, uint16_t rnti,uint8_t mcsTb, uint16_t size)
135 {
136  NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcsTb << size);
137  NS_LOG_INFO ("Write UL Mac Stats in " << GetUlOutputFilename ().c_str ());
138 
139  std::ofstream outFile;
140  if ( m_ulFirstWrite == true )
141  {
142  outFile.open (GetUlOutputFilename ().c_str ());
143  if (!outFile.is_open ())
144  {
145  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
146  return;
147  }
148  m_ulFirstWrite = false;
149  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize";
150  outFile << std::endl;
151  }
152  else
153  {
154  outFile.open (GetUlOutputFilename ().c_str (), std::ios_base::app);
155  if (!outFile.is_open ())
156  {
157  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
158  return;
159  }
160  }
161 
162  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
163  outFile << (uint32_t) cellId << "\t";
164  outFile << imsi << "\t";
165  outFile << frameNo << "\t";
166  outFile << subframeNo << "\t";
167  outFile << rnti << "\t";
168  outFile << (uint32_t) mcsTb << "\t";
169  outFile << size << std::endl;
170  outFile.close ();
171 }
172 
173 void
175  std::string path, uint32_t frameNo, uint32_t subframeNo,
176  uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1,
177  uint8_t mcsTb2, uint16_t sizeTb2)
178 {
179  NS_LOG_FUNCTION (macStats << path);
180  uint64_t imsi = 0;
181  std::ostringstream pathAndRnti;
182  pathAndRnti << path << "/" << rnti;
183  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
184  {
185  imsi = macStats->GetImsiPath (pathAndRnti.str ());
186  }
187  else
188  {
189  imsi = FindImsiFromEnbMac (path, rnti);
190  macStats->SetImsiPath (pathAndRnti.str (), imsi);
191  }
192 
193  uint16_t cellId = 0;
194  if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
195  {
196  cellId = macStats->GetCellIdPath (pathAndRnti.str ());
197  }
198  else
199  {
200  cellId = FindCellIdFromEnbMac (path, rnti);
201  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
202  }
203 
204  macStats->DlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
205 }
206 
207 void
209  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
210  uint8_t mcs, uint16_t size)
211 {
212  NS_LOG_FUNCTION (macStats << path);
213 
214  uint64_t imsi = 0;
215  std::ostringstream pathAndRnti;
216  pathAndRnti << path << "/" << rnti;
217  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
218  {
219  imsi = macStats->GetImsiPath (pathAndRnti.str ());
220  }
221  else
222  {
223  imsi = FindImsiFromEnbMac (path, rnti);
224  macStats->SetImsiPath (pathAndRnti.str (), imsi);
225  }
226  uint16_t cellId = 0;
227  if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
228  {
229  cellId = macStats->GetCellIdPath (pathAndRnti.str ());
230  }
231  else
232  {
233  cellId = FindCellIdFromEnbMac (path, rnti);
234  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
235  }
236 
237  macStats->UlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcs, size);
238 }
239 
240 
241 } // 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 "...
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
Retrieves IMSI from Enb MAC path in the attribute system.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Hold variables of type string.
Definition: string.h:41
static void DlSchedulingCallback(Ptr< MacStatsCalculator > macStats, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
Trace sink for the ns3::LteEnbMac::DlScheduling trace source.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
static uint16_t FindCellIdFromEnbMac(std::string path, uint16_t rnti)
Retrieves CellId from Enb MAC path in the attribute system.
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.
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.
void DlScheduling(uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
Notifies the stats calculator that an downlink scheduling has occurred.
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
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:223
static void UlSchedulingCallback(Ptr< MacStatsCalculator > macStats, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcs, uint16_t size)
Trace sink for the ns3::LteEnbMac::UlScheduling trace source.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:339
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
void UlScheduling(uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb, uint16_t sizeTb)
Notifies the stats calculator that an uplink scheduling has occurred.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
virtual ~MacStatsCalculator()
Destructor.
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:51
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.