A Discrete-Event Network Simulator
API
lte-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 "lte-stats-calculator.h"
22 
23 #include <ns3/log.h>
24 #include <ns3/config.h>
25 #include <ns3/lte-enb-rrc.h>
26 #include <ns3/lte-ue-rrc.h>
27 #include <ns3/lte-enb-net-device.h>
28 #include <ns3/lte-ue-net-device.h>
29 
30 namespace ns3 {
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 }
43 
45 {
46  // Nothing to do here
47 }
48 
49 
50 TypeId
52 {
53  static TypeId tid = TypeId ("ns3::LteStatsCalculator")
54  .SetParent<Object> ()
55  .SetGroupName("Lte")
56  .AddConstructor<LteStatsCalculator> ()
57  ;
58  return tid;
59 }
60 
61 
62 void
63 LteStatsCalculator::SetUlOutputFilename (std::string outputFilename)
64 {
65  m_ulOutputFilename = outputFilename;
66 }
67 
68 std::string
70 {
71  return m_ulOutputFilename;
72 }
73 
74 void
75 LteStatsCalculator::SetDlOutputFilename (std::string outputFilename)
76 {
77  m_dlOutputFilename = outputFilename;
78 }
79 
80 std::string
82 {
83  return m_dlOutputFilename;
84 }
85 
86 
87 bool
89 {
90  if (m_pathImsiMap.find (path) == m_pathImsiMap.end () )
91  {
92  return false;
93  }
94  else
95  {
96  return true;
97  }
98 }
99 
100 void
101 LteStatsCalculator::SetImsiPath (std::string path, uint64_t imsi)
102 {
103  NS_LOG_FUNCTION (this << path << imsi);
104  m_pathImsiMap[path] = imsi;
105 }
106 
107 uint64_t
109 {
110  return m_pathImsiMap.find (path)->second;
111 }
112 
113 bool
115 {
116  if (m_pathCellIdMap.find (path) == m_pathCellIdMap.end () )
117  {
118  return false;
119  }
120  else
121  {
122  return true;
123  }
124 }
125 
126 void
127 LteStatsCalculator::SetCellIdPath (std::string path, uint16_t cellId)
128 {
129  NS_LOG_FUNCTION (this << path << cellId);
130  m_pathCellIdMap[path] = cellId;
131 }
132 
133 uint16_t
135 {
136  return m_pathCellIdMap.find (path)->second;
137 }
138 
139 
140 uint64_t
142 {
143  NS_LOG_FUNCTION (path);
144  // Sample path input:
145  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
146 
147  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
148  std::string ueMapPath = path.substr (0, path.find ("/DataRadioBearerMap"));
149  Config::MatchContainer match = Config::LookupMatches (ueMapPath);
150 
151  if (match.GetN () != 0)
152  {
153  Ptr<Object> ueInfo = match.Get (0);
154  NS_LOG_LOGIC ("FindImsiFromEnbRlcPath: " << path << ", " << ueInfo->GetObject<UeManager> ()->GetImsi ());
155  return ueInfo->GetObject<UeManager> ()->GetImsi ();
156  }
157  else
158  {
159  NS_FATAL_ERROR ("Lookup " << ueMapPath << " got no matches");
160  }
161  return 0; // Silence compiler warning about lack of return value
162 }
163 
164 uint64_t
166 {
167  NS_LOG_FUNCTION (path);
168  // Sample path input:
169  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
170 
171  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
172  std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
173  ueRlcPath += "/LteUeRrc";
174  Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
175 
176  if (match.GetN () != 0)
177  {
178  Ptr<Object> ueRrc = match.Get (0);
179  return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
180  }
181  else
182  {
183  NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
184  }
185  return 0;
186 }
187 
188 
189 uint64_t
191 {
192  NS_LOG_FUNCTION (path);
193  // Sample path input:
194  // /NodeList/#NodeId/DeviceList/#DeviceId/
195 
196  // We retrieve the Imsi associated to the LteUeNetDevice
198 
199  if (match.GetN () != 0)
200  {
201  Ptr<Object> ueNetDevice = match.Get (0);
202  NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
203  return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
204  }
205  else
206  {
207  NS_FATAL_ERROR ("Lookup " << path << " got no matches");
208  }
209  return 0; // Silence compiler warning about lack of return value
210 }
211 
212 uint16_t
214 {
215  NS_LOG_FUNCTION (path);
216  // Sample path input:
217  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
218 
219  // We retrieve the CellId associated to the Enb
220  std::string enbNetDevicePath = path.substr (0, path.find ("/LteEnbRrc"));
221  Config::MatchContainer match = Config::LookupMatches (enbNetDevicePath);
222  if (match.GetN () != 0)
223  {
224  Ptr<Object> enbNetDevice = match.Get (0);
225  NS_LOG_LOGIC ("FindCellIdFromEnbRlcPath: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
226  return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
227  }
228  else
229  {
230  NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
231  }
232  return 0; // Silence compiler warning about lack of return value
233 }
234 
235 uint64_t
236 LteStatsCalculator::FindImsiFromEnbMac (std::string path, uint16_t rnti)
237 {
238  NS_LOG_FUNCTION (path << rnti);
239 
240  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
241  std::ostringstream oss;
242  std::string p = path.substr (0, path.find ("/LteEnbMac"));
243  oss << rnti;
244  p += "/LteEnbRrc/UeMap/" + oss.str ();
245  uint64_t imsi = FindImsiFromEnbRlcPath (p);
246  NS_LOG_LOGIC ("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
247  return imsi;
248 }
249 
250 uint16_t
251 LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
252 {
253  NS_LOG_FUNCTION (path << rnti);
254  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
255  std::ostringstream oss;
256  std::string p = path.substr (0, path.find ("/LteEnbMac"));
257  oss << rnti;
258  p += "/LteEnbRrc/UeMap/" + oss.str ();
259  uint16_t cellId = FindCellIdFromEnbRlcPath (p);
260  NS_LOG_LOGIC ("FindCellIdFromEnbMac: " << path << ", "<< rnti << ", " << cellId);
261  return cellId;
262 }
263 
264 
265 uint64_t
266 LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
267 {
268  NS_LOG_FUNCTION (path << rnti);
269  uint64_t imsi = 0;
270  if (path.find ("/DlPhyTransmission"))
271  {
272  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
273  std::ostringstream oss;
274  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
275  oss << rnti;
276  p += "/LteEnbRrc/UeMap/" + oss.str ();
277  imsi = FindImsiFromEnbRlcPath (p);
278  NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
279  }
280  else if (path.find ("/UlPhyReception"))
281  {
282  std::string p = path.substr (0, path.find ("/LteUePhy"));
283  imsi = FindImsiFromLteNetDevice (p);
284  NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
285  }
286  return imsi;
287 }
288 
289 
290 uint64_t
291 LteStatsCalculator::FindImsiForUe (std::string path, uint16_t rnti)
292 {
293  NS_LOG_FUNCTION (path << rnti);
294  uint64_t imsi = 0;
295  if (path.find ("/UlPhyTransmission"))
296  {
297  std::string p = path.substr (0, path.find ("/LteUePhy"));
298  imsi = FindImsiFromLteNetDevice (p);
299  NS_LOG_LOGIC ("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
300  }
301  else if (path.find ("/DlPhyReception"))
302  {
303  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
304  std::ostringstream oss;
305  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
306  oss << rnti;
307  p += "/LteEnbRrc/UeMap/" + oss.str ();
308  imsi = FindImsiFromEnbRlcPath (p);
309  NS_LOG_LOGIC ("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
310  }
311  return imsi;
312 }
313 
314 
315 } // namespace ns3
hold a set of objects which match a specific search string.
Definition: config.h:193
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
std::size_t GetN(void) const
Definition: config.cc:69
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.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.
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.
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.
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.
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.
virtual ~LteStatsCalculator()
Destructor.
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink 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 TypeId GetTypeId(void)
Register this type.
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:88
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition: lte-enb-rrc.h:75
uint64_t GetImsi(void) const
MatchContainer LookupMatches(std::string path)
Definition: config.cc:940
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.