A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
35  : m_dlOutputFilename (""),
36  m_ulOutputFilename ("")
37 {
38  // Nothing to do here
39 
40 }
41 
43 {
44  // Nothing to do here
45 }
46 
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::LteStatsCalculator")
52  .SetParent<Object> ()
53  .AddConstructor<LteStatsCalculator> ()
54  ;
55  return tid;
56 }
57 
58 
59 void
60 LteStatsCalculator::SetUlOutputFilename (std::string outputFilename)
61 {
62  m_ulOutputFilename = outputFilename;
63 }
64 
65 std::string
67 {
68  return m_ulOutputFilename;
69 }
70 
71 void
72 LteStatsCalculator::SetDlOutputFilename (std::string outputFilename)
73 {
74  m_dlOutputFilename = outputFilename;
75 }
76 
77 std::string
79 {
80  return m_dlOutputFilename;
81 }
82 
83 
84 bool
86 {
87  if (m_pathImsiMap.find (path) == m_pathImsiMap.end () )
88  {
89  return false;
90  }
91  else
92  {
93  return true;
94  }
95 }
96 
97 void
98 LteStatsCalculator::SetImsiPath (std::string path, uint64_t imsi)
99 {
100  NS_LOG_FUNCTION (this << path << imsi);
101  m_pathImsiMap[path] = imsi;
102 }
103 
104 uint64_t
106 {
107  return m_pathImsiMap.find (path)->second;
108 }
109 
110 bool
112 {
113  if (m_pathCellIdMap.find (path) == m_pathCellIdMap.end () )
114  {
115  return false;
116  }
117  else
118  {
119  return true;
120  }
121 }
122 
123 void
124 LteStatsCalculator::SetCellIdPath (std::string path, uint16_t cellId)
125 {
126  NS_LOG_FUNCTION (this << path << cellId);
127  m_pathCellIdMap[path] = cellId;
128 }
129 
130 uint16_t
132 {
133  return m_pathCellIdMap.find (path)->second;
134 }
135 
136 
137 uint64_t
139 {
140  NS_LOG_FUNCTION (path);
141  // Sample path input:
142  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
143 
144  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
145  std::string ueMapPath = path.substr (0, path.find ("/DataRadioBearerMap"));
146  Config::MatchContainer match = Config::LookupMatches (ueMapPath);
147 
148  if (match.GetN () != 0)
149  {
150  Ptr<Object> ueInfo = match.Get (0);
151  NS_LOG_LOGIC ("FindImsiFromEnbRlcPath: " << path << ", " << ueInfo->GetObject<UeManager> ()->GetImsi ());
152  return ueInfo->GetObject<UeManager> ()->GetImsi ();
153  }
154  else
155  {
156  NS_FATAL_ERROR ("Lookup " << ueMapPath << " got no matches");
157  }
158 }
159 
160 uint64_t
162 {
163  NS_LOG_FUNCTION (path);
164  // Sample path input:
165  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
166 
167  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
168  std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
169  ueRlcPath += "/LteUeRrc";
170  Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
171 
172  if (match.GetN () != 0)
173  {
174  Ptr<Object> ueRrc = match.Get (0);
175  return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
176  }
177  else
178  {
179  NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
180  }
181  return 0;
182 }
183 
184 
185 uint64_t
187 {
188  NS_LOG_FUNCTION (path);
189  // Sample path input:
190  // /NodeList/#NodeId/DeviceList/#DeviceId/
191 
192  // We retrieve the Imsi associated to the LteUeNetDevice
194 
195  if (match.GetN () != 0)
196  {
197  Ptr<Object> ueNetDevice = match.Get (0);
198  NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
199  return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
200  }
201  else
202  {
203  NS_FATAL_ERROR ("Lookup " << path << " got no matches");
204  }
205 }
206 
207 uint16_t
209 {
210  NS_LOG_FUNCTION (path);
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: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
221  return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
222  }
223  else
224  {
225  NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
226  }
227 }
228 
229 uint64_t
230 LteStatsCalculator::FindImsiFromEnbMac (std::string path, uint16_t rnti)
231 {
232  NS_LOG_FUNCTION (path << rnti);
233 
234  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
235  std::ostringstream oss;
236  std::string p = path.substr (0, path.find ("/LteEnbMac"));
237  oss << rnti;
238  p += "/LteEnbRrc/UeMap/" + oss.str ();
239  uint64_t imsi = FindImsiFromEnbRlcPath (p);
240  NS_LOG_LOGIC ("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
241  return imsi;
242 }
243 
244 uint16_t
245 LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
246 {
247  NS_LOG_FUNCTION (path << rnti);
248  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
249  std::ostringstream oss;
250  std::string p = path.substr (0, path.find ("/LteEnbMac"));
251  oss << rnti;
252  p += "/LteEnbRrc/UeMap/" + oss.str ();
253  uint16_t cellId = FindCellIdFromEnbRlcPath (p);
254  NS_LOG_LOGIC ("FindCellIdFromEnbMac: " << path << ", "<< rnti << ", " << cellId);
255  return cellId;
256 }
257 
258 
259 uint64_t
260 LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
261 {
262  NS_LOG_FUNCTION (path << rnti);
263  uint64_t imsi = 0;
264  if (path.find ("/DlPhyTransmission"))
265  {
266  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
267  std::ostringstream oss;
268  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
269  oss << rnti;
270  p += "/LteEnbRrc/UeMap/" + oss.str ();
271  imsi = FindImsiFromEnbRlcPath (p);
272  NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
273  }
274  else if (path.find ("/UlPhyReception"))
275  {
276  std::string p = path.substr (0, path.find ("/LteUePhy"));
277  imsi = FindImsiFromLteNetDevice (p);
278  NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
279  }
280  return imsi;
281 }
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 
309 } // namespace ns3
static uint64_t FindImsiFromLteNetDevice(std::string path)
static uint64_t FindImsiFromUePhy(std::string path)
#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)
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:170
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
static TypeId GetTypeId(void)
Config::MatchContainer LookupMatches(std::string path)
Definition: config.cc:739
static uint16_t FindCellIdFromEnbMac(std::string path, uint16_t rnti)
std::map< std::string, uint64_t > m_pathImsiMap
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)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
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.
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition: lte-enb-rrc.h:60
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)
static uint64_t FindImsiForUe(std::string path, uint16_t rnti)
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
virtual ~LteStatsCalculator()
Destructor.
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:64
The eNodeB device implementation.
Ptr< T > GetObject(void) const
Definition: object.h:362
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
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.