A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-rlc-tm.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011,2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Manuel Requena <manuel.requena@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 
25 #include "ns3/lte-rlc-tm.h"
26 #include "ns3/lte-rlc-tag.h"
27 
28 NS_LOG_COMPONENT_DEFINE ("LteRlcTm");
29 
30 namespace ns3 {
31 
32 NS_OBJECT_ENSURE_REGISTERED (LteRlcTm);
33 
34 LteRlcTm::LteRlcTm ()
35  : m_maxTxBufferSize (0),
36  m_txBufferSize (0)
37 {
38  NS_LOG_FUNCTION (this);
39 }
40 
41 LteRlcTm::~LteRlcTm ()
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 TypeId
47 LteRlcTm::GetTypeId (void)
48 {
49  static TypeId tid = TypeId ("ns3::LteRlcTm")
50  .SetParent<LteRlc> ()
51  .AddConstructor<LteRlcTm> ()
52  .AddAttribute ("MaxTxBufferSize",
53  "Maximum Size of the Transmission Buffer (in Bytes)",
54  UintegerValue (2 * 1024 * 1024),
55  MakeUintegerAccessor (&LteRlcTm::m_maxTxBufferSize),
56  MakeUintegerChecker<uint32_t> ())
57  ;
58  return tid;
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION (this);
65  m_rbsTimer.Cancel ();
66  m_txBuffer.clear ();
67 
69 }
70 
71 
76 void
78 {
79  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
80 
81  if (m_txBufferSize + p->GetSize () <= m_maxTxBufferSize)
82  {
84  RlcTag timeTag (Simulator::Now ());
85  p->AddPacketTag (timeTag);
86 
87  NS_LOG_LOGIC ("Tx Buffer: New packet added");
88  m_txBuffer.push_back (p);
89  m_txBufferSize += p->GetSize ();
90  NS_LOG_LOGIC ("NumOfBuffers = " << m_txBuffer.size() );
91  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
92  }
93  else
94  {
95  // Discard full RLC SDU
96  NS_LOG_LOGIC ("TxBuffer is full. RLC SDU discarded");
97  NS_LOG_LOGIC ("MaxTxBufferSize = " << m_maxTxBufferSize);
98  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
99  NS_LOG_LOGIC ("packet size = " << p->GetSize ());
100  }
101 
103  DoReportBufferStatus ();
104  m_rbsTimer.Cancel ();
105 }
106 
107 
112 void
113 LteRlcTm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId)
114 {
115  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes << (uint32_t) layer << (uint32_t) harqId);
116 
117  // 5.1.1.1 Transmit operations
118  // 5.1.1.1.1 General
119  // When submitting a new TMD PDU to lower layer, the transmitting TM RLC entity shall:
120  // - submit a RLC SDU without any modification to lower layer.
121 
122 
123  if ( m_txBuffer.size () == 0 )
124  {
125  NS_LOG_LOGIC ("No data pending");
126  return;
127  }
128 
129  Ptr<Packet> packet = (*(m_txBuffer.begin ()))->Copy ();
130 
131  if (bytes < packet->GetSize ())
132  {
133  // Stingy MAC: Header fix part is 2 bytes, we need more bytes for the data
134  NS_LOG_WARN ("TX opportunity too small = " << bytes << " (PDU size: " << packet->GetSize () << ")");
135  return;
136  }
137 
138  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
139  m_txBuffer.erase (m_txBuffer.begin ());
140 
141  // Sender timestamp
142  RlcTag rlcTag (Simulator::Now ());
143  packet->AddByteTag (rlcTag);
144  m_txPdu (m_rnti, m_lcid, packet->GetSize ());
145 
146  // Send RLC PDU to MAC layer
148  params.pdu = packet;
149  params.rnti = m_rnti;
150  params.lcid = m_lcid;
151  params.layer = layer;
152  params.harqProcessId = harqId;
153 
154  m_macSapProvider->TransmitPdu (params);
155 
156  if (! m_txBuffer.empty ())
157  {
158  m_rbsTimer.Cancel ();
159  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcTm::ExpireRbsTimer, this);
160  }
161 }
162 
163 void
164 LteRlcTm::DoNotifyHarqDeliveryFailure ()
165 {
166  NS_LOG_FUNCTION (this);
167 }
168 
169 void
170 LteRlcTm::DoReceivePdu (Ptr<Packet> p)
171 {
172  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
173 
174  // Receiver timestamp
175  RlcTag rlcTag;
176  Time delay;
177  if (p->FindFirstMatchingByteTag (rlcTag))
178  {
179  delay = Simulator::Now() - rlcTag.GetSenderTimestamp ();
180  }
181  m_rxPdu (m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
182 
183  // 5.1.1.2 Receive operations
184  // 5.1.1.2.1 General
185  // When receiving a new TMD PDU from lower layer, the receiving TM RLC entity shall:
186  // - deliver the TMD PDU without any modification to upper layer.
187 
188  m_rlcSapUser->ReceivePdcpPdu (p);
189 }
190 
191 
192 void
193 LteRlcTm::DoReportBufferStatus (void)
194 {
195  Time holDelay (0);
196  uint32_t queueSize = 0;
197 
198  if (! m_txBuffer.empty ())
199  {
200  RlcTag holTimeTag;
201  m_txBuffer.front ()->PeekPacketTag (holTimeTag);
202  holDelay = Simulator::Now () - holTimeTag.GetSenderTimestamp ();
203 
204  queueSize = m_txBufferSize; // just data in tx queue (no header overhead for RLC TM)
205  }
206 
207  LteMacSapProvider::ReportBufferStatusParameters r;
208  r.rnti = m_rnti;
209  r.lcid = m_lcid;
210  r.txQueueSize = queueSize;
211  r.txQueueHolDelay = holDelay.GetMilliSeconds () ;
212  r.retxQueueSize = 0;
213  r.retxQueueHolDelay = 0;
214  r.statusPduSize = 0;
215 
216  NS_LOG_LOGIC ("Send ReportBufferStatus = " << r.txQueueSize << ", " << r.txQueueHolDelay );
217  m_macSapProvider->ReportBufferStatus (r);
218 }
219 
220 void
221 LteRlcTm::ExpireRbsTimer (void)
222 {
223  NS_LOG_LOGIC ("RBS Timer expires");
224 
225  if (! m_txBuffer.empty ())
226  {
227  DoReportBufferStatus ();
228  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcTm::ExpireRbsTimer, this);
229  }
230 }
231 
232 } // namespace ns3
TracedCallback< uint16_t, uint8_t, uint32_t > m_txPdu
Definition: lte-rlc.h:128
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
void AddPacketTag(const Tag &tag) const
Definition: packet.cc:868
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetSize(void) const
Definition: packet.h:620
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
virtual void DoTransmitPdcpPdu(Ptr< Packet > p)
Definition: lte-rlc-tm.cc:77
virtual void ReceivePdcpPdu(Ptr< Packet > p)=0
virtual void DoDispose()
Definition: lte-rlc.cc:117
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
Ptr< Packet > Copy(void) const
Definition: packet.cc:131
static Time Now(void)
Definition: simulator.cc:179
#define NS_LOG_WARN(msg)
Definition: log.h:246
void Cancel(void)
Definition: event-id.cc:47
virtual void ReportBufferStatus(ReportBufferStatusParameters params)=0
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Definition: nstime.h:601
virtual void DoDispose()
Definition: lte-rlc-tm.cc:62
TracedCallback< uint16_t, uint8_t, uint32_t, uint64_t > m_rxPdu
Definition: lte-rlc.h:132
virtual void TransmitPdu(TransmitPduParameters params)=0
void AddByteTag(const Tag &tag) const
Definition: packet.cc:833
virtual void DoNotifyTxOpportunity(uint32_t bytes, uint8_t layer, uint8_t harqId)
Definition: lte-rlc-tm.cc:113