Skip to content

Commit 1ed5ceb

Browse files
committed
LteMac: getConnDesc(), getMacBuffers(), getBsrVirtualBuffers(): replaced with better functions
Do not expose the internal maps -- leaky abstraction, hinders refactoring,etc Replacements: - getConnDesc(cid), getActiveConnDescCids() - getMacBuffer(cid), getActiveMacBufferCids() - getBsrVirtualBuffer(cid), getActiveBsrVirtualBufferCids()
1 parent 3b23b4b commit 1ed5ceb

9 files changed

Lines changed: 64 additions & 48 deletions

File tree

src/simu5g/stack/compManager/compManagerProportional/LteCompManagerProportional.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ void LteCompManagerProportional::provisionalSchedule()
3131
provisionedBlocks_ = 0;
3232

3333
Direction dir = DL;
34-
std::map<MacCid, LteMacBuffer*> *vbuf = mac_->getMacBuffers();
3534
ActiveSet *activeSet = mac_->getActiveSet(dir);
3635
for (MacCid cid : *activeSet) {
3736
MacNodeId ueId = cid.getNodeId();
3837

39-
unsigned int queueLength = vbuf->at(cid)->getQueueOccupancy();
38+
unsigned int queueLength = mac_->getMacBuffer(cid)->getQueueOccupancy();
4039

4140
// Compute the number of bytes available in one block for this UE
4241
unsigned int bytesPerBlock = 0;

src/simu5g/stack/mac/LteMacBase.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,23 @@ class LteMacBase : public cSimpleModule
237237
return cellId_;
238238
}
239239

240-
// Returns the virtual buffers
241-
std::map<MacCid, LteMacBuffer*> *getMacBuffers()
240+
// Returns the virtual buffer for a specific CID
241+
LteMacBuffer* getMacBuffer(MacCid cid)
242242
{
243-
return &macBuffers_;
243+
auto it = macBuffers_.find(cid);
244+
if (it == macBuffers_.end())
245+
throw cRuntimeError("LteMacBase::getMacBuffer - Buffer for CID %s not found", cid.str().c_str());
246+
return it->second;
247+
}
248+
249+
// Returns list of active buffer CIDs
250+
std::vector<MacCid> getActiveMacBufferCids()
251+
{
252+
std::vector<MacCid> activeCids;
253+
activeCids.reserve(macBuffers_.size());
254+
for (const auto& [cid,_] : macBuffers_)
255+
activeCids.push_back(cid);
256+
return activeCids;
244257
}
245258

246259
// Returns Traffic Class to cid mapping
@@ -249,10 +262,23 @@ class LteMacBase : public cSimpleModule
249262
return lcgMap_;
250263
}
251264

252-
// Returns connection descriptors
253-
std::map<MacCid, FlowControlInfo>& getConnDesc()
265+
// Returns flow control info for a specific CID
266+
const FlowControlInfo& getConnDesc(MacCid cid)
267+
{
268+
auto it = connDesc_.find(cid);
269+
if (it == connDesc_.end())
270+
throw cRuntimeError("LteMacBase: Connection %s not found", cid.str().c_str());
271+
return it->second;
272+
}
273+
274+
// Returns list of active connection CIDs
275+
std::vector<MacCid> getActiveConnectionCids()
254276
{
255-
return connDesc_;
277+
std::vector<MacCid> activeCids;
278+
activeCids.reserve(connDesc_.size());
279+
for (const auto& [cid,_] : connDesc_)
280+
activeCids.push_back(cid);
281+
return activeCids;
256282
}
257283

258284
// Returns the harq tx buffers

src/simu5g/stack/mac/LteMacEnb.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,22 @@ class LteMacEnb : public LteMacBase
175175
~LteMacEnb() override;
176176

