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  .AddConstructor<LteStatsCalculator> ()
56  ;
57  return tid;
58 }
59 
60 
61 void
62 LteStatsCalculator::SetUlOutputFilename (std::string outputFilename)
63 {
64  m_ulOutputFilename = outputFilename;
65 }
66 
67 std::string
69 {
70  return m_ulOutputFilename;
71 }
72 
73 void
74 LteStatsCalculator::SetDlOutputFilename (std::string outputFilename)
75 {
76  m_dlOutputFilename = outputFilename;
77 }
78 
79 std::string
81 {
82  return m_dlOutputFilename;
83 }
84 
85 
86 bool
88 {
89  if (m_pathImsiMap.find (path) == m_pathImsiMap.end () )
90  {
91  return false;
92  }
93  else
94  {
95  return true;
96  }
97 }
98 
99 void
100 LteStatsCalculator::SetImsiPath (std::string path, uint64_t imsi)
101 {
102  NS_LOG_FUNCTION (this << path << imsi);
103  m_pathImsiMap[path] = imsi;
104 }
105 
106 uint64_t
108 {
109  return m_pathImsiMap.find (path)->second;
110 }
111 
112 bool
114 {
115  if (m_pathCellIdMap.find (path) == m_pathCellIdMap.end () )
116  {
117  return false;
118  }
119  else
120  {
121  return true;
122  }
123 }
124 
125 void
126 LteStatsCalculator::SetCellIdPath (std::string path, uint16_t cellId)
127 {
128  NS_LOG_FUNCTION (this << path << cellId);
129  m_pathCellIdMap[path] = cellId;
130 }
131 
132 uint16_t
134 {
135  return m_pathCellIdMap.find (path)->second;
136 }
137 
138 
139 uint64_t
141 {
142  NS_LOG_FUNCTION (path);
143  // Sample path input:
144  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
145 
146  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
147  std::string ueMapPath = path.substr (0, path.find ("/DataRadioBearerMap"));
148  Config::MatchContainer match = Config::LookupMatches (ueMapPath);
149 
150  if (match.GetN () != 0)
151  {
152  Ptr<Object> ueInfo = match.Get (0);
153  NS_LOG_LOGIC ("FindImsiFromEnbRlcPath: " << path << ", " << ueInfo->GetObject<UeManager> ()->GetImsi ());
154  return ueInfo->GetObject<UeManager> ()->GetImsi ();
155  }
156  else
157  {
158  NS_FATAL_ERROR ("Lookup " << ueMapPath << " got no matches");
159  }
160 }
161 
162 uint64_t
164 {
165  NS_LOG_FUNCTION (path);
166  // Sample path input:
167  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
168 
169  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
170  std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
171  ueRlcPath += "/LteUeRrc";
172  Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
173 
174  if (match.GetN () != 0)
175  {
176  Ptr<Object> ueRrc = match.Get (0);
177  return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
178  }
179  else
180  {
181  NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
182  }
183  return 0;
184 }
185 
186 
187 uint64_t
189 {
190  NS_LOG_FUNCTION (path);
191  // Sample path input:
192  // /NodeList/#NodeId/DeviceList/#DeviceId/
193 
194  // We retrieve the Imsi associated to the LteUeNetDevice
196 
197  if (match.GetN () != 0)
198  {
199  Ptr<Object> ueNetDevice = match.Get (0);
200  NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
201  return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
202  }
203  else
204  {
205  NS_FATAL_ERROR ("Lookup " << path << " got no matches");
206  }
207 }
208 
209 uint16_t
211 {
212  NS_LOG_FUNCTION (path);
213  // Sample path input:
214  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
215 
216  // We retrieve the CellId associated to the Enb
217  std::string enbNetDevicePath = path.substr (0, path.find ("/LteEnbRrc"));
218  Config::MatchContainer match = Config::LookupMatches (enbNetDevicePath);
219  if (match.GetN () != 0)
220  {
221  Ptr<Object> enbNetDevice = match.Get (0);
222  NS_LOG_LOGIC ("FindCellIdFromEnbRlcPath: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
223  return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
224  }
225  else
226  {
227  NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
228  }
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
247 LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
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 
261 uint64_t
262 LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
263 {
264  NS_LOG_FUNCTION (path << rnti);
265  uint64_t imsi = 0;
266  if (path.find ("/DlPhyTransmission"))
267  {
268  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
269  std::ostringstream oss;
270  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
271  oss << rnti;
272  p += "/LteEnbRrc/UeMap/" + oss.str ();
273  imsi = FindImsiFromEnbRlcPath (p);
274  NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
275  }
276  else if (path.find ("/UlPhyReception"))
277  {
278  std::string p = path.substr (0, path.find ("/LteUePhy"));
279  imsi = FindImsiFromLteNetDevice (p);
280  NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
281  }
282  return imsi;
283 }
284 
285 
286 uint64_t
287 LteStatsCalculator::FindImsiForUe (std::string path, uint16_t rnti)
288 {
289  NS_LOG_FUNCTION (path << rnti);
290  uint64_t imsi = 0;
291  if (path.find ("/UlPhyTransmission"))
292  {
293  std::string p = path.substr (0, path.find ("/LteUePhy"));
294  imsi = FindImsiFromLteNetDevice (p);
295  NS_LOG_LOGIC ("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
296  }
297  else if (path.find ("/DlPhyReception"))
298  {
299  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
300  std::ostringstream oss;
301  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
302  oss << rnti;
303  p += "/LteEnbRrc/UeMap/" + oss.str ();
304  imsi = FindImsiFromEnbRlcPath (p);
305  NS_LOG_LOGIC ("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
306  }
307  return imsi;
308 }
309 
310 
311 } // namespace ns3
static uint64_t FindImsiFromLteNetDevice(std::string path)
Retrieves IMSI from LteNetDevice path in the attribute system.
static uint64_t FindImsiFromUePhy(std::string path)
Retrieves IMSI from Ue PHY path in the attribute system.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
Retrieves IMSI from Enb MAC path in the attribute system.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
uint16_t GetCellId() const
void SetCellIdPath(std::string path, uint16_t cellId)
Stores the (path, cellId) pairs in a map.
uint64_t GetImsi() const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
Retrieves CellId from Enb RLC path in the attribute system.
static TypeId GetTypeId(void)
Register this type.
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:749
static uint16_t FindCellIdFromEnbMac(std::string path, uint16_t rnti)
Retrieves CellId from Enb MAC 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 uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
Retrieves IMSI from path for Enb in the attribute system.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
uint32_t GetN(void) const
Definition: config.cc:63
std::string GetUlOutputFilename(void)
Get the name of the file where the uplink statistics will be stored.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition: lte-enb-rrc.h:62
bool ExistsCellIdPath(std::string path)
Checks if there is an already stored cell id for the given path.
void SetDlOutputFilename(std::string outputFilename)
Set the name of the file where the downlink statistics will be stored.
Ptr< Object > Get(uint32_t i) const
Definition: config.cc:69
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.
hold a set of objects which match a specific search string.
Definition: config.h:127
uint16_t GetCellIdPath(std::string path)
Retrieves the cell id information for the given path.
uint64_t GetImsi(void) const
uint64_t GetImsiPath(std::string path)
Retrieves the imsi information for the given path.
std::map< std::string, uint16_t > m_pathCellIdMap
List of CellId by path in the attribute system.
virtual ~LteStatsCalculator()
Destructor.
std::string m_dlOutputFilename
Name of the file where the downlink results will be saved.
void SetImsiPath(std::string path, uint64_t imsi)
Stores the (path, imsi) pairs in a map.
A base class which provides memory management and object aggregation.
Definition: object.h:87
std::string m_ulOutputFilename
Name of the file where the uplink results will be saved.
The eNodeB device implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
bool ExistsImsiPath(std::string path)
Checks if there is an already stored IMSI for the given path.
std::string GetDlOutputFilename(void)
Get the name of the file where the downlink statistics will be stored.
The LteUeNetDevice class implements the UE net device.