13#ifndef _SIMU5G_RLCUMENTITYD2D_H_
14#define _SIMU5G_RLCUMENTITYD2D_H_
16#include <inet/common/ModuleRefByPar.h>
18#include "simu5g/stack/d2d/rlc/ID2dRlcUmTxEntity.h"
19#include "simu5g/stack/d2d/rrc/D2DModeController.h"
20#include "simu5g/stack/rlc/um/LteRlcUmTxEntity.h"
21#include "simu5g/stack/rlc/um/NrRlcUmTxEntity.h"
22#include "simu5g/stack/rlc/um/LteRlcUmRxEntity.h"
23#include "simu5g/stack/rlc/um/NrRlcUmRxEntity.h"
24#include "simu5g/stack/rlc/packet/LteRlcNewDataTag_m.h"
28using namespace omnetpp;
57 inet::ModuleRefByPar<D2DModeController> d2dModeController_;
64 bool notifyEmptyBuffer_ =
false;
67 bool holdingDownstreamInPackets_ =
false;
70 inet::cPacketQueue sduHoldingQueue_;
72 void initialize(
int stage)
override
74 Base::initialize(stage);
75 if (stage == inet::INITSTAGE_LOCAL) {
76 d2dModeController_.reference(
this,
"d2dModeControllerModule",
false);
77 WATCH(registeredPeerId_);
78 WATCH(notifyEmptyBuffer_);
79 WATCH(holdingDownstreamInPackets_);
80 WATCH(sduHoldingQueue_);
84 void setFlowControlInfo(FlowControlInfo *info)
override
86 Base::setFlowControlInfo(info);
91 if (d2dModeController_) {
93 registeredPeerId_ = MacNodeId(this->flowControlInfo_->getD2dRxPeerId());
94 d2dModeController_->registerD2DPeerTxEntity(registeredPeerId_,
this);
108 if (d2dModeController_ && registeredPeerId_ !=
NODEID_NONE)
109 d2dModeController_->unregisterD2DPeerTxEntity(registeredPeerId_,
this);
114 bool interceptSdu(inet::Packet *pkt)
override
116 if (holdingDownstreamInPackets_) {
118 EV << NOW <<
" RlcUmTxEntityD2D::interceptSdu - storing new SDU into the holding buffer" << endl;
119 sduHoldingQueue_.insert(pkt);
122 return Base::interceptSdu(pkt);
126 void onTxBufferEmptied()
override
128 if (notifyEmptyBuffer_ && this->isTxBufferEmpty()) {
129 notifyEmptyBuffer_ =
false;
130 if (d2dModeController_ && this->flowControlInfo_)
131 d2dModeController_->resumeDownstreamInPackets(this->flowControlInfo_->getD2dRxPeerId());
153 EV << NOW <<
" RlcUmTxEntityD2D::resumeDownstreamInPackets - resume buffering incoming downstream packets of the RLC entity associated with the new mode" << endl;
155 holdingDownstreamInPackets_ =
false;
158 while (!sduHoldingQueue_.isEmpty()) {
159 auto pktRlc = check_and_cast<inet::Packet *>(sduHoldingQueue_.front());
160 sduHoldingQueue_.pop();
163 this->bufferSduAndNotifyMac(pktRlc);
172 Enter_Method_Silent(
"rlcHandleD2DModeSwitch()");
175 if (getNodeTypeById(this->ownerNodeId_) == NODEB) {
176 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - nothing to do on DL leg of IM flow" << endl;
181 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - clear TX buffer of the RLC entity associated with the old mode" << endl;
184 else if (!this->isTxBufferEmpty()) {
185 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - check when the TX buffer of the old mode becomes empty" << endl;
186 notifyEmptyBuffer_ =
true;
189 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - TX buffer of the old mode is already empty" << endl;
193 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - reset numbering of the RLC TX entity corresponding to the new mode" << endl;
196 if (!clearBuffer && d2dModeController_ && this->flowControlInfo_ &&
197 d2dModeController_->isEmptyingTxBuffer(this->flowControlInfo_->getD2dRxPeerId())) {
199 EV << NOW <<
" RlcUmTxEntityD2D::rlcHandleD2DModeSwitch - halt incoming downstream connections of the new mode" << endl;
241 bool isD2DMultiConnection() {
return this->flowControlInfo_->getDirection() == D2D_MULTI; }
246 simsignal_t rlcDelayD2DSignal_ = SIMSIGNAL_NULL;
247 simsignal_t rlcThroughputD2DSignal_ = SIMSIGNAL_NULL;
248 simsignal_t rlcPduDelayD2DSignal_ = SIMSIGNAL_NULL;
249 simsignal_t rlcPduThroughputD2DSignal_ = SIMSIGNAL_NULL;
251 void initialize(
int stage)
override
253 Base::initialize(stage);
254 if (stage == inet::INITSTAGE_LOCAL) {
255 rlcDelayD2DSignal_ = cComponent::registerSignal(
"rlcDelayD2D");
256 rlcThroughputD2DSignal_ = cComponent::registerSignal(
"rlcThroughputD2D");
257 rlcPduDelayD2DSignal_ = cComponent::registerSignal(
"rlcPduDelayD2D");
258 rlcPduThroughputD2DSignal_ = cComponent::registerSignal(
"rlcPduThroughputD2D");
277 Enter_Method_Silent(
"rlcHandleD2DModeSwitch()");
280 if (getNodeTypeById(this->ownerNodeId_) == UE && oldMode == IM) {
281 EV << NOW <<
" RlcUmRxEntityD2D::rlcHandleD2DModeSwitch - nothing to do on DL leg of IM flow" << endl;
286 EV << NOW <<
" RlcUmRxEntityD2D::rlcHandleD2DModeSwitch - clear RX buffer of the RLC entity associated with the old mode" << endl;
291 EV << NOW <<
" RlcUmRxEntityD2D::rlcHandleD2DModeSwitch - handle numbering of the RLC entity associated with the newly selected mode" << endl;
308 bool resetFlag_ =
false;
310 void initialize(
int stage)
override
312 RlcUmRxEntityD2D<LteRlcUmRxEntity>::initialize(stage);
313 if (stage == inet::INITSTAGE_LOCAL)
320 void onFirstPduEnqueued(
unsigned int pduSno)
override;
321 bool consumeReassemblyReset(
unsigned int pduSno)
override;
322 void emitPduStats(Direction dir,
double tputSample, simtime_t creationTime)
override;
323 void emitSduStats(Direction dir,
double tputSample, simtime_t creationTime)
override;
335 void emitRxStatistics(
bool perPdu,
double throughput, simtime_t delay)
override;
What a D2D UM RX entity offers the D2D-aware RLC mux.
Definition ID2dRlcUmTxEntity.h:70
What a D2D UM TX entity offers the D2D mode controller.
Definition ID2dRlcUmTxEntity.h:30
D2D-capable LTE (TS 36.322) RLC UM receiving entity.
Definition RlcUmEntityD2D.h:305
void discardRxBufferForModeSwitch() override
void resetRxNumbering() override
D2D-capable LTE (TS 36.322, FI framing) RLC UM transmitting entity.
Definition RlcUmEntityD2D.h:210
void resetTxNumbering() override
Definition RlcUmEntityD2D.h:212
D2D-capable NR (TS 38.322) RLC UM receiving entity.
Definition RlcUmEntityD2D.h:330
void discardRxBufferForModeSwitch() override
void resetRxNumbering() override
D2D-capable NR (TS 38.322, SO framing) RLC UM transmitting entity.
Definition RlcUmEntityD2D.h:219
void resetTxNumbering() override
Definition RlcUmEntityD2D.h:221
D2D mode-switch machinery for an RLC UM receiving entity.
Definition RlcUmEntityD2D.h:238
void rlcHandleD2DModeSwitch(bool oldConnection, bool oldMode, bool clearBuffer) override
Definition RlcUmEntityD2D.h:275
virtual void discardRxBufferForModeSwitch()=0
virtual void resetRxNumbering()=0
D2D mode-switch machinery for an RLC UM transmitting entity.
Definition RlcUmEntityD2D.h:54
void unregisterFromD2DModeController()
Definition RlcUmEntityD2D.h:106
void resumeDownstreamInPackets() override
Definition RlcUmEntityD2D.h:151
void startHoldingDownstreamInPackets() override
Definition RlcUmEntityD2D.h:145
void rlcHandleD2DModeSwitch(bool oldConnection, bool clearBuffer) override
Definition RlcUmEntityD2D.h:167
virtual void resetTxNumbering()=0
bool isHoldingDownstreamInPackets() override
Definition RlcUmEntityD2D.h:147
bool isEmptyingBuffer() override
Definition RlcUmEntityD2D.h:149
Definition AlertReceiver.h:24
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54