177177
/// Returns the BSR virtual buffers.
178-
std::map<MacCid, LteMacBuffer*> *getBsrVirtualBuffers()
178+
LteMacBuffer *getBsrVirtualBuffer(MacCid cid)
179179
{
180-
return &bsrbuf_;
180+
auto it = bsrbuf_.find(cid);
181+
if (it == bsrbuf_.end())
182+
throw cRuntimeError("LteMacBase::getBsrVirtualBuffer - Buffer for CID %s not found", cid.str().c_str());
183+
return it->second;
184+
}
185+
186+
// Returns list of active buffer CIDs
187+
std::vector<MacCid> getActiveBsrVirtualBufferCids()
188+
{
189+
std::vector<MacCid> activeCids;
190+
activeCids.reserve(bsrbuf_.size());
191+
for (const auto& [cid,_] : bsrbuf_)
192+
activeCids.push_back(cid);
193+
return activeCids;
181194
}
182195

183196
/**

src/simu5g/stack/mac/scheduler/LcgScheduler.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran
7979
for (it = it_pair.first; it != et; ++it) {
8080
// get the Flow descriptor
8181
MacCid cid = it->second.first;
82-
FlowControlInfo connDesc = mac_->getConnDesc().at(cid);
82+
FlowControlInfo connDesc = mac_->getConnDesc(cid);
8383
if (connDesc.getDirection() == D2D) {
8484
// get the connection virtual buffer
8585
LteMacBuffer *vQueue = it->second.second;
@@ -106,7 +106,7 @@ ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction gran
106106
MacCid cid = it->second.first;
107107

108108
// get the Flow descriptor
109-
FlowControlInfo connDesc = mac_->getConnDesc().at(cid);
109+
FlowControlInfo connDesc = mac_->getConnDesc(cid);
110110
// TODO get the QoS parameters
111111

112112
// connection must have the same direction as the grant
@@ -341,4 +341,3 @@ ScheduleList& LcgScheduler::getScheduledBytesList()
341341
}
342342

343343
} //namespace simu5g
344-

src/simu5g/stack/mac/scheduler/LteSchedulerEnb.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ LteSchedulerEnb& LteSchedulerEnb::operator=(const LteSchedulerEnb& other)
4848
activeConnectionSet_ = other.activeConnectionSet_;
4949
scheduleList_ = other.scheduleList_;
5050
allocatedCws_ = other.allocatedCws_;
51-
vbuf_ = other.vbuf_;
52-
bsrbuf_ = other.bsrbuf_;
5351
harqTxBuffers_ = other.harqTxBuffers_;
5452
harqRxBuffers_ = other.harqRxBuffers_;
5553
resourceBlocks_ = other.resourceBlocks_;
@@ -93,9 +91,6 @@ void LteSchedulerEnb::initialize(Direction dir, LteMacEnb *mac, Binder *binder)
9391

9492
binder_ = binder;
9593

96-
vbuf_ = mac_->getMacBuffers();
97-
bsrbuf_ = mac_->getBsrVirtualBuffers();
98-
9994
harqTxBuffers_ = mac_->getHarqTxBuffers();
10095
harqRxBuffers_ = mac_->getHarqRxBuffers();
10196

@@ -347,7 +342,7 @@ unsigned int LteSchedulerEnb::scheduleGrant(MacCid cid, unsigned int bytes, bool
347342
}
348343

349344
// Get virtual buffer reference
350-
LteMacBuffer *conn = ((dir == DL) ? vbuf_->at(cid) : bsrbuf_->at(cid));
345+
LteMacBuffer *conn = (dir == DL) ? mac_->getMacBuffer(cid) : mac_->getBsrVirtualBuffer(cid);
351346

352347
// get the buffer size
353348
unsigned int queueLength = conn->getQueueOccupancy(); // in bytes

src/simu5g/stack/mac/scheduler/LteSchedulerEnb.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ class LteSchedulerEnb
9393
// Codeword list
9494
LteMacAllocatedCws allocatedCws_;
9595

96-
// Pointer to downlink virtual buffers (that are in LteMacBase)
97-
std::map<MacCid, LteMacBuffer*> *vbuf_ = nullptr;
98-
99-
// Pointer to uplink virtual buffers (that are in LteMacBase)
100-
std::map<MacCid, LteMacBuffer*> *bsrbuf_ = nullptr;
101-
10296
// Pointer to Harq Tx Buffers (that are in LteMacBase)
10397
std::map<GHz, HarqTxBuffers> *harqTxBuffers_ = nullptr;
10498

src/simu5g/stack/mac/scheduling_modules/LteAllocatorBestFit.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void LteAllocatorBestFit::prepareSchedule()
137137
MacNodeId nodeId = cid.getNodeId();
138138

139139
// Get virtual buffer reference
140-
LteMacBuffer *conn = eNbScheduler_->bsrbuf_->at(cid);
140+
LteMacBuffer *conn = eNbScheduler_->mac_->getBsrVirtualBuffer(cid);
141141
// Check whether the virtual buffer is empty
142142
if (conn->isEmpty()) {
143143
// The BSR buffer for this node is empty. Abort scheduling for the node: no data to transmit.
@@ -228,7 +228,7 @@ void LteAllocatorBestFit::prepareSchedule()
228228
// Compute Tx params for the extracted node
229229
const UserTxParams& txParams = mac_->getAmc()->computeTxParams(nodeId, dir, carrierFrequency_);
230230
// Get virtual buffer reference
231-
LteMacBuffer *conn = eNbScheduler_->bsrbuf_->at(cid);
231+
LteMacBuffer *conn = eNbScheduler_->mac_->getBsrVirtualBuffer(cid);
232232

233233
// Get a reference of the first BSR
234234
PacketInfo vpkt = conn->front();

src/simu5g/stack/mac/scheduling_modules/LteDrr.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,20 @@ void LteDrr::commitSchedule()
119119

120120
void LteDrr::updateSchedulingInfo()
121121
{
122-
// Get connections.
123-
std::map<MacCid, LteMacBuffer*> *conn;
124-
125-
if (direction_ == DL) {
126-
conn = eNbScheduler_->mac_->getMacBuffers();
127-
}
128-
else if (direction_ == UL) {
129-
conn = eNbScheduler_->mac_->getBsrVirtualBuffers();
130-
}
131-
else {
132-
conn = nullptr;
122+
// Get active buffer CIDs based on direction.
123+
std::vector<MacCid> activeCids;
124+
125+
if (direction_ == DL)
126+
activeCids = eNbScheduler_->mac_->getActiveMacBufferCids();
127+
else if (direction_ == UL)
128+
activeCids = eNbScheduler_->mac_->getActiveBsrVirtualBufferCids();
129+
else
133130
throw cRuntimeError("LteDrr::updateSchedulingInfo invalid direction");
134-
}
135131

136132
// Select the minimum rate and MAC SDU size.
137133
double minSize = 0;
138134
double minRate = 0;
139-
for (auto& it : *conn) {
140-
MacCid cid = it.first;
135+
for (MacCid cid : activeCids) {
141136
MacNodeId nodeId = cid.getNodeId();
142137
bool eligible = true;
143138
const UserTxParams& info = eNbScheduler_->mac_->getAmc()->computeTxParams(nodeId, direction_, carrierFrequency_);
@@ -181,4 +176,3 @@ void LteDrr::notifyActiveConnection(MacCid cid)
181176
}
182177

183178
} //namespace
184-

src/simu5g/stack/mac/scheduling_modules/LteMaxCiOptMB.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ void LteMaxCiOptMB::generateProblem()
235235

236236
appFileStream << "\\ ================ Constraint 6 ================" << endl;
237237
for ( iUe = 0; iUe < totUes; ++iUe) {
238-
std::map<MacCid, LteMacBuffer*> *buf = mac_->getMacBuffers();
239-
std::map<MacCid, LteMacBuffer*>::iterator it = buf->find(cidList_[iUe]);
240-
int queue = 0;
241-
if (it == mac_->getMacBuffers()->end())
242-
cRuntimeError("LteMaxCiOptMB::generateProblem: Cannot find CID %s", cidList_[iUe].str().c_str());
243-
queue = it->second->getQueueOccupancy();
238+
LteMacBuffer *macBuffer = mac_->getMacBuffer(cidList_[iUe]);
239+
int queue = macBuffer->getQueueOccupancy();
244240
MacNodeId ueId = ueList_[iUe];
245241
appFileStream << "v" << ueId << " - p" << ueId << " <= " << queue << endl;
246242
}

0 commit comments

Comments
 (0)