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  ;
34 
36  : m_dlOutputFilename (""),
37  m_ulOutputFilename ("")
38 {
39  // Nothing to do here
40 
41 }
42 
44 {
45  // Nothing to do here
46 }
47 
48 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::LteStatsCalculator")
53  .SetParent<Object> ()
54  .AddConstructor<LteStatsCalculator> ()
55  ;
56  return tid;
57 }
58 
59 
60 void
61 LteStatsCalculator::SetUlOutputFilename (std::string outputFilename)
62 {
63  m_ulOutputFilename = outputFilename;
64 }
65 
66 std::string
68 {
69  return m_ulOutputFilename;
70 }
71 
72 void
73 LteStatsCalculator::SetDlOutputFilename (std::string outputFilename)
74 {
75  m_dlOutputFilename = outputFilename;
76 }
77 
78 std::string
80 {
81  return m_dlOutputFilename;
82 }
83 
84 
85 bool
87 {
88  if (m_pathImsiMap.find (path) == m_pathImsiMap.end () )
89  {
90  return false;
91  }
92  else
93  {
94  return true;
95  }
96 }
97 
98 void
99 LteStatsCalculator::SetImsiPath (std::string path, uint64_t imsi)
100 {
101  NS_LOG_FUNCTION (this << path << imsi);
102  m_pathImsiMap[path] = imsi;
103 }
104 
105 uint64_t
107 {
108  return m_pathImsiMap.find (path)->second;
109 }
110 
111 bool
113 {
114  if (m_pathCellIdMap.find (path) == m_pathCellIdMap.end () )
115  {
116  return false;
117  }
118  else
119  {
120  return true;
121  }
122 }
123 
124 void
125 LteStatsCalculator::SetCellIdPath (std::string path, uint16_t cellId)
126 {
127  NS_LOG_FUNCTION (this << path << cellId);
128  m_pathCellIdMap[path] = cellId;
129 }
130 
131 uint16_t
133 {
134  return m_pathCellIdMap.find (path)->second;
135 }
136 
137 
138 uint64_t
140 {
141  NS_LOG_FUNCTION (path);
142  // Sample path input:
143  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
144 
145  // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
146  std::string ueMapPath = path.substr (0, path.find ("/DataRadioBearerMap"));
147  Config::MatchContainer match = Config::LookupMatches (ueMapPath);
148 
149  if (match.GetN () != 0)
150  {
151  Ptr<Object> ueInfo = match.Get (0);
152  NS_LOG_LOGIC ("FindImsiFromEnbRlcPath: " << path << ", " << ueInfo->GetObject<UeManager> ()->GetImsi ());
153  return ueInfo->GetObject<UeManager> ()->GetImsi ();
154  }
155  else
156  {
157  NS_FATAL_ERROR ("Lookup " << ueMapPath << " got no matches");
158  }
159 }
160 
161 uint64_t
163 {
164  NS_LOG_FUNCTION (path);
165  // Sample path input:
166  // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
167 
168  // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
169  std::string ueRlcPath = path.substr (0, path.find ("/LteUePhy"));
170  ueRlcPath += "/LteUeRrc";
171  Config::MatchContainer match = Config::LookupMatches (ueRlcPath);
172 
173  if (match.GetN () != 0)
174  {
175  Ptr<Object> ueRrc = match.Get (0);
176  return ueRrc->GetObject<LteUeRrc> ()->GetImsi ();
177  }
178  else
179  {
180  NS_FATAL_ERROR ("Lookup " << ueRlcPath << " got no matches");
181  }
182  return 0;
183 }
184 
185 
186 uint64_t
188 {
189  NS_LOG_FUNCTION (path);
190  // Sample path input:
191  // /NodeList/#NodeId/DeviceList/#DeviceId/
192 
193  // We retrieve the Imsi associated to the LteUeNetDevice
195 
196  if (match.GetN () != 0)
197  {
198  Ptr<Object> ueNetDevice = match.Get (0);
199  NS_LOG_LOGIC ("FindImsiFromLteNetDevice: " << path << ", " << ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ());
200  return ueNetDevice->GetObject<LteUeNetDevice> ()->GetImsi ();
201  }
202  else
203  {
204  NS_FATAL_ERROR ("Lookup " << path << " got no matches");
205  }
206 }
207 
208 uint16_t
210 {
211  NS_LOG_FUNCTION (path);
212  // Sample path input:
213  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
214 
215  // We retrieve the CellId associated to the Enb
216  std::string enbNetDevicePath = path.substr (0, path.find ("/LteEnbRrc"));
217  Config::MatchContainer match = Config::LookupMatches (enbNetDevicePath);
218  if (match.GetN () != 0)
219  {
220  Ptr<Object> enbNetDevice = match.Get (0);
221  NS_LOG_LOGIC ("FindCellIdFromEnbRlcPath: " << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ());
222  return enbNetDevice->GetObject<LteEnbNetDevice> ()->GetCellId ();
223  }
224  else
225  {
226  NS_FATAL_ERROR ("Lookup " << enbNetDevicePath << " got no matches");
227  }
228 }
229 
230 uint64_t
231 LteStatsCalculator::FindImsiFromEnbMac (std::string path, uint16_t rnti)
232 {
233  NS_LOG_FUNCTION (path << rnti);
234 
235  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
236  std::ostringstream oss;
237  std::string p = path.substr (0, path.find ("/LteEnbMac"));
238  oss << rnti;
239  p += "/LteEnbRrc/UeMap/" + oss.str ();
240  uint64_t imsi = FindImsiFromEnbRlcPath (p);
241  NS_LOG_LOGIC ("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
242  return imsi;
243 }
244 
245 uint16_t
246 LteStatsCalculator::FindCellIdFromEnbMac (std::string path, uint16_t rnti)
247 {
248  NS_LOG_FUNCTION (path << rnti);
249  // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
250  std::ostringstream oss;
251  std::string p = path.substr (0, path.find ("/LteEnbMac"));
252  oss << rnti;
253  p += "/LteEnbRrc/UeMap/" + oss.str ();
254  uint16_t cellId = FindCellIdFromEnbRlcPath (p);
255  NS_LOG_LOGIC ("FindCellIdFromEnbMac: " << path << ", "<< rnti << ", " << cellId);
256  return cellId;
257 }
258 
259 
260 uint64_t
261 LteStatsCalculator::FindImsiForEnb (std::string path, uint16_t rnti)
262 {
263  NS_LOG_FUNCTION (path << rnti);
264  uint64_t imsi = 0;
265  if (path.find ("/DlPhyTransmission"))
266  {
267  // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
268  std::ostringstream oss;
269  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
270  oss << rnti;
271  p += "/LteEnbRrc/UeMap/" + oss.str ();
272  imsi = FindImsiFromEnbRlcPath (p);
273  NS_LOG_LOGIC ("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
274  }
275  else if (path.find ("/UlPhyReception"))
276  {
277  std::string p = path.substr (0, path.find ("/LteUePhy"));
278  imsi = FindImsiFromLteNetDevice (p);
279  NS_LOG_LOGIC ("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
280  }
281  return imsi;
282 }
283 
284 
285 uint64_t
286 LteStatsCalculator::FindImsiForUe (std::string path, uint16_t rnti)
287 {
288  NS_LOG_FUNCTION (path << rnti);
289  uint64_t imsi = 0;
290  if (path.find ("/UlPhyTransmission"))
291  {
292  std::string p = path.substr (0, path.find ("/LteUePhy"));
293  imsi = FindImsiFromLteNetDevice (p);
294  NS_LOG_LOGIC ("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
295  }
296  else if (path.find ("/DlPhyReception"))
297  {
298  // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
299  std::ostringstream oss;
300  std::string p = path.substr (0, path.find ("/LteEnbPhy"));
301  oss << rnti;
302  p += "/LteEnbRrc/UeMap/" + oss.str ();
303  imsi = FindImsiFromEnbRlcPath (p);
304  NS_LOG_LOGIC ("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
305  }
306  return imsi;
307 }
308 
309 
310 } // namespace ns3
static uint64_t FindImsiFromLteNetDevice(std::string path)
static uint64_t FindImsiFromUePhy(std::string path)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
static uint64_t FindImsiFromEnbMac(std::string path, uint16_t rnti)
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
uint16_t GetCellId() const
void SetCellIdPath(std::string path, uint16_t cellId)
Stores the (path, cellId) pairs in a map.
uint64_t GetImsi() const
static uint16_t FindCellIdFromEnbRlcPath(std::string path)
static TypeId GetTypeId(void)
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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)
Definition: log.h:368
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:63
The eNodeB device implementation.
Ptr< T > GetObject(void) const
Definition: object.h:361
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
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.