5G-LENA nr-v4.0
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-rlc.cc
1// Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Nicola Baldo <nbaldo@cttc.es>
6
7#include "nr-rlc.h"
8
9#include "nr-rlc-sap.h"
10#include "nr-rlc-tag.h"
11// #include "nr-mac-sap.h"
12// #include "nr-ff-mac-sched-sap.h"
13
14#include "ns3/log.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("NrRlc");
21
23class NrRlcSpecificNrMacSapUser : public NrMacSapUser
24{
25 public:
31 NrRlcSpecificNrMacSapUser(NrRlc* rlc);
32
33 // Interface implemented from NrMacSapUser
34 void NotifyTxOpportunity(NrMacSapUser::TxOpportunityParameters params) override;
35 void NotifyHarqDeliveryFailure() override;
36 void ReceivePdu(NrMacSapUser::ReceivePduParameters params) override;
37
38 private:
39 NrRlcSpecificNrMacSapUser();
40 NrRlc* m_rlc;
41};
42
43NrRlcSpecificNrMacSapUser::NrRlcSpecificNrMacSapUser(NrRlc* rlc)
44 : m_rlc(rlc)
45{
46}
47
48NrRlcSpecificNrMacSapUser::NrRlcSpecificNrMacSapUser()
49{
50}
51
52void
53NrRlcSpecificNrMacSapUser::NotifyTxOpportunity(TxOpportunityParameters params)
54{
55 m_rlc->DoNotifyTxOpportunity(params);
56}
57
58void
59NrRlcSpecificNrMacSapUser::NotifyHarqDeliveryFailure()
60{
61 m_rlc->DoNotifyHarqDeliveryFailure();
62}
63
64void
65NrRlcSpecificNrMacSapUser::ReceivePdu(NrMacSapUser::ReceivePduParameters params)
66{
67 m_rlc->DoReceivePdu(params);
68}
69
71
72NS_OBJECT_ENSURE_REGISTERED(NrRlc);
73
74NrRlc::NrRlc()
75 : m_rlcSapUser(nullptr),
76 m_macSapProvider(nullptr),
77 m_rnti(0),
78 m_lcid(0)
79{
80 NS_LOG_FUNCTION(this);
81 m_rlcSapProvider = new NrRlcSpecificNrRlcSapProvider<NrRlc>(this);
82 m_macSapUser = new NrRlcSpecificNrMacSapUser(this);
83}
84
85NrRlc::~NrRlc()
86{
87 NS_LOG_FUNCTION(this);
88}
89
90TypeId
91NrRlc::GetTypeId()
92{
93 static TypeId tid = TypeId("ns3::NrRlc")
94 .SetParent<Object>()
95 .SetGroupName("Nr")
96 .AddTraceSource("TxPDU",
97 "PDU transmission notified to the MAC.",
98 MakeTraceSourceAccessor(&NrRlc::m_txPdu),
99 "ns3::NrRlc::NotifyTxTracedCallback")
100 .AddTraceSource("RxPDU",
101 "PDU received.",
102 MakeTraceSourceAccessor(&NrRlc::m_rxPdu),
103 "ns3::NrRlc::ReceiveTracedCallback")
104 .AddTraceSource("TxDrop",
105 "Trace source indicating a packet "
106 "has been dropped before transmission",
107 MakeTraceSourceAccessor(&NrRlc::m_txDropTrace),
108 "ns3::Packet::TracedCallback");
109 return tid;
110}
111
112void
113NrRlc::DoDispose()
114{
115 NS_LOG_FUNCTION(this);
116 delete (m_rlcSapProvider);
117 delete (m_macSapUser);
118}
119
120void
121NrRlc::SetRnti(uint16_t rnti)
122{
123 NS_LOG_FUNCTION(this << (uint32_t)rnti);
124 m_rnti = rnti;
125}
126
127void
128NrRlc::SetLcId(uint8_t lcId)
129{
130 NS_LOG_FUNCTION(this << (uint32_t)lcId);
131 m_lcid = lcId;
132}
133
134void
135NrRlc::SetPacketDelayBudgetMs(uint16_t packetDelayBudget)
136{
137 NS_LOG_FUNCTION(this << +packetDelayBudget);
138 m_packetDelayBudgetMs = packetDelayBudget;
139}
140
141void
142NrRlc::SetNrRlcSapUser(NrRlcSapUser* s)
143{
144 NS_LOG_FUNCTION(this << s);
145 m_rlcSapUser = s;
146}
147
149NrRlc::GetNrRlcSapProvider()
150{
151 NS_LOG_FUNCTION(this);
152 return m_rlcSapProvider;
153}
154
155void
156NrRlc::SetNrMacSapProvider(NrMacSapProvider* s)
157{
158 NS_LOG_FUNCTION(this << s);
159 m_macSapProvider = s;
160}
161
163NrRlc::GetNrMacSapUser()
164{
165 NS_LOG_FUNCTION(this);
166 return m_macSapUser;
167}
168
170
171NS_OBJECT_ENSURE_REGISTERED(NrRlcSm);
172
173NrRlcSm::NrRlcSm()
174{
175 NS_LOG_FUNCTION(this);
176}
177
178NrRlcSm::~NrRlcSm()
179{
180 NS_LOG_FUNCTION(this);
181}
182
183TypeId
184NrRlcSm::GetTypeId()
185{
186 static TypeId tid =
187 TypeId("ns3::NrRlcSm").SetParent<NrRlc>().SetGroupName("Nr").AddConstructor<NrRlcSm>();
188 return tid;
189}
190
191void
192NrRlcSm::DoInitialize()
193{
194 NS_LOG_FUNCTION(this);
195 BufferStatusReport();
196}
197
198void
199NrRlcSm::DoDispose()
200{
201 NS_LOG_FUNCTION(this);
202 NrRlc::DoDispose();
203}
204
205void
206NrRlcSm::DoTransmitPdcpPdu(Ptr<Packet> p)
207{
208 NS_LOG_FUNCTION(this << p);
209}
210
211void
212NrRlcSm::DoReceivePdu(NrMacSapUser::ReceivePduParameters rxPduParams)
213{
214 NS_LOG_FUNCTION(this << rxPduParams.p);
215 // RLC Performance evaluation
216 NrRlcTag rlcTag;
217 Time delay;
218 bool ret = rxPduParams.p->FindFirstMatchingByteTag(rlcTag);
219 NS_ASSERT_MSG(ret, "NrRlcTag is missing");
220 delay = Simulator::Now() - rlcTag.GetSenderTimestamp();
221 NS_LOG_LOGIC(" RNTI=" << m_rnti << " LCID=" << (uint32_t)m_lcid << " size="
222 << rxPduParams.p->GetSize() << " delay=" << delay.As(Time::NS));
223 m_rxPdu(m_rnti, m_lcid, rxPduParams.p->GetSize(), delay.GetNanoSeconds());
224}
225
226void
227NrRlcSm::DoNotifyTxOpportunity(NrMacSapUser::TxOpportunityParameters txOpParams)
228{
229 NS_LOG_FUNCTION(this << txOpParams.bytes);
231 NrRlcTag tag(Simulator::Now());
232
233 params.pdu = Create<Packet>(txOpParams.bytes);
234 NS_ABORT_MSG_UNLESS(txOpParams.bytes > 0, "Bytes must be > 0");
239 params.pdu->AddByteTag(tag, 1, params.pdu->GetSize());
240
241 params.rnti = m_rnti;
242 params.lcid = m_lcid;
243 params.layer = txOpParams.layer;
244 params.harqProcessId = txOpParams.harqId;
245 params.componentCarrierId = txOpParams.componentCarrierId;
246
247 // RLC Performance evaluation
248 NS_LOG_LOGIC(" RNTI=" << m_rnti << " LCID=" << (uint32_t)m_lcid
249 << " size=" << txOpParams.bytes);
250 m_txPdu(m_rnti, m_lcid, txOpParams.bytes);
251
252 m_macSapProvider->TransmitPdu(params);
253 BufferStatusReport();
254}
255
256void
257NrRlcSm::DoNotifyHarqDeliveryFailure()
258{
259 NS_LOG_FUNCTION(this);
260}
261
262void
263NrRlcSm::BufferStatusReport()
264{
265 NS_LOG_FUNCTION(this);
267 p.rnti = m_rnti;
268 p.lcid = m_lcid;
269 p.txQueueSize = 80000;
270 p.txQueueHolDelay = 10;
271 p.retxQueueSize = 0;
272 p.retxQueueHolDelay = 0;
273 p.statusPduSize = 0;
274 p.expBsrTimer = false;
275 m_macSapProvider->BufferStatusReport(p);
276}
277
279
280// NrRlcTm::~NrRlcTm ()
281// {
282// }
283
285
286// NrRlcUm::~NrRlcUm ()
287// {
288// }
289
291
292// NrRlcAm::~NrRlcAm ()
293// {
294// }
295
296} // namespace ns3
Time GetSenderTimestamp() const
Definition nr-rlc-tag.h:51