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