5G-LENA nr-v3.0-33-g7aea1e4
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-stats-calculator.cc
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2021 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "nr-stats-calculator.h"
8
9#include <ns3/config.h>
10#include <ns3/log.h>
11#include <ns3/lte-enb-rrc.h>
12#include <ns3/lte-ue-rrc.h>
13#include <ns3/nr-gnb-net-device.h>
14#include <ns3/nr-ue-net-device.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("NrStatsCalculator");
20
21NS_OBJECT_ENSURE_REGISTERED(NrStatsCalculator);
22
24 : m_dlOutputFilename(""),
25 m_ulOutputFilename("")
26{
27 // Nothing to do here
28}
29
31{
32 // Nothing to do here
33}
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::NrStatsCalculator")
39 .SetParent<Object>()
40 .SetGroupName("nr")
41 .AddConstructor<NrStatsCalculator>();
42 return tid;
43}
44
45void
46NrStatsCalculator::SetUlOutputFilename(std::string outputFilename)
47{
48 m_ulOutputFilename = outputFilename;
49}
50
51std::string
53{
54 return m_ulOutputFilename;
55}
56
57void
58NrStatsCalculator::SetDlOutputFilename(std::string outputFilename)
59{
60 m_dlOutputFilename = outputFilename;
61}
62
63std::string
65{
66 return m_dlOutputFilename;
67}
68
69bool
71{
72 return m_pathImsiMap.find(path) != m_pathImsiMap.end();
73}
74
75void
76NrStatsCalculator::SetImsiPath(std::string path, uint64_t imsi)
77{
78 NS_LOG_FUNCTION(this << path << imsi);
79 m_pathImsiMap[path] = imsi;
80}
81
82uint64_t
84{
85 return m_pathImsiMap.find(path)->second;
86}
87
88bool
90{
91 return m_pathCellIdMap.find(path) != m_pathCellIdMap.end();
92}
93
94void
95NrStatsCalculator::SetCellIdPath(std::string path, uint16_t cellId)
96{
97 NS_LOG_FUNCTION(this << path << cellId);
98 m_pathCellIdMap[path] = cellId;
99}
100
101uint16_t
103{
104 return m_pathCellIdMap.find(path)->second;
105}
106
107uint64_t
109{
110 NS_LOG_FUNCTION(path);
111 // Sample path input:
112 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
113
114 // We retrieve the UeManager associated to the C-RNTI and perform the IMSI lookup
115 std::string ueMapPath = path.substr(0, path.find("/DataRadioBearerMap"));
116 Config::MatchContainer match = Config::LookupMatches(ueMapPath);
117
118 if (match.GetN() != 0)
119 {
120 Ptr<Object> ueInfo = match.Get(0);
121 NS_LOG_LOGIC("FindImsiFromEnbRlcPath: " << path << ", "
122 << ueInfo->GetObject<UeManager>()->GetImsi());
123 return ueInfo->GetObject<UeManager>()->GetImsi();
124 }
125 else
126 {
127 NS_FATAL_ERROR("Lookup " << ueMapPath << " got no matches");
128 return 0; // Silence compiler warning
129 }
130}
131
132uint64_t
134{
135 NS_LOG_FUNCTION(path);
136 // Sample path input:
137 // /NodeList/#NodeId/DeviceList/#DeviceId/
138
139 // We retrieve the Imsi associated to the LteUeNetDevice
140 Config::MatchContainer match = Config::LookupMatches(path);
141
142 if (match.GetN() != 0)
143 {
144 Ptr<Object> ueNetDevice = match.Get(0);
145 NS_LOG_LOGIC("FindImsiFromNrUeNetDevice: "
146 << path << ", " << ueNetDevice->GetObject<NrUeNetDevice>()->GetImsi());
147 return ueNetDevice->GetObject<NrUeNetDevice>()->GetImsi();
148 }
149 else
150 {
151 NS_FATAL_ERROR("Lookup " << path << " got no matches");
152 return 0; // Silence compiler warning
153 }
154}
155
156uint16_t
158{
159 NS_LOG_FUNCTION(path);
160 // Sample path input:
161 // /NodeList/#NodeId/DeviceList/#DeviceId/LteEnbRrc/UeMap/#C-RNTI/DataRadioBearerMap/#LCID/LteRlc/RxPDU
162
163 // We retrieve the CellId associated to the gNB
164 std::string gnbNetDevicePath = path.substr(0, path.find("/LteEnbRrc"));
165 Config::MatchContainer match = Config::LookupMatches(gnbNetDevicePath);
166 if (match.GetN() != 0)
167 {
168 Ptr<Object> enbNetDevice = match.Get(0);
169 NS_LOG_LOGIC("FindCellIdFromGnbRlcPath: "
170 << path << ", " << enbNetDevice->GetObject<NrGnbNetDevice>()->GetCellId());
171 return enbNetDevice->GetObject<NrGnbNetDevice>()->GetCellId();
172 }
173 else
174 {
175 NS_FATAL_ERROR("Lookup " << gnbNetDevicePath << " got no matches");
176 return 0; // Silence compiler warning
177 }
178}
179
180uint64_t
181NrStatsCalculator::FindImsiFromGnbMac(std::string path, uint16_t rnti)
182{
183 NS_LOG_FUNCTION(path << rnti);
184
185 // /NodeList/#NodeId/DeviceList/#DeviceId/BandwidthPartMap/#BwpId/NrGnbMac/DlScheduling
186 std::ostringstream oss;
187 std::string p = path.substr(0, path.find("/BandwidthPartMap"));
188 oss << rnti;
189 p += "/LteEnbRrc/UeMap/" + oss.str();
190 uint64_t imsi = FindImsiFromGnbRlcPath(p);
191 NS_LOG_LOGIC("FindImsiFromEnbMac: " << path << ", " << rnti << ", " << imsi);
192 return imsi;
193}
194
195uint16_t
196NrStatsCalculator::FindCellIdFromGnbMac(std::string path, uint16_t rnti)
197{
198 NS_LOG_FUNCTION(path << rnti);
199 // /NodeList/#NodeId/DeviceList/#DeviceId/BandwidthPartMap/#BwpId/NrGnbMac/DlScheduling
200 std::ostringstream oss;
201 std::string p = path.substr(0, path.find("/BandwidthPartMap"));
202 oss << rnti;
203 p += "/LteEnbRrc/UeMap/" + oss.str();
204 uint16_t cellId = FindCellIdFromGnbRlcPath(p);
205 NS_LOG_LOGIC("FindCellIdFromGnbMac: " << path << ", " << rnti << ", " << cellId);
206 return cellId;
207}
208
209} // namespace ns3
The NrGnbNetDevice class.
uint16_t GetCellId() const
void SetCellIdPath(std::string path, uint16_t cellId)
static uint64_t FindImsiFromGnbRlcPath(std::string path)
static uint16_t FindCellIdFromGnbMac(std::string path, uint16_t rnti)
static uint16_t FindCellIdFromGnbRlcPath(std::string path)
static uint64_t FindImsiFromGnbMac(std::string path, uint16_t rnti)
uint16_t GetCellIdPath(std::string path)
uint64_t GetImsiPath(std::string path)
bool ExistsImsiPath(std::string path)
bool ExistsCellIdPath(std::string path)
static uint64_t FindImsiFromNrUeNetDevice(std::string path)
void SetDlOutputFilename(std::string outputFilename)
void SetUlOutputFilename(std::string outputFilename)
void SetImsiPath(std::string path, uint64_t imsi)
The User Equipment NetDevice.
uint64_t GetImsi() const
Get the Imsi.