Skip to content

Commit 0ec497a

Browse files
committed
LteMacBase: merge the std::maps connDesc_, macBuffers_ and macQueues_ into one connDescOut_
Because they have the same key set (inserted and deleted together). Benefits: - Emphasizes for the reader which data structures belong together. - New name connDescOut_ emphasizes that these belong to OUTGOING (TX) connections. - Eliminate chance of these maps getting out of sync with each other. - Opens possibility to reduce number of map lookups.
1 parent 745b687 commit 0ec497a

8 files changed

Lines changed: 139 additions & 143 deletions

File tree

src/simu5g/stack/mac/LteMacBase.cc

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ simsignal_t LteMacBase::sentPacketToLowerLayerSignal_ = registerSignal("sentPack
4040

4141
LteMacBase::~LteMacBase()
4242
{
43-
for (auto& [key, buffer] : macQueues_)
44-
delete buffer;
45-
for (auto& [key, buffer] : macBuffers_)
46-
delete buffer;
43+
for (auto& [key, connInfo] : connDescOut_) {
44+
delete connInfo.queue;
45+
delete connInfo.buffer;
46+
}
4747

4848
for (auto& [key, txBuffers] : harqTxBuffers_)
4949
for (auto& [key, buffer] : txBuffers)
@@ -182,17 +182,17 @@ void LteMacBase::fromPhy(cPacket *pktAux)
182182

183183
void LteMacBase::createOutgoingConnection(MacCid cid, const FlowControlInfo& lteInfo)
184184
{
185-
ASSERT(macQueues_.find(cid) == macQueues_.end());
185+
ASSERT(connDescOut_.find(cid) == connDescOut_.end());
186186

187-
macQueues_[cid] = new LteMacQueue(queueSize_);
188-
macBuffers_[cid] = new LteMacBuffer();
189-
take(macQueues_[cid]);
187+
LteMacQueue* realBuffer = new LteMacQueue(queueSize_);
188+
LteMacBuffer* virtualBuffer = new LteMacBuffer();
189+
take(realBuffer);
190190

191-
connDesc_[cid] = lteInfo;
191+
connDescOut_[cid] = OutgoingConnectionInfo(lteInfo, realBuffer, virtualBuffer);
192192

193193
// register connection to LCG map.
194194
LteTrafficClass tClass = (LteTrafficClass)lteInfo.getTraffic();
195-
lcgMap_.insert(LcgPair(tClass, CidBufferPair(cid, macBuffers_[cid])));
195+
lcgMap_.insert(LcgPair(tClass, CidBufferPair(cid, virtualBuffer)));
196196
}
197197

198198
void LteMacBase::createIncomingConnection(MacCid cid, const FlowControlInfo& lteInfo)
@@ -214,11 +214,12 @@ bool LteMacBase::bufferizePacket(cPacket *cpkt)
214214
MacCid cid = ctrlInfoToMacCid(lteInfo);
215215

216216
// check if queues exist, create them if they don't
217-
if (macQueues_.find(cid) == macQueues_.end())
217+
if (connDescOut_.find(cid) == connDescOut_.end())
218218
createOutgoingConnection(cid, *lteInfo);
219219

220-
LteMacQueue *queue = macQueues_.at(cid);
221-
LteMacBuffer *vqueue = macBuffers_.at(cid);
220+
OutgoingConnectionInfo& connInfo = connDescOut_.at(cid);
221+
LteMacQueue *queue = connInfo.queue;
222+
LteMacBuffer *vqueue = connInfo.buffer;
222223

223224
bool dropped = !queue->pushBack(pkt);
224225

@@ -243,36 +244,32 @@ bool LteMacBase::bufferizePacket(cPacket *cpkt)
243244
EV << "LteMacBuffers : Using buffer for " << cid << ", Space left in the Queue: " << spaceLeft << "\n";
244245

245246
// After bufferization buffers must be synchronized
246-
ASSERT(macQueues_[cid]->getQueueLength() == macBuffers_[cid]->getQueueLength());
247+
ASSERT(connInfo.queue->getQueueLength() == connInfo.buffer->getQueueLength());
247248
return true;
248249
}
249250

250251
void LteMacBase::deleteQueues(MacNodeId nodeId)
251252
{
252-
for (auto mit = macQueues_.begin(); mit != macQueues_.end(); ) {
253+
for (auto mit = connDescOut_.begin(); mit != connDescOut_.end(); ) {
253254
if (mit->first.getNodeId() == nodeId) {
254-
while (!mit->second->isEmpty()) {
255-
cPacket *pkt = mit->second->popFront();
255+
// Empty and delete the real buffer
256+
while (!mit->second.queue->isEmpty()) {
257+
cPacket *pkt = mit->second.queue->popFront();
256258
delete pkt;
257259
}
258-
delete mit->second; // Delete Queue
259-
mit = macQueues_.erase(mit); // Delete Element
260+
delete mit->second.queue;
261+
262+
// Empty and delete the virtual buffer
263+
while (!mit->second.buffer->isEmpty())
264+
mit->second.buffer->popFront();
265+
delete mit->second.buffer;
266+
267+
mit = connDescOut_.erase(mit); // Delete Element
260268
}
261269
else {
262270
++mit;
263271
}
264272
}
265-
for (auto vit = macBuffers_.begin(); vit != macBuffers_.end(); ) {
266-
if (vit->first.getNodeId() == nodeId) {
267-
while (!vit->second->isEmpty())
268-
vit->second->popFront();
269-
delete vit->second; // Delete Queue
270-
vit = macBuffers_.erase(vit); // Delete Element
271-
}
272-
else {
273-
++vit;
274-
}
275-
}
276273

277274
// delete H-ARQ buffers
278275
for (auto& [key, harqBuffers] : harqTxBuffers_) {
@@ -354,10 +351,8 @@ void LteMacBase::initialize(int stage)
354351

355352
WATCH(queueSize_);
356353
WATCH(nodeId_);
357-
WATCH_MAP(macQueues_);
358-
WATCH_MAP(macBuffers_);
359-
WATCH_MAP(connDesc_);
360-
WATCH_MAP(connDescIn_);
354+
// WATCH_MAP(connDescOut_);
355+
// WATCH_MAP(connDescIn_);
361356
}
362357
}
363358

src/simu5g/stack/mac/LteMacBase.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,21 @@ class LteMacBase : public cSimpleModule
114114
/// Mac Buffers maximum queue size
115115
unsigned int queueSize_;
116116

117-
/// Mac Sdu Real Buffers
118-
std::map<MacCid, LteMacQueue*> macQueues_;
117+
/*
118+
* Outgoing connection information structure
119+
* Consolidates connection descriptor, real buffer, and virtual buffer
120+
*/
121+
struct OutgoingConnectionInfo {
122+
FlowControlInfo flowInfo; // Connection flow information
123+
LteMacQueue *queue = nullptr; // Real MAC buffer for actual packets
124+
LteMacBuffer *buffer = nullptr; // Virtual buffer for scheduling decisions
119125

120-
/// Mac Sdu Virtual Buffers
121-
std::map<MacCid, LteMacBuffer*> macBuffers_;
126+
OutgoingConnectionInfo() {}
127+
OutgoingConnectionInfo(const FlowControlInfo& info, LteMacQueue *q, LteMacBuffer *buf) : flowInfo(info), queue(q), buffer(buf) {}
128+
};
129+
130+
/// Consolidated outgoing connection information (replaces mbuf_, macBuffers_, and connDesc_)
131+
std::map<MacCid, OutgoingConnectionInfo> connDescOut_;
122132

123133
/// List of pdus finalized for each user on each codeword (one entry per carrier)
124134
std::map<GHz, MacPduList> macPduList_;
@@ -129,11 +139,6 @@ class LteMacBase : public cSimpleModule
129139
/// Harq Rx Buffers (one entry per carrier)
130140
std::map<GHz, HarqRxBuffers> harqRxBuffers_;
131141

132-
/* Connection Descriptors
133-
* Holds flow-related information
134-
*/
135-
std::map<MacCid, FlowControlInfo> connDesc_;
136-
137142
/* Incoming Connection Descriptors:
138143
* a connection is stored at the first MAC SDU delivered to the RLC
139144
*/
@@ -240,20 +245,16 @@ class LteMacBase : public cSimpleModule
240245
// Returns the virtual buffer for a specific CID
241246
LteMacBuffer* getMacBuffer(MacCid cid)
242247
{
243-
auto it = macBuffers_.find(cid);
244-
if (it == macBuffers_.end())
248+
auto it = connDescOut_.find(cid);
249+
if (it == connDescOut_.end())
245250
throw cRuntimeError("LteMacBase::getMacBuffer - Buffer for CID %s not found", cid.str().c_str());
246-
return it->second;
251+
return it->second.buffer;
247252
}
248253

249254
// Returns list of active buffer CIDs
250255
std::vector<MacCid> getActiveMacBufferCids()
251256
{
252-
std::vector<MacCid> activeCids;
253-
activeCids.reserve(macBuffers_.size());
254-
for (const auto& [cid,_] : macBuffers_)
255-
activeCids.push_back(cid);
256-
return activeCids;
257+
return getActiveConnectionCids();
257258
}
258259

259260
// Returns Traffic Class to cid mapping
@@ -265,18 +266,18 @@ class LteMacBase : public cSimpleModule
265266
// Returns flow control info for a specific CID
266267
const FlowControlInfo& getConnDesc(MacCid cid)
267268
{
268-
auto it = connDesc_.find(cid);
269-
if (it == connDesc_.end())
269+
auto it = connDescOut_.find(cid);
270+
if (it == connDescOut_.end())
270271
throw cRuntimeError("LteMacBase: Connection %s not found", cid.str().c_str());
271-
return it->second;
272+
return it->second.flowInfo;
272273
}
273274

274275
// Returns list of active connection CIDs
275276
std::vector<MacCid> getActiveConnectionCids()
276277
{
277278
std::vector<MacCid> activeCids;
278-
activeCids.reserve(connDesc_.size());
279-
for (const auto& [cid,_] : connDesc_)
279+
activeCids.reserve(connDescOut_.size());
280+
for (const auto& [cid,_] : connDescOut_)
280281
activeCids.push_back(cid);
281282
return activeCids;
282283
}

src/simu5g/stack/mac/LteMacEnb.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void LteMacEnb::macSduRequest()
270270
" (queue size: %d, SDU request requires: %d)", queueSize_, macSduRequest->getSduSize());
271271
}
272272
auto tag = pkt->addTag<FlowControlInfo>();
273-
*tag = connDesc_[destCid];
273+
*tag = connDescOut_[destCid].flowInfo;
274274
sendUpperPackets(pkt);
275275
}
276276
}
@@ -499,7 +499,7 @@ void LteMacEnb::macPduMake(MacCid cid)
499499

