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 }
162 
163 uint64_t
165 {
166  NS_LOG_FUNCTION (path);
167  // Sample path input:
168  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
169 
170  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
171  std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
172  ueRlcPath += "/LteUeRrc";
173  Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
174 
175  if (match.GetN () != 0)
176  {
177  Ptr<Object> ueRrc = match.Get (0);
178  return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
179  }
180  else
181  {
182  NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
183  }
184  return 0;
185 }
186 
187 
188 uint64_t
190 {
191  NS_LOG_FUNCTION (path);
192  // Sample path input:
193  // /NodeList/#NodeId/DeviceList/#DeviceId/
194 
195  // We retrieve the Imsi associated to the LteUeNetDevice
197 
198  if (match.GetN () != 0)
199  {
200  Ptr<Object> ueNetDevice = match.Get (0);
201  NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
202  return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
203  }
204  else
205  {
206  NS_FATAL_ERROR ("Lookup " << path << " got no matches");
207  }
208 }
209 
210 uint16_t
212 {
213  NS_LOG_FUNCTION (path);
214  // Sample path input:
215  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
216 
217  // We retrieve the CellId associated to the Enb
218  std::string enbNetDevicePath = path.substr (0, path.find ("/LteEnbRrc"));
219  Config::MatchContainer match = Config::LookupMatches (enbNetDevicePath);
220  if (match.GetN () != 0)
221  {
222  Ptr<Object> enbNetDevice = match.Get (0);
223  NS_LOG_LOGIC ("FindCellIdFromEnbRlcPath: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
224  return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
225  }
226  else
227  {
228  NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
229  }
230 }
231 
232 uint64_t
233 LteStatsCalculator::FindImsiFromEnbMac (std::string path, uint16_t rnti)
234 {
235  NS_LOG_FUNCTION (path << rnti);
236 
237  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
238  std::ostringstream oss;
239  std::string p = path.substr (0, path.find ("/LteEnbMac"));
240  oss << rnti;
241  p += "/LteEnbRrc/UeMap/" + oss.str ();
242  uint64_t imsi = FindImsiFromEnbRlcPath (p);
243  NS_LOG_LOGIC ("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
244  return imsi;
245 }
246 
247 uint16_t
248 LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
249 {
250  NS_LOG_FUNCTION (path << rnti);
251  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
252  std::ostringstream oss;
253  std::string p = path.substr (0, path.find ("/LteEnbMac"));
254  oss << rnti;
255  p += "/LteEnbRrc/UeMap/" + oss.str ();
256  uint16_t cellId = FindCellIdFromEnbRlcPath (p);
257  NS_LOG_LOGIC ("FindCellIdFromEnbMac: " << path << ", "<< rnti << ", " << cellId);
258  return cellId;
259 }
260 
261 
262 uint64_t
263 LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
264 {
265  NS_LOG_FUNCTION (path << rnti);
266  uint64_t imsi = 0;
267  if (path.find ("/DlPhyTransmission"))
268  {
269  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
270  std::ostringstream oss;
271  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
272  oss << rnti;
273  p += "/LteEnbRrc/UeMap/" + oss.str ();
274  imsi = FindImsiFromEnbRlcPath (p);
275  NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
276  }
277  else if (path.find ("/UlPhyReception"))
278  {
279  std::string p = path.substr (0, path.find ("/LteUePhy"));
280  imsi = FindImsiFromLteNetDevice (p);
281  NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
282  }
283  return imsi;
284 }
285 
286 
287 uint64_t
288 LteStatsCalculator::FindImsiForUe (std::string path, uint16_t rnti)
289 {
290  NS_LOG_FUNCTION (path << rnti);
291  uint64_t imsi = 0;
292  if (path.find ("/UlPhyTransmission"))
293  {
294  std::string p = path.substr (0, path.find ("/LteUePhy"));
295  imsi = FindImsiFromLteNetDevice (p);
296  NS_LOG_LOGIC ("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
297  }
298  else if (path.find ("/DlPhyReception"))
299  {
300  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
301  std::ostringstream oss;
302  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
303  oss << rnti;
304  p += "/LteEnbRrc/UeMap/" + oss.str ();
305  imsi = FindImsiFromEnbRlcPath (p);
306  NS_LOG_LOGIC ("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
307  }
308  return imsi;
309 }
310 
311 
312 } // namespace ns3
Base class for ***StatsCalculator classes.
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:45
void SetCellIdPath(std::string path, uint16_t cellId)
Stores the (path, cellId) pairs in a map.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint64_t GetImsi(void) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
std::size_t GetN(void) const
Definition: config.cc:69
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
Retrieves CellId from Enb RLC path in the attribute system.
static TypeId GetTypeId(void)
Register this type.
uint64_t GetImsi() const
Get the IMSI.
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.
uint16_t GetCellId() const
static uint64_t FindImsiForEnb(std::string path, uint16_t rnti)
Retrieves IMSI from path for Enb in the attribute system.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:461
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:74
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.
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:151
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint16_t GetCellIdPath(std::string path)
Retrieves the cell id information for the given path.
uint64_t GetImsiPath(std::string path)
Retrieves the imsi information for the given path.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:884
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.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
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.