A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
31 NS_OBJECT_ENSURE_REGISTERED (MacStatsCalculator)
32  ;
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  .AddConstructor<MacStatsCalculator> ()
53  .AddAttribute ("DlOutputFilename",
54  "Name of the file where the downlink results will be saved.",
55  StringValue ("DlMacStats.txt"),
56  MakeStringAccessor (&MacStatsCalculator::SetDlOutputFilename),
57  MakeStringChecker ())
58  .AddAttribute ("UlOutputFilename",
59  "Name of the file where the uplink results will be saved.",
60  StringValue ("UlMacStats.txt"),
61  MakeStringAccessor (&MacStatsCalculator::SetUlOutputFilename),
62  MakeStringChecker ())
63  ;
64  return tid;
65 }
66 
67 void
68 MacStatsCalculator::SetUlOutputFilename (std::string outputFilename)
69 {
71 }
72 
73 std::string
75 {
77 }
78 
79 void
80 MacStatsCalculator::SetDlOutputFilename (std::string outputFilename)
81 {
83 }
84 
85 std::string
87 {
89 }
90 
91 void
92 MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo,
93  uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
94 {
95  NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcsTb1 << sizeTb1 << (uint32_t) mcsTb2 << sizeTb2);
96  NS_LOG_INFO ("Write DL Mac Stats in " << GetDlOutputFilename ().c_str ());
97 
98  std::ofstream outFile;
99  if ( m_dlFirstWrite == true )
100  {
101  outFile.open (GetDlOutputFilename ().c_str ());
102  if (!outFile.is_open ())
103  {
104  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
105  return;
106  }
107  m_dlFirstWrite = false;
108  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcsTb1\tsizeTb1\tmcsTb2\tsizeTb2";
109  outFile << std::endl;
110  }
111  else
112  {
113  outFile.open (GetDlOutputFilename ().c_str (), std::ios_base::app);
114  if (!outFile.is_open ())
115  {
116  NS_LOG_ERROR ("Can't open file " << GetDlOutputFilename ().c_str ());
117  return;
118  }
119  }
120 
121  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
122  outFile << (uint32_t) cellId << "\t";
123  outFile << imsi << "\t";
124  outFile << frameNo << "\t";
125  outFile << subframeNo << "\t";
126  outFile << rnti << "\t";
127  outFile << (uint32_t) mcsTb1 << "\t";
128  outFile << sizeTb1 << "\t";
129  outFile << (uint32_t) mcsTb2 << "\t";
130  outFile << sizeTb2 << std::endl;
131  outFile.close ();
132 }
133 
134 void
135 MacStatsCalculator::UlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo,
136  uint32_t subframeNo, uint16_t rnti,uint8_t mcsTb, uint16_t size)
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  std::ofstream outFile;
142  if ( m_ulFirstWrite == true )
143  {
144  outFile.open (GetUlOutputFilename ().c_str ());
145  if (!outFile.is_open ())
146  {
147  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
148  return;
149  }
150  m_ulFirstWrite = false;
151  outFile << "% time\tcellId\tIMSI\tframe\tsframe\tRNTI\tmcs\tsize";
152  outFile << std::endl;
153  }
154  else
155  {
156  outFile.open (GetUlOutputFilename ().c_str (), std::ios_base::app);
157  if (!outFile.is_open ())
158  {
159  NS_LOG_ERROR ("Can't open file " << GetUlOutputFilename ().c_str ());
160  return;
161  }
162  }
163 
164  outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t";
165  outFile << (uint32_t) cellId << "\t";
166  outFile << imsi << "\t";
167  outFile << frameNo << "\t";
168  outFile << subframeNo << "\t";
169  outFile << rnti << "\t";
170  outFile << (uint32_t) mcsTb << "\t";
171  outFile << size << std::endl;
172  outFile.close ();
173 }
174 
175 void
177  std::string path, uint32_t frameNo, uint32_t subframeNo,
178  uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1,
179  uint8_t mcsTb2, uint16_t sizeTb2)
180 {
181  NS_LOG_FUNCTION (macStats << path);
182  uint64_t imsi = 0;
183  std::ostringstream pathAndRnti;
184  pathAndRnti << path << "/" << rnti;
185  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
186  {
187  imsi = macStats->GetImsiPath (pathAndRnti.str ());
188  }
189  else
190  {
191  imsi = FindImsiFromEnbMac (path, rnti);
192  macStats->SetImsiPath (pathAndRnti.str (), imsi);
193  }
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 = FindCellIdFromEnbMac (path, rnti);
203  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
204  }
205 
206  macStats->DlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
207 }
208 
209 void
211  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
212  uint8_t mcs, uint16_t size)
213 {
214  NS_LOG_FUNCTION (macStats << path);
215 
216  uint64_t imsi = 0;
217  std::ostringstream pathAndRnti;
218  pathAndRnti << path << "/" << rnti;
219  if (macStats->ExistsImsiPath (pathAndRnti.str ()) == true)
220  {
221  imsi = macStats->GetImsiPath (pathAndRnti.str ());
222  }
223  else
224  {
225  imsi = FindImsiFromEnbMac (path, rnti);
226  macStats->SetImsiPath (pathAndRnti.str (), imsi);
227  }
228  uint16_t cellId = 0;
229  if (macStats->ExistsCellIdPath (pathAndRnti.str ()) == true)
230  {
231  cellId = macStats->GetCellIdPath (pathAndRnti.str ());
232  }
233  else
234  {
235  cellId = FindCellIdFromEnbMac (path, rnti);
236  macStats->SetCellIdPath (pathAndRnti.str (), cellId);
237  }
238 
239  macStats->UlScheduling (cellId, imsi, frameNo, subframeNo, rnti, mcs, size);
240 }
241 
242 
243 } // namespace ns3
Doxygen introspection did not find any typical Config paths.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
hold variables of type string
Definition: string.h:19
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.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_INFO(msg)
Definition: log.h:298
static uint16_t FindCellIdFromEnbMac(std::string path, uint16_t rnti)
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)
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
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.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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
Definition: nstime.h:299
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)
Definition: log.h:271
virtual ~MacStatsCalculator()
Destructor.
a unique identifier for an interface.
Definition: type-id.h:49
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:611
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.