500500
// Check whether the RLC has sent some data. If not, skip
501501
// (e.g. because the size of the MAC PDU would contain only MAC header - MAC SDU requested size = 0B)
502-
if (macQueues_[destCid]->getQueueLength() == 0)
502+
if (connDescOut_[destCid].queue->getQueueLength() == 0)
503503
break;
504504

505505
Codeword cw = it.first.second;
@@ -553,13 +553,13 @@ void LteMacEnb::macPduMake(MacCid cid)
553553
}
554554

555555
while (sduPerCid > 0) {
556-
if ((macQueues_[destCid]->getQueueLength()) < (int)sduPerCid) {
556+
if ((connDescOut_[destCid].queue->getQueueLength()) < (int)sduPerCid) {
557557
throw cRuntimeError("Abnormal queue length detected while building MAC PDU for cid %s "
558558
"Queue real SDU length is %d while scheduled SDUs are %d",
559-
destCid.str().c_str(), macQueues_[destCid]->getQueueLength(), sduPerCid);
559+
destCid.str().c_str(), connDescOut_[destCid].queue->getQueueLength(), sduPerCid);
560560
}
561561

562-
auto pkt = check_and_cast<Packet *>(macQueues_[destCid]->popFront());
562+
auto pkt = check_and_cast<Packet *>(connDescOut_[destCid].queue->popFront());
563563
ASSERT(pkt != nullptr);
564564

565565
drop(pkt);
@@ -669,10 +669,11 @@ bool LteMacEnb::bufferizePacket(cPacket *cpkt)
669669
MacCid cid = ctrlInfoToMacCid(lteInfo);
670670

671671
// check if queues exist, create them if they don't
672-
if (macQueues_.find(cid) == macQueues_.end())
672+
if (connDescOut_.find(cid) == connDescOut_.end())
673673
createOutgoingConnection(cid, *lteInfo);
674-
LteMacQueue *queue = macQueues_.at(cid);
675-
LteMacBuffer *vqueue = macBuffers_.at(cid);
674+
OutgoingConnectionInfo& connInfo = connDescOut_.at(cid);
675+
LteMacQueue *queue = connInfo.queue;
676+
LteMacBuffer *vqueue = connInfo.buffer;
676677

677678
// this packet is used to signal the arrival of new data in the RLC buffers
678679
if (checkIfHeaderType<LteRlcPduNewData>(pkt)) {
@@ -957,8 +958,8 @@ int LteMacEnb::getActiveUesNumber(Direction dir)
957958
*/
958959
if (dir == DL) {
959960
// from macCid to NodeId
960-
for (auto& item : macQueues_) {
961-
if (item.second->getQueueLength() != 0)
961+
for (auto& item : connDescOut_) {
962+
if (item.second.queue->getQueueLength() != 0)
962963
activeUeSet.insert(item.first.getNodeId()); // active users in MAC
963964
}
964965

@@ -975,8 +976,8 @@ int LteMacEnb::getActiveUesNumber(Direction dir)
975976

976977
// every time an RLC SDU enters the layer, a newPktData is sent to
977978
// mac to inform the presence of data in RLC.
978-
for (const auto& vit : macBuffers_) {
979-
if (!vit.second->isEmpty())
979+
for (const auto& vit : connDescOut_) {
980+
if (!vit.second.buffer->isEmpty())
980981
activeUeSet.insert(vit.first.getNodeId()); // active users in RLC
981982
}
982983
}

src/simu5g/stack/mac/LteMacEnbD2D.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void LteMacEnbD2D::macHandleD2DModeSwitch(cPacket *pktAux)
417417

418418
if (!switchPkt->getTxSide()) { // address the receiving endpoint of the D2D flow (tx entities at the eNB)
419419
// get the outgoing connection corresponding to the DL connection for the RX endpoint of the D2D flow
420-
for (auto& [cid, lteInfo] : connDesc_) {
420+
for (auto& [cid, connInfo] : connDescOut_) {
421421
if (cid.getNodeId() == nodeId) {
422422
EV << NOW << " LteMacEnbD2D::sendModeSwitchNotification - send signal for TX entity to upper layers in the eNB (cid=" << cid << ")" << endl;
423423

@@ -431,7 +431,7 @@ void LteMacEnbD2D::macHandleD2DModeSwitch(cPacket *pktAux)
431431
else
432432
switchPktTx->setOldConnection(false);
433433
pktTx->insertAtFront(switchPktTx);
434-
*(pktTx->addTag<FlowControlInfo>()) = lteInfo;
434+
*(pktTx->addTag<FlowControlInfo>()) = connInfo.flowInfo;
435435
sendUpperPackets(pktTx);
436436
break;
437437
}

0 commit comments

Comments
 (0)