A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
NS_OBJECT_ENSURE_REGISTERED
(MacStatsCalculator);
31
32
MacStatsCalculator::MacStatsCalculator
()
33
: m_dlFirstWrite (true),
34
m_ulFirstWrite (true)
35
{
36
NS_LOG_FUNCTION
(
this
);
37
38
}
39
40
MacStatsCalculator::~MacStatsCalculator
()
41
{
42
NS_LOG_FUNCTION
(
this
);
43
}
44
45
TypeId
46
MacStatsCalculator::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::MacStatsCalculator"
)
49
.
SetParent
<
LteStatsCalculator
> ()
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
{
68
LteStatsCalculator::SetUlOutputFilename
(outputFilename);
69
}
70
71
std::string
72
MacStatsCalculator::GetUlOutputFilename
(
void
)
73
{
74
return
LteStatsCalculator::GetUlOutputFilename
();
75
}
76
77
void
78
MacStatsCalculator::SetDlOutputFilename
(std::string outputFilename)
79
{
80
LteStatsCalculator::SetDlOutputFilename
(outputFilename);
81
}
82
83
std::string
84
MacStatsCalculator::GetDlOutputFilename
(
void
)
85
{
86
return
LteStatsCalculator::GetDlOutputFilename
();
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
src
lte
helper
mac-stats-calculator.cc
Generated on Tue May 14 2013 11:08:24 for ns-3 by
1.8.1.2