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 
36  : m_maxTxBufferSize (2 * 1024 * 1024),
37  m_txBufferSize (0),
38  m_sequenceNumber (0),
39  m_vrUr (0),
40  m_vrUx (0),
41  m_vrUh (0),
42  m_windowSize (512),
43  m_expectedSeqNumber (0)
44 {
45  NS_LOG_FUNCTION (this);
47 
49 }
50 
52 {
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 (2 * 1024 * 1024),
64  MakeUintegerAccessor (&LteRlcUm::m_maxTxBufferSize),
65  MakeUintegerChecker<uint32_t> ())
66  ;
67  return tid;
68 }
69 
70 
75 void
77 {
78  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
79 
81  {
83  RlcTag timeTag (Simulator::Now ());
84  p->AddPacketTag (timeTag);
85 
90  p->AddPacketTag (tag);
91 
92  NS_LOG_LOGIC ("Tx Buffer: New packet added");
93  m_txBuffer.push_back (p);
94  m_txBufferSize += p->GetSize ();
95  NS_LOG_LOGIC ("NumOfBuffers = " << m_txBuffer.size() );
96  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
97  }
98  else
99  {
100  // Discard full RLC SDU
101  NS_LOG_LOGIC ("TxBuffer is full. RLC SDU discarded");
102  NS_LOG_LOGIC ("MaxTxBufferSize = " << m_maxTxBufferSize);
103  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize);
104  NS_LOG_LOGIC ("packet size = " << p->GetSize ());
105  }
106 
109  m_rbsTimer.Cancel ();
110 }
111 
112 
117 void
118 LteRlcUm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer)
119 {
120  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes);
121 
122  if (bytes <= 2)
123  {
124  // Stingy MAC: Header fix part is 2 bytes, we need more bytes for the data
125  NS_LOG_LOGIC ("TX opportunity too small = " << bytes);
126  return;
127  }
128 
129  Ptr<Packet> packet = Create<Packet> ();
130  LteRlcHeader rlcHeader;
131 
132  // Build Data field
133  uint32_t nextSegmentSize = bytes - 2;
134  uint32_t nextSegmentId = 1;
135  uint32_t dataFieldTotalSize = 0;
136  uint32_t dataFieldAddedSize = 0;
137  std::vector < Ptr<Packet> > dataField;
138 
139  // Remove the first packet from the transmission buffer.
140  // If only a segment of the packet is taken, then the remaining is given back later
141  if ( m_txBuffer.size () == 0 )
142  {
143  NS_LOG_LOGIC ("No data pending");
144  return;
145  }
146 
147  NS_LOG_LOGIC ("SDUs in TxBuffer = " << m_txBuffer.size ());
148  NS_LOG_LOGIC ("First SDU buffer = " << *(m_txBuffer.begin()));
149  NS_LOG_LOGIC ("First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
150  NS_LOG_LOGIC ("Next segment size = " << nextSegmentSize);
151  NS_LOG_LOGIC ("Remove SDU from TxBuffer");
152  Ptr<Packet> firstSegment = (*(m_txBuffer.begin ()))->Copy ();
153  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
154  NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize );
155  m_txBuffer.erase (m_txBuffer.begin ());
156 
157  while ( firstSegment && (firstSegment->GetSize () > 0) && (nextSegmentSize > 0) )
158  {
159  NS_LOG_LOGIC ("WHILE ( firstSegment && firstSegment->GetSize > 0 && nextSegmentSize > 0 )");
160  NS_LOG_LOGIC (" firstSegment size = " << firstSegment->GetSize ());
161  NS_LOG_LOGIC (" nextSegmentSize = " << nextSegmentSize);
162  if ( (firstSegment->GetSize () > nextSegmentSize) ||
163  // Segment larger than 2047 octets can only be mapped to the end of the Data field
164  (firstSegment->GetSize () > 2047)
165  )
166  {
167  // Take the minimum size, due to the 2047-bytes 3GPP exception
168  // This exception is due to the length of the LI field (just 11 bits)
169  uint32_t currSegmentSize = std::min (firstSegment->GetSize (), nextSegmentSize);
170 
171  NS_LOG_LOGIC (" IF ( firstSegment > nextSegmentSize ||");
172  NS_LOG_LOGIC (" firstSegment > 2047 )");
173 
174  // Segment txBuffer.FirstBuffer and
175  // Give back the remaining segment to the transmission buffer
176  Ptr<Packet> newSegment = firstSegment->CreateFragment (0, currSegmentSize);
177  NS_LOG_LOGIC (" newSegment size = " << newSegment->GetSize ());
178 
179  // Status tag of the new and remaining segments
180  // Note: This is the only place where a PDU is segmented and
181  // therefore its status can change
182  LteRlcSduStatusTag oldTag, newTag;
183  firstSegment->RemovePacketTag (oldTag);
184  newSegment->RemovePacketTag (newTag);
185  if (oldTag.GetStatus () == LteRlcSduStatusTag::FULL_SDU)
186  {
187  newTag.SetStatus (LteRlcSduStatusTag::FIRST_SEGMENT);
188  oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
189  }
190  else if (oldTag.GetStatus () == LteRlcSduStatusTag::LAST_SEGMENT)
191  {
192  newTag.SetStatus (LteRlcSduStatusTag::MIDDLE_SEGMENT);
193  //oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
194  }
195 
196  // Give back the remaining segment to the transmission buffer
197  firstSegment->RemoveAtStart (currSegmentSize);
198  NS_LOG_LOGIC (" firstSegment size (after RemoveAtStart) = " << firstSegment->GetSize ());
199  if (firstSegment->GetSize () > 0)
200  {
201  firstSegment->AddPacketTag (oldTag);
202 
203  m_txBuffer.insert (m_txBuffer.begin (), firstSegment);
204  m_txBufferSize += (*(m_txBuffer.begin()))->GetSize ();
205 
206  NS_LOG_LOGIC (" TX buffer: Give back the remaining segment");
207  NS_LOG_LOGIC (" TX buffers = " << m_txBuffer.size ());
208  NS_LOG_LOGIC (" Front buffer size = " << (*(m_txBuffer.begin()))->GetSize ());
209  NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize );
210  }
211  else
212  {
213  // Whole segment was taken, so adjust tag
214  if (newTag.GetStatus () == LteRlcSduStatusTag::FIRST_SEGMENT)
215  {
216  newTag.SetStatus (LteRlcSduStatusTag::FULL_SDU);
217  }
218  else if (newTag.GetStatus () == LteRlcSduStatusTag::MIDDLE_SEGMENT)
219  {
220  newTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT);
221  }
222  }
223  // Segment is completely taken or
224  // the remaining segment is given back to the transmission buffer
225  firstSegment = 0;
226 
227  // Put status tag once it has been adjusted
228  newSegment->AddPacketTag (newTag);
229 
230  // Add Segment to Data field
231  dataFieldAddedSize = newSegment->GetSize ();
232  dataFieldTotalSize += dataFieldAddedSize;
233  dataField.push_back (newSegment);
234  newSegment = 0;
235 
236  // ExtensionBit (Next_Segment - 1) = 0
237  rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS);
238 
239  // no LengthIndicator for the last one
240 
241  nextSegmentSize -= dataFieldAddedSize;
242  nextSegmentId++;
243 
244  // nextSegmentSize MUST be zero (only if segment is smaller or equal to 2047)
245 
246  // (NO more segments) → exit
247  // break;
248  }
249  else if ( (nextSegmentSize - firstSegment->GetSize () <= 2) || (m_txBuffer.size () == 0) )
250  {
251  NS_LOG_LOGIC (" IF nextSegmentSize - firstSegment->GetSize () <= 2 || txBuffer.size == 0");
252  // Add txBuffer.FirstBuffer to DataField
253  dataFieldAddedSize = firstSegment->GetSize ();
254  dataFieldTotalSize += dataFieldAddedSize;
255  dataField.push_back (firstSegment);
256  firstSegment = 0;
257 
258  // ExtensionBit (Next_Segment - 1) = 0
259  rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS);
260 
261  // no LengthIndicator for the last one
262 
263  nextSegmentSize -= dataFieldAddedSize;
264  nextSegmentId++;
265 
266  NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ());
267  if (m_txBuffer.size () > 0)
268  {
269  NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin()));
270  NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
271  }
272  NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize);
273 
274  // nextSegmentSize <= 2 (only if txBuffer is not empty)
275 
276  // (NO more segments) → exit
277  // break;
278  }
279  else // (firstSegment->GetSize () < m_nextSegmentSize) && (m_txBuffer.size () > 0)
280  {
281  NS_LOG_LOGIC (" IF firstSegment < NextSegmentSize && txBuffer.size > 0");
282  // Add txBuffer.FirstBuffer to DataField
283  dataFieldAddedSize = firstSegment->GetSize ();
284  dataFieldTotalSize += dataFieldAddedSize;
285  dataField.push_back (firstSegment);
286 
287  // ExtensionBit (Next_Segment - 1) = 1
288  rlcHeader.PushExtensionBit (LteRlcHeader::E_LI_FIELDS_FOLLOWS);
289 
290  // LengthIndicator (Next_Segment) = txBuffer.FirstBuffer.length()
291  rlcHeader.PushLengthIndicator (firstSegment->GetSize ());
292 
293  nextSegmentSize -= ((nextSegmentId % 2) ? (2) : (1)) + dataFieldAddedSize;
294  nextSegmentId++;
295 
296  NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ());
297  if (m_txBuffer.size () > 0)
298  {
299  NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin()));
300  NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begin()))->GetSize ());
301  }
302  NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize);
303  NS_LOG_LOGIC (" Remove SDU from TxBuffer");
304 
305  // (more segments)
306  firstSegment = (*(m_txBuffer.begin ()))->Copy ();
307  m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize ();
308  m_txBuffer.erase (m_txBuffer.begin ());
309  NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize );
310  }
311 
312  }
313 
314  // Build RLC header
315  rlcHeader.SetSequenceNumber (m_sequenceNumber++);
316 
317  // Build RLC PDU with DataField and Header
318  std::vector< Ptr<Packet> >::iterator it;
319  it = dataField.begin ();
320 
321  uint8_t framingInfo = 0;
322 
323  // FIRST SEGMENT
324  LteRlcSduStatusTag tag;
325  (*it)->RemovePacketTag (tag);
326  if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) ||
328  {
329  framingInfo |= LteRlcHeader::FIRST_BYTE;
330  }
331  else
332  {
333  framingInfo |= LteRlcHeader::NO_FIRST_BYTE;
334  }
335  (*it)->AddPacketTag (tag);
336 
337  while (it < dataField.end ())
338  {
339  NS_LOG_LOGIC ("Adding SDU/segment to packet, length = " << (*it)->GetSize ());
340 
341  packet->AddAtEnd (*it);
342  it++;
343  }
344 
345  // LAST SEGMENT (Note: There could be only one and be the first one)
346  it--;
347  (*it)->RemovePacketTag (tag);
348  if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) ||
350  {
351  framingInfo |= LteRlcHeader::LAST_BYTE;
352  }
353  else
354  {
355  framingInfo |= LteRlcHeader::NO_LAST_BYTE;
356  }
357  (*it)->AddPacketTag (tag);
358 
359  rlcHeader.SetFramingInfo (framingInfo);
360 
361  NS_LOG_LOGIC ("RLC header: " << rlcHeader);
362  packet->AddHeader (rlcHeader);
363 
364  // Sender timestamp
365  RlcTag rlcTag (Simulator::Now ());
366  packet->AddByteTag (rlcTag);
367  m_txPdu (m_rnti, m_lcid, packet->GetSize ());
368 
369  // Send RLC PDU to MAC layer
371  params.pdu = packet;
372  params.rnti = m_rnti;
373  params.lcid = m_lcid;
374  params.layer = layer;
375 
376  m_macSapProvider->TransmitPdu (params);
377 
378  if (! m_txBuffer.empty ())
379  {
380  m_rbsTimer.Cancel ();
382  }
383 }
384 
385 void
387 {
388  NS_LOG_FUNCTION (this);
389 }
390 
391 void
393 {
394  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
395 
396  // Receiver timestamp
397  RlcTag rlcTag;
398  Time delay;
399  if (p->FindFirstMatchingByteTag (rlcTag))
400  {
401  delay = Simulator::Now() - rlcTag.GetSenderTimestamp ();
402  }
403  m_rxPdu (m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
404 
405  // 5.1.2.2 Receive operations
406 
407  // Get RLC header parameters
408  LteRlcHeader rlcHeader;
409  p->PeekHeader (rlcHeader);
410  NS_LOG_LOGIC ("RLC header: " << rlcHeader);
411  SequenceNumber10 seqNumber = rlcHeader.GetSequenceNumber ();
412 
413  // 5.1.2.2.1 General
414  // The receiving UM RLC entity shall maintain a reordering window according to state variable VR(UH) as follows:
415  // - a SN falls within the reordering window if (VR(UH) - UM_Window_Size) <= SN < VR(UH);
416  // - a SN falls outside of the reordering window otherwise.
417  // When receiving an UMD PDU from lower layer, the receiving UM RLC entity shall:
418  // - either discard the received UMD PDU or place it in the reception buffer (see sub clause 5.1.2.2.2);
419  // - if the received UMD PDU was placed in the reception buffer:
420  // - 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);
421  // When t-Reordering expires, the receiving UM RLC entity shall:
422  // - 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).
423 
424  // 5.1.2.2.2 Actions when an UMD PDU is received from lower layer
425  // When an UMD PDU with SN = x is received from lower layer, the receiving UM RLC entity shall:
426  // - if VR(UR) < x < VR(UH) and the UMD PDU with SN = x has been received before; or
427  // - if (VR(UH) - UM_Window_Size) <= x < VR(UR):
428  // - discard the received UMD PDU;
429  // - else:
430  // - place the received UMD PDU in the reception buffer.
431 
432  NS_LOG_LOGIC ("VR(UR) = " << m_vrUr);
433  NS_LOG_LOGIC ("VR(UX) = " << m_vrUx);
434  NS_LOG_LOGIC ("VR(UH) = " << m_vrUh);
435  NS_LOG_LOGIC ("SN = " << seqNumber);
436 
439  seqNumber.SetModulusBase (m_vrUh - m_windowSize);
440 
441  if ( ( (m_vrUr < seqNumber) && (seqNumber < m_vrUh) && (m_rxBuffer.count (seqNumber.GetValue ()) > 0) ) ||
442  ( ((m_vrUh - m_windowSize) <= seqNumber) && (seqNumber < m_vrUr) )
443  )
444  {
445  NS_LOG_LOGIC ("PDU discarded");
446  p = 0;
447  return;
448  }
449  else
450  {
451  NS_LOG_LOGIC ("Place PDU in the reception buffer");
452  m_rxBuffer[seqNumber.GetValue ()] = p;
453  }
454 
455 
456  // 5.1.2.2.3 Actions when an UMD PDU is placed in the reception buffer
457  // When an UMD PDU with SN = x is placed in the reception buffer, the receiving UM RLC entity shall:
458 
459  // - if x falls outside of the reordering window:
460  // - update VR(UH) to x + 1;
461  // - reassemble RLC SDUs from any UMD PDUs with SN that falls outside of the reordering window, remove
462  // RLC headers when doing so and deliver the reassembled RLC SDUs to upper layer in ascending order of the
463  // RLC SN if not delivered before;
464  // - if VR(UR) falls outside of the reordering window:
465  // - set VR(UR) to (VR(UH) - UM_Window_Size);
466 
467  if ( ! IsInsideReorderingWindow (seqNumber))
468  {
469  NS_LOG_LOGIC ("SN is outside the reordering window");
470 
471  m_vrUh = seqNumber + 1;
472  NS_LOG_LOGIC ("New VR(UH) = " << m_vrUh);
473 
475 
477  {
479  NS_LOG_LOGIC ("VR(UR) is outside the reordering window");
480  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
481  }
482  }
483 
484  // - if the reception buffer contains an UMD PDU with SN = VR(UR):
485  // - update VR(UR) to the SN of the first UMD PDU with SN > current VR(UR) that has not been received;
486  // - reassemble RLC SDUs from any UMD PDUs with SN < updated VR(UR), remove RLC headers when doing
487  // so and deliver the reassembled RLC SDUs to upper layer in ascending order of the RLC SN if not delivered
488  // before;
489 
490  if ( m_rxBuffer.count (m_vrUr.GetValue ()) > 0 )
491  {
492  NS_LOG_LOGIC ("Reception buffer contains SN = " << m_vrUr);
493 
494  std::map <uint16_t, Ptr<Packet> >::iterator it;
495  uint16_t newVrUr;
496  SequenceNumber10 oldVrUr = m_vrUr;
497 
498  it = m_rxBuffer.find (m_vrUr.GetValue ());
499  newVrUr = (it->first) + 1;
500  while ( m_rxBuffer.count (newVrUr) > 0 )
501  {
502  newVrUr++;
503  }
504  m_vrUr = newVrUr;
505  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
506 
507  ReassembleSnInterval (oldVrUr, m_vrUr);
508  }
509 
510  // m_vrUh can change previously, set new modulus base
511  // for the t-Reordering timer-related comparisons
515 
516  // - if t-Reordering is running:
517  // - if VR(UX) <= VR(UR); or
518  // - if VR(UX) falls outside of the reordering window and VR(UX) is not equal to VR(UH)::
519  // - stop and reset t-Reordering;
520  if ( m_reorderingTimer.IsRunning () )
521  {
522  NS_LOG_LOGIC ("Reordering timer is running");
523 
524  if ( (m_vrUx <= m_vrUr) ||
525  ((! IsInsideReorderingWindow (m_vrUx)) && (m_vrUx != m_vrUh)) )
526  {
527  NS_LOG_LOGIC ("Stop reordering timer");
529  }
530  }
531 
532  // - if t-Reordering is not running (includes the case when t-Reordering is stopped due to actions above):
533  // - if VR(UH) > VR(UR):
534  // - start t-Reordering;
535  // - set VR(UX) to VR(UH).
536  if ( ! m_reorderingTimer.IsRunning () )
537  {
538  NS_LOG_LOGIC ("Reordering timer is not running");
539 
540  if ( m_vrUh > m_vrUr )
541  {
542  NS_LOG_LOGIC ("VR(UH) > VR(UR)");
543  NS_LOG_LOGIC ("Start reordering timer");
546  m_vrUx = m_vrUh;
547  NS_LOG_LOGIC ("New VR(UX) = " << m_vrUx);
548  }
549  }
550 
551 }
552 
553 
554 void
556 {
557  NS_LOG_FUNCTION (this);
558 
560 }
561 
562 
563 bool
565 {
566  NS_LOG_FUNCTION (this << seqNumber);
567  NS_LOG_LOGIC ("Reordering Window: " <<
568  m_vrUh << " - " << m_windowSize << " <= " << seqNumber << " < " << m_vrUh);
569 
571  seqNumber.SetModulusBase (m_vrUh - m_windowSize);
572 
573  if ( ((m_vrUh - m_windowSize) <= seqNumber) && (seqNumber < m_vrUh))
574  {
575  NS_LOG_LOGIC (seqNumber << " is INSIDE the reordering window");
576  return true;
577  }
578  else
579  {
580  NS_LOG_LOGIC (seqNumber << " is OUTSIDE the reordering window");
581  return false;
582  }
583 }
584 
585 
586 void
588 {
589  LteRlcHeader rlcHeader;
590  packet->RemoveHeader (rlcHeader);
591  uint8_t framingInfo = rlcHeader.GetFramingInfo ();
592  SequenceNumber10 currSeqNumber = rlcHeader.GetSequenceNumber ();
593  bool expectedSnLost;
594 
595  if ( currSeqNumber != m_expectedSeqNumber )
596  {
597  expectedSnLost = true;
598  NS_LOG_LOGIC ("There are losses. Expected SN = " << m_expectedSeqNumber << ". Current SN = " << currSeqNumber);
599  m_expectedSeqNumber = currSeqNumber + 1;
600  }
601  else
602  {
603  expectedSnLost = false;
604  NS_LOG_LOGIC ("No losses. Expected SN = " << m_expectedSeqNumber << ". Current SN = " << currSeqNumber);
606  }
607 
608  // Build list of SDUs
609  uint8_t extensionBit;
610  uint16_t lengthIndicator;
611  do
612  {
613  extensionBit = rlcHeader.PopExtensionBit ();
614  NS_LOG_LOGIC ("E = " << (uint16_t)extensionBit);
615 
616  if ( extensionBit == 0 )
617  {
618  m_sdusBuffer.push_back (packet);
619  }
620  else // extensionBit == 1
621  {
622  lengthIndicator = rlcHeader.PopLengthIndicator ();
623  NS_LOG_LOGIC ("LI = " << lengthIndicator);
624 
625  // Check if there is enough data in the packet
626  if ( lengthIndicator >= packet->GetSize () )
627  {
628  NS_LOG_LOGIC ("INTERNAL ERROR: Not enough data in the packet (" << packet->GetSize () << "). Needed LI=" << lengthIndicator);
629  }
630 
631  // Split packet in two fragments
632  Ptr<Packet> data_field = packet->CreateFragment (0, lengthIndicator);
633  packet->RemoveAtStart (lengthIndicator);
634 
635  m_sdusBuffer.push_back (data_field);
636  }
637  }
638  while ( extensionBit == 1 );
639 
640  std::list < Ptr<Packet> >::iterator it;
641 
642  // Current reassembling state
643  if (m_reassemblingState == WAITING_S0_FULL) NS_LOG_LOGIC ("Reassembling State = 'WAITING_S0_FULL'");
644  else if (m_reassemblingState == WAITING_SI_SF) NS_LOG_LOGIC ("Reassembling State = 'WAITING_SI_SF'");
645  else NS_LOG_LOGIC ("Reassembling State = Unknown state");
646 
647  // Received framing Info
648  NS_LOG_LOGIC ("Framing Info = " << (uint16_t)framingInfo);
649 
650  // Reassemble the list of SDUs (when there is no losses)
651  if (!expectedSnLost)
652  {
653  switch (m_reassemblingState)
654  {
655  case WAITING_S0_FULL:
656  switch (framingInfo)
657  {
660 
664  for ( it = m_sdusBuffer.begin () ; it != m_sdusBuffer.end () ; it++ )
665  {
667  }
668  m_sdusBuffer.clear ();
669  break;
670 
673 
677  while ( m_sdusBuffer.size () > 1 )
678  {
680  m_sdusBuffer.pop_front ();
681  }
682 
686  m_keepS0 = m_sdusBuffer.front ();
687  m_sdusBuffer.pop_front ();
688  break;
689 
692 
696  m_sdusBuffer.pop_front ();
697 
701  while ( ! m_sdusBuffer.empty () )
702  {
704  m_sdusBuffer.pop_front ();
705  }
706  break;
707 
709  if ( m_sdusBuffer.size () == 1 )
710  {
712  }
713  else
714  {
716  }
717 
721  m_sdusBuffer.pop_front ();
722 
723  if ( m_sdusBuffer.size () > 0 )
724  {
728  while ( m_sdusBuffer.size () > 1 )
729  {
731  m_sdusBuffer.pop_front ();
732  }
733 
737  m_keepS0 = m_sdusBuffer.front ();
738  m_sdusBuffer.pop_front ();
739  }
740  break;
741 
742  default:
746  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
747  break;
748  }
749  break;
750 
751  case WAITING_SI_SF:
752  switch (framingInfo)
753  {
756 
760  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
761  m_sdusBuffer.pop_front ();
763 
767  while ( ! m_sdusBuffer.empty () )
768  {
770  m_sdusBuffer.pop_front ();
771  }
772  break;
773 
776 
780  if ( m_sdusBuffer.size () == 1 )
781  {
782  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
783  m_sdusBuffer.pop_front ();
784  }
785  else // m_sdusBuffer.size () > 1
786  {
790  m_keepS0->AddAtEnd (m_sdusBuffer.front ());
791  m_sdusBuffer.pop_front ();
793 
797  while ( m_sdusBuffer.size () > 1 )
798  {
800  m_sdusBuffer.pop_front ();
801  }
802 
806  m_keepS0 = m_sdusBuffer.front ();
807  m_sdusBuffer.pop_front ();
808  }
809  break;
810 
813  default:
817  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
818  break;
819  }
820  break;
821 
822  default:
823  NS_LOG_LOGIC ("INTERNAL ERROR: Wrong reassembling state = " << (uint32_t) m_reassemblingState);
824  break;
825  }
826  }
827  else // Reassemble the list of SDUs (when there are losses, i.e. the received SN is not the expected one)
828  {
829  switch (m_reassemblingState)
830  {
831  case WAITING_S0_FULL:
832  switch (framingInfo)
833  {
836 
840  for ( it = m_sdusBuffer.begin () ; it != m_sdusBuffer.end () ; it++ )
841  {
843  }
844  m_sdusBuffer.clear ();
845  break;
846 
849 
853  while ( m_sdusBuffer.size () > 1 )
854  {
856  m_sdusBuffer.pop_front ();
857  }
858 
862  m_keepS0 = m_sdusBuffer.front ();
863  m_sdusBuffer.pop_front ();
864  break;
865 
868 
872  m_sdusBuffer.pop_front ();
873 
877  while ( ! m_sdusBuffer.empty () )
878  {
880  m_sdusBuffer.pop_front ();
881  }
882  break;
883 
885  if ( m_sdusBuffer.size () == 1 )
886  {
888  }
889  else
890  {
892  }
893 
897  m_sdusBuffer.pop_front ();
898 
899  if ( m_sdusBuffer.size () > 0 )
900  {
904  while ( m_sdusBuffer.size () > 1 )
905  {
907  m_sdusBuffer.pop_front ();
908  }
909 
913  m_keepS0 = m_sdusBuffer.front ();
914  m_sdusBuffer.pop_front ();
915  }
916  break;
917 
918  default:
922  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
923  break;
924  }
925  break;
926 
927  case WAITING_SI_SF:
928  switch (framingInfo)
929  {
932 
936  m_keepS0 = 0;
937 
941  while ( ! m_sdusBuffer.empty () )
942  {
944  m_sdusBuffer.pop_front ();
945  }
946  break;
947 
950 
954  m_keepS0 = 0;
955 
959  while ( m_sdusBuffer.size () > 1 )
960  {
962  m_sdusBuffer.pop_front ();
963  }
964 
968  m_keepS0 = m_sdusBuffer.front ();
969  m_sdusBuffer.pop_front ();
970 
971  break;
972 
975 
979  m_keepS0 = 0;
980 
984  m_sdusBuffer.pop_front ();
985 
989  while ( ! m_sdusBuffer.empty () )
990  {
992  m_sdusBuffer.pop_front ();
993  }
994  break;
995 
997  if ( m_sdusBuffer.size () == 1 )
998  {
1000  }
1001  else
1002  {
1004  }
1005 
1009  m_keepS0 = 0;
1010 
1014  m_sdusBuffer.pop_front ();
1015 
1016  if ( m_sdusBuffer.size () > 0 )
1017  {
1021  while ( m_sdusBuffer.size () > 1 )
1022  {
1024  m_sdusBuffer.pop_front ();
1025  }
1026 
1030  m_keepS0 = m_sdusBuffer.front ();
1031  m_sdusBuffer.pop_front ();
1032  }
1033  break;
1034 
1035  default:
1039  NS_LOG_LOGIC ("INTERNAL ERROR: Transition not possible. FI = " << (uint32_t) framingInfo);
1040  break;
1041  }
1042  break;
1043 
1044  default:
1045  NS_LOG_LOGIC ("INTERNAL ERROR: Wrong reassembling state = " << (uint32_t) m_reassemblingState);
1046  break;
1047  }
1048  }
1049 
1050 }
1051 
1052 
1053 void
1055 {
1056  NS_LOG_LOGIC ("Reassemble Outside Window");
1057 
1058  std::map <uint16_t, Ptr<Packet> >::iterator it;
1059  it = m_rxBuffer.begin ();
1060 
1061  while ( (it != m_rxBuffer.end ()) && ! IsInsideReorderingWindow (SequenceNumber10 (it->first)) )
1062  {
1063  NS_LOG_LOGIC ("SN = " << it->first);
1064 
1065  // Reassemble RLC SDUs and deliver the PDCP PDU to upper layer
1066  ReassembleAndDeliver (it->second);
1067 
1068  std::map <uint16_t, Ptr<Packet> >::iterator it_tmp = it;
1069  ++it;
1070  m_rxBuffer.erase (it_tmp);
1071  }
1072 
1073  if (it != m_rxBuffer.end ())
1074  {
1075  NS_LOG_LOGIC ("(SN = " << it->first << ") is inside the reordering window");
1076  }
1077 }
1078 
1079 void
1081 {
1082  NS_LOG_LOGIC ("Reassemble SN between " << lowSeqNumber << " and " << highSeqNumber);
1083 
1084  std::map <uint16_t, Ptr<Packet> >::iterator it;
1085 
1086  SequenceNumber10 reassembleSn = lowSeqNumber;
1087  NS_LOG_LOGIC ("reassembleSN = " << reassembleSn);
1088  NS_LOG_LOGIC ("highSeqNumber = " << highSeqNumber);
1089  while (reassembleSn < highSeqNumber)
1090  {
1091  NS_LOG_LOGIC ("reassembleSn < highSeqNumber");
1092  it = m_rxBuffer.find (reassembleSn.GetValue ());
1093  NS_LOG_LOGIC ("it->first = " << it->first);
1094  NS_LOG_LOGIC ("it->second = " << it->second);
1095  if (it != m_rxBuffer.end () )
1096  {
1097  NS_LOG_LOGIC ("SN = " << it->first);
1098 
1099  // Reassemble RLC SDUs and deliver the PDCP PDU to upper layer
1100  ReassembleAndDeliver (it->second);
1101 
1102  m_rxBuffer.erase (it);
1103  }
1104 
1105  reassembleSn++;
1106  }
1107 }
1108 
1109 
1110 void
1112 {
1113  Time holDelay (0);
1114  uint32_t queueSize = 0;
1115 
1116  if (! m_txBuffer.empty ())
1117  {
1118  RlcTag holTimeTag;
1119  m_txBuffer.front ()->PeekPacketTag (holTimeTag);
1120  holDelay = Simulator::Now () - holTimeTag.GetSenderTimestamp ();
1121 
1122  queueSize = m_txBufferSize + 2 * m_txBuffer.size (); // Data in tx queue + estimated headers size
1123  }
1124 
1126  r.rnti = m_rnti;
1127  r.lcid = m_lcid;
1128  r.txQueueSize = queueSize;
1129  r.txQueueHolDelay = holDelay.GetMilliSeconds () ;
1130  r.retxQueueSize = 0;
1131  r.retxQueueHolDelay = 0;
1132  r.statusPduSize = 0;
1133 
1134  NS_LOG_LOGIC ("Send ReportBufferStatus = " << r.txQueueSize << ", " << r.txQueueHolDelay );
1136 }
1137 
1138 
1139 void
1141 {
1142  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid);
1143  NS_LOG_LOGIC ("Reordering timer has expired");
1144 
1145  // 5.1.2.2.4 Actions when t-Reordering expires
1146  // When t-Reordering expires, the receiving UM RLC entity shall:
1147  // - update VR(UR) to the SN of the first UMD PDU with SN >= VR(UX) that has not been received;
1148  // - reassemble RLC SDUs from any UMD PDUs with SN < updated VR(UR), remove RLC headers when doing so
1149  // and deliver the reassembled RLC SDUs to upper layer in ascending order of the RLC SN if not delivered before;
1150  // - if VR(UH) > VR(UR):
1151  // - start t-Reordering;
1152  // - set VR(UX) to VR(UH).
1153 
1154  std::map <uint16_t, Ptr<Packet> >::iterator it;
1155  SequenceNumber10 newVrUr = m_vrUx;
1156 
1157  while ( (it = m_rxBuffer.find (newVrUr.GetValue ())) != m_rxBuffer.end () )
1158  {
1159  newVrUr++;
1160  }
1161  SequenceNumber10 oldVrUr = m_vrUr;
1162  m_vrUr = newVrUr;
1163  NS_LOG_LOGIC ("New VR(UR) = " << m_vrUr);
1164 
1165  ReassembleSnInterval (oldVrUr, m_vrUr);
1166 
1167  if ( m_vrUh > m_vrUr)
1168  {
1169  NS_LOG_LOGIC ("Start reordering timer");
1172  m_vrUx = m_vrUh;
1173  NS_LOG_LOGIC ("New VR(UX) = " << m_vrUx);
1174  }
1175 }
1176 
1177 
1178 void
1180 {
1181  NS_LOG_LOGIC ("RBS Timer expires");
1182 
1183  if (! m_txBuffer.empty ())
1184  {
1187  }
1188 }
1189 
1190 } // namespace ns3