A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jaume Nin <jnin@cttc.es>
7 */
8
10
11#include <ns3/config.h>
12#include <ns3/log.h>
13#include <ns3/lte-enb-net-device.h>
14#include <ns3/lte-enb-rrc.h>
15#include <ns3/lte-ue-net-device.h>
16#include <ns3/lte-ue-rrc.h>
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("LteStatsCalculator");
22
23NS_OBJECT_ENSURE_REGISTERED(LteStatsCalculator);
24
26 : m_dlOutputFilename(""),
27 m_ulOutputFilename("")
28{
29 // Nothing to do here
30}
31
33{
34 // Nothing to do here
35}
36
39{
40 static TypeId tid = TypeId("ns3::LteStatsCalculator")
42 .SetGroupName("Lte")
43 .AddConstructor<LteStatsCalculator>();
44 return tid;
45}
46
47void
48LteStatsCalculator::SetUlOutputFilename(std::string outputFilename)
49{
50 m_ulOutputFilename = outputFilename;
51}
52
53std::string
58
59void
60LteStatsCalculator::SetDlOutputFilename(std::string outputFilename)
61{
62 m_dlOutputFilename = outputFilename;
63}
64
65std::string
70
71bool
73{
74 return m_pathImsiMap.find(path) != m_pathImsiMap.end();
75}
76
77void
78LteStatsCalculator::SetImsiPath(std::string path, uint64_t imsi)
79{
80 NS_LOG_FUNCTION(this << path << imsi);
81 m_pathImsiMap[path] = imsi;
82}
83
84uint64_t
86{
87 return m_pathImsiMap.find(path)->second;
88}
89
90bool
92{
93 return m_pathCellIdMap.find(path) != m_pathCellIdMap.end();
94}
95
96void
97LteStatsCalculator::SetCellIdPath(std::string path, uint16_t cellId)
98{
99 NS_LOG_FUNCTION(this << path << cellId);
100 m_pathCellIdMap[path] = cellId;
101}
102
103uint16_t
105{
106 return m_pathCellIdMap.find(path)->second;
107}
108
109uint64_t
111{
112 NS_LOG_FUNCTION(path);
113 // Sample path input:
114 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
115
116 // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
117 std::string ueMapPath = path.substr(0, path.find("/DataRadioBearerMap"));
119
120 if (match.GetN() != 0)
121 {
122 Ptr<Object> ueInfo = match.Get(0);
123 NS_LOG_LOGIC("FindImsiFromEnbRlcPath: " << path << ", "
124 << ueInfo->GetObject<UeManager>()->GetImsi());
125 return ueInfo->GetObject<UeManager>()->GetImsi();
126 }
127 else
128 {
129 NS_FATAL_ERROR("Lookup " << ueMapPath << " got no matches");
130 }
131 return 0; // Silence compiler warning about lack of return value
132}
133
134uint64_t
136{
137 NS_LOG_FUNCTION(path);
138 // Sample path input:
139 // /NodeList/#NodeId/DeviceList/#DeviceId/LteUePhy
140
141 // We retrieve the UeInfo associated to the C-RNTI and perform the IMSI lookup
142 std::string ueRlcPath = path.substr(0, path.find("/LteUePhy"));
143 ueRlcPath += "/LteUeRrc";
145
146 if (match.GetN() != 0)
147 {
148 Ptr<Object> ueRrc = match.Get(0);
149 return ueRrc->GetObject<LteUeRrc>()->GetImsi();
150 }
151 else
152 {
153 NS_FATAL_ERROR("Lookup " << ueRlcPath << " got no matches");
154 }
155 return 0;
156}
157
158uint64_t
160{
161 NS_LOG_FUNCTION(path);
162 // Sample path input:
163 // /NodeList/#NodeId/DeviceList/#DeviceId/
164
165 // We retrieve the Imsi associated to the LteUeNetDevice
167
168 if (match.GetN() != 0)
169 {
170 Ptr<Object> ueNetDevice = match.Get(0);
171 NS_LOG_LOGIC("FindImsiFromLteNetDevice: "
172 << path << ", " << ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi());
173 return ueNetDevice->GetObject<LteUeNetDevice>()->GetImsi();
174 }
175 else
176 {
177 NS_FATAL_ERROR("Lookup " << path << " got no matches");
178 }
179 return 0; // Silence compiler warning about lack of return value
180}
181
182uint16_t
184{
185 NS_LOG_FUNCTION(path);
186 // Sample path input:
187 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
188
189 // We retrieve the CellId associated to the Enb
190 std::string enbNetDevicePath = path.substr(0, path.find("/LteEnbRrc"));
191 Config::MatchContainer match = Config::LookupMatches(enbNetDevicePath);
192 if (match.GetN() != 0)
193 {
194 Ptr<Object> enbNetDevice = match.Get(0);
195 NS_LOG_LOGIC("FindCellIdFromEnbRlcPath: "
196 << path << ", " << enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId());
197 return enbNetDevice->GetObject<LteEnbNetDevice>()->GetCellId();
198 }
199 else
200 {
201 NS_FATAL_ERROR("Lookup " << enbNetDevicePath << " got no matches");
202 }
203 return 0; // Silence compiler warning about lack of return value
204}
205
206uint64_t
207LteStatsCalculator::FindImsiFromEnbMac(std::string path, uint16_t rnti)
208{
209 NS_LOG_FUNCTION(path << rnti);
210
211 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
212 std::ostringstream oss;
213 std::string p = path.substr(0, path.find("/LteEnbMac"));
214 oss << rnti;
215 p += "/LteEnbRrc/UeMap/" + oss.str();
216 uint64_t imsi = FindImsiFromEnbRlcPath(p);
217 NS_LOG_LOGIC("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
218 return imsi;
219}
220
221uint16_t
222LteStatsCalculator::FindCellIdFromEnbMac(std::string path, uint16_t rnti)
223{
224 NS_LOG_FUNCTION(path << rnti);
225 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbMac/DlScheduling
226 std::ostringstream oss;
227 std::string p = path.substr(0, path.find("/LteEnbMac"));
228 oss << rnti;
229 p += "/LteEnbRrc/UeMap/" + oss.str();
230 uint16_t cellId = FindCellIdFromEnbRlcPath(p);
231 NS_LOG_LOGIC("FindCellIdFromEnbMac: " << path << ", " << rnti << ", " << cellId);
232 return cellId;
233}
234
235uint64_t
236LteStatsCalculator::FindImsiForEnb(std::string path, uint16_t rnti)
237{
238 NS_LOG_FUNCTION(path << rnti);
239 uint64_t imsi = 0;
240 if (path.find("/DlPhyTransmission"))
241 {
242 // /NodeList/0/DeviceList/0/LteEnbPhy/DlPhyTransmission/LteEnbRrc/UeMap/1
243 std::ostringstream oss;
244 std::string p = path.substr(0, path.find("/LteEnbPhy"));
245 oss << rnti;
246 p += "/LteEnbRrc/UeMap/" + oss.str();
247 imsi = FindImsiFromEnbRlcPath(p);
248 NS_LOG_LOGIC("FindImsiForEnb[Tx]: " << path << ", " << rnti << ", " << imsi);
249 }
250 else if (path.find("/UlPhyReception"))
251 {
252 std::string p = path.substr(0, path.find("/LteUePhy"));
253 imsi = FindImsiFromLteNetDevice(p);
254 NS_LOG_LOGIC("FindImsiForEnb[Rx]: " << path << ", " << rnti << ", " << imsi);
255 }
256 return imsi;
257}
258
259uint64_t
260LteStatsCalculator::FindImsiForUe(std::string path, uint16_t rnti)
261{
262 NS_LOG_FUNCTION(path << rnti);
263 uint64_t imsi = 0;
264 if (path.find("/UlPhyTransmission"))
265 {
266 std::string p = path.substr(0, path.find("/LteUePhy"));
267 imsi = FindImsiFromLteNetDevice(p);
268 NS_LOG_LOGIC("FindImsiForUe[Tx]: " << path << ", " << rnti << ", " << imsi);
269 }
270 else if (path.find("/DlPhyReception"))
271 {
272 // /NodeList/0/DeviceList/0/LteEnbPhy/LteSpectrumPhy
273 std::ostringstream oss;
274 std::string p = path.substr(0, path.find("/LteEnbPhy"));
275 oss << rnti;
276 p += "/LteEnbRrc/UeMap/" + oss.str();
277 imsi = FindImsiFromEnbRlcPath(p);
278 NS_LOG_LOGIC("FindImsiForUe[Rx]: " << path << ", " << rnti << ", " << imsi);
279 }
280 return imsi;
281}
282
283} // namespace ns3
hold a set of objects which match a specific search string.
Definition config.h:184
Ptr< Object > Get(std::size_t i) const
Definition config.cc:75
std::size_t GetN() const
Definition config.cc:68
The eNodeB device implementation.
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:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Manages all the radio bearer information possessed by the ENB RRC for a single UE.
Definition lte-enb-rrc.h:57
uint64_t GetImsi() const
MatchContainer LookupMatches(std::string path)
Definition config.cc:991
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.