A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mac-stats-calculator.cc
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"),
54  MakeStringAccessor (&MacStatsCalculator::SetDlOutputFilename),
55  MakeStringChecker ())
56  .AddAttribute ("UlOutputFilename",
57  "Name of the file where the uplink results will be saved.",
58  StringValue ("UlMacStats.txt"),
59  MakeStringAccessor (&MacStatsCalculator::SetUlOutputFilename),
60  MakeStringChecker ())
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 mcs, uint16_t size)
135 {
136  NS_LOG_FUNCTION (this << cellId << imsi << frameNo << subframeNo << rnti << (uint32_t) mcs << 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) mcs << "\t";
169  outFile << size << std::endl;
170  outFile.close ();
171 }
172 
173 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
hold variables of type string
Definition: string.h:19
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
void SetUlOutputFilename(std::string outputFilename)
void SetDlOutputFilename(std::string outputFilename)
static TypeId GetTypeId(void)
std::string GetUlOutputFilename(void)
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)
void SetDlOutputFilename(std::string outputFilename)
std::string GetDlOutputFilename(void)
static Time Now(void)
Definition: simulator.cc:179
int64_t GetNanoSeconds(void) const
Definition: nstime.h:287
std::string GetUlOutputFilename(void)
#define NS_LOG_ERROR(msg)
Definition: log.h:237
a unique identifier for an interface.
Definition: type-id.h:44
void SetUlOutputFilename(std::string outputFilename)
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
void UlScheduling(uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcs, uint16_t sizeTb)
std::string GetDlOutputFilename(void)