5G-LENA nr-v3.3-18-g7e4df5bb
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-scheduling-stats.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-mac-scheduling-stats.h"
6
7#include "ns3/string.h"
8#include <ns3/log.h>
9#include <ns3/simulator.h>
10
11namespace ns3
12{
13
14NS_LOG_COMPONENT_DEFINE("NrMacSchedulingStats");
15
16NS_OBJECT_ENSURE_REGISTERED(NrMacSchedulingStats);
17
24
26{
27 NS_LOG_FUNCTION(this);
28 if (outDlFile.is_open())
29 {
30 outDlFile.close();
31 }
32 if (outUlFile.is_open())
33 {
34 outUlFile.close();
35 }
36}
37
38TypeId
40{
41 static TypeId tid =
42 TypeId("ns3::NrMacSchedulingStats")
43 .SetParent<NrStatsCalculator>()
44 .SetGroupName("nr")
45 .AddConstructor<NrMacSchedulingStats>()
46 .AddAttribute("DlOutputFilename",
47 "Name of the file where the downlink results will be saved.",
48 StringValue("NrDlMacStats.txt"),
50 MakeStringChecker())
51 .AddAttribute("UlOutputFilename",
52 "Name of the file where the uplink results will be saved.",
53 StringValue("NrUlMacStats.txt"),
55 MakeStringChecker());
56 return tid;
57}
58
59void
61{
63 if (outUlFile.is_open())
64 {
65 outUlFile.close();
66 }
67 outUlFile.open(GetUlOutputFilename().c_str());
68 if (!outUlFile.is_open())
69 {
70 NS_LOG_ERROR("Can't open file " << GetUlOutputFilename().c_str());
71 return;
72 }
73 outUlFile << "% "
74 "time(s)"
75 "\tcellId\tbwpId\tIMSI\tRNTI\tframe\tsframe\tslot\tsymStart\tnumSym\thar"
76 "qId\tndi\trv\tmcs\ttbSize";
77 outUlFile << std::endl;
78}
79
80std::string
85
86void
88{
90 if (outDlFile.is_open())
91 {
92 outDlFile.close();
93 }
94 outDlFile.open(GetDlOutputFilename().c_str());
95 if (!outDlFile.is_open())
96 {
97 NS_LOG_ERROR("Can't open file " << GetDlOutputFilename().c_str());
98 return;
99 }
100 outDlFile << "% "
101 "time(s)"
102 "\tcellId\tbwpId\tIMSI\tRNTI\tframe\tsframe\tslot\tsymStart\tnumSym\thar"
103 "qId\tndi\trv\tmcs\ttbSize";
104 outDlFile << std::endl;
105}
106
107std::string
112
113void
115 uint64_t imsi,
116 const NrSchedulingCallbackInfo& traceInfo)
117{
118 NS_LOG_FUNCTION(this << cellId << imsi << traceInfo.m_frameNum << traceInfo.m_subframeNum
119 << traceInfo.m_rnti << (uint32_t)traceInfo.m_mcs << traceInfo.m_tbSize);
120 NS_LOG_INFO("Write DL Mac Stats in " << GetDlOutputFilename().c_str());
121
122 outDlFile << Simulator::Now().GetSeconds() << "\t";
123 outDlFile << (uint32_t)cellId << "\t";
124 outDlFile << (uint32_t)traceInfo.m_bwpId << "\t";
125 outDlFile << imsi << "\t";
126 outDlFile << traceInfo.m_rnti << "\t";
127 outDlFile << traceInfo.m_frameNum << "\t";
128 outDlFile << (uint32_t)traceInfo.m_subframeNum << "\t";
129 outDlFile << traceInfo.m_slotNum << "\t";
130 outDlFile << (uint32_t)traceInfo.m_symStart << "\t";
131 outDlFile << (uint32_t)traceInfo.m_numSym << "\t";
132 outDlFile << (uint32_t)traceInfo.m_harqId << "\t";
133 outDlFile << (uint32_t)traceInfo.m_ndi << "\t";
134 outDlFile << (uint32_t)traceInfo.m_rv << "\t";
135 outDlFile << (uint32_t)traceInfo.m_mcs << "\t";
136 outDlFile << traceInfo.m_tbSize << std::endl;
137}
138
139void
141 uint64_t imsi,
142 const NrSchedulingCallbackInfo& traceInfo)
143{
144 NS_LOG_FUNCTION(this << cellId << imsi << traceInfo.m_frameNum << traceInfo.m_subframeNum
145 << traceInfo.m_rnti << (uint32_t)traceInfo.m_mcs << traceInfo.m_tbSize);
146 NS_LOG_INFO("Write UL Mac Stats in " << GetUlOutputFilename().c_str());
147
148 outUlFile << Simulator::Now().GetSeconds() << "\t";
149 outUlFile << (uint32_t)cellId << "\t";
150 outUlFile << (uint32_t)traceInfo.m_bwpId << "\t";
151 outUlFile << imsi << "\t";
152 outUlFile << traceInfo.m_rnti << "\t";
153 outUlFile << traceInfo.m_frameNum << "\t";
154 outUlFile << (uint32_t)traceInfo.m_subframeNum << "\t";
155 outUlFile << traceInfo.m_slotNum << "\t";
156 outUlFile << (uint32_t)traceInfo.m_symStart << "\t";
157 outUlFile << (uint32_t)traceInfo.m_numSym << "\t";
158 outUlFile << (uint32_t)traceInfo.m_harqId << "\t";
159 outUlFile << (uint32_t)traceInfo.m_ndi << "\t";
160 outUlFile << (uint32_t)traceInfo.m_rv << "\t";
161 outUlFile << (uint32_t)traceInfo.m_mcs << "\t";
162 outUlFile << traceInfo.m_tbSize << std::endl;
163}
164
165void
166NrMacSchedulingStats::DlSchedulingCallback(Ptr<NrMacSchedulingStats> macStats,
167 std::string path,
168 NrSchedulingCallbackInfo traceInfo)
169{
170 NS_LOG_FUNCTION(macStats << path);
171 uint64_t imsi = 0;
172 std::ostringstream pathAndRnti;
173 std::string pathGnb = path.substr(0, path.find("/BandwidthPartMap"));
174 pathAndRnti << pathGnb << "/NrGnbRrc/UeMap/" << traceInfo.m_rnti;
175 if (macStats->ExistsImsiPath(pathAndRnti.str()))
176 {
177 imsi = macStats->GetImsiPath(pathAndRnti.str());
178 }
179 else
180 {
181 imsi = FindImsiFromGnbRlcPath(pathAndRnti.str());
182 macStats->SetImsiPath(pathAndRnti.str(), imsi);
183 }
184 uint16_t cellId = 0;
185 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
186 {
187 cellId = macStats->GetCellIdPath(pathAndRnti.str());
188 }
189 else
190 {
191 cellId = FindCellIdFromGnbRlcPath(pathAndRnti.str());
192 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
193 }
194
195 macStats->DlScheduling(cellId, imsi, traceInfo);
196}
197
198void
199NrMacSchedulingStats::UlSchedulingCallback(Ptr<NrMacSchedulingStats> macStats,
200 std::string path,
201 NrSchedulingCallbackInfo traceInfo)
202{
203 NS_LOG_FUNCTION(macStats << path);
204
205 uint64_t imsi = 0;
206 std::ostringstream pathAndRnti;
207 std::string pathGnb = path.substr(0, path.find("/BandwidthPartMap"));
208 pathAndRnti << pathGnb << "/NrGnbRrc/UeMap/" << traceInfo.m_rnti;
209 if (macStats->ExistsImsiPath(pathAndRnti.str()))
210 {
211 imsi = macStats->GetImsiPath(pathAndRnti.str());
212 }
213 else
214 {
215 imsi = FindImsiFromGnbRlcPath(pathAndRnti.str());
216 macStats->SetImsiPath(pathAndRnti.str(), imsi);
217 }
218 uint16_t cellId = 0;
219 if (macStats->ExistsCellIdPath(pathAndRnti.str()))
220 {
221 cellId = macStats->GetCellIdPath(pathAndRnti.str());
222 }
223 else
224 {
225 cellId = FindCellIdFromGnbRlcPath(pathAndRnti.str());
226 macStats->SetCellIdPath(pathAndRnti.str(), cellId);
227 }
228
229 macStats->UlScheduling(cellId, imsi, traceInfo);
230}
231
232} // namespace ns3
void DlScheduling(uint16_t cellId, uint64_t imsi, const NrSchedulingCallbackInfo &traceInfo)
void SetDlOutputFilename(std::string outputFilename)
void SetUlOutputFilename(std::string outputFilename)
void UlScheduling(uint16_t cellId, uint64_t imsi, const NrSchedulingCallbackInfo &traceInfo)
static void UlSchedulingCallback(Ptr< NrMacSchedulingStats > macStats, std::string path, NrSchedulingCallbackInfo traceInfo)
static void DlSchedulingCallback(Ptr< NrMacSchedulingStats > macStats, std::string path, NrSchedulingCallbackInfo traceInfo)
static uint64_t FindImsiFromGnbRlcPath(std::string path)
static uint16_t FindCellIdFromGnbRlcPath(std::string path)
void SetDlOutputFilename(std::string outputFilename)
void SetUlOutputFilename(std::string outputFilename)
NrSchedulingCallbackInfo structure.
uint8_t m_ndi
New data indicator.
uint8_t m_symStart
starting symbol index
uint8_t m_subframeNum
subframe number
uint16_t m_frameNum
frame number
uint8_t m_bwpId
Bandwidth Part ID.
uint16_t m_slotNum
slot number
uint8_t m_numSym
number of symbols