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