A Discrete-Event Network Simulator
API
lte-stats-calculator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Jaume Nin <jnin@cttc.es>
18  */
19 
20 #include "lte-stats-calculator.h"
21 
22 #include <ns3/config.h>
23 #include <ns3/log.h>
24 #include <ns3/lte-enb-net-device.h>
25 #include <ns3/lte-enb-rrc.h>
26 #include <ns3/lte-ue-net-device.h>
27 #include <ns3/lte-ue-rrc.h>
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("LteStatsCalculator");
33 
34 NS_OBJECT_ENSURE_REGISTERED(LteStatsCalculator);
35 
37  : m_dlOutputFilename(""),
38  m_ulOutputFilename("")
39 {
40  // Nothing to do here
41 }
42 
44 {
45  // Nothing to do here
46 }
47 
48 TypeId
50 {
51  static TypeId tid = TypeId("ns3::LteStatsCalculator")
52  .SetParent<Object>()
53  .SetGroupName("Lte")
54  .AddConstructor<LteStatsCalculator>();
55  return tid;
56 }
57 
58 void
59 LteStatsCalculator::SetUlOutputFilename(std::string outputFilename)
60 {
61  m_ulOutputFilename = outputFilename;
62 }
63 
64 std::string
66 {
67  return m_ulOutputFilename;
68 }
69 
70 void
71 LteStatsCalculator::SetDlOutputFilename(std::string outputFilename)
72 {
73  m_dlOutputFilename = outputFilename;
74 }
75 
76 std::string
78 {
79  return m_dlOutputFilename;
80 }
81 
82 bool
84 {
85  if (m_pathImsiMap.find(path) == m_pathImsiMap.end())
86  {
87  return false;
88  }
89  else
90  {
91  return true;
92  }
93 }
94 
95 void
96 LteStatsCalculator::SetImsiPath(std::string path, uint64_t imsi)
97 {
98  NS_LOG_FUNCTION(this << path << imsi);
99  m_pathImsiMap[path] = imsi;
100 }
101 
102 uint64_t
104 {
105  return m_pathImsiMap.find(path)->second;
106 }
107 
108 bool
110 {
111  if (m_pathCellIdMap.find(path) == m_pathCellIdMap.end())
112  {
113  return false;
114  }
115  else
116  {
117  return true;
118  }
119 }
120 
121 void
122 LteStatsCalculator::SetCellIdPath(std::string path, uint16_t cellId)
123 {
124  NS_LOG_FUNCTION(this << path << cellId);
125  m_pathCellIdMap[path] = cellId;
126 }
127 
128 uint16_t
130 {
131  return m_pathCellIdMap.find(path)->second;
132 }
133 
134 uint64_t
136 {
138  // Sample path input:
139  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
140 
141  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
142  std::string ueMapPath = path.substr(0, path.find("/DataRadioBearerMap"));
144 
145  if (match.GetN() != 0)
146  {
147  Ptr<Object> ueInfo = match.Get(0);
148  NS_LOG_LOGIC("FindImsiFromEnbRlcPath: " << path << ", "
149  << ueInfo->GetObject<UeManager>()->GetImsi());
150  return ueInfo->GetObject<UeManager>()->GetImsi();
151  }
152  else
153  {
154  NS_FATAL_ERROR("Lookup " << ueMapPath << " got no matches");
155  }
156  return 0; // Silence compiler warning about lack of return value
157 }
158 
159 uint64_t
161 {
163  // Sample path input:
164  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
165 
166  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
167  std::string ueRlcPath = path.substr(0, path.find("/LteUePhy"));
168  ueRlcPath += "/LteUeRrc";
170 
171  if (match.GetN() != 0)
172  {
173  Ptr<Object> ueRrc = match.Get(0);
174  return ueRrc->GetObject<LteUeRrc>()->GetImsi();
175  }
176  else
177  {
178  NS_FATAL_ERROR("Lookup " << ueRlcPath << " got no matches");
179  }
180  return 0;
181 }
182 
183 uint64_t
185 {
187  // Sample path input:
188  // /NodeList/#NodeId/DeviceList/#DeviceId/
189 
190  // We retrieve the Imsi associated to the LteUeNetDevice
192 
193  if (match.GetN() != 0)
194  {
195  Ptr<Object> ueNetDevice = match.Get(0);
196  NS_LOG_LOGIC("FindImsiFromLteNetDevice: "
197  << path << ", " << ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi());
198  return ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi();
199  }
200  else
201  {
202  NS_FATAL_ERROR("Lookup " << path << " got no matches");
203  }
204  return 0; // Silence compiler warning about lack of return value
205 }
206 
207 uint16_t
209 {
211  // Sample path input:
212  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
213 
214  // We retrieve the CellId associated to the Enb
215  std::string enbNetDevicePath = path.substr(0, path.find("/LteEnbRrc"));
216  Config::MatchContainer match = Config::LookupMatches(enbNetDevicePath);
217  if (match.GetN() != 0)
218  {
219  Ptr<Object> enbNetDevice = match.Get(0);
220  NS_LOG_LOGIC("FindCellIdFromEnbRlcPath: "
221  << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId());
222  return enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId();
223  }
224  else
225  {
226  NS_FATAL_ERROR("Lookup " << enbNetDevicePath << " got no matches");
227  }
228  return 0; // Silence compiler warning about lack of return value
229 }
230 
231 uint64_t
232 LteStatsCalculator::FindImsiFromEnbMac(std::string path, uint16_t rnti)
233 {
234  NS_LOG_FUNCTION(path << rnti);
235 
236  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
237  std::ostringstream oss;
238  std::string p = path.substr(0, path.find("/LteEnbMac"));
239  oss << rnti;
240  p += "/LteEnbRrc/UeMap/" + oss.str();
241  uint64_t imsi = FindImsiFromEnbRlcPath(p);
242  NS_LOG_LOGIC("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
243  return imsi;
244 }
245 
246 uint16_t
248 {
249  NS_LOG_FUNCTION(path << rnti);
250  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
251  std::ostringstream oss;
252  std::string p = path.substr(0, path.find("/LteEnbMac"));
253  oss << rnti;
254  p += "/LteEnbRrc/UeMap/" + oss.str();
255  uint16_t cellId = FindCellIdFromEnbRlcPath(p);
256  NS_LOG_LOGIC("FindCellIdFromEnbMac: " << path << ", " << rnti << ", " << cellId);
257  return cellId;
258 }
259 
260 uint64_t
261 LteStatsCalculator::FindImsiForEnb(std::string path, uint16_t rnti)
262 {
263  NS_LOG_FUNCTION(path << rnti);
264  uint64_t imsi = 0;
265  if (path.find("/DlPhyTransmission"))
266  {
267  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
268  std::ostringstream oss;
269  std::string p = path.substr(0, path.find("/LteEnbPhy"));
270  oss << rnti;
271  p += "/LteEnbRrc/UeMap/" + oss.str();
272  imsi = FindImsiFromEnbRlcPath(p);
273  NS_LOG_LOGIC("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
274  }
275  else if (path.find("/UlPhyReception"))
276  {
277  std::string p = path.substr(0, path.find("/LteUePhy"));
278  imsi = FindImsiFromLteNetDevice(p);
279  NS_LOG_LOGIC("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
280  }
281  return imsi;
282 }
283 
284 uint64_t
285 LteStatsCalculator::FindImsiForUe(std::string path, uint16_t rnti)
286 {
287  NS_LOG_FUNCTION(path << rnti);
288  uint64_t imsi = 0;
289  if (path.find("/UlPhyTransmission"))
290  {
291  std::string p = path.substr(0, path.find("/LteUePhy"));
292  imsi = FindImsiFromLteNetDevice(p);
293  NS_LOG_LOGIC("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
294  }
295  else if (path.find("/DlPhyReception"))
296  {
297  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
298  std::ostringstream oss;
299  std::string p = path.substr(0, path.find("/LteEnbPhy"));
300  oss << rnti;
301  p += "/LteEnbRrc/UeMap/" + oss.str();
302  imsi = FindImsiFromEnbRlcPath(p);
303  NS_LOG_LOGIC("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
304  }
305  return imsi;
306 }
307 
308 } // namespace ns3
hold a set of objects which match a specific search string.
Definition: config.h:195
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:82
std::size_t GetN() const
Definition: config.cc:75
The eNodeB device implementation.
uint16_t GetCellId() const
Base class for ***StatsCalculator classes.
void SetImsiPath(std::string path, uint64_t imsi)
Stores the (path, imsi) pairs in a map.
void SetCellIdPath(std::string path, uint16_t cellId)
Stores the (path, cellId) pairs in a map.
bool ExistsCellIdPath(std::string path)
Checks if there is an already stored cell id for the given path.
std::string m_ulOutputFilename
Name of the file where the uplink results will be saved.
std::string GetUlOutputFilename()
Get 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 uint64_t FindImsiFromEnbRlcPath(std::string path)
Retrieves IMSI from Enb RLC path in the attribute system.
static uint64_t FindImsiForUe(std::string path, uint16_t rnti)
Retrieves IMSI from path for Ue in the attribute system.
uint64_t GetImsiPath(std::string path)
Retrieves the imsi information for the given path.
~LteStatsCalculator() override
Destructor.
static uint64_t FindImsiFromUePhy(std::string path)
Retrieves IMSI from Ue PHY path in the attribute system.
std::map< std::string, uint64_t > m_pathImsiMap
List of IMSI by path in the attribute system.
void SetUlOutputFilename(std::string outputFilename)
Set the name of the file where the uplink statistics will be stored.
static TypeId GetTypeId()
Register this type.
std::map< std::string, uint16_t > m_pathCellIdMap
List of CellId by path in the attribute system.
bool ExistsImsiPath(std::string path)
Checks if there is an already stored IMSI for the given path.
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
Retrieves CellId from Enb RLC path in the attribute system.
std::string GetDlOutputFilename()
Get the name of the file where the downlink statistics will be stored.
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
static uint16_t FindCellIdFromEnbMac(std::string path, uint16_t rnti)
Retrieves CellId from Enb MAC path in the attribute system.
uint16_t GetCellIdPath(std::string path)
Retrieves the cell id information for the given path.
std::string m_dlOutputFilename
Name of the file where the downlink results will be saved.
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
Retrieves IMSI from Enb MAC path in the attribute system.
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
Retrieves IMSI from path for Enb in the attribute system.
The LteUeNetDevice class implements the UE net device.
uint64_t GetImsi() const
Get the IMSI.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition: lte-enb-rrc.h:72
uint64_t GetImsi() const
MatchContainer LookupMatches(std::string path)
Definition: config.cc:999
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.