forked from nsnam/ns-3-dev-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlte-stats-calculator.cc
312 lines (268 loc) · 8.26 KB
/
lte-stats-calculator.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Jaume Nin <[email protected]>
*/
#include "lte-stats-calculator.h"
#include <ns3/log.h>
#include <ns3/config.h>
#include <ns3/lte-enb-rrc.h>
#include <ns3/lte-ue-rrc.h>
#include <ns3/lte-enb-net-device.h>
#include <ns3/lte-ue-net-device.h>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("LteStatsCalculator");
NS_OBJECT_ENSURE_REGISTERED (LteStatsCalculator);
LteStatsCalculator::LteStatsCalculator ()
: m_dlOutputFilename (""),
m_ulOutputFilename ("")
{
// Nothing to do here
}
LteStatsCalculator::~LteStatsCalculator ()
{
// Nothing to do here
}
TypeId
LteStatsCalculator::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::LteStatsCalculator")
.SetParent<Object> ()
.SetGroupName("Lte")
.AddConstructor<LteStatsCalculator> ()
;
return tid;
}
void
LteStatsCalculator::SetUlOutputFilename (std::string outputFilename)
{
m_ulOutputFilename = outputFilename;
}
std::string
LteStatsCalculator::GetUlOutputFilename (void)
{
return m_ulOutputFilename;
}
void
LteStatsCalculator::SetDlOutputFilename (std::string outputFilename)
{
m_dlOutputFilename = outputFilename;
}
std::string
LteStatsCalculator::GetDlOutputFilename (void)
{
return m_dlOutputFilename;
}
bool
LteStatsCalculator::ExistsImsiPath (std::string path)
{
if (m_pathImsiMap.find (path) == m_pathImsiMap.end () )
{
return false;
}
else
{
return true;
}
}
void
LteStatsCalculator::SetImsiPath (std::string path, uint64_t imsi)
{
NS_LOG_FUNCTION (this << path << imsi);
m_pathImsiMap[path] = imsi;
}
uint64_t
LteStatsCalculator::GetImsiPath (std::string path)
{
return m_pathImsiMap.find (path)->second;
}
bool
LteStatsCalculator::ExistsCellIdPath (std::string path)
{
if (m_pathCellIdMap.find (path) == m_pathCellIdMap.end () )
{
return false;
}
else
{
return true;
}
}
void
LteStatsCalculator::SetCellIdPath (std::string path, uint16_t cellId)
{
NS_LOG_FUNCTION (this << path << cellId);
m_pathCellIdMap[path] = cellId;
}
uint16_t
LteStatsCalculator::GetCellIdPath (std::string path)
{
return m_pathCellIdMap.find (path)->second;
}
uint64_t
LteStatsCalculator::FindImsiFromEnbRlcPath (std::string path)
{
NS_LOG_FUNCTION (path);
// Sample path input:
// /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
// We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
std::string ueMapPath = path.substr (0, path.find ("/DataRadioBearerMap"));
Config::MatchContainer match = Config::LookupMatches (ueMapPath);
if (match.GetN () != 0)
{
Ptr<Object> ueInfo = match.Get (0);
NS_LOG_LOGIC ("FindImsiFromEnbRlcPath: " << path << ", " << ueInfo->GetObject<UeManager> ()->GetImsi ());
return ueInfo->GetObject<UeManager> ()->GetImsi ();
}
else
{
NS_FATAL_ERROR ("Lookup " << ueMapPath << " got no matches");
}
}
uint64_t
LteStatsCalculator::FindImsiFromUePhy (std::string path)
{
NS_LOG_FUNCTION (path);
// Sample path input:
// /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
// We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
ueRlcPath += "/LteUeRrc";
Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
if (match.GetN () != 0)
{
Ptr<Object> ueRrc = match.Get (0);
return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
}
else
{
NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
}
return 0;
}
uint64_t
LteStatsCalculator::FindImsiFromLteNetDevice (std::string path)
{
NS_LOG_FUNCTION (path);
// Sample path input:
// /NodeList/#NodeId/DeviceList/#DeviceId/
// We retrieve the Imsi associated to the LteUeNetDevice
Config::MatchContainer match = Config::LookupMatches (path);
if (match.GetN () != 0)
{
Ptr<Object> ueNetDevice = match.Get (0);
NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
}
else
{
NS_FATAL_ERROR ("Lookup " << path << " got no matches");
}
}
uint16_t
LteStatsCalculator::FindCellIdFromEnbRlcPath (std::string path)
{
NS_LOG_FUNCTION (path);
// Sample path input:
// /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
// We retrieve the CellId associated to the Enb
std::string enbNetDevicePath = path.substr (0, path.find ("/LteEnbRrc"));
Config::MatchContainer match = Config::LookupMatches (enbNetDevicePath);
if (match.GetN () != 0)
{
Ptr<Object> enbNetDevice = match.Get (0);
NS_LOG_LOGIC ("FindCellIdFromEnbRlcPath: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
}
else
{
NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
}
}
uint64_t
LteStatsCalculator::FindImsiFromEnbMac (std::string path, uint16_t rnti)
{
NS_LOG_FUNCTION (path << rnti);
// /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
std::ostringstream oss;
std::string p = path.substr (0, path.find ("/LteEnbMac"));
oss << rnti;
p += "/LteEnbRrc/UeMap/" + oss.str ();
uint64_t imsi = FindImsiFromEnbRlcPath (p);
NS_LOG_LOGIC ("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
return imsi;
}
uint16_t
LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
{
NS_LOG_FUNCTION (path << rnti);
// /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
std::ostringstream oss;
std::string p = path.substr (0, path.find ("/LteEnbMac"));
oss << rnti;
p += "/LteEnbRrc/UeMap/" + oss.str ();
uint16_t cellId = FindCellIdFromEnbRlcPath (p);
NS_LOG_LOGIC ("FindCellIdFromEnbMac: " << path << ", "<< rnti << ", " << cellId);
return cellId;
}
uint64_t
LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
{
NS_LOG_FUNCTION (path << rnti);
uint64_t imsi = 0;
if (path.find ("/DlPhyTransmission"))
{
// /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
std::ostringstream oss;
std::string p = path.substr (0, path.find ("/LteEnbPhy"));
oss << rnti;
p += "/LteEnbRrc/UeMap/" + oss.str ();
imsi = FindImsiFromEnbRlcPath (p);
NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
}
else if (path.find ("/UlPhyReception"))
{
std::string p = path.substr (0, path.find ("/LteUePhy"));
imsi = FindImsiFromLteNetDevice (p);
NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
}
return imsi;
}
uint64_t
LteStatsCalculator::FindImsiForUe (std::string path, uint16_t rnti)
{
NS_LOG_FUNCTION (path << rnti);
uint64_t imsi = 0;
if (path.find ("/UlPhyTransmission"))
{
std::string p = path.substr (0, path.find ("/LteUePhy"));
imsi = FindImsiFromLteNetDevice (p);
NS_LOG_LOGIC ("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
}
else if (path.find ("/DlPhyReception"))
{
// /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
std::ostringstream oss;
std::string p = path.substr (0, path.find ("/LteEnbPhy"));
oss << rnti;
p += "/LteEnbRrc/UeMap/" + oss.str ();
imsi = FindImsiFromEnbRlcPath (p);
NS_LOG_LOGIC ("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
}
return imsi;
}
} // namespace ns3