LteMacEnb.h Source File

Simu5G: LteMacEnb.h Source File
Simu5G
LteMacEnb.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef _LTE_LTEMACENB_H_
14#define _LTE_LTEMACENB_H_
15
16#include <inet/common/ModuleRefByPar.h>
17
18#include "simu5g/common/cellInfo/CellInfo.h"
19#include "simu5g/stack/mac/LteMacBase.h"
20#include "simu5g/stack/mac/amc/LteAmc.h"
21#include "simu5g/common/LteCommon.h"
22#include "simu5g/background/trafficGenerator/IBackgroundTrafficManager.h"
23#include "simu5g/stack/mac/DrbQosProfile.h"
24#include "simu5g/stack/mac/UlBacklogRegistry.h"
25
26namespace simu5g {
27
28using namespace omnetpp;
29
30class MacBsr;
31class LteAmc;
34class ConflictGraph;
36
37class LteMacEnb : public LteMacBase
38{
39 protected:
41 inet::ModuleRefByPar<CellInfo> cellInfo_;
42
44 LteAmc *amc_ = nullptr;
45
47 std::map<GHz, LteMacScheduleList> *scheduleListDl_ = nullptr;
48
49 // For NR-SO DL cids: number of RLC PDUs requested this TTI (>1 = multiplexed into
50 // one MAC PDU). The MAC PDU is built only once all of them have arrived from RLC.
51 std::map<MacCid, unsigned int> soExpectedSdus_;
52
53 int eNodeBCount;
54
56 std::map<GHz, IBackgroundTrafficManager *> bgTrafficManager_;
57
58 /*******************************************************************************************/
59
61 int numPreambles_ = 64;
62
65 std::map<int, std::vector<inet::Packet *>> pendingRacRequests_;
66
71 UlBacklogRegistry ulBacklog_;
72
74 LteSchedulerEnbDl *enbSchedulerDl_ = nullptr;
75
77 LteSchedulerEnbUl *enbSchedulerUl_ = nullptr;
78
80 std::map<GHz, std::map<Direction, int>> needRtx_;
81
83 std::map<DrbKey, DrbQosProfile> drbQosMap_;
84
88 void initialize(int stage) override;
89
94 void handleMessage(cMessage *msg) override;
95
100 virtual void sendGrants(std::map<GHz, LteMacScheduleList> *scheduleList);
101
104 typedef std::map<std::pair<MacNodeId, Direction>, std::map<Codeword, unsigned int>> PerUeGrantBlocks;
105
115 virtual PerUeGrantBlocks foldScheduleEntries(const LteMacScheduleList& entries) const;
116
119 struct GrantBlocks { unsigned int totalBlocks = 0; unsigned int codewords = 0; };
120
128 virtual GrantBlocks grantBlocksOf(MacNodeId nodeId, const std::map<Codeword, unsigned int>& cwBlocks) const;
129
134 virtual Direction grantDirection(LogicalCid lcid) const { return directionFromBsrLcid(lcid, UL); }
135
143 virtual inet::b grantChunkLength() const { return inet::B(1); }
144
151 void macPduMake(MacCid cid) override;
152
163 void macPduUnmake(cPacket *pkt) override;
164
170 virtual void macSduRequest();
171
181 virtual void bufferizeBsr(const MacBsr *bsr, const UserControlInfo *lteInfo);
182
190 bool bufferizePacket(cPacket *pkt) override;
191
196 void handleUpperMessage(cPacket *pkt) override;
197
201 void handleSelfMessage() override;
205 void macHandleFeedbackPkt(cPacket *pkt) override;
206
207 /*
208 * Buffers incoming RAC requests for preamble collision detection.
209 */
210 void macHandleRac(cPacket *pkt) override;
211
212 /*
213 * Resolves buffered RAC requests: detects preamble collisions and sends
214 * success/failure responses. Called at the start of each TTI.
215 */
216 virtual void resolveRacCollisions();
217
218 /*
219 * Update UserTxParam stored in every lteMacPdu when an RTX changes this information.
220 */
221 void updateUserTxParam(cPacket *pkt) override;
222
226 virtual void flushHarqBuffers();
227
228 public:
229
230 LteMacEnb();
231 ~LteMacEnb() override;
232
234 LteMacBuffer *getBsrVirtualBuffer(MacCid cid) { return ulBacklog_.mirror(cid); }
235
237 std::vector<MacCid> getActiveBsrVirtualBufferCids() { return ulBacklog_.keys(); }
238
240 std::vector<LteMacBuffer *> getUlBacklogMirrors(MacNodeId nodeId) const { return ulBacklog_.ulMirrorsOf(nodeId); }
241
243 virtual void clearBsrBuffers(MacNodeId ueId);
244
251 void deleteQueues(MacNodeId nodeId) override;
252
256 virtual LteAmc *getAmc()
257 {
258 return amc_;
259 }
260
264 virtual CellInfo *getCellInfo();
265
269 virtual IBackgroundTrafficManager *getBackgroundTrafficManager(GHz carrierFrequency)
270 {
271 if (bgTrafficManager_.find(carrierFrequency) == bgTrafficManager_.end())
272 throw cRuntimeError("LteMacEnb::getBackgroundTrafficManager - carrier frequency [%f] not valid.", carrierFrequency.get());
273 return bgTrafficManager_[carrierFrequency];
274 }
275
279 virtual int getNumAntennas();
280
285 SchedDiscipline getSchedDiscipline(Direction dir);
286
287 /*
288 * Return the current active set (active connections).
289 * @param direction
290 */
291 ActiveSet *getActiveSet(Direction dir);
292
293 /*
294 * Inform the base station that the given node will need a retransmission.
295 */
296 virtual void signalProcessForRtx(MacNodeId nodeId, GHz carrierFrequency, Direction dir, bool rtx = true);
297
298 /*
299 * Get the number of nodes requesting retransmissions for the given carrier and direction.
300 */
301 virtual int getProcessForRtx(GHz carrierFrequency, Direction dir);
302
304 virtual int getPendingRtxOtherThan(GHz carrierFrequency, Direction excluded);
305
306 // Get band occupation for this/previous TTI. Used for interference computation purposes.
307 unsigned int getDlBandStatus(Band b);
308 unsigned int getDlPrevBandStatus(Band b);
309
310 // Configuration push: RRC installs (or replaces) a bearer's QoS profile. MAC does
311 // not author its own configuration; this is the only write path into the map.
312 virtual void configureDrbQos(DrbKey key, const DrbQosProfile& qos);
313
314 // The DRB QoS map (DrbKey -> QoS profile), as RRC pushes it. The address stays
315 // valid for the module's lifetime, so a reader that takes it once (the scheduler,
316 // at its creation) sees the bearers configured later too.
317 const std::map<DrbKey, DrbQosProfile> *getDrbQosMap() { return &drbQosMap_; }
318
319 /*
320 * @author Alessandro Noferi
321 * Gets percentage of block utilized during the last TTI.
322 * @param dir UL or DL.
323 */
324 double getUtilization(Direction dir);
325
326 /* Gets the number of active users based on the direction.
327 * A user is active (according to TS 136 314) if:
328 * - it has buffered data in MAC RLC or PDCP layers -> ActiveSet.
329 * - it has data for which HARQ transmission has not yet terminated -> !EMPTY HarqBuffer.
330 *
331 * @param direction
332 */
333 int getActiveUesNumber(Direction dir);
334
335};
336
337} //namespace
338
339#endif
Define the manager of the conflict graph (CG) for resource allocation purposes.
Definition ConflictGraph.h:83
Lte AMC module for Omnet++ simulator.
Definition LteAmc.h:45
Definition LteHarqProcessRx.h:42
MAC Layer.
Definition LteMacBase.h:80
virtual void handleSelfMessage()=0
Definition LteSchedulerEnbDl.h:27
Definition LteSchedulerEnbUl.h:24
Definition AlertReceiver.h:24
unsigned short Band
Logical band.
Definition LteTypes.h:140
Direction directionFromBsrLcid(LogicalCid lcid, Direction fallback)
std::map< std::pair< MacCid, Codeword >, unsigned int > LteMacScheduleList
Definition LteCommon.h:344
Definition LteMacEnb.h:119