From 07f63bfb1b9875bf8b5e6857721e0e37014713bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schuhb=C3=A4ck?= Date: Mon, 26 Jul 2021 16:22:18 +0200 Subject: [PATCH] fix RLC/MAC Buffer divergence in in multiconnection use case macSduRequest() might remove MAC_HEADER from empty sdu leading to wrong Byte count in some other connection. --- src/stack/mac/layer/LteMacUe.cc | 4 +- src/stack/mac/scheduler/LcgScheduler.cc | 51 +++++++++++---------- src/stack/mac/scheduler/LcgScheduler.h | 6 +++ src/stack/mac/scheduler/LteSchedulerUeUl.cc | 4 ++ src/stack/mac/scheduler/LteSchedulerUeUl.h | 2 + 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/stack/mac/layer/LteMacUe.cc b/src/stack/mac/layer/LteMacUe.cc index 06b14bbf..e48c4f51 100644 --- a/src/stack/mac/layer/LteMacUe.cc +++ b/src/stack/mac/layer/LteMacUe.cc @@ -176,7 +176,6 @@ int LteMacUe::macSduRequest() allocatedBytes.push_back(schedulingGrant_->getGrantedCwBytes(cw)); LteMacScheduleList* scheduledBytesList = lcgScheduler_->getScheduledBytesList(); - bool firstSdu = true; // Ask for a MAC sdu for each scheduled user on each codeword LteMacScheduleList::const_iterator it; @@ -190,10 +189,9 @@ int LteMacUe::macSduRequest() LteMacScheduleList::const_iterator bit = scheduledBytesList->find(key); unsigned int sduSize = bit->second; - if (firstSdu) + if (lcgScheduler_->isFirstSdu(destCid)) { sduSize -= MAC_HEADER; // do not consider MAC header size - firstSdu = false; } // consume bytes on this codeword diff --git a/src/stack/mac/scheduler/LcgScheduler.cc b/src/stack/mac/scheduler/LcgScheduler.cc index 00f276d8..45ac31d8 100644 --- a/src/stack/mac/scheduler/LcgScheduler.cc +++ b/src/stack/mac/scheduler/LcgScheduler.cc @@ -40,11 +40,18 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran */ statusMap_.clear(); + /* + * clean firstSduCid + */ + firstSduCid = 0; + // If true, assure a minimum reserved rate to all connection (LCP first // phase), if false, provide a best effort service (LCP second phase) bool priorityService = true; bool firstSdu = true; + // reserve Bytes for MAC_HEADER + availableBytes -= MAC_HEADER; LcgMap& lcgMap = mac_->getLcgMap(); @@ -80,27 +87,24 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran // TODO get the QoS parameters // connection must have the same direction of the grant - if (connDesc.getDirection() != grantDir) + if (connDesc.getDirection() != grantDir){ continue; - - unsigned int toServe = queueLength; + } // Check whether the virtual buffer is empty if (queueLength == 0) { EV << "LcgScheduler::schedule scheduled connection is no more active " << endl; continue; // go to next connection } - else - { - // we need to consider also the size of RLC and MAC headers - if (connDesc.getRlcType() == UM) - toServe += RLC_HEADER_UM; - else if (connDesc.getRlcType() == AM) - toServe += RLC_HEADER_AM; - - if (firstSdu) - toServe += MAC_HEADER; - } + + + unsigned int toServe = queueLength; + // we need to consider also the size of RLC and MAC headers + if (connDesc.getRlcType() == UM) + toServe += RLC_HEADER_UM; + else if (connDesc.getRlcType() == AM) + toServe += RLC_HEADER_AM; + // get a pointer to the appropriate status element: we need a tracing element // in order to store information about connections and data transmitted. These @@ -111,7 +115,7 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran { // the element does not exist, initialize it elem = &statusMap_[cid]; - elem->occupancy_ = vQueue->getQueueLength(); + elem->occupancy_ = vQueue->getQueueOccupancy(); // in bytes elem->sentData_ = 0; elem->sentSdus_ = 0; // TODO set bucket from QoS parameters @@ -204,11 +208,6 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran // check if there is space for a SDU int alloc = toServe; - if (firstSdu) - { - alloc -= MAC_HEADER; - firstSdu = false; - } if (connDesc.getRlcType() == UM) alloc -= RLC_HEADER_UM; else if (connDesc.getRlcType() == AM) @@ -247,11 +246,6 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran elem->sentData_ += availableBytes; int alloc = availableBytes; - if (firstSdu) - { - alloc -= MAC_HEADER; - firstSdu = false; - } if (connDesc.getRlcType() == UM) alloc -= RLC_HEADER_UM; else if (connDesc.getRlcType() == AM) @@ -323,6 +317,13 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran // signal service for current connection unsigned int* servicedSdu = nullptr; + if (elem->sentData_ > 0 && firstSdu){ + // if current element was scheduled and it is the first add MAC_HEADER + elem->sentData_ += MAC_HEADER; + firstSdu = false; + firstSduCid = cid; // remeber first cid for first sdu + } + if (scheduleList_.find(cid) == scheduleList_.end()) { // the element does not exist, initialize it diff --git a/src/stack/mac/scheduler/LcgScheduler.h b/src/stack/mac/scheduler/LcgScheduler.h index a4e49519..f637acf1 100644 --- a/src/stack/mac/scheduler/LcgScheduler.h +++ b/src/stack/mac/scheduler/LcgScheduler.h @@ -73,6 +73,8 @@ class SIMULTE_API LcgScheduler // scheduled bytes list ScheduleList scheduledBytesList_; + MacCid firstSduCid; + /// Cid List typedef std::list CidList; @@ -111,6 +113,10 @@ class SIMULTE_API LcgScheduler */ virtual ScheduleList& getScheduledBytesList(); + inline virtual bool isFirstSdu(const MacCid& cid){ + return firstSduCid == cid; + } + // ***************************************************************************************** // /// performs request of grant to the eNbScheduler diff --git a/src/stack/mac/scheduler/LteSchedulerUeUl.cc b/src/stack/mac/scheduler/LteSchedulerUeUl.cc index f161fb2c..0fbc0530 100644 --- a/src/stack/mac/scheduler/LteSchedulerUeUl.cc +++ b/src/stack/mac/scheduler/LteSchedulerUeUl.cc @@ -111,3 +111,7 @@ LteMacScheduleList* LteSchedulerUeUl::getScheduledBytesList() { return &scheduledBytesList_; } + +bool LteSchedulerUeUl::isFirstSdu(const MacCid& cid){ + return lcgScheduler_->isFirstSdu(cid); +} diff --git a/src/stack/mac/scheduler/LteSchedulerUeUl.h b/src/stack/mac/scheduler/LteSchedulerUeUl.h index 00ceaedb..23865280 100644 --- a/src/stack/mac/scheduler/LteSchedulerUeUl.h +++ b/src/stack/mac/scheduler/LteSchedulerUeUl.h @@ -47,6 +47,8 @@ class SIMULTE_API LteSchedulerUeUl */ LteMacScheduleList* getScheduledBytesList(); + bool isFirstSdu(const MacCid& cid); + /* * constructor */