A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-rlc-um.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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  */
20 
21 #include "ns3/simulator.h"
22 #include "ns3/log.h"
23 
24 #include "ns3/lte-rlc-header.h"
25 #include "ns3/lte-rlc-um.h"
26 #include "ns3/lte-rlc-sdu-status-tag.h"
27 #include "ns3/lte-rlc-tag.h"
28 
29 NS_LOG_COMPONENT_DEFINE ("LteRlcUm");
30 
31 namespace ns3 {
32 
34  ;
35 
37  : m_maxTxBufferSize (10 * 1024),
38  m_txBufferSize (0),
39  m_sequenceNumber (0),
40  m_vrUr (0),
41  m_vrUx (0),
42  m_vrUh (0),
43  m_windowSize (512),
44  m_expectedSeqNumber (0)
45 {
46  NS_LOG_FUNCTION (this);
48 }
49 
51 {
52  NS_LOG_FUNCTION (this);
53 }
54 
55 TypeId
57 {
58  static TypeId tid = TypeId ("ns3::LteRlcUm")
59  .SetParent<LteRlc> ()
60  .AddConstructor<LteRlcUm> ()
61  .AddAttribute ("MaxTxBufferSize",
62  "Maximum Size of the Transmission Buffer (in Bytes)",
63  UintegerValue (10 * 1024),
64  MakeUintegerAccessor (&LteRlcUm::m_maxTxBufferSize),
65  MakeUintegerChecker<uint32_t> ())
66  ;
67  return tid;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this);
75  m_rbsTimer.Cancel ();
76 
78 }
79 
84 void
86 {
87  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
88 
90  {
92  RlcTag timeTag (Simulator::Now ());
93  p->AddPacketTag (timeTag);
94 
99  p->AddPacketTag (tag);
100 
101  NS_LOG_LOGIC ("Tx Buffer: New packet added");
102  m_txBuffer.push_back (p);
103  m_txBufferSize += p->GetSize ();
104  NS_LOG_LOGIC ("NumOfBuffers = " << m_txBuffer.size() );
105  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
106  }
107  else
108  {
109  // Discard full RLC SDU
110  NS_LOG_LOGIC ("TxBuffer is full. RLC SDU discarded");
111  NS_LOG_LOGIC ("MaxTxBufferSize = " << m_maxTxBufferSize);
112  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
113  NS_LOG_LOGIC ("packet size = " << p->GetSize ());
114  }
115 
118  m_rbsTimer.Cancel ();
119 }
120 
121 
126 void
127 LteRlcUm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId)
128 {
129  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes);
130 
131  if (bytes <= 2)
132  {
133  // Stingy MAC: Header fix part is 2 bytes, we need more bytes for the data
134  NS_LOG_LOGIC ("TX opportunity too small = " << bytes);
135  return;
136  }
137 
138  Ptr<Packet> packet = Create<Packet> ();
139  LteRlcHeader rlcHeader;
140 
141  // Build Data field
142  uint32_t nextSegmentSize = bytes - 2;
143  uint32_t nextSegmentId = 1;
144  uint32_t dataFieldTotalSize = 0;
145  uint32_t dataFieldAddedSize = 0;
146  std::vector < Ptr<Packet> > dataField;
147 
148  // Remove the first packet from the transmission buffer.
149  // If only a segment of the packet is taken, then the remaining is given back later
150  if ( m_txBuffer.size () == 0 )
151  {
152  NS_LOG_LOGIC ("No data pending");
153  return;
154  }
155 
156  NS_LOG_LOGIC ("SDUs in TxBuffer = " << m_txBuffer.size ());
157  NS_LOG_LOGIC ("First SDU buffer = " << *(m_txBuffer.begin()));
158  NS_LOG_LOGIC ("First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
159  NS_LOG_LOGIC ("Next segment size = " << nextSegmentSize);
160  NS_LOG_LOGIC ("Remove SDU from TxBuffer");
161  Ptr<Packet> firstSegment = (*(m_txBuffer.begin ()))->Copy ();
162  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
163  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize );
164  m_txBuffer.erase (m_txBuffer.begin ());
165 
166  while ( firstSegment && (firstSegment->GetSize () > 0) && (nextSegmentSize > 0) )
167  {
168  NS_LOG_LOGIC ("WHILE ( firstSegment && firstSegment->GetSize > 0 && nextSegmentSize > 0 )");
169  NS_LOG_LOGIC (" firstSegment size = " << firstSegment->GetSize ());
170  NS_LOG_LOGIC (" nextSegmentSize = " << nextSegmentSize);
171  if ( (firstSegment->GetSize () > nextSegmentSize) ||
172  // Segment larger than 2047 octets can only be mapped to the end of the Data field
173  (firstSegment->GetSize () > 2047)
174  )
175  {
176  // Take the minimum size, due to the 2047-bytes 3GPP exception
177  // This exception is due to the length of the LI field (just 11 bits)
178  uint32_t currSegmentSize = std::min (firstSegment->GetSize (), nextSegmentSize);
179 
180  NS_LOG_LOGIC (" IF ( firstSegment > nextSegmentSize ||");
181  NS_LOG_LOGIC (" firstSegment > 2047 )");
182 
183  // Segment txBuffer.FirstBuffer and
184  // Give back the remaining segment to the transmission buffer
185  Ptr<Packet> newSegment = firstSegment->CreateFragment (0, currSegmentSize);
186  NS_LOG_LOGIC (" newSegment size = " << newSegment->GetSize ());
187 
188  // Status tag of the new and remaining segments
189  // Note: This is the only place where a PDU is segmented and
190  // therefore its status can change
191  LteRlcSduStatusTag oldTag, newTag;
192  firstSegment->RemovePacketTag (oldTag);
193  newSegment->RemovePacketTag (newTag);
194  if (oldTag.GetStatus () == LteRlcSduStatusTag::FULL_SDU)
195  {
196  newTag.SetStatus (LteRlcSduStatusTag::FIRST_SEGMENT);
197  oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
198  }
199  else if (oldTag.GetStatus () == LteRlcSduStatusTag::LAST_SEGMENT)
200  {
201  newTag.SetStatus (LteRlcSduStatusTag::MIDDLE_SEGMENT);
202  //oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
203  }
204 
205  // Give back the remaining segment to the transmission buffer
206  firstSegment->RemoveAtStart (currSegmentSize);
207  NS_LOG_LOGIC (" firstSegment size (after RemoveAtStart) = " << firstSegment->GetSize ());
208  if (firstSegment->GetSize () > 0)
209  {
210  firstSegment->AddPacketTag (oldTag);
211 
212  m_txBuffer.insert (m_txBuffer.begin (), firstSegment);
213  m_txBufferSize += (*(m_txBuffer.begin()))->GetSize ();
214 
215  NS_LOG_LOGIC (" TX buffer: Give back the remaining segment");
216  NS_LOG_LOGIC (" TX buffers = " << m_txBuffer.size ());
217  NS_LOG_LOGIC (" Front buffer size = " << (*(m_txBuffer.begin()))->GetSize ());
218  NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize );
219  }
220  else
221  {
222  // Whole segment was taken, so adjust tag
223  if (newTag.GetStatus () == LteRlcSduStatusTag::FIRST_SEGMENT)
224  {
225  newTag.SetStatus (LteRlcSduStatusTag::FULL_SDU);
226  }
227  else if (newTag.GetStatus () == LteRlcSduStatusTag::MIDDLE_SEGMENT)
228  {
229  newTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
230  }
231  }
232  // Segment is completely taken or
233  // the remaining segment is given back to the transmission buffer
234  firstSegment = 0;
235 
236  // Put status tag once it has been adjusted
237  newSegment->AddPacketTag (newTag);
238 
239  // Add Segment to Data field
240  dataFieldAddedSize = newSegment->GetSize ();
241  dataFieldTotalSize += dataFieldAddedSize;
242  dataField.push_back (newSegment);
243  newSegment = 0;
244 
245  // ExtensionBit (Next_Segment - 1) = 0
246  rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS);
247 
248  // no LengthIndicator for the last one
249 
250  nextSegmentSize -= dataFieldAddedSize;
251  nextSegmentId++;
252 
253  // nextSegmentSize MUST be zero (only if segment is smaller or equal to 2047)
254 
255  // (NO more segments) → exit
256  // break;
257  }
258  else if ( (nextSegmentSize - firstSegment->GetSize () <= 2) || (m_txBuffer.size () == 0) )
259  {
260  NS_LOG_LOGIC (" IF nextSegmentSize - firstSegment->GetSize () <= 2 || txBuffer.size == 0");
261  // Add txBuffer.FirstBuffer to DataField
262  dataFieldAddedSize = firstSegment->GetSize ();
263  dataFieldTotalSize += dataFieldAddedSize;
264  dataField.push_back (firstSegment);
265  firstSegment = 0;
266 
267  // ExtensionBit (Next_Segment - 1) = 0
268  rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS);
269 
270  // no LengthIndicator for the last one
271 
272  nextSegmentSize -= dataFieldAddedSize;
273  nextSegmentId++;
274 
275  NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ());
276  if (m_txBuffer.size () > 0)
277  {
278  NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin()));
279  NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
280  }
281  NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize);
282 
283  // nextSegmentSize <= 2 (only if txBuffer is not empty)
284 
285  // (NO more segments) → exit
286  // break;
287  }
288  else // (firstSegment->GetSize () < m_nextSegmentSize) && (m_txBuffer.size () > 0)
289  {
290  NS_LOG_LOGIC (" IF firstSegment < NextSegmentSize && txBuffer.size > 0");
291  // Add txBuffer.FirstBuffer to DataField
292  dataFieldAddedSize = firstSegment->GetSize ();
293  dataFieldTotalSize += dataFieldAddedSize;
294  dataField.push_back (firstSegment);
295 
296  // ExtensionBit (Next_Segment - 1) = 1
297  rlcHeader.PushExtensionBit (LteRlcHeader::E_LI_FIELDS_FOLLOWS);
298 
299  // LengthIndicator (Next_Segment) = txBuffer.FirstBuffer.length()
300  rlcHeader.PushLengthIndicator (firstSegment->GetSize ());
301 
302  nextSegmentSize -= ((nextSegmentId % 2) ? (2) : (1)) + dataFieldAddedSize;
303  nextSegmentId++;
304 
305  NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ());
306  if (m_txBuffer.size () > 0)
307  {
308  NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin()));
309  NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
310  }
311  NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize);
312  NS_LOG_LOGIC (" Remove SDU from TxBuffer");
313 
314  // (more segments)
315  firstSegment = (*(m_txBuffer.begin ()))->Copy ();
316  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
317  m_txBuffer.erase (m_txBuffer.begin ());
318  NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize );
319  }
320 
321  }
322 
323  // Build RLC header
324  rlcHeader.SetSequenceNumber (m_sequenceNumber++);
325 
326  // Build RLC PDU with DataField and Header
327  std::vector< Ptr<Packet> >::iterator it;
328  it = dataField.begin ();
329 
330  uint8_t framingInfo = 0;
331 
332  // FIRST SEGMENT
333  LteRlcSduStatusTag tag;
334  (*it)->RemovePacketTag (tag);
335  if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) ||
337  {
338  framingInfo |= LteRlcHeader::FIRST_BYTE;
339  }
340  else
341  {
342  framingInfo |= LteRlcHeader::NO_FIRST_BYTE;
343  }
344  (*it)->AddPacketTag (tag);
345 
346  while (it < dataField.end ())
347  {
348  NS_LOG_LOGIC ("Adding SDU/segment to packet, length = " << (*it)->GetSize ());
349 
350  packet->AddAtEnd (*it);
351  it++;
352  }
353 
354  // LAST SEGMENT (Note: There could be only one and be the first one)
355  it--;
356  (*it)->RemovePacketTag (tag);
357  if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) ||
359  {
360  framingInfo |= LteRlcHeader::LAST_BYTE;
361  }
362  else
363  {
364  framingInfo |= LteRlcHeader::NO_LAST_BYTE;
365  }
366  (*it)->AddPacketTag (tag);
367 
368  rlcHeader.SetFramingInfo (framingInfo);
369 
370  NS_LOG_LOGIC ("RLC header: " << rlcHeader);
371  packet->AddHeader (rlcHeader);
372 
373  // Sender timestamp
374  RlcTag rlcTag (Simulator::Now ());
375  packet->AddByteTag (rlcTag);
376  m_txPdu (m_rnti, m_lcid, packet->GetSize ());
377 
378  // Send RLC PDU to MAC layer
380  params.pdu = packet;
381  params.rnti = m_rnti;
382  params.lcid = m_lcid;
383  params.layer = layer;
384  params.harqProcessId = harqId;
385 
386  m_macSapProvider->TransmitPdu (params);
387 
388  if (! m_txBuffer.empty ())
389  {
390  m_rbsTimer.Cancel ();
391  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsTimer, this);
392  }
393 }
394 
395 void
397 {
398  NS_LOG_FUNCTION (this);
399 }
400 
401 void
403 {
404  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
405 
406  // Receiver timestamp
407  RlcTag rlcTag;
408  Time delay;
409  if (p->FindFirstMatchingByteTag (rlcTag))
410  {
411  delay = Simulator::Now() - rlcTag.GetSenderTimestamp ();
412  }
413  m_rxPdu (m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
414 
415  // 5.1.2.2 Receive operations
416 
417  // Get RLC header parameters
418  LteRlcHeader rlcHeader;
419  p->PeekHeader (rlcHeader);
420  NS_LOG_LOGIC ("RLC header: " << rlcHeader);
421  SequenceNumber10 seqNumber = rlcHeader.GetSequenceNumber ();
422 
423  // 5.1.2.2.1 General
424  // The receiving UM RLC entity shall maintain a reordering window according to state variable VR(UH) as follows:
425  // - a SN falls within the reordering window if (VR(UH) - UM_Window_Size) <= SN < VR(UH);
426  // - a SN falls outside of the reordering window otherwise.
427  // When receiving an UMD PDU from lower layer, the receiving UM RLC entity shall:
428  // - either discard the received UMD PDU or place it in the reception buffer (see sub clause 5.1.2.2.2);
429  // - if the received UMD PDU was placed in the reception buffer:
430  // - update state variables, reassemble and deliver RLC SDUs to upper layer and start/stop t-Reordering as needed (see sub clause 5.1.2.2.3);
431  // When t-Reordering expires, the receiving UM RLC entity shall:
432  // - update state variables, reassemble and deliver RLC SDUs to upper layer and start t-Reordering as needed (see sub clause 5.1.2.2.4).
433 
434  // 5.1.2.2.2 Actions when an UMD PDU is received from lower layer
435  // When an UMD PDU with SN = x is received from lower layer, the receiving UM RLC entity shall:
436  // - if VR(UR) < x < VR(UH) and the UMD PDU with SN = x has been received before; or
437  // - if (VR(UH) - UM_Window_Size) <= x < VR(UR):
438  // - discard the received UMD PDU;
439  // - else:
440  // - place the received UMD PDU in the reception buffer.
441 
442  NS_LOG_LOGIC ("VR(UR) = " << m_vrUr);
443  NS_LOG_LOGIC ("VR(UX) = " << m_vrUx);
444  NS_LOG_LOGIC ("VR(UH) = " << m_vrUh);
445  NS_LOG_LOGIC ("SN = " << seqNumber);
446 
449  seqNumber.SetModulusBase (m_vrUh - m_windowSize);
450 
451  if ( ( (m_vrUr < seqNumber) && (seqNumber < m_vrUh) && (m_rxBuffer.count (seqNumber.GetValue ()) > 0) ) ||
452  ( ((m_vrUh - m_windowSize) <= seqNumber) && (seqNumber < m_vrUr) )
453  )
454  {
455  NS_LOG_LOGIC ("PDU discarded");
456  p = 0;
457  return;
458  }
459  else
460  {
461  NS_LOG_LOGIC ("Place PDU in the reception buffer");
462  m_rxBuffer[seqNumber.GetValue ()] = p;
463  }
464 
465 
466  // 5.1.2.2.3 Actions when an UMD PDU is placed in the reception buffer
467  // When an UMD PDU with SN = x is placed in the reception buffer, the receiving UM RLC entity shall:
468 
469  // - if x falls outside of the reordering window:
470  // - update VR(UH) to x + 1;
471  // - reassemble RLC SDUs from any UMD PDUs with SN that falls outside of the reordering window, remove
472  // RLC headers when doing so and deliver the reassembled RLC SDUs to upper layer in ascending order of the
473  // RLC SN if not delivered before;
474  // - if VR(UR) falls outside of the reordering window:
475  // - set VR(UR) to (VR(UH) - UM_Window_Size);
476 
477  if ( ! IsInsideReorderingWindow (seqNumber))
478  {
479  NS_LOG_LOGIC ("SN is outside the reordering window");
480 
481  m_vrUh = seqNumber + 1;
482  NS_LOG_LOGIC ("New VR(UH) = " << m_vrUh);
483 
485 
487  {
489  NS_LOG_LOGIC ("VR(UR) is outside the reordering window");
490  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
491  }
492  }
493 
494  // - if the reception buffer contains an UMD PDU with SN = VR(UR):
495  // - update VR(UR) to the SN of the first UMD PDU with SN > current VR(UR) that has not been received;
496  // - reassemble RLC SDUs from any UMD PDUs with SN < updated VR(UR), remove RLC headers when doing
497  // so and deliver the reassembled RLC SDUs to upper layer in ascending order of the RLC SN if not delivered
498  // before;
499 
500  if ( m_rxBuffer.count (m_vrUr.GetValue ()) > 0 )
501  {
502  NS_LOG_LOGIC ("Reception buffer contains SN = " << m_vrUr);
503 
504  std::map <uint16_t, Ptr<Packet> >::iterator it;
505  uint16_t newVrUr;
506  SequenceNumber10 oldVrUr = m_vrUr;
507 
508  it = m_rxBuffer.find (m_vrUr.GetValue ());
509  newVrUr = (it->first) + 1;
510  while ( m_rxBuffer.count (newVrUr) > 0 )
511  {
512  newVrUr++;
513  }
514  m_vrUr = newVrUr;
515  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
516 
517  ReassembleSnInterval (oldVrUr, m_vrUr);
518  }
519 
520  // m_vrUh can change previously, set new modulus base
521  // for the t-Reordering timer-related comparisons
525 
526  // - if t-Reordering is running:
527  // - if VR(UX) <= VR(UR); or
528  // - if VR(UX) falls outside of the reordering window and VR(UX) is not equal to VR(UH)::
529  // - stop and reset t-Reordering;
530  if ( m_reorderingTimer.IsRunning () )
531  {
532  NS_LOG_LOGIC ("Reordering timer is running");
533 
534  if ( (m_vrUx <= m_vrUr) ||
535  ((! IsInsideReorderingWindow (m_vrUx)) && (m_vrUx != m_vrUh)) )
536  {
537  NS_LOG_LOGIC ("Stop reordering timer");
539  }
540  }
541 
542  // - if t-Reordering is not running (includes the case when t-Reordering is stopped due to actions above):
543  // - if VR(UH) > VR(UR):
544  // - start t-Reordering;
545  // - set VR(UX) to VR(UH).
546  if ( ! m_reorderingTimer.IsRunning () )
547  {
548  NS_LOG_LOGIC ("Reordering timer is not running");
549 
550  if ( m_vrUh > m_vrUr )
551  {
552  NS_LOG_LOGIC ("VR(UH) > VR(UR)");
553  NS_LOG_LOGIC ("Start reordering timer");
556  m_vrUx = m_vrUh;
557  NS_LOG_LOGIC ("New VR(UX) = " << m_vrUx);
558  }
559  }
560 
561 }
562 
563 
564 bool
566 {
567  NS_LOG_FUNCTION (this << seqNumber);
568  NS_LOG_LOGIC ("Reordering Window: " <<
569  m_vrUh << " - " << m_windowSize << " <= " << seqNumber << " < " << m_vrUh);
570 
572  seqNumber.SetModulusBase (m_vrUh - m_windowSize);
573 
574  if ( ((m_vrUh - m_windowSize) <= seqNumber) && (seqNumber < m_vrUh))
575  {
576  NS_LOG_LOGIC (seqNumber << " is INSIDE the reordering window");
577  return true;
578  }
579  else
580  {
581  NS_LOG_LOGIC (seqNumber << " is OUTSIDE the reordering window");
582  return false;
583  }
584 }
585 
586 
587 void
589 {
590  LteRlcHeader rlcHeader;
591  packet->RemoveHeader (rlcHeader);
592  uint8_t framingInfo = rlcHeader.GetFramingInfo ();
593  SequenceNumber10 currSeqNumber = rlcHeader.GetSequenceNumber ();
594  bool expectedSnLost;
595 
596  if ( currSeqNumber != m_expectedSeqNumber )
597  {
598  expectedSnLost = true;
599  NS_LOG_LOGIC ("There are losses. Expected SN = " << m_expectedSeqNumber << ". Current SN = " << currSeqNumber);
600  m_expectedSeqNumber = currSeqNumber + 1;
601  }
602  else
603  {
604  expectedSnLost = false;
605  NS_LOG_LOGIC ("No losses. Expected SN = " << m_expectedSeqNumber << ". Current SN = " << currSeqNumber);
607  }
608 
609  // Build list of SDUs
610  uint8_t extensionBit;
611  uint16_t lengthIndicator;
612  do
613  {
614  extensionBit = rlcHeader.PopExtensionBit ();
615  NS_LOG_LOGIC ("E = " << (uint16_t)extensionBit);
616 
617  if ( extensionBit == 0 )
618  {
619  m_sdusBuffer.push_back (packet);
620  }
621  else // extensionBit == 1
622  {
623  lengthIndicator = rlcHeader.PopLengthIndicator ();
624  NS_LOG_LOGIC ("LI = " << lengthIndicator);
625 
626  // Check if there is enough data in the packet
627  if ( lengthIndicator >= packet->GetSize () )
628  {
629  NS_LOG_LOGIC ("INTERNAL ERROR: Not enough data in the packet (" << packet->GetSize () << "). Needed LI=" << lengthIndicator);
630  }
631 
632  // Split packet in two fragments
633  Ptr<Packet> data_field = packet->CreateFragment (0, lengthIndicator);
634  packet->RemoveAtStart (lengthIndicator);
635 
636  m_sdusBuffer.push_back (data_field);
637  }
638  }
639  while ( extensionBit == 1 );
640 
641  std::list < Ptr<Packet> >::iterator it;
642 
643  // Current reassembling state
644  if (m_reassemblingState == WAITING_S0_FULL) NS_LOG_LOGIC ("Reassembling State = 'WAITING_S0_FULL'");
645  else if (m_reassemblingState == WAITING_SI_SF) NS_LOG_LOGIC ("Reassembling State = 'WAITING_SI_SF'");
646  else NS_LOG_LOGIC ("Reassembling State = Unknown state");
647 
648  // Received framing Info
649  NS_LOG_LOGIC ("Framing Info = " << (uint16_t)framingInfo);
650 
651  // Reassemble the list of SDUs (when there is no losses)
652  if (!expectedSnLost)
653  {
654  switch (m_reassemblingState)
655  {
656  case WAITING_S0_FULL:
657  switch (framingInfo)
658  {
661 
665  for ( it = m_sdusBuffer.begin () ; it != m_sdusBuffer.end () ; it++ )
666  {
668  }
669  m_sdusBuffer.clear ();
670  break;
671 
674 
678  while ( m_sdusBuffer.size () > 1 )
679  {
681  m_sdusBuffer.pop_front ();
682  }
683 
687  m_keepS0 = m_sdusBuffer.front ();
688  m_sdusBuffer.pop_front ();
689  break;
690 
693 
697  m_sdusBuffer.pop_front ();
698 
702  while ( ! m_sdusBuffer.empty () )
703  {
705  m_sdusBuffer.pop_front ();
706  }
707  break;
708 
710  if ( m_sdusBuffer.size () == 1 )
711  {
713  }
714  else
715  {
717  }
718 
722  m_sdusBuffer.pop_front ();
723 
724  if ( m_sdusBuffer.size () > 0 )
725  {
729  while ( m_sdusBuffer.size () > 1 )
730  {
732  m_sdusBuffer.pop_front ();
733  }
734 
738  m_keepS0 = m_sdusBuffer.front ();
739  m_sdusBuffer.pop_front ();
740  }
741  break;
742 
743  default:
747  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
748  break;
749  }
750  break;
751 
752  case WAITING_SI_SF:
753  switch (framingInfo)
754  {
757 
761  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
762  m_sdusBuffer.pop_front ();
764 
768  while ( ! m_sdusBuffer.empty () )
769  {
771  m_sdusBuffer.pop_front ();
772  }
773  break;
774 
777 
781  if ( m_sdusBuffer.size () == 1 )
782  {
783  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
784  m_sdusBuffer.pop_front ();
785  }
786  else // m_sdusBuffer.size () > 1
787  {
791  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
792  m_sdusBuffer.pop_front ();
794 
798  while ( m_sdusBuffer.size () > 1 )
799  {
801  m_sdusBuffer.pop_front ();
802  }
803 
807  m_keepS0 = m_sdusBuffer.front ();
808  m_sdusBuffer.pop_front ();
809  }
810  break;
811 
814  default:
818  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
819  break;
820  }
821  break;
822 
823  default:
824  NS_LOG_LOGIC ("INTERNAL ERROR: Wrong reassembling state = " << (uint32_t) m_reassemblingState);
825  break;
826  }
827  }
828  else // Reassemble the list of SDUs (when there are losses, i.e. the received SN is not the expected one)
829  {
830  switch (m_reassemblingState)
831  {
832  case WAITING_S0_FULL:
833  switch (framingInfo)
834  {
837 
841  for ( it = m_sdusBuffer.begin () ; it != m_sdusBuffer.end () ; it++ )
842  {
844  }
845  m_sdusBuffer.clear ();
846  break;
847 
850 
854  while ( m_sdusBuffer.size () > 1 )
855  {
857  m_sdusBuffer.pop_front ();
858  }
859 
863  m_keepS0 = m_sdusBuffer.front ();
864  m_sdusBuffer.pop_front ();
865  break;
866 
869 
873  m_sdusBuffer.pop_front ();
874 
878  while ( ! m_sdusBuffer.empty () )
879  {
881  m_sdusBuffer.pop_front ();
882  }
883  break;
884 
886  if ( m_sdusBuffer.size () == 1 )
887  {
889  }
890  else
891  {
893  }
894 
898  m_sdusBuffer.pop_front ();
899 
900  if ( m_sdusBuffer.size () > 0 )
901  {
905  while ( m_sdusBuffer.size () > 1 )
906  {
908  m_sdusBuffer.pop_front ();
909  }
910 
914  m_keepS0 = m_sdusBuffer.front ();
915  m_sdusBuffer.pop_front ();
916  }
917  break;
918 
919  default:
923  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
924  break;
925  }
926  break;
927 
928  case WAITING_SI_SF:
929  switch (framingInfo)
930  {
933 
937  m_keepS0 = 0;
938 
942  while ( ! m_sdusBuffer.empty () )
943  {
945  m_sdusBuffer.pop_front ();
946  }
947  break;
948 
951 
955  m_keepS0 = 0;
956 
960  while ( m_sdusBuffer.size () > 1 )
961  {
963  m_sdusBuffer.pop_front ();
964  }
965 
969  m_keepS0 = m_sdusBuffer.front ();
970  m_sdusBuffer.pop_front ();
971 
972  break;
973 
976 
980  m_keepS0 = 0;
981 
985  m_sdusBuffer.pop_front ();
986 
990  while ( ! m_sdusBuffer.empty () )
991  {
993  m_sdusBuffer.pop_front ();
994  }
995  break;
996 
998  if ( m_sdusBuffer.size () == 1 )
999  {
1001  }
1002  else
1003  {
1005  }
1006 
1010  m_keepS0 = 0;
1011 
1015  m_sdusBuffer.pop_front ();
1016 
1017  if ( m_sdusBuffer.size () > 0 )
1018  {
1022  while ( m_sdusBuffer.size () > 1 )
1023  {
1025  m_sdusBuffer.pop_front ();
1026  }
1027 
1031  m_keepS0 = m_sdusBuffer.front ();
1032  m_sdusBuffer.pop_front ();
1033  }
1034  break;
1035 
1036  default:
1040  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
1041  break;
1042  }
1043  break;
1044 
1045  default:
1046  NS_LOG_LOGIC ("INTERNAL ERROR: Wrong reassembling state = " << (uint32_t) m_reassemblingState);
1047  break;
1048  }
1049  }
1050 
1051 }
1052 
1053 
1054 void
1056 {
1057  NS_LOG_LOGIC ("Reassemble Outside Window");
1058 
1059  std::map <uint16_t, Ptr<Packet> >::iterator it;
1060  it = m_rxBuffer.begin ();
1061 
1062  while ( (it != m_rxBuffer.end ()) && ! IsInsideReorderingWindow (SequenceNumber10 (it->first)) )
1063  {
1064  NS_LOG_LOGIC ("SN = " << it->first);
1065 
1066  // Reassemble RLC SDUs and deliver the PDCP PDU to upper layer
1067  ReassembleAndDeliver (it->second);
1068 
1069  std::map <uint16_t, Ptr<Packet> >::iterator it_tmp = it;
1070  ++it;
1071  m_rxBuffer.erase (it_tmp);
1072  }
1073 
1074  if (it != m_rxBuffer.end ())
1075  {
1076  NS_LOG_LOGIC ("(SN = " << it->first << ") is inside the reordering window");
1077  }
1078 }
1079 
1080 void
1082 {
1083  NS_LOG_LOGIC ("Reassemble SN between " << lowSeqNumber << " and " << highSeqNumber);
1084 
1085  std::map <uint16_t, Ptr<Packet> >::iterator it;
1086 
1087  SequenceNumber10 reassembleSn = lowSeqNumber;
1088  NS_LOG_LOGIC ("reassembleSN = " << reassembleSn);
1089  NS_LOG_LOGIC ("highSeqNumber = " << highSeqNumber);
1090  while (reassembleSn < highSeqNumber)
1091  {
1092  NS_LOG_LOGIC ("reassembleSn < highSeqNumber");
1093  it = m_rxBuffer.find (reassembleSn.GetValue ());
1094  NS_LOG_LOGIC ("it->first = " << it->first);
1095  NS_LOG_LOGIC ("it->second = " << it->second);
1096  if (it != m_rxBuffer.end () )
1097  {
1098  NS_LOG_LOGIC ("SN = " << it->first);
1099 
1100  // Reassemble RLC SDUs and deliver the PDCP PDU to upper layer
1101  ReassembleAndDeliver (it->second);
1102 
1103  m_rxBuffer.erase (it);
1104  }
1105 
1106  reassembleSn++;
1107  }
1108 }
1109 
1110 
1111 void
1113 {
1114  Time holDelay (0);
1115  uint32_t queueSize = 0;
1116 
1117  if (! m_txBuffer.empty ())
1118  {
1119  RlcTag holTimeTag;
1120  m_txBuffer.front ()->PeekPacketTag (holTimeTag);
1121  holDelay = Simulator::Now () - holTimeTag.GetSenderTimestamp ();
1122 
1123  queueSize = m_txBufferSize + 2 * m_txBuffer.size (); // Data in tx queue + estimated headers size
1124  }
1125 
1127  r.rnti = m_rnti;
1128  r.lcid = m_lcid;
1129  r.txQueueSize = queueSize;
1130  r.txQueueHolDelay = holDelay.GetMilliSeconds () ;
1131  r.retxQueueSize = 0;
1132  r.retxQueueHolDelay = 0;
1133  r.statusPduSize = 0;
1134 
1135  NS_LOG_LOGIC ("Send ReportBufferStatus = " << r.txQueueSize << ", " << r.txQueueHolDelay );
1137 }
1138 
1139 
1140 void
1142 {
1143  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid);
1144  NS_LOG_LOGIC ("Reordering timer has expired");
1145 
1146  // 5.1.2.2.4 Actions when t-Reordering expires
1147  // When t-Reordering expires, the receiving UM RLC entity shall:
1148  // - update VR(UR) to the SN of the first UMD PDU with SN >= VR(UX) that has not been received;
1149  // - reassemble RLC SDUs from any UMD PDUs with SN < updated VR(UR), remove RLC headers when doing so
1150  // and deliver the reassembled RLC SDUs to upper layer in ascending order of the RLC SN if not delivered before;
1151  // - if VR(UH) > VR(UR):
1152  // - start t-Reordering;
1153  // - set VR(UX) to VR(UH).
1154 
1155  std::map <uint16_t, Ptr<Packet> >::iterator it;
1156  SequenceNumber10 newVrUr = m_vrUx;
1157 
1158  while ( (it = m_rxBuffer.find (newVrUr.GetValue ())) != m_rxBuffer.end () )
1159  {
1160  newVrUr++;
1161  }
1162  SequenceNumber10 oldVrUr = m_vrUr;
1163  m_vrUr = newVrUr;
1164  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
1165 
1166  ReassembleSnInterval (oldVrUr, m_vrUr);
1167 
1168  if ( m_vrUh > m_vrUr)
1169  {
1170  NS_LOG_LOGIC ("Start reordering timer");
1173  m_vrUx = m_vrUh;
1174  NS_LOG_LOGIC ("New VR(UX) = " << m_vrUx);
1175  }
1176 }
1177 
1178 
1179 void
1181 {
1182  NS_LOG_LOGIC ("RBS Timer expires");
1183 
1184  if (! m_txBuffer.empty ())
1185  {
1187  m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsTimer, this);
1188  }
1189 }
1190 
1191 } // namespace ns3
uint32_t m_maxTxBufferSize
Definition: lte-rlc-um.h:69
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
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
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
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
virtual ~LteRlcUm()
Definition: lte-rlc-um.cc:50
void ReassembleAndDeliver(Ptr< Packet > packet)
Definition: lte-rlc-um.cc:588
void DoReportBufferStatus()
Definition: lte-rlc-um.cc:1112
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)
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
virtual void DoTransmitPdcpPdu(Ptr< Packet > p)
RLC SAP.
Definition: lte-rlc-um.cc:85
uint8_t PopExtensionBit(void)
uint16_t m_rnti
Definition: lte-rlc.h:122
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
Definition: event-id.cc:59
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
virtual void DoNotifyHarqDeliveryFailure()
Definition: lte-rlc-um.cc:396
SequenceNumber10 m_vrUr
Definition: lte-rlc-um.h:82
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-mac-sap.h:68
SequenceNumber10 m_sequenceNumber
State variables.
Definition: lte-rlc-um.h:80
void ReassembleSnInterval(SequenceNumber10 lowSeqNumber, SequenceNumber10 highSeqNumber)
Definition: lte-rlc-um.cc:1081
void SetModulusBase(SequenceNumber10 modulusBase)
The packet header for the Radio Link Control (RLC) protocol packets.
Parameters for LteMacSapProvider::ReportBufferStatus.
Definition: lte-mac-sap.h:66
SequenceNumber10 m_vrUh
Definition: lte-rlc-um.h:84
uint16_t txQueueHolDelay
the Head Of Line delay of the transmission queue
Definition: lte-mac-sap.h:71
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:228
virtual void DoReceivePdu(Ptr< Packet > p)
Definition: lte-rlc-um.cc:402
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:317
uint16_t PopLengthIndicator(void)
LteRlcSapUser * m_rlcSapUser
Definition: lte-rlc.h:111
SequenceNumber10 m_expectedSeqNumber
Expected Sequence Number.
Definition: lte-rlc-um.h:109
std::vector< Ptr< Packet > > m_txBuffer
Definition: lte-rlc-um.h:71
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:353
NS_LOG_COMPONENT_DEFINE("LteRlcUm")
virtual void DoNotifyTxOpportunity(uint32_t bytes, uint8_t layer, uint8_t harqId)
MAC SAP.
Definition: lte-rlc-um.cc:127
static TypeId GetTypeId(void)
Definition: lte-rlc-um.cc:56
Hold an unsigned integer type.
Definition: uinteger.h:46
ReassemblingState_t m_reassemblingState
Definition: lte-rlc-um.h:103
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...
uint8_t GetStatus(void) const
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
Ptr< Packet > m_keepS0
Definition: lte-rlc-um.h:104
Ptr< Packet > Copy(void) const
Definition: packet.cc:122
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
SequenceNumber10 m_vrUx
Definition: lte-rlc-um.h:83
uint16_t m_windowSize
Constants.
Definition: lte-rlc-um.h:89
void ExpireReorderingTimer(void)
Definition: lte-rlc-um.cc:1141
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
std::map< uint16_t, Ptr< Packet > > m_rxBuffer
Definition: lte-rlc-um.h:72
EventId m_reorderingTimer
Timers.
Definition: lte-rlc-um.h:94
int64_t GetNanoSeconds(void) const
Definition: nstime.h:299
SequenceNumber10 GetSequenceNumber() const
uint16_t statusPduSize
the current size of the pending STATUS RLC PDU message in bytes
Definition: lte-mac-sap.h:74
std::list< Ptr< Packet > > m_sdusBuffer
Definition: lte-rlc-um.h:75
This class implements a tag that carries the status of a RLC SDU for the fragmentation process Status...
uint8_t GetFramingInfo() const
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:848
void ReassembleOutsideWindow(void)
Definition: lte-rlc-um.cc:1055
bool IsInsideReorderingWindow(SequenceNumber10 seqNumber)
Definition: lte-rlc-um.cc:565
void SetStatus(uint8_t status)
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lte-rlc-um.cc:71
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.
uint32_t m_txBufferSize
Definition: lte-rlc-um.h:70
void ExpireRbsTimer(void)
Definition: lte-rlc-um.cc:1180
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
EventId m_rbsTimer
Definition: lte-rlc-um.h:95
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 AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808
Parameters for LteMacSapProvider::TransmitPdu.
Definition: lte-mac-sap.h:45