A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-rlc-tm.cc
Go to the documentation of this file.
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 
33  ;
34 
36  : m_maxTxBufferSize (0),
37  m_txBufferSize (0)
38 {
39  NS_LOG_FUNCTION (this);
40 }
41 
43 {
44  NS_LOG_FUNCTION (this);
45 }
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::LteRlcTm")
51  .SetParent<LteRlc> ()
52  .AddConstructor<LteRlcTm> ()
53  .AddAttribute ("MaxTxBufferSize",
54  "Maximum Size of the Transmission Buffer (in Bytes)",
55  UintegerValue (2 * 1024 * 1024),
56  MakeUintegerAccessor (&LteRlcTm::m_maxTxBufferSize),
57  MakeUintegerChecker<uint32_t> ())
58  ;
59  return tid;
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION (this);
66  m_rbsTimer.Cancel ();
67  m_txBuffer.clear ();
68 
70 }
71 
72 
77 void
79 {
80  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
81 
83  {
85  RlcTag timeTag (Simulator::Now ());
86  p->AddPacketTag (timeTag);
87 
88  NS_LOG_LOGIC ("Tx Buffer: New packet added");
89  m_txBuffer.push_back (p);
90  m_txBufferSize += p->GetSize ();
91  NS_LOG_LOGIC ("NumOfBuffers = " << m_txBuffer.size() );
92  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
93  }
94  else
95  {
96  // Discard full RLC SDU
97  NS_LOG_LOGIC ("TxBuffer is full. RLC SDU discarded");
98  NS_LOG_LOGIC ("MaxTxBufferSize = " << m_maxTxBufferSize);
99  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
100  NS_LOG_LOGIC ("packet size = " << p->GetSize ());
101  }
102 
105  m_rbsTimer.Cancel ();
106 }
107 
108 
113 void
114 LteRlcTm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId)
115 {
116  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes << (uint32_t) layer << (uint32_t) harqId);
117 
118  // 5.1.1.1 Transmit operations
119  // 5.1.1.1.1 General
120  // When submitting a new TMD PDU to lower layer, the transmitting TM RLC entity shall:
121  // - submit a RLC SDU without any modification to lower layer.
122 
123 
124  if ( m_txBuffer.size () == 0 )
125  {
126  NS_LOG_LOGIC ("No data pending");
127  return;
128  }
129 
130  Ptr<Packet> packet = (*(m_txBuffer.begin ()))->Copy ();
131 
132  if (bytes < packet->GetSize ())
133  {
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
165 {
166  NS_LOG_FUNCTION (this);
167 }
168 
169 void
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 
189 }
190 
191 
192 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 
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 );
218 }
219 
220 void
222 {
223  NS_LOG_LOGIC ("RBS Timer expires");
224 
225  if (! m_txBuffer.empty ())
226  {
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
Used to inform of a PDU delivery to the MAC SAP provider.
Definition: lte-rlc.h:128
bool FindFirstMatchingByteTag(Tag &tag) const
Definition: packet.cc:824
NS_LOG_COMPONENT_DEFINE("LteRlcTm")
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
uint32_t m_txBufferSize
Definition: lte-rlc-tm.h:61
virtual void DoNotifyHarqDeliveryFailure()
Definition: lte-rlc-tm.cc:164
void ExpireRbsTimer(void)
Definition: lte-rlc-tm.cc:221
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:841
Tag to calculate the per-PDU delay from eNb RLC to UE RLC.
Definition: lte-rlc-tag.h:36
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void DoReportBufferStatus()
Definition: lte-rlc-tm.cc:193
uint32_t GetSize(void) const
Definition: packet.h:650
uint32_t retxQueueSize
the current size of the RLC retransmission queue in bytes
Definition: lte-mac-sap.h:72
uint16_t m_rnti
Definition: lte-rlc.h:122
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
uint8_t m_lcid
Definition: lte-rlc.h:123
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-mac-sap.h:68
Parameters for LteMacSapProvider::ReportBufferStatus.
Definition: lte-mac-sap.h:66
uint16_t txQueueHolDelay
the Head Of Line delay of the transmission queue
Definition: lte-mac-sap.h:71
LteRlcSapUser * m_rlcSapUser
Definition: lte-rlc.h:111
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual void DoTransmitPdcpPdu(Ptr< Packet > p)
RLC SAP.
Definition: lte-rlc-tm.cc:78
virtual void ReceivePdcpPdu(Ptr< Packet > p)=0
Called by the RLC entity to notify the PDCP entity of the reception of a new PDCP PDU...
virtual ~LteRlcTm()
Definition: lte-rlc-tm.cc:42
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lte-rlc.cc:118
LteMacSapProvider * m_macSapProvider
Definition: lte-rlc.h:120
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
EventId m_rbsTimer
Definition: lte-rlc-tm.h:64
Ptr< Packet > Copy(void) const
Definition: packet.cc:122
std::vector< Ptr< Packet > > m_txBuffer
Definition: lte-rlc-tm.h:62
static TypeId GetTypeId(void)
Definition: lte-rlc-tm.cc:48
Time GetSenderTimestamp(void) const
Get the instant when the RLC delivers the PDU to the MAC SAP provider.
Definition: lte-rlc-tag.h:60
uint8_t lcid
the logical channel id corresponding to the sending RLC instance
Definition: lte-mac-sap.h:69
uint32_t txQueueSize
the current size of the RLC transmission queue
Definition: lte-mac-sap.h:70
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
int64_t GetNanoSeconds(void) const
Definition: nstime.h:299
virtual void DoReceivePdu(Ptr< Packet > p)
Definition: lte-rlc-tm.cc:170
uint16_t statusPduSize
the current size of the pending STATUS RLC PDU message in bytes
Definition: lte-mac-sap.h:74
#define NS_LOG_WARN(msg)
Definition: log.h:280
uint32_t m_maxTxBufferSize
Definition: lte-rlc-tm.h:60
uint16_t retxQueueHolDelay
the Head Of Line delay of the retransmission queue
Definition: lte-mac-sap.h:73
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
Definition: event-id.cc:47
virtual void ReportBufferStatus(ReportBufferStatusParameters params)=0
Report the RLC buffer status to the MAC.
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lte-rlc-tm.cc:63
TracedCallback< uint16_t, uint8_t, uint32_t, uint64_t > m_rxPdu
Used to inform of a PDU reception from the MAC SAP user.
Definition: lte-rlc.h:132
virtual void TransmitPdu(TransmitPduParameters params)=0
send an RLC PDU to the MAC for transmission.
This abstract base class defines the API to interact with the Radio Link Control (LTE_RLC) in LTE...
Definition: lte-rlc.h:50
a unique identifier for an interface.
Definition: type-id.h:49
int64_t GetMilliSeconds(void) const
Definition: nstime.h:283
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808
virtual void DoNotifyTxOpportunity(uint32_t bytes, uint8_t layer, uint8_t harqId)
MAC SAP.
Definition: lte-rlc-tm.cc:114
Parameters for LteMacSapProvider::TransmitPdu.
Definition: lte-mac-sap.h:45