5G-LENA nr-v3.0-33-g7aea1e4
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-bearer-stats-simple.cc
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2022 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "nr-bearer-stats-simple.h"
8
9#include "ns3/nstime.h"
10#include "ns3/string.h"
11#include <ns3/log.h>
12
13namespace ns3
14{
15
16NS_LOG_COMPONENT_DEFINE("NrBearerStatsSimple");
17NS_OBJECT_ENSURE_REGISTERED(NrBearerStatsBase);
18NS_OBJECT_ENSURE_REGISTERED(NrBearerStatsSimple);
19
20TypeId
22{
23 static TypeId tid = TypeId("ns3::NrBearerStatsBase").SetParent<Object>().SetGroupName("nr");
24 return tid;
25}
26
27void
28NrBearerStatsBase::DoDispose()
29{
30 NS_LOG_FUNCTION(this);
31 Object::DoDispose();
32}
33
35 : m_protocolType("RLC")
36{
37 NS_LOG_FUNCTION(this);
38}
39
41{
42 NS_LOG_FUNCTION(this);
43 m_protocolType = protocolType;
44}
45
47{
48 NS_LOG_FUNCTION(this);
49}
50
51TypeId
53{
54 static TypeId tid =
55 TypeId("ns3::NrBearerStatsSimple")
56 .SetParent<NrBearerStatsBase>()
57 .AddConstructor<NrBearerStatsSimple>()
58 .SetGroupName("nr")
59 .AddAttribute("DlRlcTxOutputFilename",
60 "Name of the file where the RLC downlink TX results will be saved.",
61 StringValue("NrDlTxRlcStats.txt"),
62 MakeStringAccessor(&NrBearerStatsSimple::m_dlRlcTxOutputFilename),
63 MakeStringChecker())
64 .AddAttribute("DlRlcRxOutputFilename",
65 "Name of the file where the RLC downlink RX results will be saved.",
66 StringValue("NrDlRxRlcStats.txt"),
67 MakeStringAccessor(&NrBearerStatsSimple::m_dlRlcRxOutputFilename),
68 MakeStringChecker())
69 .AddAttribute("UlRlcTxOutputFilename",
70 "Name of the file where the RLC uplink RX results will be saved.",
71 StringValue("NrUlRlcTxStats.txt"),
72 MakeStringAccessor(&NrBearerStatsSimple::m_ulRlcTxOutputFilename),
73 MakeStringChecker())
74 .AddAttribute("UlRlcRxOutputFilename",
75 "Name of the file where the RLC uplink TX results will be saved.",
76 StringValue("NrUlRlcRxStats.txt"),
77 MakeStringAccessor(&NrBearerStatsSimple::m_ulRlcRxOutputFilename),
78 MakeStringChecker())
79 .AddAttribute("DlPdcpTxOutputFilename",
80 "Name of the file where the downlink PDCP TX results will be saved.",
81 StringValue("NrDlPdcpTxStats.txt"),
82 MakeStringAccessor(&NrBearerStatsSimple::m_dlPdcpTxOutputFilename),
83 MakeStringChecker())
84 .AddAttribute("DlPdcpRxOutputFilename",
85 "Name of the file where the downlink PDCP RX results will be saved.",
86 StringValue("NrDlPdcpRxStats.txt"),
87 MakeStringAccessor(&NrBearerStatsSimple::m_dlPdcpRxOutputFilename),
88 MakeStringChecker())
89 .AddAttribute("UlPdcpTxOutputFilename",
90 "Name of the file where the uplink PDCP TX results will be saved.",
91 StringValue("NrUlPdcpTxStats.txt"),
92 MakeStringAccessor(&NrBearerStatsSimple::m_ulPdcpTxOutputFilename),
93 MakeStringChecker())
94 .AddAttribute("UlPdcpRxOutputFilename",
95 "Name of the file where the uplink PDCP RX results will be saved.",
96 StringValue("NrUlPdcpRxStats.txt"),
97 MakeStringAccessor(&NrBearerStatsSimple::m_ulPdcpRxOutputFilename),
98 MakeStringChecker());
99 return tid;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this);
106 m_dlTxOutFile.close();
107 m_dlRxOutFile.close();
108 m_ulTxOutFile.close();
109 m_ulRxOutFile.close();
110 NrBearerStatsBase::DoDispose();
111}
112
113void
115 uint64_t imsi,
116 uint16_t rnti,
117 uint8_t lcid,
118 uint32_t packetSize)
119{
120 NS_LOG_FUNCTION(this << cellId << imsi << rnti << (uint32_t)lcid << packetSize);
121
122 if (!m_ulTxOutFile.is_open())
123 {
124 m_ulTxOutFile.open(GetUlTxOutputFilename().c_str());
125 m_ulTxOutFile << "time(s)"
126 << "\t"
127 << "cellId"
128 << "\t"
129 << "rnti"
130 << "\t"
131 << "lcid"
132 << "\t"
133 << "packetSize" << std::endl;
134 }
135 m_ulTxOutFile << Simulator::Now().GetSeconds() << "\t" << cellId << "\t" << rnti << "\t"
136 << (uint32_t)lcid << "\t" << packetSize << std::endl;
137}
138
139void
141 uint64_t imsi,
142 uint16_t rnti,
143 uint8_t lcid,
144 uint32_t packetSize)
145{
146 NS_LOG_FUNCTION(this << cellId << imsi << rnti << (uint32_t)lcid << packetSize);
147
148 if (!m_dlTxOutFile.is_open())
149 {
150 m_dlTxOutFile.open(GetDlTxOutputFilename().c_str());
151 m_dlTxOutFile << "time(s)"
152 << "\t"
153 << "cellId"
154 << "\t"
155 << "rnti"
156 << "\t"
157 << "lcid"
158 << "\t"
159 << "packetSize" << std::endl;
160 }
161
162 m_dlTxOutFile << Simulator::Now().GetSeconds() << "\t" << cellId << "\t" << rnti << "\t"
163 << (uint32_t)lcid << "\t" << packetSize << std::endl;
164}
165
166void
168 uint64_t imsi,
169 uint16_t rnti,
170 uint8_t lcid,
171 uint32_t packetSize,
172 uint64_t delay)
173{
174 NS_LOG_FUNCTION(this << cellId << imsi << rnti << (uint32_t)lcid << packetSize << delay);
175
176 if (!m_ulRxOutFile.is_open())
177 {
178 m_ulRxOutFile.open(GetUlRxOutputFilename().c_str());
179 m_ulRxOutFile << "time(s)"
180 << "\t"
181 << "cellId"
182 << "\t"
183 << "rnti"
184 << "\t"
185 << "lcid"
186 << "\t"
187 << "packetSize"
188 << "\t"
189 << "delay(s)" << std::endl;
190 }
191
192 m_ulRxOutFile << Simulator::Now().GetSeconds() << "\t" << cellId << "\t" << rnti << "\t"
193 << (uint32_t)lcid << "\t" << packetSize << "\t" << delay * 1e-9 << std::endl;
194}
195
196void
198 uint64_t imsi,
199 uint16_t rnti,
200 uint8_t lcid,
201 uint32_t packetSize,
202 uint64_t delay)
203{
204 NS_LOG_FUNCTION(this << cellId << imsi << rnti << (uint32_t)lcid << packetSize << delay);
205
206 if (!m_dlRxOutFile.is_open())
207 {
208 m_dlRxOutFile.open(GetDlRxOutputFilename().c_str());
209 m_dlRxOutFile << "time(s)"
210 << "\t"
211 << "cellId"
212 << "\t"
213 << "rnti"
214 << "\t"
215 << "lcid"
216 << "\t"
217 << "packetSize"
218 << "\t"
219 << "delay(s)" << std::endl;
220 }
221
222 m_dlRxOutFile << Simulator::Now().GetSeconds() << "\t" << cellId << "\t" << rnti << "\t"
223 << (uint32_t)lcid << "\t" << packetSize << "\t" << delay * 1e-9 << std::endl;
224}
225
226std::string
228{
229 if (m_protocolType == "RLC")
230 {
231 return m_ulRlcTxOutputFilename;
232 }
233 else
234 {
235 return m_ulPdcpTxOutputFilename;
236 }
237}
238
239std::string
241{
242 if (m_protocolType == "RLC")
243 {
244 return m_ulRlcRxOutputFilename;
245 }
246 else
247 {
248 return m_ulPdcpRxOutputFilename;
249 }
250}
251
252std::string
254{
255 if (m_protocolType == "RLC")
256 {
257 return m_dlRlcTxOutputFilename;
258 }
259 else
260 {
261 return m_dlPdcpTxOutputFilename;
262 }
263}
264
265std::string
267{
268 if (m_protocolType == "RLC")
269 {
270 return m_dlRlcRxOutputFilename;
271 }
272 else
273 {
274 return m_dlPdcpRxOutputFilename;
275 }
276}
277
278} // namespace ns3
void UlRxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay) override
void DlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize) override
void UlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize) override
void DlRxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay) override