OLD | NEW |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) | 3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 /** Report Buffer Status */ | 116 /** Report Buffer Status */ |
117 DoReportBufferStatus (); | 117 DoReportBufferStatus (); |
118 m_rbsTimer.Cancel (); | 118 m_rbsTimer.Cancel (); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 /** | 122 /** |
123 * MAC SAP | 123 * MAC SAP |
124 */ | 124 */ |
125 | 125 /* |
126 void | 126 void |
127 LteRlcUm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId) | 127 LteRlcUm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId) |
128 { | 128 { |
129 NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes); | 129 NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes); |
130 | 130 |
131 if (bytes <= 2) | 131 if (bytes <= 2) |
132 { | 132 { |
133 // Stingy MAC: Header fix part is 2 bytes, we need more bytes for the data | 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); | 134 NS_LOG_LOGIC ("TX opportunity too small = " << bytes); |
135 return; | 135 return; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 params.harqProcessId = harqId; | 384 params.harqProcessId = harqId; |
385 | 385 |
386 m_macSapProvider->TransmitPdu (params); | 386 m_macSapProvider->TransmitPdu (params); |
387 | 387 |
388 if (! m_txBuffer.empty ()) | 388 if (! m_txBuffer.empty ()) |
389 { | 389 { |
390 m_rbsTimer.Cancel (); | 390 m_rbsTimer.Cancel (); |
391 m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsT
imer, this); | 391 m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsT
imer, this); |
392 } | 392 } |
393 } | 393 } |
| 394 */ |
| 395 |
| 396 void |
| 397 LteRlcUm::DoNotifyTxOpportunity (uint32_t bytes, uint8_t layer, uint8_t harqId,
uint8_t componentCarrierId, uint16_t rnti, uint8_t lcid) |
| 398 { |
| 399 NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << bytes); |
| 400 |
| 401 if (bytes <= 2) |
| 402 { |
| 403 // Stingy MAC: Header fix part is 2 bytes, we need more bytes for the data |
| 404 NS_LOG_LOGIC ("TX opportunity too small = " << bytes); |
| 405 return; |
| 406 } |
| 407 |
| 408 Ptr<Packet> packet = Create<Packet> (); |
| 409 LteRlcHeader rlcHeader; |
| 410 |
| 411 // Build Data field |
| 412 uint32_t nextSegmentSize = bytes - 2; |
| 413 uint32_t nextSegmentId = 1; |
| 414 uint32_t dataFieldTotalSize = 0; |
| 415 uint32_t dataFieldAddedSize = 0; |
| 416 std::vector < Ptr<Packet> > dataField; |
| 417 |
| 418 // Remove the first packet from the transmission buffer. |
| 419 // If only a segment of the packet is taken, then the remaining is given back
later |
| 420 if ( m_txBuffer.size () == 0 ) |
| 421 { |
| 422 NS_LOG_LOGIC ("No data pending"); |
| 423 return; |
| 424 } |
| 425 |
| 426 NS_LOG_LOGIC ("SDUs in TxBuffer = " << m_txBuffer.size ()); |
| 427 NS_LOG_LOGIC ("First SDU buffer = " << *(m_txBuffer.begin())); |
| 428 NS_LOG_LOGIC ("First SDU size = " << (*(m_txBuffer.begin()))->GetSize ()); |
| 429 NS_LOG_LOGIC ("Next segment size = " << nextSegmentSize); |
| 430 NS_LOG_LOGIC ("Remove SDU from TxBuffer"); |
| 431 Ptr<Packet> firstSegment = (*(m_txBuffer.begin ()))->Copy (); |
| 432 m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize (); |
| 433 NS_LOG_LOGIC ("txBufferSize = " << m_txBufferSize ); |
| 434 m_txBuffer.erase (m_txBuffer.begin ()); |
| 435 |
| 436 while ( firstSegment && (firstSegment->GetSize () > 0) && (nextSegmentSize > 0
) ) |
| 437 { |
| 438 NS_LOG_LOGIC ("WHILE ( firstSegment && firstSegment->GetSize > 0 && nextSe
gmentSize > 0 )"); |
| 439 NS_LOG_LOGIC (" firstSegment size = " << firstSegment->GetSize ()); |
| 440 NS_LOG_LOGIC (" nextSegmentSize = " << nextSegmentSize); |
| 441 if ( (firstSegment->GetSize () > nextSegmentSize) || |
| 442 // Segment larger than 2047 octets can only be mapped to the end of t
he Data field |
| 443 (firstSegment->GetSize () > 2047) |
| 444 ) |
| 445 { |
| 446 // Take the minimum size, due to the 2047-bytes 3GPP exception |
| 447 // This exception is due to the length of the LI field (just 11 bits) |
| 448 uint32_t currSegmentSize = std::min (firstSegment->GetSize (), nextSeg
mentSize); |
| 449 |
| 450 NS_LOG_LOGIC (" IF ( firstSegment > nextSegmentSize ||"); |
| 451 NS_LOG_LOGIC (" firstSegment > 2047 )"); |
| 452 |
| 453 // Segment txBuffer.FirstBuffer and |
| 454 // Give back the remaining segment to the transmission buffer |
| 455 Ptr<Packet> newSegment = firstSegment->CreateFragment (0, currSegmentS
ize); |
| 456 NS_LOG_LOGIC (" newSegment size = " << newSegment->GetSize ()); |
| 457 |
| 458 // Status tag of the new and remaining segments |
| 459 // Note: This is the only place where a PDU is segmented and |
| 460 // therefore its status can change |
| 461 LteRlcSduStatusTag oldTag, newTag; |
| 462 firstSegment->RemovePacketTag (oldTag); |
| 463 newSegment->RemovePacketTag (newTag); |
| 464 if (oldTag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) |
| 465 { |
| 466 newTag.SetStatus (LteRlcSduStatusTag::FIRST_SEGMENT); |
| 467 oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT); |
| 468 } |
| 469 else if (oldTag.GetStatus () == LteRlcSduStatusTag::LAST_SEGMENT) |
| 470 { |
| 471 newTag.SetStatus (LteRlcSduStatusTag::MIDDLE_SEGMENT); |
| 472 //oldTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT); |
| 473 } |
| 474 |
| 475 // Give back the remaining segment to the transmission buffer |
| 476 firstSegment->RemoveAtStart (currSegmentSize); |
| 477 NS_LOG_LOGIC (" firstSegment size (after RemoveAtStart) = " << firs
tSegment->GetSize ()); |
| 478 if (firstSegment->GetSize () > 0) |
| 479 { |
| 480 firstSegment->AddPacketTag (oldTag); |
| 481 |
| 482 m_txBuffer.insert (m_txBuffer.begin (), firstSegment); |
| 483 m_txBufferSize += (*(m_txBuffer.begin()))->GetSize (); |
| 484 |
| 485 NS_LOG_LOGIC (" TX buffer: Give back the remaining segment"); |
| 486 NS_LOG_LOGIC (" TX buffers = " << m_txBuffer.size ()); |
| 487 NS_LOG_LOGIC (" Front buffer size = " << (*(m_txBuffer.begin())
)->GetSize ()); |
| 488 NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize ); |
| 489 } |
| 490 else |
| 491 { |
| 492 // Whole segment was taken, so adjust tag |
| 493 if (newTag.GetStatus () == LteRlcSduStatusTag::FIRST_SEGMENT) |
| 494 { |
| 495 newTag.SetStatus (LteRlcSduStatusTag::FULL_SDU); |
| 496 } |
| 497 else if (newTag.GetStatus () == LteRlcSduStatusTag::MIDDLE_SEGMENT
) |
| 498 { |
| 499 newTag.SetStatus (LteRlcSduStatusTag::LAST_SEGMENT); |
| 500 } |
| 501 } |
| 502 // Segment is completely taken or |
| 503 // the remaining segment is given back to the transmission buffer |
| 504 firstSegment = 0; |
| 505 |
| 506 // Put status tag once it has been adjusted |
| 507 newSegment->AddPacketTag (newTag); |
| 508 |
| 509 // Add Segment to Data field |
| 510 dataFieldAddedSize = newSegment->GetSize (); |
| 511 dataFieldTotalSize += dataFieldAddedSize; |
| 512 dataField.push_back (newSegment); |
| 513 newSegment = 0; |
| 514 |
| 515 // ExtensionBit (Next_Segment - 1) = 0 |
| 516 rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS); |
| 517 |
| 518 // no LengthIndicator for the last one |
| 519 |
| 520 nextSegmentSize -= dataFieldAddedSize; |
| 521 nextSegmentId++; |
| 522 |
| 523 // nextSegmentSize MUST be zero (only if segment is smaller or equal t
o 2047) |
| 524 |
| 525 // (NO more segments) → exit |
| 526 // break; |
| 527 } |
| 528 else if ( (nextSegmentSize - firstSegment->GetSize () <= 2) || (m_txBuffer
.size () == 0) ) |
| 529 { |
| 530 NS_LOG_LOGIC (" IF nextSegmentSize - firstSegment->GetSize () <= 2
|| txBuffer.size == 0"); |
| 531 // Add txBuffer.FirstBuffer to DataField |
| 532 dataFieldAddedSize = firstSegment->GetSize (); |
| 533 dataFieldTotalSize += dataFieldAddedSize; |
| 534 dataField.push_back (firstSegment); |
| 535 firstSegment = 0; |
| 536 |
| 537 // ExtensionBit (Next_Segment - 1) = 0 |
| 538 rlcHeader.PushExtensionBit (LteRlcHeader::DATA_FIELD_FOLLOWS); |
| 539 |
| 540 // no LengthIndicator for the last one |
| 541 |
| 542 nextSegmentSize -= dataFieldAddedSize; |
| 543 nextSegmentId++; |
| 544 |
| 545 NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ()); |
| 546 if (m_txBuffer.size () > 0) |
| 547 { |
| 548 NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin
())); |
| 549 NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begi
n()))->GetSize ()); |
| 550 } |
| 551 NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize); |
| 552 |
| 553 // nextSegmentSize <= 2 (only if txBuffer is not empty) |
| 554 |
| 555 // (NO more segments) → exit |
| 556 // break; |
| 557 } |
| 558 else // (firstSegment->GetSize () < m_nextSegmentSize) && (m_txBuffer.size
() > 0) |
| 559 { |
| 560 NS_LOG_LOGIC (" IF firstSegment < NextSegmentSize && txBuffer.size
> 0"); |
| 561 // Add txBuffer.FirstBuffer to DataField |
| 562 dataFieldAddedSize = firstSegment->GetSize (); |
| 563 dataFieldTotalSize += dataFieldAddedSize; |
| 564 dataField.push_back (firstSegment); |
| 565 |
| 566 // ExtensionBit (Next_Segment - 1) = 1 |
| 567 rlcHeader.PushExtensionBit (LteRlcHeader::E_LI_FIELDS_FOLLOWS); |
| 568 |
| 569 // LengthIndicator (Next_Segment) = txBuffer.FirstBuffer.length() |
| 570 rlcHeader.PushLengthIndicator (firstSegment->GetSize ()); |
| 571 |
| 572 nextSegmentSize -= ((nextSegmentId % 2) ? (2) : (1)) + dataFieldAddedS
ize; |
| 573 nextSegmentId++; |
| 574 |
| 575 NS_LOG_LOGIC (" SDUs in TxBuffer = " << m_txBuffer.size ()); |
| 576 if (m_txBuffer.size () > 0) |
| 577 { |
| 578 NS_LOG_LOGIC (" First SDU buffer = " << *(m_txBuffer.begin
())); |
| 579 NS_LOG_LOGIC (" First SDU size = " << (*(m_txBuffer.begi
n()))->GetSize ()); |
| 580 } |
| 581 NS_LOG_LOGIC (" Next segment size = " << nextSegmentSize); |
| 582 NS_LOG_LOGIC (" Remove SDU from TxBuffer"); |
| 583 |
| 584 // (more segments) |
| 585 firstSegment = (*(m_txBuffer.begin ()))->Copy (); |
| 586 m_txBufferSize -= (*(m_txBuffer.begin()))->GetSize (); |
| 587 m_txBuffer.erase (m_txBuffer.begin ()); |
| 588 NS_LOG_LOGIC (" txBufferSize = " << m_txBufferSize ); |
| 589 } |
| 590 |
| 591 } |
| 592 |
| 593 // Build RLC header |
| 594 rlcHeader.SetSequenceNumber (m_sequenceNumber++); |
| 595 |
| 596 // Build RLC PDU with DataField and Header |
| 597 std::vector< Ptr<Packet> >::iterator it; |
| 598 it = dataField.begin (); |
| 599 |
| 600 uint8_t framingInfo = 0; |
| 601 |
| 602 // FIRST SEGMENT |
| 603 LteRlcSduStatusTag tag; |
| 604 (*it)->RemovePacketTag (tag); |
| 605 if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) || |
| 606 (tag.GetStatus () == LteRlcSduStatusTag::FIRST_SEGMENT) ) |
| 607 { |
| 608 framingInfo |= LteRlcHeader::FIRST_BYTE; |
| 609 } |
| 610 else |
| 611 { |
| 612 framingInfo |= LteRlcHeader::NO_FIRST_BYTE; |
| 613 } |
| 614 (*it)->AddPacketTag (tag); |
| 615 |
| 616 while (it < dataField.end ()) |
| 617 { |
| 618 NS_LOG_LOGIC ("Adding SDU/segment to packet, length = " << (*it)->GetSize
()); |
| 619 |
| 620 packet->AddAtEnd (*it); |
| 621 it++; |
| 622 } |
| 623 |
| 624 // LAST SEGMENT (Note: There could be only one and be the first one) |
| 625 it--; |
| 626 (*it)->RemovePacketTag (tag); |
| 627 if ( (tag.GetStatus () == LteRlcSduStatusTag::FULL_SDU) || |
| 628 (tag.GetStatus () == LteRlcSduStatusTag::LAST_SEGMENT) ) |
| 629 { |
| 630 framingInfo |= LteRlcHeader::LAST_BYTE; |
| 631 } |
| 632 else |
| 633 { |
| 634 framingInfo |= LteRlcHeader::NO_LAST_BYTE; |
| 635 } |
| 636 (*it)->AddPacketTag (tag); |
| 637 |
| 638 rlcHeader.SetFramingInfo (framingInfo); |
| 639 |
| 640 NS_LOG_LOGIC ("RLC header: " << rlcHeader); |
| 641 packet->AddHeader (rlcHeader); |
| 642 |
| 643 // Sender timestamp |
| 644 RlcTag rlcTag (Simulator::Now ()); |
| 645 packet->AddByteTag (rlcTag); |
| 646 m_txPdu (m_rnti, m_lcid, packet->GetSize ()); |
| 647 |
| 648 // Send RLC PDU to MAC layer |
| 649 LteMacSapProvider::TransmitPduParameters params; |
| 650 params.pdu = packet; |
| 651 params.rnti = m_rnti; |
| 652 params.lcid = m_lcid; |
| 653 params.layer = layer; |
| 654 params.harqProcessId = harqId; |
| 655 params.componentCarrierId = componentCarrierId; |
| 656 |
| 657 m_macSapProvider->TransmitPdu (params); |
| 658 |
| 659 if (! m_txBuffer.empty ()) |
| 660 { |
| 661 m_rbsTimer.Cancel (); |
| 662 m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsT
imer, this); |
| 663 } |
| 664 } |
394 | 665 |
395 void | 666 void |
396 LteRlcUm::DoNotifyHarqDeliveryFailure () | 667 LteRlcUm::DoNotifyHarqDeliveryFailure () |
397 { | 668 { |
398 NS_LOG_FUNCTION (this); | 669 NS_LOG_FUNCTION (this); |
399 } | 670 } |
400 | 671 |
401 void | 672 void |
402 LteRlcUm::DoReceivePdu (Ptr<Packet> p) | 673 LteRlcUm::DoReceivePdu (Ptr<Packet> p, uint16_t rnti, uint8_t lcid) |
403 { | 674 { |
404 NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ()); | 675 NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ()); |
405 | 676 |
406 // Receiver timestamp | 677 // Receiver timestamp |
407 RlcTag rlcTag; | 678 RlcTag rlcTag; |
408 Time delay; | 679 Time delay; |
409 if (p->FindFirstMatchingByteTag (rlcTag)) | 680 if (p->FindFirstMatchingByteTag (rlcTag)) |
410 { | 681 { |
411 delay = Simulator::Now() - rlcTag.GetSenderTimestamp (); | 682 delay = Simulator::Now() - rlcTag.GetSenderTimestamp (); |
412 } | 683 } |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 NS_LOG_LOGIC ("RBS Timer expires"); | 1453 NS_LOG_LOGIC ("RBS Timer expires"); |
1183 | 1454 |
1184 if (! m_txBuffer.empty ()) | 1455 if (! m_txBuffer.empty ()) |
1185 { | 1456 { |
1186 DoReportBufferStatus (); | 1457 DoReportBufferStatus (); |
1187 m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsT
imer, this); | 1458 m_rbsTimer = Simulator::Schedule (MilliSeconds (10), &LteRlcUm::ExpireRbsT
imer, this); |
1188 } | 1459 } |
1189 } | 1460 } |
1190 | 1461 |
1191 } // namespace ns3 | 1462 } // namespace ns3 |
OLD | NEW |