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