5G-LENA nr-v4.1
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-rx-trace.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "nr-mac-rx-trace.h"
6
7#include "ns3/log.h"
8#include "ns3/simulator.h"
9
10#include <fstream>
11
12namespace ns3
13{
14
15NS_LOG_COMPONENT_DEFINE("NrMacRxTrace");
16
17NS_OBJECT_ENSURE_REGISTERED(NrMacRxTrace);
18
19std::ofstream NrMacRxTrace::m_rxedGnbMacCtrlMsgsFile;
20std::string NrMacRxTrace::m_rxedGnbMacCtrlMsgsFileName;
21std::ofstream NrMacRxTrace::m_txedGnbMacCtrlMsgsFile;
22std::string NrMacRxTrace::m_txedGnbMacCtrlMsgsFileName;
23
24std::ofstream NrMacRxTrace::m_rxedUeMacCtrlMsgsFile;
25std::string NrMacRxTrace::m_rxedUeMacCtrlMsgsFileName;
26std::ofstream NrMacRxTrace::m_txedUeMacCtrlMsgsFile;
27std::string NrMacRxTrace::m_txedUeMacCtrlMsgsFileName;
28
29NrMacRxTrace::NrMacRxTrace()
30{
31}
32
33NrMacRxTrace::~NrMacRxTrace()
34{
35 if (m_rxedGnbMacCtrlMsgsFile.is_open())
36 {
37 m_rxedGnbMacCtrlMsgsFile.close();
38 }
39
40 if (m_txedGnbMacCtrlMsgsFile.is_open())
41 {
42 m_txedGnbMacCtrlMsgsFile.close();
43 }
44
45 if (m_rxedUeMacCtrlMsgsFile.is_open())
46 {
47 m_rxedUeMacCtrlMsgsFile.close();
48 }
49
50 if (m_txedUeMacCtrlMsgsFile.is_open())
51 {
52 m_txedUeMacCtrlMsgsFile.close();
53 }
54}
55
56TypeId
57NrMacRxTrace::GetTypeId()
58{
59 static TypeId tid =
60 TypeId("ns3::NrMacRxTrace").SetParent<Object>().AddConstructor<NrMacRxTrace>();
61 return tid;
62}
63
64void
66 std::string path,
67 SfnSf sfn,
68 uint16_t nodeId,
69 uint16_t rnti,
70 uint8_t bwpId,
71 Ptr<const NrControlMessage> msg)
72{
73 if (!m_rxedGnbMacCtrlMsgsFile.is_open())
74 {
75 m_rxedGnbMacCtrlMsgsFileName = "RxedGnbMacCtrlMsgsTrace.txt";
76 m_rxedGnbMacCtrlMsgsFile.open(m_rxedGnbMacCtrlMsgsFileName.c_str());
77 m_rxedGnbMacCtrlMsgsFile << "Time"
78 << "\t"
79 << "Entity"
80 << "\t"
81 << "Frame"
82 << "\t"
83 << "SF"
84 << "\t"
85 << "Slot"
86 << "\t"
87 << "VarTTI"
88 << "\t"
89 << "nodeId"
90 << "\t"
91 << "RNTI"
92 << "\t"
93 << "bwpId"
94 << "\t"
95 << "MsgType" << std::endl;
96
97 if (!m_rxedGnbMacCtrlMsgsFile.is_open())
98 {
99 NS_FATAL_ERROR("Could not open tracefile");
100 }
101 }
102
103 m_rxedGnbMacCtrlMsgsFile << Simulator::Now().GetNanoSeconds() / (double)1e9 << "\t"
104 << "gNB MAC Rxed"
105 << "\t" << sfn.GetFrame() << "\t"
106 << static_cast<uint32_t>(sfn.GetSubframe()) << "\t"
107 << static_cast<uint32_t>(sfn.GetSlot()) << "\t" << nodeId << "\t"
108 << rnti << "\t" << static_cast<uint32_t>(bwpId) << "\t";
109
110 if (msg->GetMessageType() == NrControlMessage::SR)
111 {
112 m_rxedGnbMacCtrlMsgsFile << "SR";
113 }
114 else if (msg->GetMessageType() == NrControlMessage::DL_CQI)
115 {
116 m_rxedGnbMacCtrlMsgsFile << "DL_CQI";
117 }
118 else if (msg->GetMessageType() == NrControlMessage::BSR)
119 {
120 m_rxedGnbMacCtrlMsgsFile << "BSR";
121 }
122 else if (msg->GetMessageType() == NrControlMessage::DL_HARQ)
123 {
124 m_rxedGnbMacCtrlMsgsFile << "DL_HARQ";
125 }
126 else if (msg->GetMessageType() == NrControlMessage::RACH_PREAMBLE)
127 {
128 m_rxedGnbMacCtrlMsgsFile << "RACH_PREAMBLE";
129 }
130 else
131 {
132 m_rxedGnbMacCtrlMsgsFile << "Other";
133 }
134 m_rxedGnbMacCtrlMsgsFile << std::endl;
135}
136
137void
139 std::string path,
140 SfnSf sfn,
141 uint16_t nodeId,
142 uint16_t rnti,
143 uint8_t bwpId,
144 Ptr<const NrControlMessage> msg)
145{
146 if (!m_txedGnbMacCtrlMsgsFile.is_open())
147 {
148 m_txedGnbMacCtrlMsgsFileName = "TxedGnbMacCtrlMsgsTrace.txt";
149 m_txedGnbMacCtrlMsgsFile.open(m_txedGnbMacCtrlMsgsFileName.c_str());
150 m_txedGnbMacCtrlMsgsFile << "Time"
151 << "\t"
152 << "Entity"
153 << "\t"
154 << "Frame"
155 << "\t"
156 << "SF"
157 << "\t"
158 << "Slot"
159 << "\t"
160 << "VarTTI"
161 "\t"
162 << "nodeId"
163 << "\t"
164 << "RNTI"
165 << "\t"
166 << "bwpId"
167 << "\t"
168 << "MsgType" << std::endl;
169
170 if (!m_txedGnbMacCtrlMsgsFile.is_open())
171 {
172 NS_FATAL_ERROR("Could not open tracefile");
173 }
174 }
175
176 m_txedGnbMacCtrlMsgsFile << Simulator::Now().GetNanoSeconds() / (double)1e9 << "\t"
177 << "gNB MAC Txed"
178 << "\t" << sfn.GetFrame() << "\t"
179 << static_cast<uint32_t>(sfn.GetSubframe()) << "\t"
180 << static_cast<uint32_t>(sfn.GetSlot()) << "\t" << nodeId << "\t"
181 << rnti << "\t" << static_cast<uint32_t>(bwpId) << "\t";
182
183 if (msg->GetMessageType() == NrControlMessage::RAR)
184 {
185 m_txedGnbMacCtrlMsgsFile << "RAR";
186 }
187 else if (msg->GetMessageType() == NrControlMessage::DL_CQI)
188 {
189 m_txedGnbMacCtrlMsgsFile << "DL_CQI";
190 }
191 else
192 {
193 m_txedGnbMacCtrlMsgsFile << "Other";
194 }
195
196 m_txedGnbMacCtrlMsgsFile << std::endl;
197}
198
199void
201 std::string path,
202 SfnSf sfn,
203 uint16_t nodeId,
204 uint16_t rnti,
205 uint8_t bwpId,
206 Ptr<const NrControlMessage> msg)
207{
208 if (!m_rxedUeMacCtrlMsgsFile.is_open())
209 {
210 m_rxedUeMacCtrlMsgsFileName = "RxedUeMacCtrlMsgsTrace.txt";
211 m_rxedUeMacCtrlMsgsFile.open(m_rxedUeMacCtrlMsgsFileName.c_str());
212 m_rxedUeMacCtrlMsgsFile << "Time"
213 << "\t"
214 << "Entity"
215 << "\t"
216 << "Frame"
217 << "\t"
218 << "SF"
219 << "\t"
220 << "Slot"
221 << "\t"
222 << "VarTTI"
223 << "\t"
224 << "nodeId"
225 << "\t"
226 << "RNTI"
227 << "\t"
228 << "bwpId"
229 << "\t"
230 << "MsgType" << std::endl;
231
232 if (!m_rxedUeMacCtrlMsgsFile.is_open())
233 {
234 NS_FATAL_ERROR("Could not open tracefile");
235 }
236 }
237
238 m_rxedUeMacCtrlMsgsFile << Simulator::Now().GetNanoSeconds() / (double)1e9 << "\t"
239 << "UE MAC Rxed"
240 << "\t" << sfn.GetFrame() << "\t"
241 << static_cast<uint32_t>(sfn.GetSubframe()) << "\t"
242 << static_cast<uint32_t>(sfn.GetSlot()) << "\t" << nodeId << "\t"
243 << rnti << "\t" << static_cast<uint32_t>(bwpId) << "\t";
244
245 if (msg->GetMessageType() == NrControlMessage::UL_DCI)
246 {
247 m_rxedUeMacCtrlMsgsFile << "UL_DCI";
248 }
249 else if (msg->GetMessageType() == NrControlMessage::DL_DCI)
250 {
251 m_rxedUeMacCtrlMsgsFile << "DL_DCI";
252 }
253 else if (msg->GetMessageType() == NrControlMessage::RAR)
254 {
255 m_rxedUeMacCtrlMsgsFile << "RAR";
256 }
257 else
258 {
259 m_rxedUeMacCtrlMsgsFile << "Other";
260 }
261 m_rxedUeMacCtrlMsgsFile << std::endl;
262}
263
264void
266 std::string path,
267 SfnSf sfn,
268 uint16_t nodeId,
269 uint16_t rnti,
270 uint8_t bwpId,
271 Ptr<const NrControlMessage> msg)
272{
273 if (!m_txedUeMacCtrlMsgsFile.is_open())
274 {
275 m_txedUeMacCtrlMsgsFileName = "TxedUeMacCtrlMsgsTrace.txt";
276 m_txedUeMacCtrlMsgsFile.open(m_txedUeMacCtrlMsgsFileName.c_str());
277 m_txedUeMacCtrlMsgsFile << "Time"
278 << "\t"
279 << "Entity"
280 << "\t"
281 << "Frame"
282 << "\t"
283 << "SF"
284 << "\t"
285 << "Slot"
286 << "\t"
287 << "VarTTI"
288 << "\t"
289 << "nodeId"
290 << "\t"
291 << "RNTI"
292 << "\t"
293 << "bwpId"
294 << "\t"
295 << "MsgType" << std::endl;
296
297 if (!m_txedUeMacCtrlMsgsFile.is_open())
298 {
299 NS_FATAL_ERROR("Could not open tracefile");
300 }
301 }
302
303 m_txedUeMacCtrlMsgsFile << Simulator::Now().GetNanoSeconds() / (double)1e9 << "\t"
304 << "UE MAC Txed"
305 << "\t" << sfn.GetFrame() << "\t"
306 << static_cast<uint32_t>(sfn.GetSubframe()) << "\t"
307 << static_cast<uint32_t>(sfn.GetSlot()) << "\t" << nodeId << "\t"
308 << rnti << "\t" << static_cast<uint32_t>(bwpId) << "\t";
309
310 if (msg->GetMessageType() == NrControlMessage::BSR)
311 {
312 m_txedUeMacCtrlMsgsFile << "BSR";
313 }
314 else if (msg->GetMessageType() == NrControlMessage::SR)
315 {
316 m_txedUeMacCtrlMsgsFile << "SR";
317 }
318 else if (msg->GetMessageType() == NrControlMessage::RACH_PREAMBLE)
319 {
320 m_txedUeMacCtrlMsgsFile << "RACH_PREAMBLE";
321 }
322 else
323 {
324 m_txedUeMacCtrlMsgsFile << "Other";
325 }
326 m_txedUeMacCtrlMsgsFile << std::endl;
327}
328
329} /* namespace ns3 */
@ UL_DCI
The resources allocation map from the BS to the attached UEs (UL)
@ DL_HARQ
DL HARQ feedback.
@ RACH_PREAMBLE
Random Access Preamble.
@ SR
Scheduling Request: asking for space.
@ BSR
Buffer Status Report.
@ RAR
Random Access Response.
@ DL_DCI
The resources allocation map from the BS to the attached UEs (DL)
static void RxedGnbMacCtrlMsgsCallback(Ptr< NrMacRxTrace > macStats, std::string path, SfnSf sfn, uint16_t nodeId, uint16_t rnti, uint8_t bwpId, Ptr< const NrControlMessage > msg)
static void TxedGnbMacCtrlMsgsCallback(Ptr< NrMacRxTrace > macStats, std::string path, SfnSf sfn, uint16_t nodeId, uint16_t rnti, uint8_t bwpId, Ptr< const NrControlMessage > msg)
static void RxedUeMacCtrlMsgsCallback(Ptr< NrMacRxTrace > macStats, std::string path, SfnSf sfn, uint16_t nodeId, uint16_t rnti, uint8_t bwpId, Ptr< const NrControlMessage > msg)
static void TxedUeMacCtrlMsgsCallback(Ptr< NrMacRxTrace > macStats, std::string path, SfnSf sfn, uint16_t nodeId, uint16_t rnti, uint8_t bwpId, Ptr< const NrControlMessage > msg)
The SfnSf class.
Definition sfnsf.h:32
uint8_t GetSubframe() const
GetSubframe.
Definition sfnsf.cc:170
uint8_t GetSlot() const
GetSlot.
Definition sfnsf.cc:176
uint32_t GetFrame() const
GetFrame.
Definition sfnsf.cc:164