28#include "ns3/simulator.h"
94 .AddAttribute(
"PollRetransmitTimer",
95 "Value of the t-PollRetransmit timer (See section 7.3 of 3GPP TS 36.322)",
99 .AddAttribute(
"ReorderingTimer",
100 "Value of the t-Reordering timer (See section 7.3 of 3GPP TS 36.322)",
104 .AddAttribute(
"StatusProhibitTimer",
105 "Value of the t-StatusProhibit timer (See section 7.3 of 3GPP TS 36.322)",
110 "ReportBufferStatusTimer",
111 "How much to wait to issue a new Report Buffer Status since the last time "
112 "a new SDU was received",
116 .AddAttribute(
"TxOpportunityForRetxAlwaysBigEnough",
117 "If true, always pretend that the size of a TxOpportunity is big enough "
118 "for retransmission. If false (default and realistic behavior), no retx "
119 "is performed unless the corresponding TxOpportunity is big enough.",
123 .AddAttribute(
"MaxTxBufferSize",
124 "Maximum Size of the Transmission Buffer (in Bytes). If zero is "
125 "configured, the buffer is unlimited.",
128 MakeUintegerChecker<uint32_t>());
170 p->AddPacketTag(tag);
203 if (txOpParams.
bytes < 4)
209 "TxOpportunity (size = "
210 << txOpParams.
bytes <<
") too small.\n"
211 <<
"Your MAC scheduler is assigned too few resource blocks.");
221 <<
") too small for the STATUS PDU (size = "
224 "TxOpportunity (size = "
225 << txOpParams.
bytes <<
") too small for the STATUS PDU (size = "
227 <<
"Your MAC scheduler is assigned too few resource blocks.");
241 std::map<uint16_t, PduBuffer>::iterator pduIt;
251 if (pduIt ==
m_rxonBuffer.end() || (!(pduIt->second.m_pduComplete)))
262 while ((sn <
m_vrMs) && (pduIt !=
m_rxonBuffer.end()) && (pduIt->second.m_pduComplete))
271 "first SN not reported as missing = " << sn <<
", VR(MS) = " <<
m_vrMs);
275 packet->AddHeader(rlcAmHeader);
287 params.layer = txOpParams.
layer;
288 params.harqProcessId = txOpParams.
harqId;
303 NS_LOG_LOGIC(
"Sending data from Retransmission Buffer");
309 uint16_t seqNumberValue = sn.
GetValue();
317 if ((packet->GetSize() <= txOpParams.
bytes) ||
322 packet->RemoveHeader(rlcAmHeader);
330 <<
" packet->GetSize ()=" << packet->GetSize());
365 packet->AddHeader(rlcAmHeader);
381 params.layer = txOpParams.
layer;
382 params.harqProcessId = txOpParams.
harqId;
389 NS_LOG_INFO(
"Incr RETX_COUNT for SN = " << seqNumberValue);
392 NS_LOG_INFO(
"Max RETX_COUNT for SN = " << seqNumberValue);
395 NS_LOG_INFO(
"Move SN = " << seqNumberValue <<
" back to txedBuffer");
417 <<
") too small for retransmission of the packet (size = "
418 << packet->GetSize() <<
")");
424 NS_ASSERT_MSG(
false,
"m_retxBufferSize > 0, but no PDU considered for retx found");
428 if (txOpParams.
bytes < 7)
432 <<
") too small for DATA PDU");
434 "TxOpportunity (size = "
435 << txOpParams.
bytes <<
") too small for DATA PDU\n"
436 <<
"Your MAC scheduler is assigned too few resource blocks.");
443 NS_LOG_INFO(
"cannot transmit new RLC PDU due to window stalling");
469 std::vector<Ptr<Packet>> dataField;
482 NS_LOG_LOGIC(
"Next segment size = " << nextSegmentSize);
490 while (firstSegment && (firstSegment->GetSize() > 0) && (nextSegmentSize > 0))
492 NS_LOG_LOGIC(
"WHILE ( firstSegment && firstSegment->GetSize > 0 && nextSegmentSize > 0 )");
493 NS_LOG_LOGIC(
" firstSegment size = " << firstSegment->GetSize());
495 if ((firstSegment->GetSize() > nextSegmentSize) ||
497 (firstSegment->GetSize() > 2047))
501 uint32_t currSegmentSize = std::min(firstSegment->GetSize(), nextSegmentSize);
503 NS_LOG_LOGIC(
" IF ( firstSegment > nextSegmentSize ||");
508 Ptr<Packet> newSegment = firstSegment->CreateFragment(0, currSegmentSize);
509 NS_LOG_LOGIC(
" newSegment size = " << newSegment->GetSize());
516 firstSegment->RemovePacketTag(oldTag);
517 newSegment->RemovePacketTag(newTag);
530 firstSegment->RemoveAtStart(currSegmentSize);
532 " firstSegment size (after RemoveAtStart) = " << firstSegment->GetSize());
533 if (firstSegment->GetSize() > 0)
535 firstSegment->AddPacketTag(oldTag);
540 NS_LOG_LOGIC(
" Txon buffer: Give back the remaining segment");
559 firstSegment =
nullptr;
562 newSegment->AddPacketTag(newTag);
565 dataFieldAddedSize = newSegment->GetSize();
566 dataField.push_back(newSegment);
567 newSegment =
nullptr;
574 nextSegmentSize -= dataFieldAddedSize;
582 else if ((nextSegmentSize - firstSegment->GetSize() <= 2) ||
m_txonBuffer.empty())
585 " IF nextSegmentSize - firstSegment->GetSize () <= 2 || txonBuffer.size == 0");
588 dataFieldAddedSize = firstSegment->GetSize();
589 dataField.push_back(firstSegment);
590 firstSegment =
nullptr;
597 nextSegmentSize -= dataFieldAddedSize;
605 " First SDU size = " <<
m_txonBuffer.begin()->m_pdu->GetSize());
607 NS_LOG_LOGIC(
" Next segment size = " << nextSegmentSize);
616 NS_LOG_LOGIC(
" IF firstSegment < NextSegmentSize && txonBuffer.size > 0");
618 dataFieldAddedSize = firstSegment->GetSize();
619 dataField.push_back(firstSegment);
627 nextSegmentSize -= ((nextSegmentId % 2) ? (2) : (1)) + dataFieldAddedSize;
635 " First SDU size = " <<
m_txonBuffer.begin()->m_pdu->GetSize());
637 NS_LOG_LOGIC(
" Next segment size = " << nextSegmentSize);
642 firstSegmentTime =
m_txonBuffer.begin()->m_waitingSince;
662 uint8_t framingInfo = 0;
663 std::vector<Ptr<Packet>>::iterator it;
664 it = dataField.begin();
668 NS_ASSERT_MSG((*it)->PeekPacketTag(tag),
"LteRlcSduStatusTag is missing");
669 (*it)->PeekPacketTag(tag);
681 while (it < dataField.end())
683 NS_LOG_LOGIC(
"Adding SDU/segment to packet, length = " << (*it)->GetSize());
685 NS_ASSERT_MSG((*it)->PeekPacketTag(tag),
"LteRlcSduStatusTag is missing");
686 (*it)->RemovePacketTag(tag);
687 if (packet->GetSize() > 0)
689 packet->AddAtEnd(*it);
758 packet->AddHeader(rlcAmHeader);
775 params.layer = txOpParams.
layer;
776 params.harqProcessId = txOpParams.
harqId;
803 NS_ASSERT_MSG(ret,
"RlcTag not found in RLC Header. The packet went into a real network?");
871 NS_LOG_LOGIC(
"PDU segment received ( SN = " << seqNumber <<
" )");
875 NS_LOG_LOGIC(
"PDU received ( SN = " << seqNumber <<
" )");
879 NS_ASSERT_MSG(
false,
"Neither a PDU segment nor a PDU received");
932 NS_ASSERT(!it->second.m_byteSegments.empty());
934 "re-segmentation not supported");
935 NS_LOG_LOGIC(
"PDU segment already received, discarded");
939 NS_LOG_LOGIC(
"Place PDU in the reception buffer ( SN = " << seqNumber <<
" )");
952 if (seqNumber >=
m_vrH)
954 m_vrH = seqNumber + 1;
963 if (it !=
m_rxonBuffer.end() && it->second.m_pduComplete)
966 while (it !=
m_rxonBuffer.end() && it->second.m_pduComplete)
987 if (seqNumber ==
m_vrR)
990 if (it !=
m_rxonBuffer.end() && it->second.m_pduComplete)
994 while (it !=
m_rxonBuffer.end() && it->second.m_pduComplete)
998 "Too many segments. PDU Reassembly process didn't work");
1073 bool incrementVtA =
true;
1075 for (sn =
m_vtA; sn < ackSn && sn <
m_vtS; sn++)
1079 uint16_t seqNumberValue = sn.
GetValue();
1090 incrementVtA =
false;
1094 NS_LOG_INFO(
"Move SN = " << seqNumberValue <<
" to retxBuffer");
1117 NS_LOG_INFO(
"ACKed SN = " << seqNumberValue <<
" from txedBuffer");
1128 NS_LOG_INFO(
"ACKed SN = " << seqNumberValue <<
" from retxBuffer");
1174 NS_LOG_LOGIC(seqNumber <<
" is INSIDE the receiving window");
1179 NS_LOG_LOGIC(seqNumber <<
" is OUTSIDE the receiving window");
1189 bool ret = packet->FindFirstMatchingByteTag(rlcTag);
1191 packet->RemoveHeader(rlcAmHeader);
1192 ret = packet->FindFirstMatchingByteTag(rlcTag);
1196 bool expectedSnLost;
1200 expectedSnLost =
true;
1202 <<
". Current SN = " << currSeqNumber);
1207 expectedSnLost =
false;
1209 <<
". Current SN = " << currSeqNumber);
1214 uint8_t extensionBit;
1215 uint16_t lengthIndicator;
1221 if (extensionBit == 0)
1231 if (lengthIndicator >= packet->GetSize())
1233 NS_LOG_LOGIC(
"INTERNAL ERROR: Not enough data in the packet ("
1234 << packet->GetSize() <<
"). Needed LI=" << lengthIndicator);
1239 Ptr<Packet> data_field = packet->CreateFragment(0, lengthIndicator);
1240 packet->RemoveAtStart(lengthIndicator);
1244 }
while (extensionBit == 1);
1246 std::list<Ptr<Packet>>::iterator it;
1250 NS_LOG_LOGIC(
"Reassembling State = 'WAITING_S0_FULL'");
1257 NS_LOG_LOGIC(
"Framing Info = " << (uint16_t)framingInfo);
1261 if (!expectedSnLost)
1266 switch (framingInfo)
1307 "INTERNAL ERROR: Transition not possible. FI = " << (
uint32_t)framingInfo);
1313 switch (framingInfo)
1379 "INTERNAL ERROR: Transition not possible. FI = " << (
uint32_t)framingInfo);
1396 switch (framingInfo)
1487 "INTERNAL ERROR: Transition not possible. FI = " << (
uint32_t)framingInfo);
1493 switch (framingInfo)
1605 "INTERNAL ERROR: Transition not possible. FI = " << (
uint32_t)framingInfo);
1632 Time txonQueueHolDelay(0);
1635 txonQueueHolDelay = now -
m_txonBuffer.front().m_waitingSince;
1639 Time retxQueueHolDelay;
1642 Time senderTimestamp;
1651 retxQueueHolDelay = now - senderTimestamp;
1655 retxQueueHolDelay =
Seconds(0);
1706 while (it !=
m_rxonBuffer.end() && it->second.m_pduComplete)
1749 <<
" to retxBuffer");
1752 bool pduAvailable = (bool)
m_txedBuffer.at(sn.GetValue()).m_pdu;
1756 uint16_t snValue = sn.GetValue();
1757 NS_LOG_INFO(
"Move PDU " << sn <<
" from txedBuffer to retxBuffer");
AttributeValue implementation for Boolean.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
virtual void TransmitPdu(TransmitPduParameters params)=0
send an RLC PDU to the MAC for transmission.
virtual void ReportBufferStatus(ReportBufferStatusParameters params)=0
Report the RLC buffer status to the MAC.
LTE RLC Acknowledged Mode (AM), see 3GPP TS 36.322.
ReassemblingState_t m_reassemblingState
reassembling state
void ExpireStatusProhibitTimer()
method called when the T_status_prohibit timer expires
SequenceNumber10 m_vrMr
VR(MR)
Time m_statusProhibitTimerValue
status prohibit timer value
bool IsInsideReceivingWindow(SequenceNumber10 seqNumber)
method called when the T_status_prohibit timer expires
uint16_t m_windowSize
Constants.
Ptr< Packet > m_keepS0
keep S0
void DoNotifyHarqDeliveryFailure() override
Notify HARQ delivery failure.
SequenceNumber10 m_vrH
VR(H)
uint32_t m_txonBufferSize
transmit on buffer size
std::vector< TxPdu > m_txonBuffer
Transmission buffer.
SequenceNumber10 m_vrMs
VR(MS)
uint16_t m_pollByte
poll byte
SequenceNumber10 m_vtS
VT(S)
void DoDispose() override
Destructor implementation.
SequenceNumber10 m_pollSn
POLL_SN.
SequenceNumber10 m_vtA
State variables.
void ExpireReorderingTimer()
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
SequenceNumber10 m_vtMs
VT(MS)
EventId m_rbsTimer
RBS timer.
uint32_t m_statusPduBufferSize
status PDU buffer size
Ptr< Packet > m_controlPduBuffer
Control PDU buffer (just one PDU)
bool m_txOpportunityForRetxAlwaysBigEnough
transmit opportunity for retransmit?
bool m_pollRetransmitTimerJustExpired
poll retransmit timer just expired?
void DoTransmitPdcpPdu(Ptr< Packet > p) override
RLC SAP.
Time m_reorderingTimerValue
reordering timer value
uint32_t m_maxTxBufferSize
maximum transmission buffer size
void DoReceivePdu(LteMacSapUser::ReceivePduParameters rxPduParams) override
Receive PDU function.
std::list< Ptr< Packet > > m_sdusBuffer
List of SDUs in a packet (PDU)
EventId m_pollRetransmitTimer
Timers.
uint16_t m_maxRetxThreshold
Configurable parameters.
SequenceNumber10 m_vrX
VR(X)
std::vector< RetxPdu > m_retxBuffer
Buffer for PDUs considered for retransmission.
uint32_t m_byteWithoutPoll
byte without poll
void ExpireRbsTimer()
Expire RBS timer.
uint32_t m_pduWithoutPoll
Counters.
static TypeId GetTypeId()
Get the type ID.
void DoNotifyTxOpportunity(LteMacSapUser::TxOpportunityParameters txOpParams) override
MAC SAP.
Time m_pollRetransmitTimerValue
poll retransmit time value
void DoReportBufferStatus()
Report buffer status.
void ReassembleAndDeliver(Ptr< Packet > packet)
Reassemble and deliver.
std::map< uint16_t, PduBuffer > m_rxonBuffer
Reception buffer.
uint32_t m_txedBufferSize
transmit ed buffer size
uint16_t m_pollPdu
poll PDU
EventId m_reorderingTimer
reordering timer
void ExpirePollRetransmitTimer()
Expire poll retransmitter.
SequenceNumber10 m_vrR
VR(R)
SequenceNumber10 m_expectedSeqNumber
Expected Sequence Number.
uint32_t m_retxBufferSize
retransmit buffer size
EventId m_statusProhibitTimer
status prohibit timer
std::vector< RetxPdu > m_txedBuffer
Buffer for transmitted and retransmitted PDUs that have not been acked but are not considered for ret...
bool m_statusPduRequested
status PDU requested
Time m_rbsTimerValue
RBS timer value.
This abstract base class defines the API to interact with the Radio Link Control (LTE_RLC) in LTE,...
LteRlcSapUser * m_rlcSapUser
RLC SAP user.
TracedCallback< Ptr< const Packet > > m_txDropTrace
The trace source fired when the RLC drops a packet before transmission.
TracedCallback< uint16_t, uint8_t, uint32_t, uint64_t > m_rxPdu
Used to inform of a PDU reception from the MAC SAP user.
void DoDispose() override
Destructor implementation.
LteMacSapProvider * m_macSapProvider
MAC SAP provider.
TracedCallback< uint16_t, uint8_t, uint32_t > m_txPdu
Used to inform of a PDU delivery to the MAC SAP provider.
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.
This class implements a tag that carries the status of a RLC SDU for the fragmentation process Status...
uint8_t GetStatus() const
Get status function.
void SetStatus(uint8_t status)
Set status function.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Smart pointer class similar to boost::intrusive_ptr.
Tag to calculate the per-PDU delay from eNb RLC to UE RLC.
Time GetSenderTimestamp() const
Get the instant when the RLC delivers the PDU to the MAC SAP provider.
void SetSenderTimestamp(Time senderTimestamp)
Set the sender timestamp.
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
void SetModulusBase(SequenceNumber10 modulusBase)
Set modulus base.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Parameters for LteMacSapProvider::ReportBufferStatus.
uint32_t txQueueSize
the current size of the RLC transmission queue
uint16_t retxQueueHolDelay
the Head Of Line delay of the retransmission queue
uint16_t txQueueHolDelay
the Head Of Line delay of the transmission queue
uint32_t retxQueueSize
the current size of the RLC retransmission queue in bytes
uint8_t lcid
the logical channel id corresponding to the sending RLC instance
uint16_t rnti
the C-RNTI identifying the UE
uint16_t statusPduSize
the current size of the pending STATUS RLC PDU message in bytes
Parameters for LteMacSapProvider::TransmitPdu.
Parameters for LteMacSapUser::ReceivePdu.
Ptr< Packet > p
the RLC PDU to be received
Parameters for LteMacSapUser::NotifyTxOpportunity.
uint8_t harqId
the HARQ ID
uint32_t bytes
the number of bytes to transmit
uint8_t componentCarrierId
the component carrier id
uint8_t layer
the layer of transmission (MIMO)
Store an incoming (from layer above us) PDU, waiting to transmit it.