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  return m_pathImsiMap.find(path) != m_pathImsiMap.end();
86 }
87 
88 void
89 LteStatsCalculator::SetImsiPath(std::string path, uint64_t imsi)
90 {
91  NS_LOG_FUNCTION(this << path << imsi);
92  m_pathImsiMap[path] = imsi;
93 }
94 
95 uint64_t
97 {
98  return m_pathImsiMap.find(path)->second;
99 }
100 
101 bool
103 {
104  return m_pathCellIdMap.find(path) != m_pathCellIdMap.end();
105 }
106 
107 void
108 LteStatsCalculator::SetCellIdPath(std::string path, uint16_t cellId)
109 {
110  NS_LOG_FUNCTION(this << path << cellId);
111  m_pathCellIdMap[path] = cellId;
112 }
113 
114 uint16_t
116 {
117  return m_pathCellIdMap.find(path)->second;
118 }
119 
120 uint64_t
122 {
123  NS_LOG_FUNCTION(path);
124  // Sample path input:
125  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
126 
127  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
128  std::string ueMapPath = path.substr(0, path.find("/DataRadioBearerMap"));
130 
131  if (match.GetN() != 0)
132  {
133  Ptr<Object> ueInfo = match.Get(0);
134  NS_LOG_LOGIC("FindImsiFromEnbRlcPath: " << path << ", "
135  << ueInfo->GetObject<UeManager>()->GetImsi());
136  return ueInfo->GetObject<UeManager>()->GetImsi();
137  }
138  else
139  {
140  NS_FATAL_ERROR("Lookup " << ueMapPath << " got no matches");
141  }
142  return 0; // Silence compiler warning about lack of return value
143 }
144 
145 uint64_t
147 {
148  NS_LOG_FUNCTION(path);
149  // Sample path input:
150  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
151 
152  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
153  std::string ueRlcPath = path.substr(0, path.find("/LteUePhy"));
154  ueRlcPath += "/LteUeRrc";
156 
157  if (match.GetN() != 0)
158  {
159  Ptr<Object> ueRrc = match.Get(0);
160  return ueRrc->GetObject<LteUeRrc>()->GetImsi();
161  }
162  else
163  {
164  NS_FATAL_ERROR("Lookup " << ueRlcPath << " got no matches");
165  }
166  return 0;
167 }
168 
169 uint64_t
171 {
172  NS_LOG_FUNCTION(path);
173  // Sample path input:
174  // /NodeList/#NodeId/DeviceList/#DeviceId/
175 
176  // We retrieve the Imsi associated to the LteUeNetDevice
178 
179  if (match.GetN() != 0)
180  {
181  Ptr<Object> ueNetDevice = match.Get(0);
182  NS_LOG_LOGIC("FindImsiFromLteNetDevice: "
183  << path << ", " << ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi());
184  return ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi();
185  }
186  else
187  {
188  NS_FATAL_ERROR("Lookup " << path << " got no matches");
189  }
190  return 0; // Silence compiler warning about lack of return value
191 }
192 
193 uint16_t
195 {
196  NS_LOG_FUNCTION(path);
197  // Sample path input:
198  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
199 
200  // We retrieve the CellId associated to the Enb
201  std::string enbNetDevicePath = path.substr(0, path.find("/LteEnbRrc"));
202  Config::MatchContainer match = Config::LookupMatches(enbNetDevicePath);
203  if (match.GetN() != 0)
204  {
205  Ptr<Object> enbNetDevice = match.Get(0);
206  NS_LOG_LOGIC("FindCellIdFromEnbRlcPath: "
207  << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId());
208  return enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId();
209  }
210  else
211  {
212  NS_FATAL_ERROR("Lookup " << enbNetDevicePath << " got no matches");
213  }
214  return 0; // Silence compiler warning about lack of return value
215 }
216 
217 uint64_t
218 LteStatsCalculator::FindImsiFromEnbMac(std::string path, uint16_t rnti)
219 {
220  NS_LOG_FUNCTION(path << rnti);
221 
222  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
223  std::ostringstream oss;
224  std::string p = path.substr(0, path.find("/LteEnbMac"));
225  oss << rnti;
226  p += "/LteEnbRrc/UeMap/" + oss.str();
227  uint64_t imsi = FindImsiFromEnbRlcPath(p);
228  NS_LOG_LOGIC("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
229  return imsi;
230 }
231 
232 uint16_t
233 LteStatsCalculator::FindCellIdFromEnbMac(std::string path, uint16_t rnti)
234 {
235  NS_LOG_FUNCTION(path << rnti);
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  uint16_t cellId = FindCellIdFromEnbRlcPath(p);
242  NS_LOG_LOGIC("FindCellIdFromEnbMac: " << path << ", " << rnti << ", " << cellId);
243  return cellId;
244 }
245 
246 uint64_t
247 LteStatsCalculator::FindImsiForEnb(std::string path, uint16_t rnti)
248 {
249  NS_LOG_FUNCTION(path << rnti);
250  uint64_t imsi = 0;
251  if (path.find("/DlPhyTransmission"))
252  {
253  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
254  std::ostringstream oss;
255  std::string p = path.substr(0, path.find("/LteEnbPhy"));
256  oss << rnti;
257  p += "/LteEnbRrc/UeMap/" + oss.str();
258  imsi = FindImsiFromEnbRlcPath(p);
259  NS_LOG_LOGIC("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
260  }
261  else if (path.find("/UlPhyReception"))
262  {
263  std::string p = path.substr(0, path.find("/LteUePhy"));
264  imsi = FindImsiFromLteNetDevice(p);
265  NS_LOG_LOGIC("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
266  }
267  return imsi;
268 }
269 
270 uint64_t
271 LteStatsCalculator::FindImsiForUe(std::string path, uint16_t rnti)
272 {
273  NS_LOG_FUNCTION(path << rnti);
274  uint64_t imsi = 0;
275  if (path.find("/UlPhyTransmission"))
276  {
277  std::string p = path.substr(0, path.find("/LteUePhy"));
278  imsi = FindImsiFromLteNetDevice(p);
279  NS_LOG_LOGIC("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
280  }
281  else if (path.find("/DlPhyReception"))
282  {
283  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
284  std::ostringstream oss;
285  std::string p = path.substr(0, path.find("/LteEnbPhy"));
286  oss << rnti;
287  p += "/LteEnbRrc/UeMap/" + oss.str();
288  imsi = FindImsiFromEnbRlcPath(p);
289  NS_LOG_LOGIC("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
290  }
291  return imsi;
292 }
293 
294 } // 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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition: lte-enb-rrc.h:68
uint64_t GetImsi() const
MatchContainer LookupMatches(std::string path)
Definition: config.cc:998
#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.