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 
35  : m_maxTxBufferSize (0),
36  m_txBufferSize (0)
37 {
38  NS_LOG_FUNCTION (this);
39 }
40 
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 TypeId
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 
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 
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  NS_LOG_WARN ("TX opportunity too small = " << bytes << " (PDU size: " << packet->GetSize () << ")");
134  return;
135  }
136 
137  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
138  m_txBuffer.erase (m_txBuffer.begin ());
139 
140  // Sender timestamp
141  RlcTag rlcTag (Simulator::Now ());
142  packet->AddByteTag (rlcTag);
143  m_txPdu (m_rnti, m_lcid, packet->GetSize ());
144 
145  // Send RLC PDU to MAC layer
147  params.pdu = packet;
148  params.rnti = m_rnti;
149  params.lcid = m_lcid;
150  params.layer = layer;
151  params.harqProcessId = harqId;
152 
153  m_macSapProvider->TransmitPdu (params);
154 
155  if (! m_txBuffer.empty ())
156  {
157  m_rbsTimer.Cancel ();
158  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcTm::ExpireRbsTimer, this);
159  }
160 }
161 
162 void
164 {
165  NS_LOG_FUNCTION (this);
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
172 
173  // Receiver timestamp
174  RlcTag rlcTag;
175  Time delay;
176  if (p->FindFirstMatchingByteTag (rlcTag))
177  {
178  delay = Simulator::Now() - rlcTag.GetSenderTimestamp ();
179  }
180  m_rxPdu (m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
181 
182  // 5.1.1.2 Receive operations
183  // 5.1.1.2.1 General
184  // When receiving a new TMD PDU from lower layer, the receiving TM RLC entity shall:
185  // - deliver the TMD PDU without any modification to upper layer.
186 
188 }
189 
190 
191 void
193 {
194  Time holDelay (0);
195  uint32_t queueSize = 0;
196 
197  if (! m_txBuffer.empty ())
198  {
199  RlcTag holTimeTag;
200  m_txBuffer.front ()->PeekPacketTag (holTimeTag);
201  holDelay = Simulator::Now () - holTimeTag.GetSenderTimestamp ();
202 
203  queueSize = m_txBufferSize; // just data in tx queue (no header overhead for RLC TM)
204  }
205 
207  r.rnti = m_rnti;
208  r.lcid = m_lcid;
209  r.txQueueSize = queueSize;
210  r.txQueueHolDelay = holDelay.GetMilliSeconds () ;
211  r.retxQueueSize = 0;
212  r.retxQueueHolDelay = 0;
213  r.statusPduSize = 0;
214 
215  NS_LOG_LOGIC ("Send ReportBufferStatus = " << r.txQueueSize << ", " << r.txQueueHolDelay );
217 }
218 
219 void
221 {
222  NS_LOG_LOGIC ("RBS Timer expires");
223 
224  if (! m_txBuffer.empty ())
225  {
227  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcTm::ExpireRbsTimer, this);
228  }
229 }
230 
231 } // 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
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:824
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_txBufferSize
Definition: lte-rlc-tm.h:61
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void DoNotifyHarqDeliveryFailure()
Definition: lte-rlc-tm.cc:163
void ExpireRbsTimer(void)
Definition: lte-rlc-tm.cc:220
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void DoReportBufferStatus()
Definition: lte-rlc-tm.cc:192
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
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:825
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:77
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:41
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lte-rlc.cc:117
LteMacSapProvider * m_macSapProvider
Definition: lte-rlc.h:120
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
EventId m_rbsTimer
Definition: lte-rlc-tm.h:64
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
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:47
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:297
virtual void DoReceivePdu(Ptr< Packet > p)
Definition: lte-rlc-tm.cc:169
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)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
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:62
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:281
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
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:113
Parameters for LteMacSapProvider::TransmitPdu.
Definition: lte-mac-sap.h:45