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