Skip to content

Commit f39bcf3

Browse files
committed
Pdcp,schedulers,etc: more use of structured bindings (c++17)
1 parent 11bf3ff commit f39bcf3

11 files changed

Lines changed: 93 additions & 94 deletions

File tree

src/simu5g/apps/d2dMultihop/eventGenerator/EventGenerator.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ void EventGenerator::computeTargetNodeSet(std::set<MacNodeId>& targetSet, MacNod
117117
inet::Coord srcCoord = uePos[sourceId];
118118

119119
// compute the distance for each UE
120-
for (auto& mit : uePos) {
121-
if (mit.second.distance(srcCoord) < maxBroadcastRadius) {
122-
EV << " - " << mit.first << endl;
123-
targetSet.insert(mit.first);
120+
for (auto& [nodeId, pos] : uePos) {
121+
if (pos.distance(srcCoord) < maxBroadcastRadius) {
122+
EV << " - " << nodeId << endl;
123+
targetSet.insert(nodeId);
124124
}
125125
}
126126
}

src/simu5g/corenetwork/statsCollector/BaseStationStatsCollector.cc

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,33 @@ void BaseStationStatsCollector::handleMessage(cMessage *msg)
158158
void BaseStationStatsCollector::resetDiscardCounterPerUe()
159159
{
160160
EV << collectorType_ << "::resetDiscardCounterPerUe " << endl;
161-
for (auto const& ue : ueCollectors_) {
162-
packetFlowManager_->resetDiscardCounterPerUe(ue.first);
161+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
162+
packetFlowManager_->resetDiscardCounterPerUe(ueId);
163163
}
164164
}
165165

166166
void BaseStationStatsCollector::resetDelayCounterPerUe()
167167
{
168168
EV << collectorType_ << "::resetDelayCounterPerUe " << endl;
169-
for (auto const& ue : ueCollectors_) {
170-
packetFlowManager_->resetDelayCounterPerUe(ue.first);
171-
ue.second->resetDelayCounter();
169+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
170+
packetFlowManager_->resetDelayCounterPerUe(ueId);
171+
ueCollector->resetDelayCounter();
172172
}
173173
}
174174

175175
void BaseStationStatsCollector::resetThroughputCountersPerUe()
176176
{
177177
EV << collectorType_ << "::resetThroughputCountersPerUe " << endl;
178-
for (auto const& ue : ueCollectors_) {
179-
packetFlowManager_->resetThroughputCounterPerUe(ue.first);
178+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
179+
packetFlowManager_->resetThroughputCounterPerUe(ueId);
180180
}
181181
}
182182

183183
void BaseStationStatsCollector::resetBytesCountersPerUe()
184184
{
185185
EV << collectorType_ << "::resetBytesCountersPerUe " << endl;
186-
for (auto const& ue : ueCollectors_) {
187-
packetFlowManager_->resetDataVolume(ue.first);
186+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
187+
packetFlowManager_->resetDataVolume(ueId);
188188
}
189189
}
190190

@@ -273,8 +273,8 @@ void BaseStationStatsCollector::add_ul_nongbr_pdr_cell()
273273
DiscardedPkts pair = { 0, 0 };
274274
DiscardedPkts temp = { 0, 0 };
275275

276-
for (auto const& ue : ueCollectors_) {
277-
temp = ue.second->getULDiscardedPkt();
276+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
277+
temp = ueCollector->getULDiscardedPkt();
278278
pair.discarded += temp.discarded;
279279
pair.total += temp.total;
280280
}
@@ -294,37 +294,37 @@ void BaseStationStatsCollector::add_dl_nongbr_pdr_cell_perUser()
294294
{
295295
EV << collectorType_ << "::add_dl_nongbr_pdr_cell_perUser()" << endl;
296296
double discard;
297-
for (auto const& ue : ueCollectors_) {
298-
discard = packetFlowManager_->getDiscardedPktPerUe(ue.first);
299-
ue.second->add_dl_nongbr_pdr_ue((int)discard);
297+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
298+
discard = packetFlowManager_->getDiscardedPktPerUe(ueId);
299+
ueCollector->add_dl_nongbr_pdr_ue((int)discard);
300300
}
301301
}
302302

303303
void BaseStationStatsCollector::add_ul_nongbr_pdr_cell_perUser()
304304
{
305305
EV << collectorType_ << "::add_ul_nongbr_pdr_cell_perUser()" << endl;
306-
for (auto const& ue : ueCollectors_) {
307-
ue.second->add_ul_nongbr_pdr_ue();
306+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
307+
ueCollector->add_ul_nongbr_pdr_ue();
308308
}
309309
}
310310

311311
void BaseStationStatsCollector::add_ul_nongbr_delay_perUser()
312312
{
313313
EV << collectorType_ << "::add_ul_nongbr_delay_perUser()" << endl;
314-
for (auto const& ue : ueCollectors_) {
315-
ue.second->add_ul_nongbr_delay_ue();
314+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
315+
ueCollector->add_ul_nongbr_delay_ue();
316316
}
317317
}
318318

319319
void BaseStationStatsCollector::add_dl_nongbr_delay_perUser()
320320
{
321321
EV << collectorType_ << "::add_dl_nongbr_delay_perUser()" << endl;
322322
double delay;
323-
for (auto const& ue : ueCollectors_) {
324-
delay = packetFlowManager_->getDelayStatsPerUe(ue.first);
325-
EV << collectorType_ << "::add_dl_nongbr_delay_perUser - delay: " << delay << " for node id: " << ue.first << endl;
323+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
324+
delay = packetFlowManager_->getDelayStatsPerUe(ueId);
325+
EV << collectorType_ << "::add_dl_nongbr_delay_perUser - delay: " << delay << " for node id: " << ueId << endl;
326326
if (delay != 0) {
327-
ue.second->add_dl_nongbr_delay_ue((int)delay);
327+
ueCollector->add_dl_nongbr_delay_ue((int)delay);
328328
}
329329
}
330330
}
@@ -333,47 +333,47 @@ void BaseStationStatsCollector::add_ul_nongbr_data_volume_ue_perUser()
333333
{
334334
EV << collectorType_ << "::add_ul_nongbr_data_volume_ue_perUser" << endl;
335335
unsigned int bytes;
336-
for (auto const& ue : ueCollectors_) {
337-
bytes = packetFlowManager_->getDataVolume(ue.first, UL);
338-
EV << collectorType_ << "::add_ul_nongbr_data_volume_ue_perUser - received: " << bytes << "B in UL from node id: " << ue.first << endl;
339-
ue.second->add_ul_nongbr_data_volume_ue(bytes);
336+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
337+
bytes = packetFlowManager_->getDataVolume(ueId, UL);
338+
EV << collectorType_ << "::add_ul_nongbr_data_volume_ue_perUser - received: " << bytes << "B in UL from node id: " << ueId << endl;
339+
ueCollector->add_ul_nongbr_data_volume_ue(bytes);
340340
}
341341
}
342342

343343
void BaseStationStatsCollector::add_dl_nongbr_data_volume_ue_perUser()
344344
{
345345
EV << collectorType_ << "::add_dl_nongbr_data_volume_ue_perUser" << endl;
346346
unsigned int bytes;
347-
for (auto const& ue : ueCollectors_) {
348-
bytes = packetFlowManager_->getDataVolume(ue.first, DL);
349-
EV << collectorType_ << "::add_dl_nongbr_data_volume_ue_perUser - sent: " << bytes << "B in DL to node id: " << ue.first << endl;
350-
ue.second->add_dl_nongbr_data_volume_ue(bytes);
347+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
348+
bytes = packetFlowManager_->getDataVolume(ueId, DL);
349+
EV << collectorType_ << "::add_dl_nongbr_data_volume_ue_perUser - sent: " << bytes << "B in DL to node id: " << ueId << endl;
350+
ueCollector->add_dl_nongbr_data_volume_ue(bytes);
351351
}
352352
}
353353

354354
void BaseStationStatsCollector::add_dl_nongbr_throughput_ue_perUser()
355355
{
356356
EV << collectorType_ << "::add_dl_nongbr_throughput_ue_perUser" << endl;
357357
double throughput;
358-
for (auto const& ue : ueCollectors_) {
359-
throughput = packetFlowManager_->getThroughputStatsPerUe(ue.first);
360-
EV << collectorType_ << "::add_dl_nongbr_throughput_ue_perUser - throughput: " << throughput << " for node " << ue.first << endl;
361-
packetFlowManager_->resetThroughputCounterPerUe(ue.first);
358+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
359+
throughput = packetFlowManager_->getThroughputStatsPerUe(ueId);
360+
EV << collectorType_ << "::add_dl_nongbr_throughput_ue_perUser - throughput: " << throughput << " for node " << ueId << endl;
361+
packetFlowManager_->resetThroughputCounterPerUe(ueId);
362362
if (throughput > 0.0)
363-
ue.second->add_dl_nongbr_throughput_ue((int)throughput);
363+
ueCollector->add_dl_nongbr_throughput_ue((int)throughput);
364364
}
365365
}
366366

367367
void BaseStationStatsCollector::add_ul_nongbr_throughput_ue_perUser()
368368
{
369369
EV << collectorType_ << "::add_ul_nongbr_throughput_ue_perUser" << endl;
370370
double throughput;
371-
for (auto const& ue : ueCollectors_) {
372-
throughput = rlc_->getUeThroughput(ue.first);
373-
EV << collectorType_ << "::add_ul_nongbr_throughput_ue_perUser - throughput: " << throughput << " for node " << ue.first << endl;
374-
rlc_->resetThroughputStats(ue.first);
371+
for (auto const& [ueId, ueCollector] : ueCollectors_) {
372+
throughput = rlc_->getUeThroughput(ueId);
373+
EV << collectorType_ << "::add_ul_nongbr_throughput_ue_perUser - throughput: " << throughput << " for node " << ueId << endl;
374+
rlc_->resetThroughputStats(ueId);
375375
if (throughput > 0.0)
376-
ue.second->add_ul_nongbr_throughput_ue((int)throughput);
376+
ueCollector->add_ul_nongbr_throughput_ue((int)throughput);
377377
}
378378
}
379379

src/simu5g/stack/mac/amc/LteAmc.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ void LteAmc::printFbhb(Direction dir)
101101

102102
for (auto& [carrier, hist] : *history) { // for each antenna
103103
EV << simTime() << " # Carrier: " << carrier << "\n";
104-
for (auto& histItem : hist) {
105-
EV << simTime() << " # Remote: " << dasToA(histItem.first) << "\n";
106-
for (size_t i = 0; i < histItem.second.size(); i++) { // for each UE
104+
for (auto& [remote, remoteHist] : hist) {
105+
EV << simTime() << " # Remote: " << dasToA(remote) << "\n";
106+
for (size_t i = 0; i < remoteHist.size(); i++) { // for each UE
107107
EV << "Ue index: " << i << ", MacNodeId: " << (*revIndex)[i] << endl;
108-
auto& txVec = histItem.second[i];
108+
auto& txVec = remoteHist[i];
109109
for (size_t t = 0; t < txVec.size(); t++) { // for each tx mode
110110
TxMode txMode = TxMode(t);
111111

@@ -1137,28 +1137,28 @@ void LteAmc::detachUser(MacNodeId nodeId, Direction dir)
11371137

11381138
// clear feedback data from history
11391139
if (dir == UL || dir == DL) {
1140-
for (auto& hit : *history) {
1140+
for (auto& [carrierFreq, hist] : *history) {
11411141
for (auto remote : remoteSet_) {
1142-
hit.second.at(remote).at(nodeIndex).clear();
1142+
hist.at(remote).at(nodeIndex).clear();
11431143
}
11441144
}
11451145
}
11461146
else { // D2D
1147-
for (auto& hit : *d2dHistory) {
1148-
for (auto& ht : hit.second) {
1149-
if (ht.first == NODEID_NONE) // skip fake UE 0
1147+
for (auto& [carrierFreq, carrierHist] : *d2dHistory) {
1148+
for (auto& [peerId, peerHist] : carrierHist) {
1149+
if (peerId == NODEID_NONE) // skip fake UE 0
11501150
continue;
11511151

11521152
for (auto remote : remoteSet_) {
1153-
ht.second.at(remote).at(nodeIndex).clear();
1153+
peerHist.at(remote).at(nodeIndex).clear();
11541154
}
11551155
}
11561156
}
11571157
}
11581158

11591159
// clear user transmission parameters for this UE
1160-
for (auto& item : *userInfoVec) {
1161-
item.second.at(nodeIndex).restoreDefaultValues();
1160+
for (auto& [carrierFreq, txParams] : *userInfoVec) {
1161+
txParams.at(nodeIndex).restoreDefaultValues();
11621162
}
11631163
}
11641164
catch (std::exception& e) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,14 @@ bool LteSchedulerEnbDl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandL
396396
// examination of HARQ process in rtx status, adding them to scheduling list
397397
for (auto it = harqQueues->begin(); it != harqQueues->end(); ) {
398398
// For each UE
399-
MacNodeId nodeId = it->first;
399+
auto& [nodeId, currHarq] = *it;
400400

401401
OmnetId id = binder_->getOmnetId(nodeId);
402402
if (id == 0) {
403403
// UE has left the simulation, erase HARQ queue
404404
it = harqQueues->erase(it);
405405
continue;
406406
}
407-
LteHarqBufferTx *currHarq = it->second;
408407
std::vector<LteHarqProcessTx *> *processes = currHarq->getHarqProcesses();
409408

410409
// Get user transmission parameters
@@ -492,8 +491,8 @@ bool LteSchedulerEnbDl::rtxscheduleBackground(GHz carrierFrequency, BandLimitVec
492491
}
493492

494493
// consume bytes
495-
for (auto & it : bgScheduledRtx)
496-
bgTrafficManager->consumeBackloggedUeBytes(it.first, it.second, direction_, true); // in bytes
494+
for (auto& [bgUeId, scheduledBytes] : bgScheduledRtx)
495+
bgTrafficManager->consumeBackloggedUeBytes(bgUeId, scheduledBytes, direction_, true); // in bytes
497496

498497
unsigned int availableBlocks = allocator_->computeTotalRbs();
499498
EV << " LteSchedulerEnbDl::rtxscheduleBackground OFDM Space: " << availableBlocks << endl;

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ bool LteSchedulerEnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandL
267267
if (freqIt != harqRxBuffers_->end()) {
268268
auto& rxBufferForCarrierFrequency = freqIt->second;
269269
for (auto it = rxBufferForCarrierFrequency.begin(); it != rxBufferForCarrierFrequency.end(); ) {
270-
// get current nodeId
271-
MacNodeId nodeId = it->first;
270+
// get current nodeId and buffer
271+
auto& [nodeId, harqBuffer] = *it;
272272

273273
if (nodeId == NODEID_NONE) {
274274
// UE has left the simulation - erase queue and continue
@@ -286,8 +286,8 @@ bool LteSchedulerEnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandL
286286

287287
// check whether the UE has a H-ARQ process waiting for retransmission. If not, skip UE.
288288
bool skip = true;
289-
unsigned char acid = (currentAcid + 2) % (it->second->getProcesses());
290-
LteHarqProcessRx *currentProcess = it->second->getProcess(acid);
289+
unsigned char acid = (currentAcid + 2) % (harqBuffer->getProcesses());
290+
LteHarqProcessRx *currentProcess = harqBuffer->getProcess(acid);
291291
std::vector<RxUnitStatus> procStatus = currentProcess->getProcessStatus();
292292
for (const auto& status : procStatus) {
293293
if (status.second == RXHARQ_PDU_CORRUPTED) {
@@ -328,8 +328,9 @@ bool LteSchedulerEnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandL
328328
HarqBuffersMirrorD2D *harqBuffersMirrorD2D = check_and_cast<LteMacEnbD2D *>(mac_.get())->getHarqBuffersMirrorD2D(carrierFrequency);
329329
if (harqBuffersMirrorD2D != nullptr) {
330330
for (auto it_d2d = harqBuffersMirrorD2D->begin(); it_d2d != harqBuffersMirrorD2D->end(); ) {
331-
MacNodeId senderId = (it_d2d->first).first; // Transmitter
332-
MacNodeId destId = (it_d2d->first).second; // Receiver
331+
auto& [d2dPair, harqBufferMirror] = *it_d2d;
332+
MacNodeId senderId = d2dPair.first; // Transmitter
333+
MacNodeId destId = d2dPair.second; // Receiver
333334

334335
if (senderId == NODEID_NONE || binder_->getOmnetId(senderId) == 0) {
335336
// UE has left the simulation - erase queue and continue
@@ -347,8 +348,8 @@ bool LteSchedulerEnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandL
347348

348349
// check whether the UE has a H-ARQ process waiting for retransmission. If not, skip UE.
349350
bool skip = true;
350-
unsigned char acid = (currentAcid + 2) % (it_d2d->second->getProcesses());
351-
LteHarqProcessMirrorD2D *currentProcess = it_d2d->second->getProcess(acid);
351+
unsigned char acid = (currentAcid + 2) % (harqBufferMirror->getProcesses());
352+
LteHarqProcessMirrorD2D *currentProcess = harqBufferMirror->getProcess(acid);
352353
std::vector<TxHarqPduStatus> procStatus = currentProcess->getProcessStatus();
353354
for (const auto& status : procStatus) {
354355
if (status == TXHARQ_PDU_BUFFERED) {
@@ -419,8 +420,8 @@ bool LteSchedulerEnbUl::rtxscheduleBackground(GHz carrierFrequency, BandLimitVec
419420
}
420421

421422
// consume bytes
422-
for (auto & it : bgScheduledRtx)
423-
bgTrafficManager->consumeBackloggedUeBytes(it.first, it.second, direction_, true); // in bytes
423+
for (auto& [bgUeId, scheduledBytes] : bgScheduledRtx)
424+
bgTrafficManager->consumeBackloggedUeBytes(bgUeId, scheduledBytes, direction_, true); // in bytes
424425

425426
int availableBlocks = allocator_->computeTotalRbs();
426427

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ bool NrSchedulerGnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandLi
115115
HarqBuffersMirrorD2D *harqBuffersMirrorD2D = check_and_cast<LteMacEnbD2D *>(mac_.get())->getHarqBuffersMirrorD2D(carrierFrequency);
116116
if (harqBuffersMirrorD2D != nullptr) {
117117
for (auto it_d2d = harqBuffersMirrorD2D->begin(); it_d2d != harqBuffersMirrorD2D->end(); ) {
118-
118+
auto& [d2dPair, currHarq] = *it_d2d;
119119
// get current nodeIDs
120-
MacNodeId senderId = (it_d2d->first).first; // Transmitter
121-
MacNodeId destId = (it_d2d->first).second; // Receiver
120+
MacNodeId senderId = d2dPair.first; // Transmitter
121+
MacNodeId destId = d2dPair.second; // Receiver
122122

123123
if (senderId == NODEID_NONE || binder_->getOmnetId(senderId) == 0) {
124124
// UE has left the simulation - erase queue and continue
@@ -131,8 +131,6 @@ bool NrSchedulerGnbUl::rtxschedule(GHz carrierFrequency, BandLimitVector *bandLi
131131
continue;
132132
}
133133

134-
LteHarqBufferMirrorD2D *currHarq = it_d2d->second;
135-
136134
// Get user transmission parameters
137135
const UserTxParams& txParams = mac_->getAmc()->computeTxParams(senderId, dir, carrierFrequency);// get the user info
138136

src/simu5g/stack/packetFlowManager/PacketFlowManagerUe.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ void PacketFlowManagerUe::insertMacPdu(inet::Ptr<const LteMacPdu> macPdu)
302302
// set the pdcp pdus related to this RLC as sent over the air since this method is called after the MAC ID
303303
// has been inserted in the HARQBuffer
304304
SequenceNumberSet pdcpSet = tit->second;
305-
for (auto pit : pdcpSet) {
306-
auto sdit = desc->pdcpStatus_.find(pit);
305+
for (auto pdcpSno : pdcpSet) {
306+
auto sdit = desc->pdcpStatus_.find(pdcpSno);
307307
if (sdit == desc->pdcpStatus_.end())
308-
throw cRuntimeError("%s::insertMacPdu - PdcpStatus for PDCP sno [%d] not present, this should not happen", pfmType.c_str(), pit);
308+
throw cRuntimeError("%s::insertMacPdu - PdcpStatus for PDCP sno [%d] not present, this should not happen", pfmType.c_str(), pdcpSno);
309309
sdit->second.sentOverTheAir = true;
310310
}
311311
}

src/simu5g/stack/pdcp/LtePdcp.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ void LtePdcpEnb::deleteEntities(MacNodeId nodeId)
358358

359359
// delete connections related to the given UE
360360
for (auto tit = txEntities_.begin(); tit != txEntities_.end(); ) {
361-
if (tit->first.getNodeId() == nodeId) {
362-
tit->second->deleteModule();
361+
auto& [cid, txEntity] = *tit;
362+
if (cid.getNodeId() == nodeId) {
363+
txEntity->deleteModule();
363364
tit = txEntities_.erase(tit);
364365
}
365366
else {
@@ -368,8 +369,9 @@ void LtePdcpEnb::deleteEntities(MacNodeId nodeId)
368369
}
369370

370371
for (auto rit = rxEntities_.begin(); rit != rxEntities_.end(); ) {
371-
if (rit->first.getNodeId() == nodeId) {
372-
rit->second->deleteModule();
372+
auto& [cid, rxEntity] = *rit;
373+
if (cid.getNodeId() == nodeId) {
374+
rxEntity->deleteModule();
373375
rit = rxEntities_.erase(rit);
374376
}
375377
else {

src/simu5g/stack/pdcp/NrPdcpEnb.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ void NrPdcpEnb::receiveDataFromSourceNode(Packet *pkt, MacNodeId sourceNode)
167167

168168
void NrPdcpEnb::activeUeUL(std::set<MacNodeId> *ueSet)
169169
{
170-
for (const auto& entity : rxEntities_) {
171-
MacNodeId nodeId = entity.first.getNodeId();
172-
if (!(entity.second->isEmpty()))
170+
for (const auto& [cid, rxEntity] : rxEntities_) {
171+
MacNodeId nodeId = cid.getNodeId();
172+
if (!(rxEntity->isEmpty()))
173173
ueSet->insert(nodeId);
174174
}
175175
}
176176

177177
} //namespace
178-

0 commit comments

Comments
 (0)